1) 增加优惠券编辑

This commit is contained in:
zhangds 2022-09-21 18:06:51 +08:00
parent d33c244727
commit 530fe828db
3 changed files with 152 additions and 59 deletions

View File

@ -919,8 +919,8 @@ export const addCoupon = (data) => {
}; };
// 编辑优惠券 // 编辑优惠券
export const editCoupon = (data) => { export const editCoupon = (id, data) => {
return req("put", baseurl + `/coupon`, data); return req("put", baseurl + `/coupon/${id}`, data);
}; };
// 查询优惠券列表 // 查询优惠券列表

View File

@ -6,7 +6,6 @@ import React, {
} from "react"; } from "react";
import { useSetState } from "ahooks"; import { useSetState } from "ahooks";
import { FixedSizeList } from "react-window"; import { FixedSizeList } from "react-window";
import { useHistory } from "react-router-dom";
import { import {
Card, Card,
DateRangePicker, DateRangePicker,
@ -253,6 +252,15 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
}); });
// 1.6 // 1.6
editFun(); 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 { } else {
@ -548,9 +556,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
onConfirm: () => { onConfirm: () => {
window.history.back(); window.history.back();
}, },
onCancel: () => {}, onCancel() {},
className: "questModal", className: "questModal",
parentComponent: () => {}, parentComponent: this,
}); });
}; };
const onChangeCombinedDate = (e) => { const onChangeCombinedDate = (e) => {

View File

@ -27,6 +27,7 @@ import {
handelResponse, handelResponse,
queryKeyBatch, queryKeyBatch,
addCoupon, addCoupon,
editCoupon,
queryPlans, queryPlans,
} from "@/assets/api.js"; } from "@/assets/api.js";
@ -194,8 +195,8 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
payment_direction: ["对私账户", "对公账户", "预付款扣除"], payment_direction: ["对私账户", "对公账户", "预付款扣除"],
isState: "", isState: "",
coupon_batch_id: "", coupon_batch_id: "",
editModel: {}, //
isEdit: false, isEdit: false,
oldProduct: {}, // ,
}); });
// //
@ -253,14 +254,26 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
// 1.6 // 1.6
editFun(); editFun();
// 1.7
let isState = sessionStorage.getItem("isState"); let isState = sessionStorage.getItem("isState");
if (isState) {
setState({
isState: isState,
});
}
// 1.7
if (isState && isState === "1") { if (isState && isState === "1") {
setForm_info_data({ setForm_info_data({
title: `${editData.title}_${editData.copy_count + 1}`, title: `${editData.title}_${editData.copy_count + 1}`,
}); });
} }
console.log("isState =>", isState);
// 1.8
if (isState && isState === "2") {
setState({
oldProduct: editData.product,
});
}
} }
}); });
} else { } else {
@ -354,7 +367,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
text: item.title, text: item.title,
}; };
}); });
console.log("arr =>", arr);
setState({ setState({
plan_OPTIONS: arr, plan_OPTIONS: arr,
}); });
@ -374,7 +386,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
queryKeyBatch({ status: "4,5", plan_id: plan_id, bind_object: 2 }).then( queryKeyBatch({ status: "4,5", plan_id: plan_id, bind_object: 2 }).then(
(res) => { (res) => {
handelResponse(res, (req, msg) => { handelResponse(res, (req, msg) => {
console.log("归属key =>", req);
let arr = req.map((item) => { let arr = req.map((item) => {
return { return {
key: item.id, key: item.id,
@ -487,53 +498,130 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
...item.only, ...item.only,
}; };
}); });
console.log("计划优惠券数据 => ", param);
return param; return param;
}; };
const onAuditSubmit = () => { const onAuditSubmit = () => {
let param = { // 1 2
plan_id: form_info_data.plan_id.key.key, if (state.isState === "2") {
key_batch_id: form_info_data.key_batch_id.key, let param = {
title: form_info_data.title, payment_direction: state.payment_direction[state.payType - 1],
begin_time: form_info_data.date_time[0], title: form_info_data.title,
end_time: form_info_data.date_time[1], begin_time: form_info_data.date_time[0],
full: form_rule_data.full, end_time: form_info_data.date_time[1],
reduce: form_rule_data.reduce, new_product: {},
quantity: form_rule_data.quantity, update_product: {},
budget: form_rule_data.budget, delete_product: [],
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) => { let goods_arr = state.tableData.filter(
handelResponse( (item) => item.checked && item.type === 1
res,
(req, msg) => {
Notify.success(res.message);
setTimeout(() => {
window.history.back();
}, 2000);
},
(err) => {
Notify.error(err);
}
); );
}); 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 // select
@ -663,8 +751,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
// //
const productEditShow = (rowData, index) => { const productEditShow = (rowData, index) => {
console.log("rowData =>", rowData);
console.log("index =>", index);
try { try {
// id // id
const direct_reseller_ids = state.direct_reseller_id; const direct_reseller_ids = state.direct_reseller_id;
@ -715,7 +801,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
}); });
} catch (err) { } catch (err) {
setState({ tableLoading: false }); setState({ tableLoading: false });
console.log("err =>", err);
} }
}; };
@ -780,7 +865,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
}; };
const onRankChange = (e) => { const onRankChange = (e) => {
console.log("e =>", e);
let new_table_data = state.tableData.map((item) => { let new_table_data = state.tableData.map((item) => {
item.checked = item.checked =
e.findIndex((checks) => { e.findIndex((checks) => {
@ -796,7 +880,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
try { try {
// //
let new_table = table_all; let new_table = table_all;
console.log("所有数据 =>", new_table);
// //
let select_opt = []; let select_opt = [];
new_table.map((item) => { new_table.map((item) => {
@ -807,7 +890,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
}); });
let select_arr = []; let select_arr = [];
new_table.map((item) => { new_table.map((item) => {
console.log("item =>", item);
let obj = {}; let obj = {};
if (item.checked) { if (item.checked) {
obj.key = item.product_id; obj.key = item.product_id;
@ -828,7 +910,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
// //
const deleteGoodsScope = (index) => { const deleteGoodsScope = (index) => {
console.log("index deleat", index);
let new_table = state.tableData; let new_table = state.tableData;
new_table.splice(index, 1); new_table.splice(index, 1);
let select_opt = []; let select_opt = [];
@ -992,6 +1073,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
width={"130px"} width={"130px"}
alignment={"left"} alignment={"left"}
front="满" front="满"
disabled={state.isEdit}
/> />
<Ipt <Ipt
onChange={(e) => { onChange={(e) => {
@ -1010,6 +1092,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
alignment={"left"} alignment={"left"}
front="减" front="减"
unit="元" unit="元"
disabled={state.isEdit}
/> />
</div> </div>
</FormItem> </FormItem>
@ -1024,7 +1107,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
onClearItem={() => { onClearItem={() => {
setForm_rule_data({ quantity: "" }); setForm_rule_data({ quantity: "" });
}} }}
disabled={state.isQuantity} disabled={state.isQuantity || state.isEdit}
value={form_rule_data.quantity} value={form_rule_data.quantity}
placeholder={"请输入"} placeholder={"请输入"}
labelWidth={"0px"} labelWidth={"0px"}
@ -1068,6 +1151,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
countShow={false} countShow={false}
width={"520px"} width={"520px"}
alignment={"left"} alignment={"left"}
disabled={state.isEdit}
/> />
</FormItem> </FormItem>
</Form> </Form>
@ -1126,6 +1210,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
countbarVisible={false} countbarVisible={false}
maxheight={state.tableHeight} maxheight={state.tableHeight}
isSwitch={false} isSwitch={false}
isShowPageBar={false}
page={state.page} page={state.page}
ref={table_el} ref={table_el}
dataCount={state.dataCount} dataCount={state.dataCount}