From 70a8ae704ea678474f15c60a380136daea1072da Mon Sep 17 00:00:00 2001 From: wangsongsole Date: Tue, 1 Aug 2023 10:41:36 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=8A=20fix:=20=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UseCouponAddEdit/index.jsx | 1236 ++++++++++----------- src/components/UseGoodsScopePop/index.jsx | 10 +- 2 files changed, 597 insertions(+), 649 deletions(-) diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index ba58d64f..583da7d6 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -1,11 +1,6 @@ -import React, { - forwardRef, - useImperativeHandle, - useRef, - useEffect -} from 'react'; -import { useSetState } from 'ahooks'; -import { FixedSizeList } from 'react-window'; +import React, { forwardRef, useImperativeHandle, useRef, useEffect } from "react" +import { useSetState } from "ahooks" +import { FixedSizeList } from "react-window" import { Card, DateRangePicker, @@ -16,13 +11,13 @@ import { RadioGroup, Radio, Sweetalert -} from 'zent'; -import moment from 'moment'; -import map from 'lodash/map'; -import { isSameDay } from 'date-fns'; -import { isAmount } from '@/tools/validate'; -import { mulNum } from '@/tools/number'; -import { knockGoldFun, submitIsKm } from '@/tools/index'; +} from "zent" +import moment from "moment" +import map from "lodash/map" +import { isSameDay } from "date-fns" +import { isAmount } from "@/tools/validate" +import { mulNum } from "@/tools/number" +import { knockGoldFun, submitIsKm } from "@/tools/index" import { handelResponse, queryKeyBatch, @@ -30,162 +25,162 @@ import { editCoupon, queryPlans, getReseller -} from '@/assets/api.js'; -import Ipt from '@/components/input/main'; -import Form from '@/components/form/main'; -import FormItem from '@/components/form-item/main'; -import Grid from '@/components/gird/main.js'; -import UseGoodsScopePop from '../UseGoodsScopePop/index'; -import './style.less'; +} from "@/assets/api.js" +import Ipt from "@/components/input/main" +import Form from "@/components/form/main" +import FormItem from "@/components/form-item/main" +import Grid from "@/components/gird/main.js" +import UseGoodsScopePop from "../UseGoodsScopePop/index" +import "./style.less" const initArray = (targetNum) => { - return Array.from({ length: targetNum }, (_, index) => index); -}; + return Array.from({ length: targetNum }, (_, index) => index) +} const tableColumn = [ { - title: '商品编号', - name: 'product_id', - prop: 'product_id', - type: 'slot', - width: 'auto' + title: "商品编号", + name: "product_id", + prop: "product_id", + type: "slot", + width: "auto" }, { - title: '商品名称', - name: 'product_name', - prop: 'product_name', - type: 'normal', - width: 'auto' + title: "商品名称", + name: "product_name", + prop: "product_name", + type: "normal", + width: "auto" }, { - title: '官方价', - name: 'official_price', - prop: 'official_price', - type: 'normal', - width: 'auto' + title: "官方价", + name: "official_price", + prop: "official_price", + type: "normal", + width: "auto" }, { - title: '合同单价', - name: 'contract_price', - prop: 'contract_price', - type: 'normal', - width: 'auto' + title: "合同单价", + name: "contract_price", + prop: "contract_price", + type: "normal", + width: "auto" }, { - title: '库存数量', - name: 'stock', - prop: 'stock', - type: 'normal', - width: 'auto' + title: "库存数量", + name: "stock", + prop: "stock", + type: "normal", + width: "auto" }, { - title: '批次号', - name: 'channel_activity_id', - prop: 'channel_activity_id', - type: 'normal', - width: 'auto' + title: "批次号", + name: "channel_activity_id", + prop: "channel_activity_id", + type: "normal", + width: "auto" }, { - title: '总预算', - name: 'all_budget', - prop: 'all_budget', - type: 'normal', - width: 'auto' + title: "总预算", + name: "all_budget", + prop: "all_budget", + type: "normal", + width: "auto" }, { - title: '有效时间段', - width: '300px', - name: 'effectDate', - prop: 'effectDate', - type: 'normal' + title: "有效时间段", + width: "300px", + name: "effectDate", + prop: "effectDate", + type: "normal" }, { - title: '创建时间', - width: '350px', - name: 'create_time', - prop: 'create_time', - type: 'normal' + title: "创建时间", + width: "350px", + name: "create_time", + prop: "create_time", + type: "normal" }, { - title: '类型', - name: 'type', - prop: 'type', - type: 'slot', - width: 'auto' + title: "类型", + name: "type", + prop: "type", + type: "slot", + width: "auto" }, { - title: '上游平台', - name: 'upstream', - prop: 'upstream', - type: 'normal', - width: 'auto' + title: "上游平台", + name: "upstream", + prop: "upstream", + type: "normal", + width: "auto" }, { - title: '', - name: '', - prop: '', - type: '', - width: '' + title: "", + name: "", + prop: "", + type: "", + width: "" }, { - title: '操作', - name: 'opearo', - prop: 'opearo', - type: 'slot', - width: 'auto' + title: "操作", + name: "opearo", + prop: "opearo", + type: "slot", + width: "auto" } -]; +] const info_rules = { - plan_id: [{ type: 'required', message: '请选择归属计划' }], - key_batch_id: [{ type: 'required', message: '请选择归属key' }], - title: [{ type: 'required', message: '请输入批次名称' }], - date_time: [{ type: 'required', message: '请选择时间' }] -}; + plan_id: [{ type: "required", message: "请选择归属计划" }], + key_batch_id: [{ type: "required", message: "请选择归属key" }], + title: [{ type: "required", message: "请输入批次名称" }], + date_time: [{ type: "required", message: "请选择时间" }] +} const rule_rules = { full: [ - { type: 'required', message: '请输入面额' }, + { type: "required", message: "请输入面额" }, { - type: 'regExp', - message: '请输入两位小数', - reg: '^[0-9][0-9]*([.][0-9]{1,2})?$' + type: "regExp", + message: "请输入两位小数", + reg: "^[0-9][0-9]*([.][0-9]{1,2})?$" } ], reduce: [ - { type: 'required', message: '请输入减' }, + { type: "required", message: "请输入减" }, { - type: 'regExp', - message: '请输入两位小数', - reg: '^[0-9][0-9]*([.][0-9]{1,2})?$' + type: "regExp", + message: "请输入两位小数", + reg: "^[0-9][0-9]*([.][0-9]{1,2})?$" } ], quantity: [ - { type: 'required', message: '请输入发放总量' }, + { type: "required", message: "请输入发放总量" }, { - type: 'regExp', - message: '请输入正整数', - reg: '^[1-9][0-9]*$' + type: "regExp", + message: "请输入正整数", + reg: "^[1-9][0-9]*$" } ], restrict: [ - { type: 'required', message: '请输入绑定数' }, + { type: "required", message: "请输入绑定数" }, { - type: 'regExp', - message: '请输入正整数', - reg: '^[1-9][0-9]*$' + type: "regExp", + message: "请输入正整数", + reg: "^[1-9][0-9]*$" } ] -}; +} const UseCouponAddEdit = forwardRef((props, ref) => { // 注意 !!!!!!!!couponType 入口类型 0优惠券新增(显示) 1计划、key批次 (是否显示归属计划和归宿key两个字段)!!!! - const { couponType = 0, direct_reseller_id, editData } = props; + const { couponType = 0, direct_reseller_id, editData } = props const [state, setState] = useSetState({ - setup1_title: '基本信息', - setup2_title: '发放规则', - setup3_title: '商品范围', + setup1_title: "基本信息", + setup2_title: "发放规则", + setup3_title: "商品范围", tableData: [], tableHeight: 500, page: 1, @@ -198,133 +193,127 @@ const UseCouponAddEdit = forwardRef((props, ref) => { isQuantity: true, plan_OPTIONS: [], key_OPTIONS: [], - product_title: '', + product_title: "", showScopePop: false, - scopePopType: '', + scopePopType: "", productData: {}, direct_reseller_id: direct_reseller_id ? direct_reseller_id : 0, table_index: -1, examinePopShow: false, payType: 3, - payment_direction: ['对私账户', '对公账户', '预付款扣除'], - coupon_batch_id: '', + payment_direction: ["对私账户", "对公账户", "预付款扣除"], + coupon_batch_id: "", oldProduct: {}, // 旧数据,为编辑做准备 - id: '', + id: "", status: -1, statusDisabled: false, // 3未开始、1进行中、2暂停中,有数据的审核驳回 productType: 1, checkedProduct: [], - KeyPcType: sessionStorage.getItem('KeyPcType'), + KeyPcType: sessionStorage.getItem("KeyPcType"), isLoadingBtn: false - }); + }) // 基础信息 const [form_info_data, setForm_info_data] = useSetState({ - plan_id: '', - key_batch_id: '', - title: '', - date_time: '' - }); - const form_info_el = useRef(null); + plan_id: "", + key_batch_id: "", + title: "", + date_time: "" + }) + const form_info_el = useRef(null) // 发放规则 const [form_rule_data, setForm_rule_data] = useSetState({ - full: '', - reduce: '', - quantity: '', - budget: '', - restrict: '' - }); - const form_rule_el = useRef(null); + full: "", + reduce: "", + quantity: "", + budget: "", + restrict: "" + }) + const form_rule_el = useRef(null) - const goodsScopePopEl = useRef(null); + const goodsScopePopEl = useRef(null) // 编辑/新增/复制 useEffect(() => { - (async function init() { - let KeyPcType = sessionStorage.getItem('KeyPcType'); - console.log('KeyPcType UseCouponAddEdit 1编辑 2复制 3新增 =>', KeyPcType); - console.log('editData =>', editData); + ;(async function init() { + let KeyPcType = sessionStorage.getItem("KeyPcType") + console.log("KeyPcType UseCouponAddEdit 1编辑 2复制 3新增 =>", KeyPcType) + console.log("editData =>", editData) // 第一步:1.判断组件是否是 优惠券管理 couponType if (couponType === 0) { // 如果是编辑 - if (editData && editData !== '') { + if (editData && editData !== "") { await getPlanList().then((arr) => { - let plan_row = arr.find( - (item) => item.text === editData.plan_title - ); - if ( - plan_row && - plan_row !== undefined && - plan_row !== 'undefined' - ) { + let plan_row = arr.find((item) => item.text === editData.plan_title) + if (plan_row && plan_row !== undefined && plan_row !== "undefined") { setForm_info_data({ plan_id: plan_row - }); + }) sessionStorage.setItem( - 'knockGold_effectDate', + "knockGold_effectDate", JSON.stringify({ begin_time: plan_row.key.dateTime[0], end_time: plan_row.key.dateTime[1] }) - ); + ) // 1.4 设置分销商 - getResellerFun(plan_row.key.reseller_id); + getResellerFun(plan_row.key.reseller_id) // 1.5 设置归属计划key setForm_info_data({ key_batch_id: { key: editData.key_batch_id, text: editData.key_batch_name } - }); + }) // 1.6 设置其它数据 - editFun(); + editFun() // 1.7 复制 - if (state.KeyPcType === '2') { + if (state.KeyPcType === "2") { setForm_info_data({ title: `${editData.title}_${editData.copy_count + 1}` - }); + }) } // 1.8 编辑 - if (state.KeyPcType === '1') { + if (state.KeyPcType === "1") { setState({ oldProduct: editData.product - }); + }) } - statusDisabledFun(editData.status); + statusDisabledFun(editData.status) } - }); + }) } else { // 如果新增 1.1 获取归属计划下拉框数据 - await getPlanList(); + await getPlanList() } } else { - if (editData && editData !== '') { + if (editData && editData !== "") { setState({ id: editData.id, status: editData.status - }); - editFun(); - statusDisabledFun(editData.status); + }) + editFun() + statusDisabledFun(editData.status) } else { // 如果是新增,给计划时间 - let deDateTime = sessionStorage.getItem('knockGold_effectDate'); + let deDateTime = sessionStorage.getItem("knockGold_effectDate") if (deDateTime) { - let times = JSON.parse(deDateTime); + let times = JSON.parse(deDateTime) setForm_info_data({ date_time: [times.begin_time, times.end_time] - }); + }) } } } - })(); - }, []); + })() + }, []) // 编辑处理函数 const editFun = () => { @@ -333,7 +322,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { setForm_info_data({ title: editData.title, date_time: [editData.begin_time, editData.end_time] - }); + }) // 规则 setForm_rule_data({ @@ -342,90 +331,87 @@ const UseCouponAddEdit = forwardRef((props, ref) => { quantity: editData.quantity, budget: mulNum(Number(editData.reduce), Number(editData.quantity)), restrict: editData.restrict - }); + }) // 商品范围 // 商品的数组 let goods_arr = editData.product.legal.map((item) => { // 如果是复制 删除id !!!!!!!! - if (state.KeyPcType === '2') { - delete item.id; + if (state.KeyPcType === "2") { + delete item.id } return { ...item, type: 1, - upstream: '直连天下', - all_budget: mulNum( - Number(item.contract_price), - Number(item.quantity) - ), - effectDate: '-' - }; - }); + upstream: "直连天下", + all_budget: mulNum(Number(item.contract_price), Number(item.quantity)), + effectDate: "-" + } + }) // 立减金 let lj_arr = editData.product.reduce.map((item) => { // 如果是复制 删除id !!!!!!!! - if (state.KeyPcType === '2') { - delete item.id; - delete item.goods_id; + if (state.KeyPcType === "2") { + delete item.id + delete item.goods_id } - let table_obj = knockGoldFun(item); - return table_obj; - }); - let scope_data = goods_arr.concat(lj_arr); + let table_obj = knockGoldFun(item) + return table_obj + }) + let scope_data = goods_arr.concat(lj_arr) scope_data = map(scope_data, (o) => { if (o.type === 2) { if (o.only.is_delete) { - o.checked = false; + o.checked = false } else { - o.checked = true; + o.checked = true } } else { if (o.is_delete) { - o.checked = false; + o.checked = false } else { - o.checked = true; + o.checked = true } } - return o; - }); + return o + }) let arr = map(scope_data, (res) => { - let obj = {}; - obj.key = res.product_id; - obj.text = res.product_name; - return obj; - }); + let obj = {} + obj.key = res.product_id + obj.text = res.product_name + return obj + }) setState({ rankOptions: arr, rank: arr, tableData: scope_data - }); + }) } catch (err) { - console.log(err); + console.log(err) } - }; + } // 状态不可修改 const statusDisabledFun = (status) => { // 第一步判断是否是复制: - if (state.KeyPcType === '2') { - return; + if (state.KeyPcType === "2") { + return } else { if ([1, 2, 3].includes(status)) { setState({ statusDisabled: true - }); + }) } } - }; + } const getPlanList = () => { return new Promise((resolve, reject) => { try { - queryPlans({ bind_object: '2' }).then((res) => { + queryPlans({ bind_object: "2" }).then((res) => { handelResponse(res, (req, msg) => { let arr = req.map((item) => { return { @@ -435,117 +421,115 @@ const UseCouponAddEdit = forwardRef((props, ref) => { dateTime: [item.begin_time, item.end_time] }, text: item.title - }; - }); + } + }) setState({ plan_OPTIONS: arr - }); - resolve(arr); - }); - }); + }) + resolve(arr) + }) + }) } catch (err) { - reject(err); + reject(err) } - }); - }; + }) + } // 获取归属key const getKey = (plan_id) => { return new Promise((resolve, reject) => { try { - queryKeyBatch({ status: '4,5', plan_id: plan_id, bind_object: 2 }).then( - (res) => { - handelResponse(res, (req, msg) => { - let arr = req.map((item) => { - return { - key: item.id, - text: item.batch_name - }; - }); - setState({ - key_OPTIONS: arr - }); - resolve(arr); - }); - } - ); + queryKeyBatch({ status: "4,5", plan_id: plan_id, bind_object: 2 }).then((res) => { + handelResponse(res, (req, msg) => { + let arr = req.map((item) => { + return { + key: item.id, + text: item.batch_name + } + }) + setState({ + key_OPTIONS: arr + }) + resolve(arr) + }) + }) } catch (err) { - reject(err); + reject(err) } - }); - }; + }) + } // 设置发放总量是否可用 useEffect(() => { - setIsQuantity(); - }, [form_rule_data.reduce, form_rule_data.full]); + setIsQuantity() + }, [form_rule_data.reduce, form_rule_data.full]) // 计算发放总数 useEffect(() => { - setBudget(); - }, [form_rule_data.reduce, form_rule_data.quantity]); + setBudget() + }, [form_rule_data.reduce, form_rule_data.quantity]) - const table_el = useRef(null); + const table_el = useRef(null) useImperativeHandle(ref, () => ({ submit: submit, getModel: getModel, clearCouponForm - })); + })) // 表单提交 const submit = () => { - let validator = false; + let validator = false // 基础信息 - let el_setup1 = form_info_el.current.validator(); + let el_setup1 = form_info_el.current.validator() if (el_setup1) { - validator = true; + validator = true } else { - validator = false; - return validator; + validator = false + return validator } // 发放规则 - let el_setup2 = form_rule_el.current.validator(); + let el_setup2 = form_rule_el.current.validator() if (el_setup2) { - validator = true; + validator = true } else { - validator = false; - return validator; + validator = false + return validator } if (validator) { // 获取商品范围数据 // 第一步:获取勾选后的数据 if (state.rank.length > 0) { - let arr = state.tableData.filter((item) => item.checked); + let arr = state.tableData.filter((item) => item.checked) // 第二步:最终的校验 // 所选商品库存和总发行数校验 - let sum = 0; + let sum = 0 arr.map((item) => { - sum += parseInt(item.quantity); - }); + sum += parseInt(item.quantity) + }) if (sum < Number(form_rule_data.quantity)) { - Notify.error('所选商品库存总数小于发放量'); - return false; + Notify.error("所选商品库存总数小于发放量") + return false } // 第三步:判断提交类型 新建还是计划的新建 if (couponType === 1) { - return true; + return true } else { setState({ examinePopShow: true - }); + }) } } else { - Notify.error(`请选择商品范围`); - return false; + Notify.error(`请选择商品范围`) + return false } } - return validator; - }; + return validator + } // 获取数据 const getModel = () => { @@ -564,46 +548,46 @@ const UseCouponAddEdit = forwardRef((props, ref) => { legal: [], reduce: [] } - }; - let arr = state.tableData.filter((item) => item.checked); - param.product.legal = arr.filter((item) => item.type === 1); // 商品 - let param_lj = arr.filter((item) => item.type === 2); // 立减金 + } + let arr = state.tableData.filter((item) => item.checked) + param.product.legal = arr.filter((item) => item.type === 1) // 商品 + let param_lj = arr.filter((item) => item.type === 2) // 立减金 param.product.reduce = param_lj.map((item) => { return { ...item.only - }; - }); - return param; - }; + } + }) + return param + } // 清除优惠券表单数据 const clearCouponForm = () => { - setState({ id: '', status: '' }); + setState({ id: "", status: "" }) setForm_rule_data({ - full: '', - reduce: '', - quantity: '', - budget: '', - restrict: '' - }); + full: "", + reduce: "", + quantity: "", + budget: "", + restrict: "" + }) setForm_info_data({ - plan_id: '', - key_batch_id: '', - title: '' - }); + plan_id: "", + key_batch_id: "", + title: "" + }) setState({ rank: [], rankOptions: [], tableData: [] - }); - }; + }) + } const onAuditSubmit = () => { setState({ isLoadingBtn: true - }); + }) // 3新增 1编辑 - if (state.KeyPcType === '1') { + if (state.KeyPcType === "1") { let param = { payment_direction: state.payment_direction[state.payType - 1], title: form_info_data.title, @@ -612,36 +596,28 @@ const UseCouponAddEdit = forwardRef((props, ref) => { new_product: {}, update_product: {}, delete_product: [] - }; + } // 第一步: 商品-立减金过滤 - let goods_arr = state.tableData.filter( - (item) => item.checked && item.type === 1 - ); - let lj_arr = state.tableData.filter( - (item) => item.checked && item.type === 2 - ); + let goods_arr = state.tableData.filter((item) => item.checked && item.type === 1) + let lj_arr = state.tableData.filter((item) => item.checked && item.type === 2) // 第二步:计算商品新增和编辑过滤 - param.new_product.legal = goods_arr.filter( - (item) => item.checked && !item.goods_id - ); // 新增 + param.new_product.legal = goods_arr.filter((item) => item.checked && !item.goods_id) // 新增 - param.update_product.legal = goods_arr.filter( - (item) => item.checked && item.goods_id - ); // 编辑 + param.update_product.legal = goods_arr.filter((item) => item.checked && item.goods_id) // 编辑 // 第三步:计算立减金新增和编辑过滤 param.new_product.reduce = lj_arr .filter((item) => item.checked && !item.only.goods_id) .map((item) => { - return item.only; - }); // 新增 + return item.only + }) // 新增 param.update_product.reduce = lj_arr .filter((item) => item.checked && item.only.goods_id) .map((item) => { - return item.only; - }); // 编辑 + return item.only + }) // 编辑 // return; // 商品立减金-删除 @@ -649,31 +625,31 @@ const UseCouponAddEdit = forwardRef((props, ref) => { .filter((item) => !item.checked && (item.goods_id || item.only)) .map((item) => { if (item.only) { - return item.only.goods_id; + return item.only.goods_id } else { - return item.goods_id; + return item.goods_id } - }); + }) editCoupon(editData.id, param).then((res) => { handelResponse( res, (req, msg) => { - Notify.success(res.message); + Notify.success(res.message) setTimeout(() => { setState({ isLoadingBtn: false - }); - window.history.back(); - }, 500); + }) + window.history.back() + }, 500) }, (err) => { setState({ isLoadingBtn: false - }); - Notify.error(err); + }) + Notify.error(err) } - ); - }); + ) + }) } else { let param = { plan_id: form_info_data.plan_id.key.key, @@ -686,66 +662,66 @@ const UseCouponAddEdit = forwardRef((props, ref) => { quantity: form_rule_data.quantity, budget: form_rule_data.budget, restrict: form_rule_data.restrict, - payment_direction: '', + payment_direction: "", product: { legal: [], reduce: [] } - }; - param.payment_direction = state.payment_direction[state.payType - 1]; // 扣款方式 - let arr = state.tableData.filter((item) => item.checked); - param.product.legal = arr.filter((item) => item.type === 1); // 商品 + } + param.payment_direction = state.payment_direction[state.payType - 1] // 扣款方式 + let arr = state.tableData.filter((item) => item.checked) + param.product.legal = arr.filter((item) => item.type === 1) // 商品 - let param_lj = arr.filter((item) => item.type === 2); // 立减金 + let param_lj = arr.filter((item) => item.type === 2) // 立减金 param.product.reduce = param_lj.map((item) => { return { ...item.only - }; - }); + } + }) // 复制id - if (state.KeyPcType === '2') { - param.copy_code_batch_id = editData.id; + if (state.KeyPcType === "2") { + param.copy_code_batch_id = editData.id param.product.legal = param.product.legal.map((item) => { - delete item.code_batch_id; - delete item.goods_id; - return item; - }); + delete item.code_batch_id + delete item.goods_id + return item + }) param.product.reduce = param.product.reduce.map((item) => { - delete item.goods_id; - return item; - }); + delete item.goods_id + return item + }) } // 校验 卡密时间判断 if (submitIsKm(param.product.legal) === false) { setState({ isLoadingBtn: false - }); - return; + }) + return } addCoupon(param).then((res) => { handelResponse( res, (req, msg) => { - Notify.success(res.message); + Notify.success(res.message) setTimeout(() => { setState({ isLoadingBtn: false - }); - window.history.back(); - }, 500); + }) + window.history.back() + }, 500) }, (err) => { setState({ isLoadingBtn: false - }); - Notify.error(err); + }) + Notify.error(err) } - ); - }); + ) + }) } - }; + } // 获取分销商id const getResellerFun = (id) => { @@ -753,474 +729,450 @@ const UseCouponAddEdit = forwardRef((props, ref) => { handelResponse( res, (req, msg) => { - setState({ direct_reseller_id: req.direct_reseller_id }); + setState({ direct_reseller_id: req.direct_reseller_id }) }, (err) => { - Notify.error(err); + Notify.error(err) } - ); - }); - }; + ) + }) + } // 计划select改变 const changePlan = async (e) => { sessionStorage.setItem( - 'knockGold_effectDate', + "knockGold_effectDate", JSON.stringify({ begin_time: e.key.dateTime[0], end_time: e.key.dateTime[1] }) - ); + ) setForm_info_data({ plan_id: e, - key_batch_id: '', + key_batch_id: "", date_time: e.key.dateTime - }); - getResellerFun(e.key.reseller_id); - await getKey(e.key.key); - }; + }) + getResellerFun(e.key.reseller_id) + await getKey(e.key.key) + } const onReturn = () => { Sweetalert.confirm({ - type: 'warning', + type: "warning", closeBtn: true, - title: '确认操作', + title: "确认操作", content:

是否返回?

, onConfirm: () => { - window.history.back(); + window.history.back() }, onCancel() {}, - className: 'questModal', + className: "questModal", parentComponent: this - }); - }; + }) + } const onChangeCombinedDate = (e) => { - setForm_info_data({ date_time: e }); + setForm_info_data({ date_time: e }) // 传入时间 sessionStorage.setItem( - 'knockGold_effectDate', + "knockGold_effectDate", JSON.stringify({ begin_time: e[0], end_time: e[1] }) - ); - }; + ) + } const onDisabledTime = (date) => { - let step1 = JSON.parse(sessionStorage.getItem('knockGold_effectDate')); - const min = new Date(step1.begin_time); - const hour = min.getHours(); - const minute = min.getMinutes(); - const second = min.getSeconds(); - const isSame = isSameDay(date, min); + let step1 = JSON.parse(sessionStorage.getItem("knockGold_effectDate")) + const min = new Date(step1.begin_time) + 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) : [], + disabledMinutes: (hourValue) => (hourValue === hour ? initArray(minute) : []), disabledSeconds: (hourValue, minuteValue) => - hourValue === hour && minuteValue === minute - ? initArray(second) - : [] + hourValue === hour && minuteValue === minute ? initArray(second) : [] } - : {}; - }; + : {} + } const onDisabledRange = (date, type) => { - let step1 = JSON.parse(sessionStorage.getItem('knockGold_effectDate')); - let isdisabled = false; - let str = moment(date).format('YYYY-MM-DD HH:mm:ss'); - const isDay = moment(step1.end_time).format('HH:mm:ss'); - if (type == 'start') { - if (isDay < '23:59:59') { + let step1 = JSON.parse(sessionStorage.getItem("knockGold_effectDate")) + let isdisabled = false + let str = moment(date).format("YYYY-MM-DD HH:mm:ss") + const isDay = moment(step1.end_time).format("HH:mm:ss") + if (type == "start") { + if (isDay < "23:59:59") { isdisabled = moment(str).isBefore(step1.begin_time) || - moment(str).subtract(1, 'days').isAfter(step1.end_time); + moment(str).subtract(1, "days").isAfter(step1.end_time) } else { - isdisabled = - moment(str).isBefore(step1.begin_time) || - moment(str).isAfter(step1.end_time); + isdisabled = moment(str).isBefore(step1.begin_time) || moment(str).isAfter(step1.end_time) } } - if (type == 'end') { + if (type == "end") { isdisabled = - moment(str).add(1, 'days').isBefore(step1.begin_time) || - moment(str).isAfter(step1.end_time); + moment(str).add(1, "days").isBefore(step1.begin_time) || moment(str).isAfter(step1.end_time) } - return isdisabled; - }; - const onPageChange = () => {}; - const onCountChange = () => {}; + return isdisabled + } + const onPageChange = () => {} + const onCountChange = () => {} // 清除商品和立减金本地存储 const clearStorageData = () => { if (state.tableData.length <= 0) { - sessionStorage.setItem('productData', ''); - sessionStorage.setItem('knockGoldData', ''); + sessionStorage.setItem("productData", "") + sessionStorage.setItem("knockGoldData", "") } // 新建商品 - let product_data = state.tableData.filter((item) => item.type === 1); + let product_data = state.tableData.filter((item) => item.type === 1) if (product_data.length <= 0) { - sessionStorage.setItem('productData', ''); + sessionStorage.setItem("productData", "") } else { - sessionStorage.setItem('productData', JSON.stringify(product_data)); + sessionStorage.setItem("productData", JSON.stringify(product_data)) } // 立减金 - let knockGold_data = state.tableData.filter((item) => item.type === 2); + let knockGold_data = state.tableData.filter((item) => item.type === 2) if (knockGold_data.length <= 0) { - sessionStorage.setItem('knockGoldData', ''); + sessionStorage.setItem("knockGoldData", "") } else { - sessionStorage.setItem('knockGoldData', JSON.stringify(knockGold_data)); + sessionStorage.setItem("knockGoldData", JSON.stringify(knockGold_data)) } - }; + } // 获取已经选择的商品数据(禁用商品选择) const getCheckedProduct = () => { - let arr = state.tableData.map((item) => Number(item.product_id)); - return arr; - }; + let arr = state.tableData.map((item) => Number(item.product_id)) + return arr + } // 新建商品 const addProduct = (type) => { try { // 第一步:获取直连天下的商品数据需要分销商 id - const direct_reseller_ids = state.direct_reseller_id; + const direct_reseller_ids = state.direct_reseller_id if (!form_info_data.plan_id && couponType === 0) { - Notify.error(`请选择归属计划`); - return; + Notify.error(`请选择归属计划`) + return } if (direct_reseller_ids <= 0) { - Notify.error(`请添加映射分销商`); - return; + Notify.error(`请添加映射分销商`) + return } // 第二步:清除本地存储数据 - clearStorageData(); + clearStorageData() // 第三步: 区分是新建商品还是立减金 - if (type === 'addProduct') { + if (type === "addProduct") { setState({ - product_title: '新建商品', - scopePopType: 'addProduct', + product_title: "新建商品", + scopePopType: "addProduct", checkedProduct: getCheckedProduct(), // 已经选择的商品 productData: null, table_index: -1, productType: 1, showScopePop: true - }); + }) } else { // 设置立减金时间 sessionStorage.setItem( - 'knockGold_effectDate', + "knockGold_effectDate", JSON.stringify({ begin_time: form_info_data.date_time[0], end_time: form_info_data.date_time[1] }) - ); + ) setState({ - product_title: '新增立减金', - scopePopType: 'addKnockGold', + product_title: "新增立减金", + scopePopType: "addKnockGold", productData: null, showScopePop: true - }); + }) } } catch (err) { - console.log('err =>', err); + console.log("err =>", err) } - }; + } // 编辑 const productEditShow = (rowData, index) => { try { // 第一步:获取直连天下的商品数据需要分销商 id - const direct_reseller_ids = state.direct_reseller_id; + const direct_reseller_ids = state.direct_reseller_id if (direct_reseller_ids <= 0) { - Notify.error(`请添加映射分销商`); - return; + Notify.error(`请添加映射分销商`) + return } // 第二步:清除本地存储数据 - clearStorageData(); + clearStorageData() // 第三步:区分是新建商品还是立减金 /* 区分立减金 */ if (rowData.type === 1) { setState({ - product_title: '编辑商品', - scopePopType: 'addProduct', + product_title: "编辑商品", + scopePopType: "addProduct", table_index: index, checkedProduct: getCheckedProduct(), // 已经选择 productType: rowData.product_type - }); + }) // 如果是复制删除 code_batch_id 如果是计划中的创建中数据 - let plan_status = sessionStorage.getItem('plan_status'); - if (state.KeyPcType === '2' || plan_status === '0') { - delete rowData.code_batch_id; + let plan_status = sessionStorage.getItem("plan_status") + if (state.KeyPcType === "2" || plan_status === "0") { + delete rowData.code_batch_id } setState({ productData: rowData, showScopePop: true - }); + }) } else { - let obj = rowData.only; - if (state.KeyPcType === '2') { - delete obj.id; + let obj = rowData.only + if (state.KeyPcType === "2") { + delete obj.id } setState({ - product_title: '编辑立减金', + product_title: "编辑立减金", productData: obj, - scopePopType: 'addKnockGold', + scopePopType: "addKnockGold", showScopePop: true, table_index: index - }); + }) } } catch (err) { - console.log('err =>', err); + console.log("err =>", err) } - }; + } const renderOptionList = (options, renderOption) => { return ( - - {({ index, style }) => ( -
{renderOption(options[index], index)}
- )} + + {({ index, style }) =>
{renderOption(options[index], index)}
}
- ); - }; + ) + } // 判断是否可用 const setIsQuantity = () => { if (isAmount(form_rule_data.reduce) && isAmount(form_rule_data.full)) { - setState({ isQuantity: false }); + setState({ isQuantity: false }) } else { - setState({ isQuantity: true }); + setState({ isQuantity: true }) } - }; + } // 计算总预算 const setBudget = () => { if (isAmount(form_rule_data.reduce) && isAmount(form_rule_data.quantity)) { - let num = mulNum( - Number(form_rule_data.reduce), - Number(form_rule_data.quantity) - ); + let num = mulNum(Number(form_rule_data.reduce), Number(form_rule_data.quantity)) setForm_rule_data({ budget: num - }); + }) } else { setForm_rule_data({ - budget: '' - }); + budget: "" + }) } - }; + } // 优惠券弹窗 取消 const scopePopClose = () => { setState({ showScopePop: false - }); - }; + }) + } const selectionFun = (e) => { - let arr = []; + let arr = [] map(e, (res) => { - let obj = {}; - obj.key = res.product_id; - obj.text = res.product_name; - arr.push(obj); - return obj; - }); - setState({ rank: arr }); - }; + let obj = {} + obj.key = res.product_id + obj.text = res.product_name + arr.push(obj) + return obj + }) + setState({ rank: arr }) + } const onRankChange = (e) => { let new_table_data = state.tableData.map((item) => { item.checked = e.findIndex((checks) => { - return checks.key == item.product_id; - }) > -1; - return item; - }); - setState({ tableData: new_table_data, rank: e }); - }; + return checks.key == item.product_id + }) > -1 + return item + }) + setState({ tableData: new_table_data, rank: e }) + } // 优惠券弹窗 提交 const scopePopSubmit = (table_all) => { try { // 格式化表格数据 - let new_table = table_all; + let new_table = table_all // 设置商品范围选择 - let select_opt = []; + let select_opt = [] new_table.map((item) => { - let obj = {}; - obj.key = item.product_id; // 确保差异 - obj.text = item.product_name; - select_opt.push(obj); - }); - let select_arr = []; + let obj = {} + obj.key = item.product_id // 确保差异 + obj.text = item.product_name + select_opt.push(obj) + }) + let select_arr = [] new_table.map((item) => { - let obj = {}; + let obj = {} if (item.checked) { - obj.key = item.product_id; - obj.text = item.product_name; - select_arr.push(obj); + obj.key = item.product_id + obj.text = item.product_name + select_arr.push(obj) } - }); + }) // 格式化商品范围 setState({ tableData: new_table, rankOptions: select_opt, rank: select_arr - }); + }) } catch (err) { - console.log('err =>', err); + console.log("err =>", err) } - }; + } const timeFalse = () => { - if (state.KeyPcType === '2') { - return false; + if (state.KeyPcType === "2") { + return false } - if ( - editData.status === 1 || - editData.status === 2 || - editData.status === 3 - ) { - return true; + if (editData.status === 1 || editData.status === 2 || editData.status === 3) { + return true } - }; + } // 提交审核弹窗 const examinePop = () => { return ( -
-
-
+
+
+
{ setState({ examinePopShow: false - }); + }) }} /> -
提交审核
-
+
提交审核
+
{ - setState({ payType: e.target.value }); + setState({ payType: e.target.value }) }} value={state.payType} - className='audit-obj'> + className="audit-obj" + > 预付款扣除 对私账户 对公账户
-
+
- ); - }; + ) + } return ( -
- +
+
{couponType === 0 ? ( - + { - setForm_info_data({ key_batch_id: e }); + setForm_info_data({ key_batch_id: e }) }} /> ) : null} - + { - setForm_info_data({ title: e }); + setForm_info_data({ title: e }) }} onClearItem={() => { - setForm_info_data({ title: '' }); + setForm_info_data({ title: "" }) }} value={form_info_data.title} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={20} - height={'36px'} + height={"36px"} countShow={true} - width={'520px'} - alignment={'left'} + width={"520px"} + alignment={"left"} /> - + { - onChangeCombinedDate(e); + onChangeCombinedDate(e) }} disabledTime={onDisabledTime} disabledDate={onDisabledRange} @@ -1229,160 +1181,152 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
- +
- + { - setForm_rule_data({ full: e }); + setForm_rule_data({ full: e }) }} onClearItem={() => { - setForm_rule_data({ full: '' }); + setForm_rule_data({ full: "" }) }} value={form_rule_data.full} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={20} - height={'36px'} + height={"36px"} countShow={false} - width={'234px'} - alignment={'left'} - front='满' + width={"234px"} + alignment={"left"} + front="满" disabled={state.statusDisabled} /> - + { - setForm_rule_data({ reduce: e }); + setForm_rule_data({ reduce: e }) }} onClearItem={() => { - setForm_rule_data({ reduce: '' }); + setForm_rule_data({ reduce: "" }) }} value={form_rule_data.reduce} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={20} - height={'36px'} + height={"36px"} countShow={false} - width={'234px'} - alignment={'left'} - front='减' - unit='元' + width={"234px"} + alignment={"left"} + front="减" + unit="元" disabled={state.statusDisabled} /> - + { setForm_rule_data({ quantity: e - }); + }) }} onClearItem={() => { - setForm_rule_data({ quantity: '' }); + setForm_rule_data({ quantity: "" }) }} disabled={state.isQuantity || state.statusDisabled} value={form_rule_data.quantity} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={20} - height={'36px'} + height={"36px"} countShow={false} - width={'520px'} - alignment={'left'} - unit='个' + width={"520px"} + alignment={"left"} + unit="个" /> - + - + { setForm_rule_data({ restrict: e - }); + }) }} onClearItem={() => { - setForm_rule_data({ restrict: '' }); + setForm_rule_data({ restrict: "" }) }} value={form_rule_data.restrict} - placeholder={'请输入'} - labelWidth={'0px'} + placeholder={"请输入"} + labelWidth={"0px"} maxLength={20} - height={'36px'} + height={"36px"} countShow={false} - width={'520px'} - alignment={'left'} + width={"520px"} + alignment={"left"} disabled={state.statusDisabled} />
- - -
+ + +