diff --git a/src/components/UseExchangeCodePop/index.jsx b/src/components/UseExchangeCodePop/index.jsx index f1859dc4..85db15bc 100644 --- a/src/components/UseExchangeCodePop/index.jsx +++ b/src/components/UseExchangeCodePop/index.jsx @@ -1,4 +1,4 @@ -import React, { useReducer } from "react"; +import React, { useReducer, useRef, useEffect } from "react"; import { Card, Drawer, @@ -22,9 +22,19 @@ import FormItem from "@/components/form-item/main"; import Grid from "@/components/gird/main.js"; import Bus from "@/assets/eventBus.js"; import _ from "lodash"; +import { isSameDay } from "date-fns"; +import moment from "moment"; +import { + handelResponse, + getAccessVerification, + getProductInfoSelect, +} from "@/assets/api.js"; import "./style.less"; -import { useRef } from "react"; +import { useState } from "react"; +const initArray = (targetNum) => { + return Array.from({ length: targetNum }, (_, index) => index); +}; const Column2 = [ { @@ -130,6 +140,11 @@ function reducer(state, action) { ...state, describe: action.payload, }; + case "date_time": + return { + ...state, + date_time: action.payload, + }; default: return; } @@ -137,10 +152,13 @@ function reducer(state, action) { // 新建/编辑兑换弹窗 const UseExchangeCodePop = (props) => { - const { title } = props; + const { title, closeDraw, time, direct_reseller_id, showProductPop } = props; const code_info = useRef(null); const code_rule = useRef(null); const [state, dispatch] = useReducer(reducer, initData); + const [addIsType, setAddIsType] = useState(""); + const [newGoodsBtnLoading, setNewGoodsBtnLoading] = useState(false); + const [newGoldLoading, setNewGoldLoading] = useState(false); const rulesForm = { code_name: [{ type: "required", message: "请输入兑换码名称" }], issued: [ @@ -156,13 +174,99 @@ const UseExchangeCodePop = (props) => { date_time: [{ type: "required", message: "请选择生效时间段" }], rank: [{ type: "required", message: "请选择商品范围" }], }; - const codeSubmit = () => {}; - const closeDraw = () => {}; - const onChangeCombinedDate = () => {}; - const onDisabledTime = () => {}; - const onDisabledRange = () => {}; + useEffect(() => { + console.log("time =>", time); + dispatch({ type: "date_time", payload: time }); + }, []); + const codeSubmit = () => { + if (code_info.current.validator() && code_rule.current.validator()) { + console.log("校验通过..."); + } + }; + const closeDrawPop = () => { + closeDraw(); + }; + const onChangeCombinedDate = (e) => { + dispatch({ type: "date_time", payload: e }); + }; + const onDisabledTime = (date, type) => { + const min = new Date(); + const hour = min.getHours(); + const minute = min.getMinutes(); + const second = min.getSeconds(); + const isSame = isSameDay(date, min); + + return isSame + ? { + disabledHours: () => initArray(hour), + disabledMinutes: (hourValue) => + hourValue === hour ? initArray(minute) : [], + disabledSeconds: (hourValue, minuteValue) => + hourValue === hour && minuteValue === minute + ? initArray(second) + : [], + } + : {}; + }; + const onDisabledRange = (date, type) => { + let isdisabled = false; + let str = moment(date).format("YYYY-MM-DD HH:mm:ss"); + if (type == "start") { + isdisabled = + moment(str).isBefore(time[0]) || moment(str).isAfter(time[1]); + } + if (type == "end") { + isdisabled = + moment(str).add(1, "days").isBefore(time[0]) || + moment(str).isAfter(time[1]); + } + return isdisabled; + }; const onRankChange = () => {}; - const addProduct = () => {}; + + // 新建商品/新建立减金 + const addProduct = (type) => { + setAddIsType(type); + /* type: 立减金/商品 */ + let direct_reseller_ids = direct_reseller_id; + if (direct_reseller_ids <= 0) { + // 老数据不能进行新增商品操作 + Notify.error(`请添加映射分销商`); + return; + } + if (type === "addProduct") { + // showProductPop({ type: true, title: "新建商品" }); + setNewGoodsBtnLoading(true); + } else { + // showProductPop({ type: true, title: "新增立减金" }); + setNewGoldLoading(true); + } + let param = { + reseller_id: direct_reseller_ids, + }; + getProductInfoSelect(param).then((res) => { + console.log("res =>", res); + if (type === "addProduct") { + setNewGoodsBtnLoading(false); + } else { + setNewGoldLoading(false); + } + if (res.code === 200) { + sessionStorage.setItem("productsList", JSON.stringify(res.data.data)); + if (type === "addProduct") { + showProductPop({ + type: true, + title: "新建商品", + productData: res.data.data, + }); + } else { + showProductPop({ type: true, title: "新增立减金" }); + } + } else { + sessionStorage.setItem("productsList", JSON.stringify([])); + } + }); + }; const productEditShow = () => {}; return (
@@ -182,7 +286,7 @@ const UseExchangeCodePop = (props) => {
} onClose={(e) => { - closeDraw(); + closeDrawPop(); }} maskClosable={false} > @@ -315,7 +419,7 @@ const UseExchangeCodePop = (props) => {