From 72bcc02051c8a305f7b059433643d268cc445164 Mon Sep 17 00:00:00 2001 From: zhangds Date: Wed, 7 Sep 2022 18:17:56 +0800 Subject: [PATCH] =?UTF-8?q?1)=20=E5=A2=9E=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E9=80=89=E4=B8=AD=E8=81=94=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UseCouponAddEdit/index.jsx | 34 ++++++++++++++++++----- src/components/UseGoodsScopePop/index.jsx | 17 ++++++++---- src/pages/plan/product/add.js | 4 ++- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index 1560fe63..48466c42 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -195,6 +195,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { productData: {}, direct_reseller_id: 23329, tableLoading: false, + table_index: -1, }); // 基础信息 @@ -349,7 +350,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }; // 编辑 - const productEditShow = (rowData) => { + const productEditShow = (rowData, index) => { + console.log("rowData =>", rowData); + console.log("index =>", index); try { // 第一步:获取直连天下的商品数据需要分销商 id const direct_reseller_ids = state.direct_reseller_id; @@ -357,6 +360,8 @@ const UseCouponAddEdit = forwardRef((props, ref) => { Notify.error(`请添加映射分销商`); return; } + // 第二步:清除本地存储数据 + clearStorageData(); setState({ tableLoading: true, }); @@ -379,6 +384,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { productData: obj, addIsType: "addKnockGold", showScopePop: true, + table_index: index, }); } else { setState({ @@ -386,6 +392,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { productData: rowData, addIsType: "addProduct", showScopePop: true, + table_index: index, }); } }, @@ -488,10 +495,25 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }); console.log("select_opt =>", select_opt); + console.log("rank =>", state.rank); + + let select_arr = []; + new_table.map((item) => { + console.log("item =>", item); + let obj = {}; + if (item.checked) { + obj.key = item.product_id; + obj.text = item.product_name; + select_arr.push(obj); + } + }); + console.log("select_arr =>", select_arr); + // 格式化商品范围 setState({ tableData: new_table, rankoptions: select_opt, + rank: select_arr, }); } catch (err) { console.log("err =>", err); @@ -500,12 +522,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => { // 商品范围删除 const deleteGoodsScope = (index) => { + console.log("index deleat", index); let new_table = state.tableData; - if (index === 0) { - new_table = []; - } else { - new_table = new_table.splice(index, 1); - } + new_table.splice(index, 1); let select_opt = []; new_table.map((item) => { let obj = {}; @@ -743,7 +762,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
productEditShow(rowData)} + onClick={() => productEditShow(rowData, rowIndex)} > 编辑 @@ -786,6 +805,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { productData={state.productData} onClose={() => scopePopClose()} tableData={state.tableData} + table_index={state.table_index} submit={(data) => scopePopSubmit(data)} >
diff --git a/src/components/UseGoodsScopePop/index.jsx b/src/components/UseGoodsScopePop/index.jsx index 6f3fe8a0..93be23e8 100644 --- a/src/components/UseGoodsScopePop/index.jsx +++ b/src/components/UseGoodsScopePop/index.jsx @@ -13,6 +13,7 @@ const UseGoodsScopePop = forwardRef((props, ref) => { productData, submit, tableData, + table_index, } = props; // 如果需要 通过ref 控制此组件 放开注释 @@ -25,18 +26,24 @@ const UseGoodsScopePop = forwardRef((props, ref) => { // 新建商品数据处理 const format_product_model = () => { - // 是编辑还是新增 - + let new_tableData = tableData; // 新增 - let form_model = product_el.current.state.model; + let form_model = product_el.current.state.form_data; form_model.goods_type = 1; form_model.upstream = "直连天下"; form_model.all_budget = Number(form_model.contract_price) * Number(form_model.quantity); form_model.effectDate = "-"; - let new_tableData = tableData; - new_tableData.push(form_model); + if (product_title === "编辑商品") { + if (table_index !== -1) { + form_model.checked = false; + new_tableData[table_index] = form_model; + console.log("new_tableData =>", new_tableData); + } + } else { + new_tableData.push(form_model); + } return new_tableData; }; diff --git a/src/pages/plan/product/add.js b/src/pages/plan/product/add.js index 4d53ca1d..5592d811 100644 --- a/src/pages/plan/product/add.js +++ b/src/pages/plan/product/add.js @@ -46,6 +46,7 @@ export default class adduserinfo extends React.Component { detail_url: "", account_type: "", }, + form_data: {}, cur_product: {}, productOption: [], products: [], @@ -200,7 +201,7 @@ export default class adduserinfo extends React.Component { } temp[index].describe_url = urls; temp[index].map_product_name = this.state.model.map_product_name; - + this.setState({ form_data: temp[index] }); sessionStorage.setItem("productData", JSON.stringify(temp)); return true; } @@ -227,6 +228,7 @@ export default class adduserinfo extends React.Component { let data = temp ? temp : []; data.push(this.state.model); sessionStorage.setItem("productData", JSON.stringify(data)); + this.setState({ form_data: model }); return true; } }