From b7dbe179f8cfcf8c5baf474dcd26df0501db9763 Mon Sep 17 00:00:00 2001 From: wangsongsole Date: Tue, 11 Oct 2022 10:35:02 +0800 Subject: [PATCH] =?UTF-8?q?style:=E9=85=8D=E5=90=88=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E8=B0=83=E8=AF=95=E5=85=91=E6=8D=A2=E7=A0=81?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=8E=A5=E5=8F=A3=20=E5=B9=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3=E5=92=8C=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91=20=E5=89=8D=E8=BA=AB=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BF=9D=E7=95=99=20=E5=BE=85=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exchangecode/exchangecodeAdd/index.jsx | 1243 ++++++++--------- .../exchangecode/exchangecodeAdd/utils.js | 2 +- 2 files changed, 622 insertions(+), 623 deletions(-) diff --git a/src/pages/exchangecode/exchangecodeAdd/index.jsx b/src/pages/exchangecode/exchangecodeAdd/index.jsx index d0b75d41..c6bec8d3 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,9 +15,9 @@ 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, @@ -30,42 +30,42 @@ import { putCodesBatch, keyEditApproval, queryPlans, - queryKeyBatch, -} from "@/assets/api.js"; -import _ from "lodash"; -import ProductForm from "../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 "../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 +76,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 +95,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,31 +115,31 @@ 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 + }) + }) + }) } /* 编辑处理数据 */ getDetailFunction(isState) { - let approval_id = sessionStorage.getItem("approval_id"); - let approval_status = sessionStorage.getItem("approval_status"); + let approval_id = sessionStorage.getItem("approval_id") + let approval_status = sessionStorage.getItem("approval_status") /* 判断是否是在审批中、状态是否时编辑 */ - if (Number(approval_id) > 0 && isState === 2) { + if (false) { //此处为审核中 getApprovalsInfo(approval_id) .then((res) => { handelResponse( res, (req, msg) => { - this.getResellerFunction(req.reseller_id); - req.update_product = [...this.transFormData1(req.update_product)]; - req.new_product = [...this.transFormData1(req.new_product, true)]; + this.getResellerFunction(req.reseller_id) + req.update_product = [...this.transFormData1(req.update_product)] + req.new_product = [...this.transFormData1(req.new_product, true)] let codeInfo = { code_name: req.title, @@ -147,122 +147,122 @@ export default class exchangeAdd extends React.Component { stock: req.stock, describe: req.describe, date_time: [req.begin_time, req.end_time], - range: req.update_product, - }; + range: req.update_product + } if (req.new_product.length > 0) { req.new_product = _.map(req.new_product, (item) => { - item.checked = false; - return item; - }); - codeInfo.range = codeInfo.range.concat(req.new_product); + item.checked = false + return item + }) + codeInfo.range = codeInfo.range.concat(req.new_product) } let new_ids = _.map(req.new_product, (o) => { - return o.only; - }); + return o.only + }) - this.setState({ new_product: new_ids }); - let delete_product = req.delete_product; - let payment_direction = req.payment_direction; + this.setState({ new_product: new_ids }) + let delete_product = req.delete_product + let payment_direction = req.payment_direction getCodesDetail(code_batch_id) .then((res) => { handelResponse( res, (req, msg) => { - codeInfo.stock = req.stock; + codeInfo.stock = req.stock this.setState({ - plan_time: [req.plan.start_time, req.plan.end_time], - }); - let reqCopy = _.cloneDeep(req); - const resData = this.transFormData(reqCopy); - this.setState({ oldTable: resData }); - let deleteArr = []; + plan_time: [req.plan.start_time, req.plan.end_time] + }) + let reqCopy = _.cloneDeep(req) + const resData = this.transFormData(reqCopy) + this.setState({ oldTable: resData }) + let deleteArr = [] for (let i = 0; i < delete_product.length; i++) { let deleteData = resData.find( (o) => o.only == delete_product[i] - ); - deleteData.checked = false; - deleteArr.push(deleteData); + ) + deleteData.checked = false + deleteArr.push(deleteData) } - this.setState({ codeInfo: codeInfo }); - this.setState({ isload: true }); - codeInfo.range = codeInfo.range.concat(deleteArr); + this.setState({ codeInfo: codeInfo }) + this.setState({ isload: true }) + codeInfo.range = codeInfo.range.concat(deleteArr) let table = _.map(codeInfo.range, (res) => { - let obj = resData.find((o) => o.only == res.only); + let obj = resData.find((o) => o.only == res.only) - res.usage = obj ? obj.usage : 0; - res.stock = obj ? obj.stock : res.quantity - res.usage; + res.usage = obj ? obj.usage : 0 + res.stock = obj ? obj.stock : res.quantity - res.usage res.checked = res.hasOwnProperty("checked") ? res.checked - : true; + : true if (approval_status == 7 && obj) { - res.checked = true; + res.checked = true } - return res; - }); + return res + }) - this.setState({ deleteProduct: [] }); + this.setState({ deleteProduct: [] }) - this.setState({ tempdata: codeInfo.range }); + this.setState({ tempdata: codeInfo.range }) - let arr = []; - let temp = []; + let arr = [] + let temp = [] _.map(codeInfo.range, (res) => { - let obj = {}; - obj.key = res.only; - obj.text = res.product_name; + let obj = {} + obj.key = res.only + obj.text = res.product_name if (new_ids.indexOf(res.only) < 0) { - this.state.oldProduct.push(res.id); + this.state.oldProduct.push(res.id) } if ( table.find((o) => o.only == res.only).checked == true ) { - temp.push(obj); + temp.push(obj) } - arr.push(obj); - return obj; - }); + arr.push(obj) + return obj + }) - this.setState({ rankoptions: arr }); - this.setState({ rank: temp }); + this.setState({ rankoptions: arr }) + this.setState({ rank: temp }) if (payment_direction) { let index = this.state.payment_direction.indexOf( payment_direction - ); - this.setState({ paytype: index + 1 }); + ) + this.setState({ payType: index + 1 }) } sessionStorage.setItem( "productData", JSON.stringify(codeInfo.range) - ); + ) sessionStorage.setItem( "knockGoldData", JSON.stringify(codeInfo.range) - ); + ) }, (err) => {} - ); + ) }) - .catch((err) => {}); + .catch((err) => {}) }, (err) => {} - ); + ) }) - .catch((err) => {}); + .catch((err) => {}) } else { getCodesDetail(code_batch_id) .then((res) => { handelResponse( res, - (req, msg) => { - let reqCopy = _.cloneDeep(req); - const resData = this.transFormData(reqCopy); - reqCopy.goods = resData; + (req) => { + let reqCopy = _.cloneDeep(req) + const resData = this.transFormData1(reqCopy.goods) + reqCopy.goods = resData let codeInfo = { code_name: reqCopy.title, issued: reqCopy.quantity, @@ -270,61 +270,81 @@ export default class exchangeAdd extends React.Component { restrict: reqCopy.restrict, describe: reqCopy.describe, date_time: [reqCopy.begin_time, reqCopy.end_time], - range: reqCopy.goods, - }; + range: [], + /* 回显计划、批次 */ + planSelect: { + key: req.plan.id, + text: req.plan.title + }, + keyBatchSelect: { + key: req.key_batch_id, + text: req.key_batch.batch_name + } + } - /* 复制状态改变code_name、回显计划、批次 */ + /* 处理新老数据 */ + if (resData.length > 0) { + let new_ids = [] /* 新数据唯一id */ + let old_ids = [] /* 老数据唯一id */ + codeInfo.range = resData.map((item) => { + if (item?.id) { + /* 老数据 */ + item.checked = true + old_ids.push(item.id) + } else { + /* 新数据 */ + item.checked = false + new_ids.push(item.only) + } + }) + 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.planSelect = { - key: req.plan.id, - text: req.plan.title, - }; - codeInfo.keyBatchSelect = { - key: req.key_batch_id, - text: req.key_batch.batch_name, - }; - this.setState({ - plan_time: [reqCopy.plan.start_time, reqCopy.plan.end_time], - }); //获取分销商 - this.getResellerFunction(reqCopy.plan.reseller_id); - this.setState({ codeInfo: codeInfo, isload: true }); + this.getResellerFunction(reqCopy.plan.reseller_id) + + /* 处理下拉框数据 */ + let arr = [] _.map(reqCopy.goods, (res) => { - res.checked = true; - return res; - }); + let obj = {} + obj.key = res.only + obj.text = res.product_name + obj.id = res.id + arr.push(obj) + return obj + }) - this.setState({ tempdata: reqCopy.goods || [] }); + /* 统一设置state */ + this.setState({ + codeInfo: codeInfo, + isload: true, + tempdata: reqCopy.goods || [], + plan_time: [reqCopy.plan.start_time, reqCopy.plan.end_time], + rank: arr, + rankoptions: arr + }) + /* 缓存到本地 */ sessionStorage.setItem( "productData", JSON.stringify(reqCopy.goods) - ); + ) sessionStorage.setItem( "knockGoldData", JSON.stringify(reqCopy.goods) - ); - - 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; - }); - this.setState({ rank: arr, rankoptions: arr }); + ) }, (err) => {} - ); + ) }) - .catch((err) => {}); + .catch((err) => {}) } } @@ -332,106 +352,108 @@ 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 }) } } /* 审核中转换数据 */ - transFormData1(req, type) { - const newData = []; + transFormData1(req) { + 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 } - 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; - if (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; - if (type) { - obj.quantity = parseInt(divNum(item1.all_budget, item1.reduce_amount)); - obj.stock = parseInt(divNum(item1.all_budget, item1.reduce_amount)); - obj.usage = 0; - } else { - obj.quantity = item1.stock; - obj.stock = parseInt( - divNum(item1.all_budget, item1.reduce_amount) - - divNum(item1.used_amount, item1.reduce_amount) - ); + let obj = {} + obj.type = 2 + obj.only = item1.channel_activity_id + obj.upstream = String(item1.channel) === "1" ? "支付宝" : "微信" //上游 + obj.origin = item1 - obj.usage = parseInt( - divNum(item1.all_budget, item1.reduce_amount) - - divNum(item1.all_budget - item1.used_amount, item1.reduce_amount) - ); + /* 复制状态删除id */ + if (this.state.isState === 1) { + delete item1.id } + + if (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.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 } /* 无审核转换数据 */ transFormData(reqCopy) { - const resData = []; + const resData = [] reqCopy.goods.map((item) => { /* type 1为商品 2为立减金 转译字符方便处理 */ /* 此处only 商品为product_id 立减金为channel_activity_id */ if (item.type === 1) { - item.entity.upstream = "直连天下"; - item.entity.only = item.entity.product_id; - item.entity.id = item.id; - item.entity.type = item.type; - item.entity.weight = item.weight; - resData.push(item.entity); + item.entity.upstream = "直连天下" + item.entity.only = item.entity.product_id + item.entity.id = item.id + item.entity.type = item.type + item.entity.weight = item.weight + resData.push(item.entity) } else if (item.type === 2) { /* 复制状态下删除id */ - if (this.state.isState === 1) delete item.entity.id; - item.entity.weight = item.weight; + if (this.state.isState === 1) delete item.entity.id + item.entity.weight = item.weight resData.push({ origin: item.entity, type: item.type, @@ -461,12 +483,12 @@ export default class exchangeAdd extends React.Component { effectDate: item.entity.time_limit.effect_time.start_time + " 至 " + - item.entity.time_limit.effect_time.end_time, //有效时间 - }); + item.entity.time_limit.effect_time.end_time //有效时间 + }) } - }); + }) - return resData; + return resData } /* select事件 */ @@ -474,11 +496,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() { @@ -489,108 +511,105 @@ 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) 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) } - }); - - console.log(this.state.reseller); + }) let data = { reseller_id: this.state.reseller.id, reseller_name: this.state.reseller.name, company_name: this.state.reseller.company_name, receive_email: this.state.reseller.receive_email, - payment_direction: this.state.payment_direction[this.state.paytype - 1], + payment_direction: this.state.payment_direction[this.state.payType - 1], title: this.state.codeInfo.code_name, range: range, describe: this.state.codeInfo.describe, @@ -599,20 +618,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], @@ -624,24 +643,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], @@ -649,80 +668,80 @@ export default class exchangeAdd extends React.Component { reseller_name: this.state.reseller.name, 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; + payment_direction: this.state.payment_direction[this.state.payType - 1], + 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) { //非审核中状态 @@ -731,24 +750,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) => { @@ -756,215 +775,216 @@ 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 (direct_reseller_ids <= 0) { - return Notify.error(`请添加映射分销商`); + return Notify.error(`请添加映射分销商`) } if (!this.state.isState && !this.state.codeInfo.keyBatchSelect.key) { - return Notify.error(`请选择归属key批次`); + return Notify.error(`请选择归属key批次`) } 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 = "直连天下"; - return item; - }); + item.type = 1 + item.only = item.product_id + item.upstream = "直连天下" + 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 //官方价 newObj.quantity = item.quantity ? item.quantity - : parseInt(divNum(item.all_budget, item.reduce_amount)); //总库 + : 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.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 ? { @@ -974,26 +994,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]) } } @@ -1001,131 +1021,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"} @@ -1158,15 +1174,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"} @@ -1176,16 +1191,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"} @@ -1195,24 +1210,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"} @@ -1221,15 +1236,14 @@ export default class exchangeAdd extends React.Component { )} + labelname='使用说明' + prop='describe' + id='describe' + required={false}> @@ -1246,86 +1260,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} /> - -
+ +