fix: 增加优惠券兑换时间

This commit is contained in:
zhangds 2022-11-01 17:23:59 +08:00
parent 2ea28a13e7
commit f842d644d2
3 changed files with 99 additions and 2 deletions

View File

@ -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 = () => { const onAuditSubmit = () => {
setState({ setState({
isLoadingBtn: true, isLoadingBtn: true,
@ -660,7 +678,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
}); });
console.log("编辑 大提交 =>", param); console.log("编辑 大提交 =>", param);
editCoupon(editData.id, param).then((res) => { editCoupon(editData.id, param).then((res) => {
handelResponse( handelResponse(
res, res,
@ -674,6 +691,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
}, 500); }, 500);
}, },
(err) => { (err) => {
setState({
isLoadingBtn: false,
});
Notify.error(err); Notify.error(err);
} }
); );
@ -720,12 +740,21 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
return item; return item;
}); });
} }
//
if (submitIsKm(param.product.legal) === false) {
setState({
isLoadingBtn: false,
});
return;
}
console.log("大提交 =>", param);
addCoupon(param).then((res) => { addCoupon(param).then((res) => {
handelResponse( handelResponse(
res, res,
(req, msg) => { (req, msg) => {
Notify.success(res.message); Notify.success(res.message);
setTimeout(() => { setTimeout(() => {
setState({ setState({
isLoadingBtn: false, isLoadingBtn: false,
@ -734,6 +763,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
}, 500); }, 500);
}, },
(err) => { (err) => {
setState({
isLoadingBtn: false,
});
Notify.error(err); Notify.error(err);
} }
); );
@ -758,6 +790,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
// select // select
const changePlan = async (e) => { const changePlan = async (e) => {
sessionStorage.setItem("datetime", JSON.stringify(e.key.dateTime));
setForm_info_data({ setForm_info_data({
plan_id: e, plan_id: e,
key_batch_id: "", key_batch_id: "",

View File

@ -12,10 +12,14 @@ import {
RadioGroup, RadioGroup,
Notify, Notify,
BlockLoading, BlockLoading,
DatePicker,
} from "zent"; } from "zent";
import { useSetState, useUpdateEffect } from "ahooks"; import { useSetState, useUpdateEffect } from "ahooks";
import _ from "lodash"; import _ from "lodash";
import moment from "moment";
import { isSameDay } from "date-fns";
import Ipt from "@/components/input/main"; import Ipt from "@/components/input/main";
import Form from "@/components/form/main"; import Form from "@/components/form/main";
import FormItem from "@/components/form-item/main"; import FormItem from "@/components/form-item/main";
@ -29,6 +33,10 @@ import {
import Swiper from "swiper/dist/js/swiper.js"; import Swiper from "swiper/dist/js/swiper.js";
import "swiper/dist/css/swiper.min.css"; import "swiper/dist/css/swiper.min.css";
const initArray = (targetNum) => {
return Array.from({ length: targetNum }, (_, index) => index);
};
// //
const formRules = { const formRules = {
product: [{ type: "required", message: "请选择映射商品" }], product: [{ type: "required", message: "请选择映射商品" }],
@ -58,6 +66,7 @@ const formRules = {
reg: "^([0-9]{0,2}|100)$", reg: "^([0-9]{0,2}|100)$",
}, },
], ],
end_time: [{ type: "required", message: "请选择兑换结束时间" }],
}; };
const UseProductPop = forwardRef((props, ref) => { const UseProductPop = forwardRef((props, ref) => {
@ -95,6 +104,7 @@ const UseProductPop = forwardRef((props, ref) => {
product_id: "", product_id: "",
account_type: "", account_type: "",
map_product_name: "", map_product_name: "",
end_time: "",
}); });
useEffect(() => { useEffect(() => {
@ -209,6 +219,7 @@ const UseProductPop = forwardRef((props, ref) => {
map_product_name: productData.map_product_name, map_product_name: productData.map_product_name,
product_type: model.product_type, product_type: model.product_type,
code_batch_id: productData.code_batch_id, code_batch_id: productData.code_batch_id,
end_time: productData.end_time,
show_url: [ show_url: [
{ {
id: new Date().getTime(), id: new Date().getTime(),
@ -261,6 +272,7 @@ const UseProductPop = forwardRef((props, ref) => {
detail_url: [], detail_url: [],
account_type: "", account_type: "",
map_product_name: "", map_product_name: "",
end_time: "",
}); });
setTimeout(() => { setTimeout(() => {
setState({ isUpdatePic: !state.isUpdatePic }); setState({ isUpdatePic: !state.isUpdatePic });
@ -283,6 +295,7 @@ const UseProductPop = forwardRef((props, ref) => {
account_type: model.account_type, account_type: model.account_type,
map_product_name: model.product_name, map_product_name: model.product_name,
goods_id: model.goods_id, 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) => { const onUploadChangeGoods = (files, type) => {
// //
if (type) { if (type) {
@ -622,6 +666,25 @@ const UseProductPop = forwardRef((props, ref) => {
/> />
</FormItem> </FormItem>
{model.product_type === 2 ? (
<FormItem id="end_time" labelname="兑换有效期" prop="end_time">
<DatePicker
className="zent-datepicker-plan"
showTime
format="YYYY-MM-DD HH:mm:ss"
value={model.end_time}
width={520}
onChange={(val) => {
setModel({
end_time: val,
});
}}
disabledTime={onDisabledTime}
disabledDate={onDisabledRange}
/>
</FormItem>
) : null}
<FormItem id="show_url" prop="show_url" labelname="商品Logo"> <FormItem id="show_url" prop="show_url" labelname="商品Logo">
<ImageUpload <ImageUpload
className="zent-image-upload-demo" className="zent-image-upload-demo"

View File

@ -571,6 +571,7 @@ export default class acclist extends React.Component {
let coupon_validator = this.refs.addEditCouponEl.submit(); let coupon_validator = this.refs.addEditCouponEl.submit();
if (coupon_validator) { if (coupon_validator) {
let param = this.refs.addEditCouponEl.getModel(); let param = this.refs.addEditCouponEl.getModel();
console.log("param =>", param);
let tempdata = this.state.couponData; let tempdata = this.state.couponData;
// 优惠券编辑 // 优惠券编辑
if (this.state.rowIndex > -1) { if (this.state.rowIndex > -1) {