From 0fb9a31c330ba6ce9c27cb0617f2a71f385a8e95 Mon Sep 17 00:00:00 2001 From: wangsongsole Date: Mon, 24 Oct 2022 11:41:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E7=AB=8B?= =?UTF-8?q?=E5=87=8F=E9=87=91=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exchangecode/exchangecodeAdd/index.jsx | 1085 ++++++++--------- 1 file changed, 534 insertions(+), 551 deletions(-) diff --git a/src/pages/exchangecode/exchangecodeAdd/index.jsx b/src/pages/exchangecode/exchangecodeAdd/index.jsx index 8fb73da1..2556e75b 100644 --- a/src/pages/exchangecode/exchangecodeAdd/index.jsx +++ b/src/pages/exchangecode/exchangecodeAdd/index.jsx @@ -1,8 +1,8 @@ -import React from "react"; -import Ipt from "@/components/input/main"; -import Form from "@/components/form/main"; -import FormItem from "@/components/form-item/main"; -import { deWeightThree } from "@/utils"; +import React from "react" +import Ipt from "@/components/input/main" +import Form from "@/components/form/main" +import FormItem from "@/components/form-item/main" +import { deWeightThree } from "@/utils" import { Card, Radio, @@ -15,14 +15,13 @@ import { RadioGroup, Notify, Input, - BlockLoading, -} from "zent"; -import Bus from "@/assets/eventBus.js"; + BlockLoading +} from "zent" +import Bus from "@/assets/eventBus.js" import { getIsRequireApproval, getApprovalsStatus, getReseller, - getApprovalsInfo, terminateApprovals, getProductInfoSelect, handelResponse, @@ -30,42 +29,42 @@ import { putCodesBatch, keyEditApproval, queryPlans, - queryKeyBatch, -} from "@/assets/api.js"; -import _ from "lodash"; -import Productform from "@/pages/plan/product/add"; -import KnockGold from "@/components/knockGold"; /* 立减金 */ -import "./index.less"; -import moment from "moment"; -import Grid from "@/components/gird/main.js"; -import { isSameDay } from "date-fns"; -import { Column2, rulesInfo, codeInfo, init } from "./utils"; + queryKeyBatch +} from "@/assets/api.js" +import _ from "lodash" +import Productform from "@/pages/plan/product/add" +import KnockGold from "@/components/knockGold" /* 立减金 */ +import "./index.less" +import moment from "moment" +import Grid from "@/components/gird/main.js" +import { isSameDay } from "date-fns" +import { Column2, rulesInfo, codeInfo, init } from "./utils" -import { divNum } from "@/tools/number"; +import { divNum } from "@/tools/number" const initArray = (targetNum) => { - return Array.from({ length: targetNum }, (_, index) => index); -}; -let code_batch_id = ""; + return Array.from({ length: targetNum }, (_, index) => index) +} +let code_batch_id = "" export default class exchangeAdd extends React.Component { constructor(props) { - super(props); - this.state = { ...init() }; + super(props) + this.state = { ...init() } } componentDidMount() { - const isState = ~~sessionStorage.getItem("isState"); /*复制1 编辑2 */ - code_batch_id = ~~sessionStorage.getItem("code_id"); /* 兑换码id */ - this.setState({ isState }); + const isState = ~~sessionStorage.getItem("isState") /*复制1 编辑2 */ + code_batch_id = ~~sessionStorage.getItem("code_id") /* 兑换码id */ + this.setState({ isState }) /* 编辑和复制时才调用 */ if (isState) { - this.getDetailFunction(isState); + this.getDetailFunction(isState) } if (isState !== 2) { - sessionStorage.setItem("productData", []); - sessionStorage.setItem("knockGoldData", []); - this.getPlanSelect(); + sessionStorage.setItem("productData", []) + sessionStorage.setItem("knockGoldData", []) + this.getPlanSelect() } } @@ -76,15 +75,15 @@ export default class exchangeAdd extends React.Component { res, (req, msg) => { const select = req.map((o) => { - return { key: o.id, text: o.title, ...o }; - }); - this.setState({ planSelectData: select }); + return { key: o.id, text: o.title, ...o } + }) + this.setState({ planSelectData: select }) }, (err) => { - Notify.error(err); + Notify.error(err) } - ); - }); + ) + }) } /* 请求归属key下拉框数据 */ @@ -95,16 +94,16 @@ export default class exchangeAdd extends React.Component { res, (req, msg) => { const select = req.map((o) => { - return { key: o.id, text: o.batch_name, ...o }; - }); - this.setState({ keyBatchSelectData: select }); + return { key: o.id, text: o.batch_name, ...o } + }) + this.setState({ keyBatchSelectData: select }) }, (err) => { - Notify.error(err); + Notify.error(err) } - ); + ) } - ); + ) } /* 获取分销商 */ @@ -115,14 +114,14 @@ export default class exchangeAdd extends React.Component { id: req1.id, name: req1.name, company_name: req1.company_name, - receive_email: req1.contact_email[0], - }; + receive_email: req1.contact_email[0] + } this.setState({ direct_reseller_id: req1.direct_reseller_id, - reseller: reseller_obj, - }); - }); - }); + reseller: reseller_obj + }) + }) + }) } /* 请求详情 */ @@ -132,9 +131,9 @@ export default class exchangeAdd extends React.Component { handelResponse( res, (req) => { - let reqCopy = _.cloneDeep(req); - const resData = this.transFormData(reqCopy.goods); - reqCopy.goods = resData; + let reqCopy = _.cloneDeep(req) + const resData = this.transFormData(reqCopy.goods) + reqCopy.goods = resData let codeInfo = { code_name: reqCopy.title, issued: reqCopy.quantity, @@ -146,67 +145,67 @@ export default class exchangeAdd extends React.Component { /* 回显计划、批次 */ planSelect: { key: req.plan.id, - text: req.plan.title, + text: req.plan.title }, keyBatchSelect: { key: req.key_batch_id, - text: req.key_batch.batch_name, - }, - }; + text: req.key_batch.batch_name + } + } /* 处理新老数据 */ if (resData.length > 0) { - let new_ids = []; /* 新数据唯一id */ - let old_ids = []; /* 老数据唯一id */ + let new_ids = [] /* 新数据唯一id */ + let old_ids = [] /* 老数据唯一id */ codeInfo.range = resData.map((item) => { if (item?.id) { /* 老数据 */ - item.checked = true; - old_ids.push(item.id); + item.checked = true + old_ids.push(item.id) } else { /* 新数据 */ - item.checked = false; - new_ids.push(item.only); + item.checked = false + new_ids.push(item.only) } - }); - this.setState({ new_product: new_ids, oldProduct: old_ids }); + }) + this.setState({ new_product: new_ids, oldProduct: old_ids }) } /* 复制状态改变code_name */ if (this.state.isState === 1) { - codeInfo.code_name = `${reqCopy.title}_${reqCopy.copy_count + 1}`; + codeInfo.code_name = `${reqCopy.title}_${reqCopy.copy_count + 1}` } //获取分销商 - this.getResellerFunction(reqCopy.plan.reseller_id); + this.getResellerFunction(reqCopy.plan.reseller_id) /* 处理下拉框数据 */ - let arr = []; + let arr = [] _.map(reqCopy.goods, (res) => { - let obj = {}; - obj.key = res.only; - obj.text = res.product_name; - obj.id = res.id; - arr.push(obj); - return obj; - }); + let obj = {} + obj.key = res.only + obj.text = res.product_name + obj.id = res.id + arr.push(obj) + return obj + }) // is_delete 有值,不勾选 _.map(reqCopy.goods, (item) => { if (item.type === 2) { if (item.origin.is_delete) { - item.checked = false; + item.checked = false } else { - item.checked = true; + item.checked = true } } else { if (item.is_delete) { - item.checked = false; + item.checked = false } else { - item.checked = true; + item.checked = true } } - return item; - }); + return item + }) /* 统一设置state */ this.setState({ @@ -215,23 +214,20 @@ export default class exchangeAdd extends React.Component { tempdata: reqCopy.goods || [], plan_time: [reqCopy.plan.start_time, reqCopy.plan.end_time], rank: arr, - rankoptions: arr, - }); + rankoptions: arr + }) /* 缓存到本地 */ - sessionStorage.setItem( - "productData", - JSON.stringify(reqCopy.goods) - ); + sessionStorage.setItem("productData", JSON.stringify(reqCopy.goods)) sessionStorage.setItem( "knockGoldData", JSON.stringify(reqCopy.goods) - ); + ) }, (err) => {} - ); + ) }) - .catch((err) => {}); + .catch((err) => {}) } // } @@ -239,95 +235,102 @@ export default class exchangeAdd extends React.Component { getProductInfoSelectData(reseller_id) { return new Promise((resolve, reject) => { let param = { - reseller_id: reseller_id, - }; + reseller_id: reseller_id + } getProductInfoSelect(param).then((res) => { if (res.code === 200) { - resolve(res.data.data); + resolve(res.data.data) } else { - reject([]); + reject([]) } - }); - }); + }) + }) } // 立减金 加款后 商品范围列表数据进行变动 getTableList() { if (sessionStorage.getItem("addMoneyData")) { - const addMoneyData = JSON.parse(sessionStorage.getItem("addMoneyData")); + const addMoneyData = JSON.parse(sessionStorage.getItem("addMoneyData")) const tempdata = _.cloneDeep(this.state.tempdata).map((item) => { addMoneyData.map((item1) => { if (item.channel_activity_id === item1.channel_activity_id) { - item.origin.recharge_amount = item1.recharge_amount; + item.origin.recharge_amount = item1.recharge_amount } - }); - return item; - }); - this.setState({ tempdata }); + }) + return item + }) + this.setState({ tempdata }) } } /* 转换数据 */ transFormData(req) { - const newData = []; + const newData = [] req.legal.map((item1) => { - item1.type = 1; - item1.only = item1.product_id; - item1.upstream = "直连天下"; + item1.type = 1 + item1.only = item1.product_id + item1.upstream = "直连天下" if (item1?.goods_id) { - item1.id = item1.goods_id; + item1.id = item1.goods_id } /* 复制状态删除批次id */ if (this.state.isState === 1) { - delete item1.code_batch_id; + delete item1.code_batch_id } - newData.push(item1); - }); + newData.push(item1) + }) req.reduce.map((item1) => { - let obj = {}; - obj.type = 2; - obj.only = item1.channel_activity_id; - obj.upstream = String(item1.channel) === "1" ? "支付宝" : "微信"; //上游 - obj.origin = item1; + let obj = {} + obj.type = 2 + obj.only = item1.channel_activity_id + obj.upstream = String(item1.channel) === "1" ? "支付宝" : "微信" //上游 + obj.origin = item1 - /* 复制状态删除id */ + /* 复制状态 */ if (this.state.isState === 1) { - delete item1.id; + obj.quantity = parseInt(divNum(item1.all_budget, item1.reduce_amount)) //总库 + obj.stock = parseInt(divNum(item1.all_budget, item1.reduce_amount)) //剩余 + obj.usage = 0 //已使用 + delete item1.id + delete item1.total_stock + delete item1.use_stock + delete item1.stock + } + + /* 编辑 */ + if (this.state.isState === 2) { + obj.stock = item1.stock + obj.quantity = item1.total_stock + obj.usage = item1.use_stock + + item1.quantity = item1.total_stock + item1.usage = item1.use_stock + + delete item1.total_stock + delete item1.use_stock } if (item1?.goods_id) { - obj.id = item1?.goods_id; + obj.id = item1?.goods_id } - obj.product_id = item1?.goods_id; - obj.code_batch_id = item1?.code_batch_id; - obj.product_type_text = "立减金"; - obj.contract_price = item1.price; - obj.create_time = item1.create_time; - obj.official_price = item1.reduce_amount; - obj.channel_activity_id = item1.channel_activity_id; - obj.product_name = item1.batch_goods_name; - obj.stock = parseInt( - divNum(item1.all_budget, item1.reduce_amount) - - divNum(item1.used_amount, item1.reduce_amount) - ); - obj.quantity = parseInt( - divNum(item1.all_budget, item1.reduce_amount) - - divNum(item1.used_amount, item1.reduce_amount) - ); - obj.usage = parseInt( - divNum(item1.all_budget, item1.reduce_amount) - - divNum(item1.all_budget - item1.used_amount, item1.reduce_amount) - ); + obj.product_id = item1?.goods_id + obj.code_batch_id = item1?.code_batch_id + obj.product_type_text = "立减金" + obj.contract_price = item1.price + obj.create_time = item1.create_time + obj.official_price = item1.reduce_amount + obj.channel_activity_id = item1.channel_activity_id + obj.product_name = item1.batch_goods_name obj.effectDate = item1.time_limit.effect_time.start_time + " 至 " + - item1.time_limit.effect_time.end_time; - newData.push(obj); - }); //有效时间 - return newData; + item1.time_limit.effect_time.end_time + newData.push(obj) + }) //有效时间 + return newData } /* select事件 */ @@ -335,11 +338,11 @@ export default class exchangeAdd extends React.Component { _.forEach(this.state.tempdata, (item) => { item.checked = e.findIndex((checks) => { - return checks.key == item.only; - }) > -1; - }); - this.setState({ tempdata: this.state.tempdata }); - this.setState({ rank: e }); + return checks.key == item.only + }) > -1 + }) + this.setState({ tempdata: this.state.tempdata }) + this.setState({ rank: e }) } cancel() { @@ -350,100 +353,98 @@ export default class exchangeAdd extends React.Component { title: "确认操作", content:

