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) => {
return req("put", baseurl + `/coupon`, data);
export const editCoupon = (id, data) => {
return req("put", baseurl + `/coupon/${id}`, data);
};
// 查询优惠券列表

View File

@ -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) => {

View File

@ -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,11 +498,87 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
...item.only,
};
});
console.log("计划优惠券数据 => ", param);
return param;
};
const onAuditSubmit = () => {
// 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: [],
};
// -
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,
@ -534,6 +621,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
}
);
});
}
};
// 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}
/>
<Ipt
onChange={(e) => {
@ -1010,6 +1092,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
alignment={"left"}
front="减"
unit="元"
disabled={state.isEdit}
/>
</div>
</FormItem>
@ -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}
/>
</FormItem>
</Form>
@ -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}