diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index f6875744..a1a4e4f2 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -257,6 +257,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { try { queryPlans({ status: "3,4,5" }).then((res) => { handelResponse(res, (req, msg) => { + console.log("计划:", req); let arr = req.map((item) => { return { key: { key: item.id, reseller_id: item.reseller_id }, @@ -402,19 +403,22 @@ const UseCouponAddEdit = forwardRef((props, ref) => { setForm_info_data({ plan_id: e }); setState({ direct_reseller_id: e.key.reseller_id }); setForm_info_data({ key_batch_id: "" }); - queryKeyBatch({ status: "4,5", plan_id: e.key.key }).then((res) => { - handelResponse(res, (req, msg) => { - let arr = req.map((item) => { - return { - key: item.id, - text: item.batch_name, - }; + queryKeyBatch({ status: "4,5", plan_id: e.key.key, bind_object: 2 }).then( + (res) => { + handelResponse(res, (req, msg) => { + console.log("req =>", req); + let arr = req.map((item) => { + return { + key: item.id, + text: item.batch_name, + }; + }); + setState({ + key_OPTIONS: arr, + }); }); - setState({ - key_OPTIONS: arr, - }); - }); - }); + } + ); }; const onReturn = () => {}; diff --git a/src/pages/coupon/commodity/index.jsx b/src/pages/coupon/commodity/index.jsx index aad47e83..fb0f76cc 100644 --- a/src/pages/coupon/commodity/index.jsx +++ b/src/pages/coupon/commodity/index.jsx @@ -12,8 +12,8 @@ import "./style.less"; const tableColumn = [ { title: "商品编号", - name: "product_id", - prop: "product_id", + name: "id", + prop: "id", type: "normal", width: "auto", }, @@ -100,12 +100,12 @@ const UseCouponCommodity = () => { tabList: [{ title: "商品范围列表", index: 0 }], tableData: [], tableHeight: 500, - dataCount: 0, lodgingTable: true, combinedValue: [], key_word: "", page: 1, limit: 10, + total: 0, isQuery: false, }); const table_el = useRef(null); @@ -136,6 +136,7 @@ const UseCouponCommodity = () => { let param = getParam(); getCodeProductList(param).then((res) => { handelResponse(res, (req, msg) => { + setState({ tableData: req.data }); console.log("res =>", req); }); }); @@ -186,12 +187,13 @@ const UseCouponCommodity = () => { spliteColor={"#fff"} tableData={state.tableData} Column={tableColumn} - countbarVisible={false} maxheight={state.tableHeight} isSwitch={false} + isShowPageBar={false} + countbarVisible={false} page={state.page} ref={table_el} - dataCount={state.dataCount} + dataCount={state.total} pageChange={(e) => onPageChange(e)} emptyText={ state.lodgingTable diff --git a/src/pages/exchangecode/exchangecodeAdd/index.jsx b/src/pages/exchangecode/exchangecodeAdd/index.jsx index 614bfa98..964e509d 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,38 +30,38 @@ 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"; 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); } else { - sessionStorage.setItem("productData", []) - sessionStorage.setItem("knockGoldData", []) - this.getPlanSelect() + sessionStorage.setItem("productData", []); + sessionStorage.setItem("knockGoldData", []); + this.getPlanSelect(); } } @@ -72,33 +72,35 @@ 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下拉框数据 */ getKeyBatchSelect(key) { - queryKeyBatch({ status: "4,5", plan_id: key }).then((res) => { - handelResponse( - res, - (req, msg) => { - const select = req.map((o) => { - return { key: o.id, text: o.batch_name, ...o } - }) - this.setState({ keyBatchSelectData: select }) - }, - (err) => { - Notify.error(err) - } - ) - }) + queryKeyBatch({ status: "4,5", plan_id: key, bind_object: 1 }).then( + (res) => { + handelResponse( + res, + (req, msg) => { + const select = req.map((o) => { + return { key: o.id, text: o.batch_name, ...o }; + }); + this.setState({ keyBatchSelectData: select }); + }, + (err) => { + Notify.error(err); + } + ); + } + ); } /* 获取分销商 */ @@ -109,20 +111,20 @@ 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) { //此处为审核中 @@ -131,9 +133,9 @@ export default class exchangeAdd extends React.Component { 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, @@ -141,122 +143,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 + let reqCopy = _.cloneDeep(req); + const resData = this.transFormData(reqCopy); + reqCopy.goods = resData; let codeInfo = { code_name: reqCopy.title, issued: reqCopy.quantity, @@ -264,59 +266,59 @@ 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: reqCopy.goods, + }; /* 复制状态改变code_name */ if (this.state.isState === 1) { codeInfo.code_name = `${reqCopy.title}_${ reqCopy.copy_count + 1 - }` + }`; } this.setState({ - plan_time: [reqCopy.plan.start_time, reqCopy.plan.end_time] - }) + plan_time: [reqCopy.plan.start_time, reqCopy.plan.end_time], + }); //获取分销商 - this.getResellerFunction(reqCopy.plan.reseller_id) + this.getResellerFunction(reqCopy.plan.reseller_id); - this.setState({ codeInfo: codeInfo, isload: true }) + this.setState({ codeInfo: codeInfo, isload: true }); _.map(reqCopy.goods, (res) => { - res.checked = true - return res - }) + res.checked = true; + return res; + }); - this.setState({ tempdata: reqCopy.goods || [] }) + this.setState({ tempdata: reqCopy.goods || [] }); let a1 = reqCopy.goods.map((item) => { let obj = { ...item, - in: true - } - return obj - }) - sessionStorage.setItem("productData", JSON.stringify(a1)) - sessionStorage.setItem("knockGoldData", JSON.stringify(a1)) + in: true, + }; + return obj; + }); + sessionStorage.setItem("productData", JSON.stringify(a1)); + sessionStorage.setItem("knockGoldData", JSON.stringify(a1)); - let arr = [] + let arr = []; _.map(reqCopy.goods, (res) => { - let obj = {} - obj.key = res.only - obj.text = res.product_name - obj.id = res.id - this.state.oldProduct.push(res.id) - arr.push(obj) - return obj - }) - this.setState({ rankoptions: arr }) - this.setState({ rank: arr }) + let obj = {}; + obj.key = res.only; + obj.text = res.product_name; + obj.id = res.id; + this.state.oldProduct.push(res.id); + arr.push(obj); + return obj; + }); + this.setState({ rankoptions: arr }); + this.setState({ rank: arr }); }, (err) => {} - ) + ); }) - .catch((err) => {}) + .catch((err) => {}); } } @@ -324,105 +326,105 @@ 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 = [] + 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 + 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.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.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 = Math.trunc(item1.all_budget / item1.reduce_amount) - obj.stock = Math.trunc(item1.all_budget / item1.reduce_amount) - obj.usage = 0 + obj.quantity = Math.trunc(item1.all_budget / item1.reduce_amount); + obj.stock = Math.trunc(item1.all_budget / item1.reduce_amount); + obj.usage = 0; } else { - obj.quantity = item1.stock + obj.quantity = item1.stock; obj.stock = Math.trunc( item1.all_budget / item1.reduce_amount - item1.used_amount / item1.reduce_amount - ) + ); obj.usage = Math.trunc( item1.all_budget / item1.reduce_amount - (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, @@ -450,12 +452,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事件 */ @@ -463,11 +465,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() { @@ -478,99 +480,101 @@ 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 - ) + ); 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) + console.log(this.state.reseller); let data = { reseller_id: this.state.reseller.id, @@ -586,20 +590,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], @@ -611,24 +615,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], @@ -636,79 +640,79 @@ 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] - } - return data + payment_direction: this.state.payment_direction[this.state.paytype - 1], + }; + 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) { //非审核中状态 @@ -717,24 +721,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) => { @@ -742,215 +746,215 @@ 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; } /* 转换商品结构 */ // 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 - : Math.trunc(item.all_budget / item.reduce_amount) //总库 + : Math.trunc(item.all_budget / item.reduce_amount); //总库 newObj.stock = item.quantity ? item.quantity - : Math.trunc(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 - }) + : Math.trunc(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 ? { @@ -960,26 +964,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]); } } @@ -987,129 +991,132 @@ 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 ( -