diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index 5a66afd6..71474741 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -602,6 +602,24 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }); }; + // 判断卡密是否能提交 + const submitIsKm = (data) => { + let visible = true; + let deDateTime = JSON.parse(sessionStorage.getItem("datetime")); + let end_time = new Date(deDateTime[1]).getTime(); // 计划结束时间 + // 校验 卡密商品数据 结束时间 + let legal_km = data.filter((item) => item.product_type === 2); + for (let i = 0; i < legal_km.length; i++) { + let end_time_km = new Date(legal_km[i].end_time).getTime(); + if (end_time < end_time_km) { + Notify.error("卡密兑换有效期,不能超过计划时间"); + return false; + } + } + + return visible; + }; + const onAuditSubmit = () => { setState({ isLoadingBtn: true, @@ -660,7 +678,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }); console.log("编辑 大提交 =>", param); - editCoupon(editData.id, param).then((res) => { handelResponse( res, @@ -674,6 +691,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }, 500); }, (err) => { + setState({ + isLoadingBtn: false, + }); Notify.error(err); } ); @@ -720,12 +740,21 @@ const UseCouponAddEdit = forwardRef((props, ref) => { return item; }); } + + // 校验 卡密时间判断 + if (submitIsKm(param.product.legal) === false) { + setState({ + isLoadingBtn: false, + }); + return; + } + + console.log("大提交 =>", param); addCoupon(param).then((res) => { handelResponse( res, (req, msg) => { Notify.success(res.message); - setTimeout(() => { setState({ isLoadingBtn: false, @@ -734,6 +763,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }, 500); }, (err) => { + setState({ + isLoadingBtn: false, + }); Notify.error(err); } ); @@ -758,6 +790,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { // 计划select改变 const changePlan = async (e) => { + sessionStorage.setItem("datetime", JSON.stringify(e.key.dateTime)); setForm_info_data({ plan_id: e, key_batch_id: "", diff --git a/src/components/UseProductPop/index.jsx b/src/components/UseProductPop/index.jsx index ca82f248..1aefff00 100644 --- a/src/components/UseProductPop/index.jsx +++ b/src/components/UseProductPop/index.jsx @@ -12,10 +12,14 @@ import { RadioGroup, Notify, BlockLoading, + DatePicker, } from "zent"; import { useSetState, useUpdateEffect } from "ahooks"; import _ from "lodash"; +import moment from "moment"; +import { isSameDay } from "date-fns"; + import Ipt from "@/components/input/main"; import Form from "@/components/form/main"; import FormItem from "@/components/form-item/main"; @@ -29,6 +33,10 @@ import { import Swiper from "swiper/dist/js/swiper.js"; import "swiper/dist/css/swiper.min.css"; +const initArray = (targetNum) => { + return Array.from({ length: targetNum }, (_, index) => index); +}; + //校验规则 const formRules = { product: [{ type: "required", message: "请选择映射商品" }], @@ -58,6 +66,7 @@ const formRules = { reg: "^([0-9]{0,2}|100)$", }, ], + end_time: [{ type: "required", message: "请选择兑换结束时间" }], }; const UseProductPop = forwardRef((props, ref) => { @@ -95,6 +104,7 @@ const UseProductPop = forwardRef((props, ref) => { product_id: "", account_type: "", map_product_name: "", + end_time: "", }); useEffect(() => { @@ -209,6 +219,7 @@ const UseProductPop = forwardRef((props, ref) => { map_product_name: productData.map_product_name, product_type: model.product_type, code_batch_id: productData.code_batch_id, + end_time: productData.end_time, show_url: [ { id: new Date().getTime(), @@ -261,6 +272,7 @@ const UseProductPop = forwardRef((props, ref) => { detail_url: [], account_type: "", map_product_name: "", + end_time: "", }); setTimeout(() => { setState({ isUpdatePic: !state.isUpdatePic }); @@ -283,6 +295,7 @@ const UseProductPop = forwardRef((props, ref) => { account_type: model.account_type, map_product_name: model.product_name, goods_id: model.goods_id, + end_time: model.end_time, }; }; @@ -430,6 +443,37 @@ const UseProductPop = forwardRef((props, ref) => { } } }; + + const onDisabledTime = (date) => { + 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 deDateTime = sessionStorage.getItem("datetime"); + let disabled = false; + if (deDateTime) { + let step1 = JSON.parse(deDateTime); + let str = moment(date).format("YYYY-MM-DD HH:mm:ss"); + disabled = + moment(str).isBefore(step1[0]) || moment(str).isAfter(step1[1]); + } + return disabled; + }; + const onUploadChangeGoods = (files, type) => { // 新增 if (type) { @@ -622,6 +666,25 @@ const UseProductPop = forwardRef((props, ref) => { /> + {model.product_type === 2 ? ( + + { + setModel({ + end_time: val, + }); + }} + disabledTime={onDisabledTime} + disabledDate={onDisabledRange} + /> + + ) : null} + ", param); let tempdata = this.state.couponData; // 优惠券编辑 if (this.state.rowIndex > -1) {