是否取消本次操作?

, onConfirm: () => { - window.location.replace("#/home/exchangecode-list"); + window.location.replace("#/home/exchangecode-list") }, onCancel: this.onCancel, className: "questModal", - parentComponent: this, - }); + parentComponent: this + }) } /* 编辑状态 数据整合 */ buildData() { - let range = []; + let range = [] _.map(this.state.rank, (o) => { - range.push(o.text); - }); - let selectData = this.refs.tempdata.getSelectData(); + range.push(o.text) + }) + let selectData = this.refs.tempdata.getSelectData() let addProduct = selectData.filter((o) => { - return this.state.oldProduct.indexOf(o.id) < 0; - }); + return this.state.oldProduct.indexOf(o.id) < 0 + }) - let updateIds = []; - let updateProduct = []; + let updateIds = [] + let updateProduct = [] _.map(selectData, (o) => { if (this.state.oldProduct.indexOf(o.id) > -1) { - updateIds.push(o.id); - let _object = {}; + updateIds.push(o.id) + let _object = {} if (o.type === 1) { - _object.contract_price = o.contract_price; - _object.cost_price = o.cost_price; - _object.describe_url = o.describe_url; - _object.official_price = o.official_price; - _object.product_id = o.product_id; - _object.account_type = o.account_type; - _object.product_name = o.product_name; - _object.product_type = o.product_type; - _object.weight = o.weight; - _object.quantity = o.quantity; - _object.show_url = o.show_url; - _object.detail_url = o.detail_url; - _object.map_product_name = o.map_product_name; - _object.goods_id = o.goods_id; - _object.type = o.type; + _object.contract_price = o.contract_price + _object.cost_price = o.cost_price + _object.describe_url = o.describe_url + _object.official_price = o.official_price + _object.product_id = o.product_id + _object.account_type = o.account_type + _object.product_name = o.product_name + _object.product_type = o.product_type + _object.weight = o.weight + _object.quantity = o.quantity + _object.show_url = o.show_url + _object.detail_url = o.detail_url + _object.map_product_name = o.map_product_name + _object.goods_id = o.goods_id + _object.type = o.type } else { - _object = { ...o.origin, type: o.type }; + _object = { ...o.origin, type: o.type } } - updateProduct.push(_object); + updateProduct.push(_object) } - }); + }) let deleteProduct = _.differenceWith( this.state.oldProduct, updateIds, _.isEqual - ); - console.log(deleteProduct); + ) + console.log(deleteProduct) deleteProduct = deleteProduct.filter((item) => { - return this.state.new_product.indexOf(item) < 0; - }); + return this.state.new_product.indexOf(item) < 0 + }) if (this.state.deleteProduct.length > 0) { - deleteProduct = deleteProduct - .concat(this.state.deleteProduct) - .map(Number); + deleteProduct = deleteProduct.concat(this.state.deleteProduct).map(Number) } updateIds = _.map(updateProduct, (o) => { - return o.only; - }); + return o.only + }) deleteProduct = _.filter(deleteProduct, (o) => { - return updateIds.indexOf(o) < 0; - }); + return updateIds.indexOf(o) < 0 + }) /* 处理新增数据 */ - const addProductCopy = { legal: [], reduce: [] }; + const addProductCopy = { legal: [], reduce: [] } addProduct.map((item) => { if (item.type === 2) { if (item.origin) { - addProductCopy.reduce.push(item.origin); + addProductCopy.reduce.push(item.origin) } } else { - addProductCopy.legal.push(item); + addProductCopy.legal.push(item) } - }); + }) /* 处理原有数据数据 */ - const updateProductCopy = { legal: [], reduce: [] }; + const updateProductCopy = { legal: [], reduce: [] } updateProduct.map((item) => { if (item.type === 2) { - updateProductCopy.reduce.push(item); + updateProductCopy.reduce.push(item) } else { - updateProductCopy.legal.push(item); + updateProductCopy.legal.push(item) } - }); + }) let data = { reseller_id: this.state.reseller.id, @@ -459,20 +460,20 @@ export default class exchangeAdd extends React.Component { quantity: this.state.codeInfo.issued, new_product: addProductCopy, update_product: updateProductCopy, - delete_product: deleteProduct, - }; + delete_product: deleteProduct + } - return { data, addProduct, updateProduct }; + return { data, addProduct, updateProduct } } /* 复制\新增状态 数据整合 */ copyOrAddBuildData() { - let range = []; + let range = [] _.map(this.state.rank, (o) => { - range.push(o.text); - }); + range.push(o.text) + }) - let selection = this.refs.tempdata.getSelectData(); + let selection = this.refs.tempdata.getSelectData() const newData = { begin_time: this.state.codeInfo.date_time[0], end_time: this.state.codeInfo.date_time[1], @@ -484,24 +485,24 @@ export default class exchangeAdd extends React.Component { product: { legal: selection.filter((item2) => { if (item2.type == 1) { - delete item2.goods_id; - delete item2.id; - delete item2.only; - delete item2.type; - return item2; + delete item2.goods_id + delete item2.id + delete item2.only + delete item2.type + return item2 } }), reduce: selection .filter((item3) => item3.type === 2) .map((item4) => { - delete item4.origin.goods_id; - return item4.origin; - }), - }, - }; + delete item4.origin.goods_id + return item4.origin + }) + } + } if (this.state.isState === 1) { - newData.copy_code_batch_id = code_batch_id; + newData.copy_code_batch_id = code_batch_id } let data = { code_batch: [newData], @@ -510,79 +511,79 @@ export default class exchangeAdd extends React.Component { company_name: this.state.reseller.company_name, receive_email: this.state.reseller.receive_email, payment_direction: this.state.payment_direction[this.state.payType - 1], - addCode: true, - }; - return data; + addCode: true + } + return data } /* 编辑状态下数据提交 */ submitCodeData() { if (!this.state.reseller) { - Notify.error("该兑换码对应分销商不存在"); - return; + Notify.error("该兑换码对应分销商不存在") + return } - let { data } = this.buildData(); + let { data } = this.buildData() putCodesBatch(code_batch_id, data).then((res) => { handelResponse( res, (req, msg) => { - let model2 = this.state.model; - model2.show_url = req.path; - this.setState({ model: model2 }); + let model2 = this.state.model + model2.show_url = req.path + this.setState({ model: model2 }) - Notify.clear(); - Notify.success(msg); + Notify.clear() + Notify.success(msg) setTimeout(() => { - window.location.replace("#/home/exchangecode-list"); - }, 1000); + window.location.replace("#/home/exchangecode-list") + }, 1000) }, (error) => { - Notify.error(error); + Notify.error(error) } - ); - }); + ) + }) } /* 复制\新增状态下数据提交 */ submitCopyOrAddCodeData() { - let data = this.copyOrAddBuildData(); - let id = sessionStorage.getItem("keyBatch_id"); + let data = this.copyOrAddBuildData() + let id = sessionStorage.getItem("keyBatch_id") keyEditApproval(id, data).then((res) => { handelResponse( res, (req, msg) => { - Notify.success("成功发起审批"); + Notify.success("成功发起审批") setTimeout(() => { - window.history.back(); - }, 1000); + window.history.back() + }, 1000) }, (err) => { - Notify.error(err); + Notify.error(err) } - ); - }); + ) + }) } submit() { if (!(this.refs.code_info.validator() && this.refs.code_rule.validator())) { - return; + return } /* 编辑状态 */ if (this.state.isState === 2) { if (this.state.uploading) { - Notify.error("还有图片上传中,不可提交"); - return; + Notify.error("还有图片上传中,不可提交") + return } - let { data, addProduct, updateProduct } = this.buildData(); + let { data, addProduct, updateProduct } = this.buildData() if ([...updateProduct, ...addProduct].length < 1) { - return Notify.error("请绑定对象"); + return Notify.error("请绑定对象") } - let approval_id = sessionStorage.getItem("approval_id"); + let approval_id = sessionStorage.getItem("approval_id") if (Number(approval_id) <= 0) { //非审核中状态 @@ -591,24 +592,24 @@ export default class exchangeAdd extends React.Component { res, (req, msg) => { if (req.is_require_approval) { - this.setState({ audit_visible: true }); + this.setState({ audit_visible: true }) } else { - this.submitCodeData(); + this.submitCodeData() } }, (err) => { - Notify.error(err); + Notify.error(err) } - ); - }); + ) + }) } else { getApprovalsStatus(approval_id).then((res) => { handelResponse( res, (req, msg) => { if (req.status == 0) { - this.setState({ approvalsStatus: true }); - this.setState({ recall_visible: true }); + this.setState({ approvalsStatus: true }) + this.setState({ recall_visible: true }) } if (req.status == 1 || req.status == 2 || req.status == 3) { getIsRequireApproval(code_batch_id, data).then((res) => { @@ -616,231 +617,234 @@ export default class exchangeAdd extends React.Component { res, (req, msg) => { if (req.is_require_approval) { - this.setState({ audit_visible: true }); + this.setState({ audit_visible: true }) } else { - this.submitCodeData(); + this.submitCodeData() } }, (err) => { - Notify.error(err); + Notify.error(err) } - ); - }); + ) + }) } }, (err) => { - Notify.error(err); + Notify.error(err) } - ); - }); + ) + }) } } else { /* 复制和新增状态 */ - let selection = this.refs.tempdata.getSelectData(); + let selection = this.refs.tempdata.getSelectData() if (this.state.uploading) { - return Notify.error("还有图片上传中,不可提交"); + return Notify.error("还有图片上传中,不可提交") } if (selection.length < 1) { - return Notify.error("请绑定对象"); + return Notify.error("请绑定对象") } if (!this.state.reseller) { - return Notify.error("该兑换码对应分销商不存在"); + return Notify.error("该兑换码对应分销商不存在") } - this.setState({ audit_visible: true }); + this.setState({ audit_visible: true }) } } onConfirm() { - this.setState({ audit_visible: false }); + this.setState({ audit_visible: false }) if (this.state.isState !== 2) { - this.submitCopyOrAddCodeData(); /* 复制、新增 */ + this.submitCopyOrAddCodeData() /* 复制、新增 */ } else { - this.submitCodeData(); /* 编辑 */ + this.submitCodeData() /* 编辑 */ } } addProduct(type) { - this.setState({ addIsType: type }); /* 类型 */ - let direct_reseller_ids = this.state.direct_reseller_id; + this.setState({ addIsType: type }) /* 类型 */ + let direct_reseller_ids = this.state.direct_reseller_id if (!this.state.isState && !this.state.codeInfo.planSelect.key) { - return Notify.error(`请选择归属计划`); + return Notify.error(`请选择归属计划`) } if (direct_reseller_ids <= 0) { - return Notify.error(`请添加映射分销商`); + return Notify.error(`请添加映射分销商`) } if (type === "addProduct") { - this.setState({ product_title: "新建商品", newGoodsBtnLoading: true }); + this.setState({ product_title: "新建商品", newGoodsBtnLoading: true }) } else { - this.setState({ product_title: "新增立减金", newGoldLoading: true }); + this.setState({ product_title: "新增立减金", newGoldLoading: true }) } let param = { - reseller_id: direct_reseller_ids, - }; + reseller_id: direct_reseller_ids + } try { getProductInfoSelect(param).then((res) => { if (res.code === 200) { - sessionStorage.setItem("productsList", JSON.stringify(res.data.data)); - this.setState({ productData: null }); - this.setState({ drawerVisible2: true }); + sessionStorage.setItem("productsList", JSON.stringify(res.data.data)) + this.setState({ productData: null }) + this.setState({ drawerVisible2: true }) } if (type === "addProduct") { - this.setState({ newGoodsBtnLoading: false }); + this.setState({ newGoodsBtnLoading: false }) } else { - this.setState({ newGoldLoading: false }); + this.setState({ newGoldLoading: false }) } - }); + }) } catch (err) { if (type === "addProduct") { - this.setState({ newGoodsBtnLoading: false }); + this.setState({ newGoodsBtnLoading: false }) } else { - this.setState({ newGoldLoading: false }); + this.setState({ newGoldLoading: false }) } } } onChangeCombinedDate(e) { - let model2 = this.state.codeInfo; - model2.date_time = e; - this.setState({ codeInfo: model2 }); + let model2 = this.state.codeInfo + model2.date_time = e + this.setState({ codeInfo: model2 }) } //渲染范围列表数据以及数据转换 async productSubmit() { - let visible = ""; + let visible = "" if (this.state.addIsType === "addProduct") { - visible = await this.refs.product.submit(); + visible = await this.refs.product.submit() } else { - visible = await this.refs.knockGold.submit(); + visible = await this.refs.knockGold.submit() } if (visible) { - this.setState({ drawerVisible2: false }); + this.setState({ drawerVisible2: false }) setTimeout(() => { - let data = null; - let temp = null; - let concatData = []; + let data = null + let temp = null + let concatData = [] /* 处理商品 */ if (this.state.addIsType === "addProduct") { data = JSON.parse(sessionStorage.getItem("productData")).filter( (item) => item.type !== 2 - ); + ) - concatData = this.state.tempdata.filter((item) => item.type !== 1); + concatData = this.state.tempdata.filter((item) => item.type !== 1) temp = _.map(data, (item) => { let index = this.state.tempdata.findIndex((o) => { - return o.product_id == item.product_id; - }); + return o.product_id == item.product_id + }) if (index > -1) { - item.checked = this.state.tempdata[index].checked; + item.checked = this.state.tempdata[index].checked } - item.type = 1; - item.only = item.product_id; - item.upstream = "直连天下"; + item.type = 1 + item.only = item.product_id + item.upstream = "直连天下" /* 赋值 剩余数量 已使用数量*/ /* 新增\复制 */ if ([0, 1].includes(this.state.isState)) { - item.stock = item.quantity; - item.usage = 0; + item.stock = item.quantity + item.usage = 0 } /* 编辑 */ if (this.state.isState === 2) { - item.stock = parseInt(item.quantity - item.usage); - item.usage = item.usage; + item.stock = parseInt(item.quantity - item.usage) + item.usage = item.usage } - return item; - }); + return item + }) } else { /* 处理立减金 */ data = JSON.parse(sessionStorage.getItem("knockGoldData")).filter( (item) => item.type !== 1 - ); + ) - concatData = this.state.tempdata.filter((item) => item.type !== 2); + concatData = this.state.tempdata.filter((item) => item.type !== 2) temp = _.map(data, (item) => { let index = this.state.tempdata.findIndex((o) => { - return o.channel_activity_id === item.channel_activity_id; - }); + return o.channel_activity_id === item.channel_activity_id + }) if (index > -1) { - item.checked = this.state.tempdata[index].checked; + item.checked = this.state.tempdata[index].checked } - console.log(item); /* 转换商品结构 */ // temp - const newObj = {}; + const newObj = {} newObj.product_name = item.batch_goods_name ? item.batch_goods_name - : item.product_name; //名字 - newObj.channel_activity_id = item.channel_activity_id; //批次号 - newObj.only = item.channel_activity_id; //批次号 - newObj.type = 2; //类型 - newObj.checked = item?.checked; - newObj.upstream = String(item.channel) === "1" ? "支付宝" : "微信"; //上游 - newObj.edit = "edit"; + : item.product_name //名字 + newObj.channel_activity_id = item.channel_activity_id //批次号 + newObj.only = item.channel_activity_id //批次号 + newObj.type = 2 //类型 + newObj.checked = item?.checked + newObj.upstream = String(item.channel) === "1" ? "支付宝" : "微信" //上游 + newObj.edit = "edit" newObj.effectDate = item.effectDate ? item.effectDate : item.time_limit?.effect_time.start_time + " 至 " + - item.time_limit?.effect_time.end_time; //有效时间 + item.time_limit?.effect_time.end_time //有效时间 newObj.contract_price = item.contract_price ? item.contract_price - : item.price; //单价 + : item.price //单价 newObj.official_price = item.official_price ? item.official_price - : item.reduce_amount; //官方价 + : item.reduce_amount //官方价 + + console.log(item) + newObj.quantity = item.quantity ? item.quantity - : parseInt(divNum(item.all_budget, item.reduce_amount)); //总库 - newObj.stock = item.quantity - ? item.quantity - : parseInt(divNum(item.all_budget, item.reduce_amount)); //剩余 - newObj.usage = 0; //已使用 - newObj.origin = item.origin ? item.origin : item; - newObj.id = item.goods_id ? item.goods_id : item.id; - return newObj; - }); + : parseInt(divNum(item.all_budget, item.reduce_amount)) //总库 + newObj.stock = item.stock + ? item.stock + : parseInt(divNum(item.all_budget, item.reduce_amount)) //剩余 + newObj.usage = item.usage ? item.usage : 0 //已使用 + + newObj.origin = item.origin ? item.origin : item + newObj.id = item.goods_id ? item.goods_id : item.id + return newObj + }) } - let newArray = deWeightThree(temp.concat(concatData), "only"); + let newArray = deWeightThree(temp.concat(concatData), "only") //select数据 - let arr = []; - let rank = []; + let arr = [] + let rank = [] _.map(newArray, (res) => { - arr.push({ key: res.only, text: res.product_name }); + arr.push({ key: res.only, text: res.product_name }) if (res.checked) { - rank.push({ key: res.only, text: res.product_name }); + rank.push({ key: res.only, text: res.product_name }) } - }); + }) - arr = deWeightThree(arr, "key"); + arr = deWeightThree(arr, "key") - this.setState({ tempdata: newArray, rankoptions: arr, rank }); - this.getTableList(); - }, 500); + this.setState({ tempdata: newArray, rankoptions: arr, rank }) + this.getTableList() + }, 500) } } 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 ? { @@ -850,26 +854,26 @@ export default class exchangeAdd extends React.Component { disabledSeconds: (hourValue, minuteValue) => hourValue === hour && minuteValue === minute ? initArray(second) - : [], + : [] } - : {}; - }; + : {} + } onDisabledRange = (date, type) => { - let isdisabled = false; - let str = moment(date).format("YYYY-MM-DD HH:mm:ss"); - const isDay = moment(this.state.plan_time[1]).format("HH:mm:ss"); + let isdisabled = false + let str = moment(date).format("YYYY-MM-DD HH:mm:ss") + const isDay = moment(this.state.plan_time[1]).format("HH:mm:ss") /* 新增和复制时才生效 */ if (type === "start" && this.state.isState !== 2) { if (isDay < "23:59:59") { isdisabled = moment(str).isBefore(this.state.plan_time[0]) || - moment(str).subtract(1, "days").isAfter(this.state.plan_time[1]); + moment(str).subtract(1, "days").isAfter(this.state.plan_time[1]) } else { isdisabled = moment(str).isBefore(this.state.plan_time[0]) || - moment(str).isAfter(this.state.plan_time[1]); + moment(str).isAfter(this.state.plan_time[1]) } } @@ -877,131 +881,128 @@ export default class exchangeAdd extends React.Component { if (this.state.isState !== 2) { isdisabled = moment(str).add(1, "days").isBefore(this.state.plan_time[0]) || - moment(str).isAfter(this.state.plan_time[1]); + moment(str).isAfter(this.state.plan_time[1]) } else { - isdisabled = moment(str).isAfter(this.state.plan_time); + isdisabled = moment(str).isAfter(this.state.plan_time) } } - return isdisabled; - }; + return isdisabled + } onReCall() { - let approval_id = sessionStorage.getItem("approval_id"); - this.setState({ recall_visible: false }); + let approval_id = sessionStorage.getItem("approval_id") + this.setState({ recall_visible: false }) terminateApprovals(approval_id).then((res) => { handelResponse( res, (req, msg) => { - this.setState({ approvalLoading: true }); + this.setState({ approvalLoading: true }) let timer_c = setInterval(() => { if (this.state.timer <= 0) { - clearInterval(timer_c); - this.setState({ approvalLoading: false }); - Notify.success("撤销成功,请重新提交审核"); + clearInterval(timer_c) + this.setState({ approvalLoading: false }) + Notify.success("撤销成功,请重新提交审核") } - let time = this.state.timer - 1; - this.setState({ timer: time }); - }, 1000); + let time = this.state.timer - 1 + this.setState({ timer: time }) + }, 1000) }, (err) => { - Notify.error(err); + Notify.error(err) } - ); - }); + ) + }) } /* 商品范围列表编辑 */ productEditShow(rowData) { if (this.state.direct_reseller_id > 0) { this.setState({ - tableLoading: true, - }); + tableLoading: true + }) this.getProductInfoSelectData(this.state.direct_reseller_id).then( (data) => { - sessionStorage.setItem("productsList", JSON.stringify(data)); + sessionStorage.setItem("productsList", JSON.stringify(data)) /* 区分立减金 */ if (rowData.type === 2) { - let temp = rowData.origin; + let temp = rowData.origin this.setState({ product_title: "编辑立减金", productData: temp, - addIsType: "addKnockGold", - }); + addIsType: "addKnockGold" + }) } else { this.setState({ product_title: "编辑商品", productData: rowData, - addIsType: "addProduct", - }); + addIsType: "addProduct" + }) } setTimeout(() => { this.setState({ - tableLoading: false, - }); - this.setState({ drawerVisible2: true }); - }, 300); + tableLoading: false + }) + this.setState({ drawerVisible2: true }) + }, 300) } - ); + ) } else { // 老数据不能进行新增商品操作 - Notify.error(`请添加映射分销商`); - return; + Notify.error(`请添加映射分销商`) + return } } /* 处理change数据 */ handleChange(value, key) { - let model = this.state.codeInfo; - model[key] = value; - this.setState({ codeInfo: model }); + let model = this.state.codeInfo + model[key] = value + this.setState({ codeInfo: model }) } /* 新增处理处理归属计划关联数据 */ vestingPlanFunction(e) { - if (!e?.key) return; - this.getKeyBatchSelect(e.key); - this.getResellerFunction(e.reseller_id); - this.handleChange("", "keyBatchSelect"); + if (!e?.key) return + this.getKeyBatchSelect(e.key) + this.getResellerFunction(e.reseller_id) + this.handleChange("", "keyBatchSelect") this.setState({ - plan_time: [e.begin_time, e.end_time], - }); + plan_time: [e.begin_time, e.end_time] + }) const time = { begin_time: e.begin_time, - end_time: e.end_time, - }; - sessionStorage.setItem("knockGold_effectDate", JSON.stringify(time)); + end_time: e.end_time + } + sessionStorage.setItem("knockGold_effectDate", JSON.stringify(time)) } render() { return ( -
+
-
+ title={"基本信息"}> +
+ ref='code_info' + className='addform'> + labelname='归属计划' + prop='planSelect' + id='planSelect'> { - this.handleChange(e, "keyBatchSelect"); + this.handleChange(e, "keyBatchSelect") /* 新增时保存key批次 */ - sessionStorage.setItem("keyBatch_id", e?.id); + sessionStorage.setItem("keyBatch_id", e?.id) }} clearable value={this.state.codeInfo.keyBatchSelect} options={this.state.keyBatchSelectData} - placeholder="请选择" + placeholder='请选择' labelWidth={"0px"} height={"36px"} width={"520px"} @@ -1034,15 +1034,14 @@ export default class exchangeAdd extends React.Component { + labelname='兑换码名称' + prop='code_name' + id='code_name'> this.handleChange(e, "code_name")} onClearItem={() => this.handleChange("", "code_name")} value={this.state.codeInfo.code_name} - placeholder="请输入兑换码名称" + placeholder='请输入兑换码名称' labelWidth={"0px"} maxLength={12} height={"36px"} @@ -1052,16 +1051,16 @@ export default class exchangeAdd extends React.Component { {this.state.isState !== 2 ? ( - + this.handleChange(e, "restrict")} onClearItem={() => this.handleChange("", "restrict")} value={this.state.codeInfo.restrict} - placeholder="请输入绑定数量" + placeholder='请输入绑定数量' labelWidth={"0px"} maxLength={6} countShow={false} - unit="条" + unit='条' height={"36px"} width={"520px"} alignment={"left"} @@ -1071,24 +1070,24 @@ export default class exchangeAdd extends React.Component { {this.state.isState === 2 ? ( <> - -
{this.state.codeInfo.issued}
+ +
{this.state.codeInfo.issued}
- -
{this.state.codeInfo.stock}
+ +
{this.state.codeInfo.stock}
) : ( - + this.handleChange(e, "issued")} onClearItem={() => this.handleChange("", "issued")} value={this.state.codeInfo.issued} - placeholder="请输入发放总量" + placeholder='请输入发放总量' labelWidth={"0px"} maxLength={6} countShow={false} - unit="条" + unit='条' height={"36px"} width={"520px"} alignment={"left"} @@ -1097,15 +1096,14 @@ export default class exchangeAdd extends React.Component { )} + labelname='使用说明' + prop='describe' + id='describe' + required={false}> @@ -1122,86 +1120,80 @@ export default class exchangeAdd extends React.Component {
+ title={"基本规则"}>
+ ref='code_rule' + className='addform'> + labelname='生效时间段' + prop='date_time' + id='date_time'> { - Bus.emit("change", "date_time", e); - this.onChangeCombinedDate(e); + Bus.emit("change", "date_time", e) + this.onChangeCombinedDate(e) }} width={245} disabledTime={this.onDisabledTime} disabledDate={this.onDisabledRange} /> - -
+ +