From 995c0deef0002ee4c8c987eaca5a5705699f7de8 Mon Sep 17 00:00:00 2001 From: zhangds Date: Mon, 1 Aug 2022 16:35:51 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=89=20=E5=A2=9E=E5=8A=A0=E5=A4=8D?= =?UTF-8?q?=E5=88=B6key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UseExchangeCodePop/index.jsx | 131 ++++++++- src/components/UsePlanCard/index.jsx | 54 +--- src/components/UseProductForm/index.jsx | 293 ++++++++++++++++++++ src/components/UseProductForm/style.less | 9 + src/components/UseProductPop/index.jsx | 70 +++++ src/components/UseProductPop/style.less | 0 src/pages/plan/copy/index.jsx | 54 +++- 7 files changed, 545 insertions(+), 66 deletions(-) create mode 100644 src/components/UseProductForm/index.jsx create mode 100644 src/components/UseProductForm/style.less create mode 100644 src/components/UseProductPop/index.jsx create mode 100644 src/components/UseProductPop/style.less 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) => {