From 530fe828dbbf95fd278ab78dd2d823fae64ed426 Mon Sep 17 00:00:00 2001 From: zhangds Date: Wed, 21 Sep 2022 18:06:51 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=89=20=E5=A2=9E=E5=8A=A0=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/api.js | 4 +- .../UseCouponAddEdit/index copy.jsx | 14 +- src/components/UseCouponAddEdit/index.jsx | 193 +++++++++++++----- 3 files changed, 152 insertions(+), 59 deletions(-) diff --git a/src/assets/api.js b/src/assets/api.js index 7b0168d3..d1f630b0 100644 --- a/src/assets/api.js +++ b/src/assets/api.js @@ -919,8 +919,8 @@ export const addCoupon = (data) => { }; // 编辑优惠券 -export const editCoupon = (data) => { - return req("put", baseurl + `/coupon`, data); +export const editCoupon = (id, data) => { + return req("put", baseurl + `/coupon/${id}`, data); }; // 查询优惠券列表 diff --git a/src/components/UseCouponAddEdit/index copy.jsx b/src/components/UseCouponAddEdit/index copy.jsx index 747b2274..d3209d56 100644 --- a/src/components/UseCouponAddEdit/index copy.jsx +++ b/src/components/UseCouponAddEdit/index copy.jsx @@ -6,7 +6,6 @@ import React, { } from "react"; import { useSetState } from "ahooks"; import { FixedSizeList } from "react-window"; -import { useHistory } from "react-router-dom"; import { Card, DateRangePicker, @@ -253,6 +252,15 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }); // 1.6 设置其它数据 editFun(); + + // 1.7 是否复制 + let isState = sessionStorage.getItem("isState"); + if (isState && isState === "1") { + setForm_info_data({ + title: `${editData.title}_${editData.copy_count + 1}`, + }); + } + console.log("isState =>", isState); } }); } else { @@ -548,9 +556,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => { onConfirm: () => { window.history.back(); }, - onCancel: () => {}, + onCancel() {}, className: "questModal", - parentComponent: () => {}, + parentComponent: this, }); }; const onChangeCombinedDate = (e) => { diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index d3209d56..4d29c12c 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -27,6 +27,7 @@ import { handelResponse, queryKeyBatch, addCoupon, + editCoupon, queryPlans, } from "@/assets/api.js"; @@ -194,8 +195,8 @@ const UseCouponAddEdit = forwardRef((props, ref) => { payment_direction: ["对私账户", "对公账户", "预付款扣除"], isState: "", coupon_batch_id: "", - editModel: {}, // 编辑数据 isEdit: false, + oldProduct: {}, // 旧数据,为编辑做准备 }); // 基础信息 @@ -253,14 +254,26 @@ const UseCouponAddEdit = forwardRef((props, ref) => { // 1.6 设置其它数据 editFun(); - // 1.7 是否复制 let isState = sessionStorage.getItem("isState"); + if (isState) { + setState({ + isState: isState, + }); + } + + // 1.7 复制 if (isState && isState === "1") { setForm_info_data({ title: `${editData.title}_${editData.copy_count + 1}`, }); } - console.log("isState =>", isState); + + // 1.8 编辑 + if (isState && isState === "2") { + setState({ + oldProduct: editData.product, + }); + } } }); } else { @@ -354,7 +367,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { text: item.title, }; }); - console.log("arr =>", arr); setState({ plan_OPTIONS: arr, }); @@ -374,7 +386,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { queryKeyBatch({ status: "4,5", plan_id: plan_id, bind_object: 2 }).then( (res) => { handelResponse(res, (req, msg) => { - console.log("归属key =>", req); let arr = req.map((item) => { return { key: item.id, @@ -487,53 +498,130 @@ const UseCouponAddEdit = forwardRef((props, ref) => { ...item.only, }; }); - console.log("计划优惠券数据 => ", param); return param; }; const onAuditSubmit = () => { - let param = { - plan_id: form_info_data.plan_id.key.key, - key_batch_id: form_info_data.key_batch_id.key, - title: form_info_data.title, - begin_time: form_info_data.date_time[0], - end_time: form_info_data.date_time[1], - full: form_rule_data.full, - reduce: form_rule_data.reduce, - quantity: form_rule_data.quantity, - budget: form_rule_data.budget, - restrict: form_rule_data.restrict, - payment_direction: "", - product: { - legal: [], - reduce: [], - }, - }; - param.payment_direction = state.payment_direction[state.payType - 1]; // 扣款方式 - let arr = state.tableData.filter((item) => item.checked); - param.product.legal = arr.filter((item) => item.type === 1); // 商品 - - let param_lj = arr.filter((item) => item.type === 2); // 立减金 - param.product.reduce = param_lj.map((item) => { - return { - ...item.only, + // 1新增 2编辑 + if (state.isState === "2") { + let param = { + payment_direction: state.payment_direction[state.payType - 1], + title: form_info_data.title, + begin_time: form_info_data.date_time[0], + end_time: form_info_data.date_time[1], + new_product: {}, + update_product: {}, + delete_product: [], }; - }); - console.log("param 优惠券新增 大提交 =>", param); - addCoupon(param).then((res) => { - handelResponse( - res, - (req, msg) => { - Notify.success(res.message); - setTimeout(() => { - window.history.back(); - }, 2000); - }, - (err) => { - Notify.error(err); - } + + // 商品-立减金过滤 + let goods_arr = state.tableData.filter( + (item) => item.checked && item.type === 1 ); - }); + let lj_arr = state.tableData.filter( + (item) => item.checked && item.type === 2 + ); + + // 商品-新增 + param.new_product.legal = goods_arr.filter( + (item) => item.checked && !item.goods_id + ); + + // 商品-编辑 + param.update_product.legal = goods_arr.filter( + (item) => item.checked && item.goods_id + ); + + // 立减金-新增 + param.new_product.reduce = lj_arr + .filter((item) => item.checked && !item.only.goods_id) + .map((item) => { + return item.only; + }); + + // 立减金-编辑 + param.update_product.reduce = lj_arr + .filter((item) => item.checked && item.only.goods_id) + .map((item) => { + return item.only; + }); + + // 商品立减金-删除 + param.delete_product = state.tableData + .filter( + (item) => !item.checked && (item.goods_id || item.only.goods_id) + ) + .map((item) => { + console.log("item =>", item); + if (item.type === 1) { + return item.goods_id; + } else { + return item.only.goods_id; + } + }); + + console.log("所有数据 =>", state.tableData); + console.log("旧数据 =>", state.oldProduct); + console.log("编辑 大提交 =>", param); + editCoupon(editData.id, param).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success(res.message); + return; + setTimeout(() => { + window.history.back(); + }, 2000); + }, + (err) => { + Notify.error(err); + } + ); + }); + } else { + let param = { + plan_id: form_info_data.plan_id.key.key, + key_batch_id: form_info_data.key_batch_id.key, + title: form_info_data.title, + begin_time: form_info_data.date_time[0], + end_time: form_info_data.date_time[1], + full: form_rule_data.full, + reduce: form_rule_data.reduce, + quantity: form_rule_data.quantity, + budget: form_rule_data.budget, + restrict: form_rule_data.restrict, + payment_direction: "", + product: { + legal: [], + reduce: [], + }, + }; + param.payment_direction = state.payment_direction[state.payType - 1]; // 扣款方式 + let arr = state.tableData.filter((item) => item.checked); + param.product.legal = arr.filter((item) => item.type === 1); // 商品 + + let param_lj = arr.filter((item) => item.type === 2); // 立减金 + param.product.reduce = param_lj.map((item) => { + return { + ...item.only, + }; + }); + console.log("param 优惠券新增 大提交 =>", param); + addCoupon(param).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success(res.message); + setTimeout(() => { + window.history.back(); + }, 2000); + }, + (err) => { + Notify.error(err); + } + ); + }); + } }; // 计划select改变 @@ -663,8 +751,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { // 编辑 const productEditShow = (rowData, index) => { - console.log("rowData =>", rowData); - console.log("index =>", index); try { // 第一步:获取直连天下的商品数据需要分销商 id const direct_reseller_ids = state.direct_reseller_id; @@ -715,7 +801,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }); } catch (err) { setState({ tableLoading: false }); - console.log("err =>", err); } }; @@ -780,7 +865,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }; const onRankChange = (e) => { - console.log("e =>", e); let new_table_data = state.tableData.map((item) => { item.checked = e.findIndex((checks) => { @@ -796,7 +880,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { try { // 格式化表格数据 let new_table = table_all; - console.log("所有数据 =>", new_table); // 设置商品范围选择 let select_opt = []; new_table.map((item) => { @@ -807,7 +890,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }); let select_arr = []; new_table.map((item) => { - console.log("item =>", item); let obj = {}; if (item.checked) { obj.key = item.product_id; @@ -828,7 +910,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { // 商品范围删除 const deleteGoodsScope = (index) => { - console.log("index deleat", index); let new_table = state.tableData; new_table.splice(index, 1); let select_opt = []; @@ -992,6 +1073,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { width={"130px"} alignment={"left"} front="满" + disabled={state.isEdit} /> { @@ -1010,6 +1092,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { alignment={"left"} front="减" unit="元" + disabled={state.isEdit} /> @@ -1024,7 +1107,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { onClearItem={() => { setForm_rule_data({ quantity: "" }); }} - disabled={state.isQuantity} + disabled={state.isQuantity || state.isEdit} value={form_rule_data.quantity} placeholder={"请输入"} labelWidth={"0px"} @@ -1068,6 +1151,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { countShow={false} width={"520px"} alignment={"left"} + disabled={state.isEdit} /> @@ -1126,6 +1210,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { countbarVisible={false} maxheight={state.tableHeight} isSwitch={false} + isShowPageBar={false} page={state.page} ref={table_el} dataCount={state.dataCount}