diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index f7558f9b..812f388f 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -184,8 +184,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { product_title: "", showScopePop: false, scopePopType: "", - productData: [], - selectGoodsScopeData: [] + productData: [] }) // 基础信息 @@ -232,9 +231,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { let el_setup2 = form_rule_el.current.validator() // console.log("el_setup2 =>", el_setup2); // console.log("发放规则 =>", form_rule_data); - - // 商品范围 - console.log("用户商品范围 =>", state.selectGoodsScopeData) } const onReturn = () => {} @@ -261,18 +257,31 @@ const UseCouponAddEdit = forwardRef((props, ref) => { } const onPageChange = () => {} const onCountChange = () => {} - // const selectionFun = (e) => { - // console.log("e =>", e) - // let arr = [] - // _.map(e, (item) => { - // let obj = {} - // obj.key = item.product_id - // obj.text = item.product_name - // arr.push(obj) - // return obj - // }) - // setState({ selectGoodsScopeData: arr }) - // } + + // 清除商品和立减金本地存储 + const clearStorageData = () => { + if (state.tableData.length <= 0) { + sessionStorage.setItem("productData", "") + sessionStorage.setItem("knockGoldData", "") + } + + // 新建商品 + let product_data = state.tableData.filter((item) => item.goods_type === 1) + if (product_data.length <= 0) { + sessionStorage.setItem("productData", "") + } else { + sessionStorage.setItem("productData", JSON.stringify(product_data)) + } + + // 立减金 + let knockGold_data = state.tableData.filter((item) => item.goods_type === 2) + if (knockGold_data.length <= 0) { + sessionStorage.setItem("knockGoldData", "") + } else { + sessionStorage.setItem("knockGoldData", JSON.stringify(knockGold_data)) + } + } + const addProduct = (type) => { try { // 第一步:获取直连天下的商品数据需要分销商 id @@ -282,7 +291,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { return } // 第二步:清除本地存储数据 - // clearStorageData() + clearStorageData() // 第三步: 区分是新建商品还是立减金 if (type === "addProduct") { @@ -291,11 +300,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { addProductBtnLoading: true, scopePopType: "addProduct" }) - // 兼容本地存储 - // console.log("--------1", state.tableData); - // data = JSON.parse(sessionStorage.getItem('productData')).filter( - // (item) => item.type !== 2 - // ) } else { setState({ product_title: "新增立减金", @@ -410,14 +414,23 @@ const UseCouponAddEdit = forwardRef((props, ref) => { try { // 格式化表格数据 let data_new = data - data_new.key_batch_id = form_info_data.key_batch_id.key - data_new.effectDate = `${form_info_data.date_time[0]} 至 ${form_info_data.date_time[1]}` let new_table = state.tableData new_table.push(data_new) + console.log("table_data =>", new_table) + + // 设置商品范围选择 + let select_opt = [] + new_table.map((item) => { + let obj = {} + obj.key = item // 确保差异 + obj.text = item.product_name + select_opt.push(obj) + }) + // 格式化商品范围 setState({ tableData: new_table, - rankoptions: [] + rankoptions: select_opt }) } catch (err) { console.log("err =>", err) @@ -646,7 +659,10 @@ const UseCouponAddEdit = forwardRef((props, ref) => { return (
编辑 - + deleteGoodsScope(rowIndex)}> 删除
@@ -654,12 +670,11 @@ const UseCouponAddEdit = forwardRef((props, ref) => { } if (com === "goods_type") { - return {rowData.type === 1 ? "商品" : "立减金"} + return {rowData.goods_type === 1 ? "商品" : "立减金"} } }} /> - {isAuditButton ? (