fix: 增加key批次商品类型

This commit is contained in:
zhangds 2022-10-24 18:30:27 +08:00
parent f67fc9017b
commit 60f1adc2d0
1 changed files with 287 additions and 19 deletions

View File

@ -26,6 +26,13 @@ import Grid from "@/components/gird/main.js";
import UseCouponAddEdit from "@/components/UseCouponAddEdit"; //
import UseExchangeAddEdit from "@/components/UseExchangeAddEdit"; //
import {
handelResponse,
getReseller,
addKeysBatchInfo,
keyEditApproval,
} from "@/assets/api.js";
const formRules = {
bind_object: [{ type: "required", message: "请选择绑定类型" }],
};
@ -40,9 +47,9 @@ const UseKeyAddEdit = () => {
recall_visible: false,
audit_visible: false,
key_status: 1,
payType: 1,
stock: 0,
payType: 3,
keyType: 1,
rowIndex: -1,
distdata: [],
couponData: [],
rowCouponData: "",
@ -156,33 +163,39 @@ const UseKeyAddEdit = () => {
timer: 0,
draw_title: "",
drawerVisible: false,
direct_reseller_id: "",
direct_reseller_id: 0,
});
const keyFormEl = useRef(null);
const bindObjEl = useRef(null);
const addEditExchangeEl = useRef(null);
const addEditCouponEl = useRef(null);
const [model, setModel] = useSetState({
plan_title: "",
batch_name: "",
style: 1,
allow_repetition: 1,
allow_loss: 1,
quantity: "",
stock: "",
});
useEffect(() => {
init();
}, []);
const init = () => {
let planItem = sessionStorage.getItem("plan_item");
if (planItem) {
setModel({
plan_title: JSON.parse(planItem).title,
});
}
// KeyPcType 1 2 3
if (state.KeyPcType === "3") {
setState({
pageTitle: "新增key",
});
let planItem = sessionStorage.getItem("plan_item");
if (planItem) {
let obj = JSON.parse(planItem);
setModel({
plan_title: obj.title,
});
getResellerFun(obj.reseller_id);
}
} else if (state.KeyPcType === "1") {
setState({
pageTitle: "编辑key",
@ -193,11 +206,47 @@ const UseKeyAddEdit = () => {
});
}
};
// id
const getResellerFun = (id) => {
getReseller(id).then((res) => {
handelResponse(
res,
(req, msg) => {
setState({ direct_reseller_id: req.direct_reseller_id });
},
(err) => {
Notify.error(err);
}
);
});
};
const onStyleChange = () => {};
const initUpload = () => {};
const planAddExchangeCoupon = () => {};
const planAddExchangeCoupon = (type) => {
if (type === 0) {
setState({ draw_title: "新建兑换码" });
setTimeout(() => {
addEditExchangeEl.current.clearExchangeForm();
}, 300);
} else {
setState({ draw_title: "新建优惠券" });
setTimeout(() => {
addEditCouponEl.current.clearCouponForm();
}, 300);
}
setState({ rowIndex: -1 });
setState({ drawerVisible: true });
};
const pageChange = () => {};
const onBindNum = () => {};
const onBindNum = (e, rowData, rowIndex) => {
if (state.keyType === 1) {
state.distdata[rowIndex].restrict = e.target.value;
setState({ distdata: state.distdata });
} else {
state.couponData[rowIndex].restrict = e.target.value;
setState({ couponData: state.couponData });
}
};
//
const coupon_range = (product) => {
let arr_legal = product.legal.map((item) => item.product_name);
@ -209,14 +258,226 @@ const UseKeyAddEdit = () => {
const rowItemClick = () => {};
const onRepetitionChange = () => {};
const onLossChange = () => {};
const onSubmit = () => {};
const Cancel = () => {};
const Cancel = () => {
Sweetalert.confirm({
type: "warning",
closeBtn: true,
title: "确认操作",
content: <p>是否取消本次操作</p>,
onConfirm: () => {
window.history.back();
},
onCancel: () => {},
className: "questModal",
parentComponent: this,
});
};
const onReCall = () => {};
const onConfirm = () => {};
/**
*
* @param {0新增addKeysBatchInfo1编辑keyEditApproval} apiType
* @param {*} data
*/
const couponExchangeSubmitApi = (apiType, data) => {
let keybatch_id = sessionStorage.getItem("keybatch_id");
if (apiType === 0) {
let create_param = {
id: state.id,
batch_name: state.model.batch_name,
style: state.model.style,
quantity: state.model.quantity,
bind_object: [state.keyType],
allow_repetition: state.model.allow_repetition,
allow_loss: state.model.allow_loss,
merge_stock: state.model.merge_stock,
mobile_excel: state.mobile_excel,
mobile_repeat: state.mobile_repeat,
reseller_id: state.reseller.id,
reseller_name: state.reseller.name,
company_name: state.reseller.company_name,
receive_email: state.reseller.contact_email[0],
payment_direction: state.payment_direction[state.payType - 1],
};
//
if (state.keyType === 1) {
create_param.code_batch = data;
} else {
create_param.coupon = data;
}
addKeysBatchInfo(state.plan_id, create_param).then((res) => {
handelResponse(
res,
(req, msg) => {
Notify.success("成功发起审批");
setTimeout(() => {
window.history.back();
}, 1000);
},
(err) => {
Notify.error(err);
}
);
});
} else {
let edit_param = {
reseller_id: state.reseller.id,
reseller_name: state.reseller.name,
company_name: state.reseller.company_name,
receive_email: state.reseller.contact_email[0],
payment_direction: state.payment_direction[state.payType - 1],
};
//
if (state.keyType === 1) {
edit_param.code_batch = data;
} else {
edit_param.coupon = data;
}
keyEditApproval(keybatch_id, edit_param).then((res) => {
handelResponse(
res,
(req, msg) => {
Notify.success("成功发起审批");
setTimeout(() => {
window.history.back();
}, 1000);
},
(err) => {
Notify.error(err);
}
);
});
}
};
//
const couponSubmit = () => {
//
let editCouponData = state.couponData.filter(
(item) =>
item.checked === true &&
(item.status === -1 || item.status === 7 || item.id === "" || !item.id)
);
//
if (state.key_status === 1) {
//
let couponArr = state.couponData.filter(
(item) => item.id && item.id !== ""
);
if (couponArr.length > 0) {
//
couponExchangeSubmitApi(1, editCouponData);
} else {
//
let addCouponData = state.couponData.filter(
(item) => item.checked === true && !item.id
);
couponExchangeSubmitApi(0, addCouponData);
}
} else {
//
couponExchangeSubmitApi(1, editCouponData);
}
};
//
const exchangeSubmit = () => {
//
let editExchangeData = state.distdata.filter(
(item) =>
item.checked === true &&
(item.status === -1 || item.status === 7 || item.id === "" || !item.id)
);
//
if (state.key_status === 1) {
//
let arr = editExchangeData.filter((item) => item.id && item.id !== "");
if (arr.length > 0) {
//
couponExchangeSubmitApi(1, editExchangeData);
} else {
//
let addArr = state.distdata.filter(
(item) => item.checked === true && !item.id
);
couponExchangeSubmitApi(0, addArr);
}
} else {
//
couponExchangeSubmitApi(1, editExchangeData);
}
};
const onConfirm = () => {
// keyType 1 2
if (state.keyType === 1) {
exchangeSubmit();
} else {
couponSubmit();
}
};
const onPayTypeChange = () => {};
const onCheckChange = () => {};
const codeSubmit = () => {};
const closeDraw = () => {};
const codeSubmit = () => {
//
if (state.keyType === 2) {
let validator = addEditCouponEl.current.submit();
if (validator) {
let param = addEditCouponEl.getModel();
let tempData = state.couponData;
//
if (state.rowIndex > -1) {
tempData[state.rowIndex] = param;
setState({ couponData: tempData });
} else {
//
tempData.push(param);
setState({ couponData: tempData });
}
setState({
drawerVisible: false,
});
}
return;
}
//
if (state.keyType === 1) {
let validator = addEditExchangeEl.current.submit();
if (validator) {
let param = addEditExchangeEl.current.getModel();
let tempData = state.distdata;
//
if (state.rowIndex > -1) {
tempData[state.rowIndex] = param;
setState({ distdata: tempData });
} else {
//
tempData.push(param);
setState({ distdata: tempData });
}
setState({
drawerVisible: false,
});
}
return;
}
};
const closeDraw = () => {
if (state.keyType === 2) {
setTimeout(() => {
addEditCouponEl.current.clearCouponForm();
}, 300);
}
if (state.keyType === 1) {
setTimeout(() => {
addEditExchangeEl.current.clearExchangeForm();
}, 300);
}
setState({ drawerVisible: false });
};
return (
<div id="addkey" className="addkey">
<Card
@ -423,7 +684,14 @@ const UseKeyAddEdit = () => {
</Card>
<div className="addkey-btn-group">
{state.isCancel ? null : (
<Button type="primary" onClick={() => onSubmit()}>
<Button
type="primary"
onClick={() =>
setState({
audit_visible: true,
})
}
>
提交审核
</Button>
)}
@ -465,14 +733,14 @@ const UseKeyAddEdit = () => {
<UseExchangeAddEdit
direct_reseller_id={state.direct_reseller_id}
editData={state.rowExChangeData}
ref="addEditExchangeEl"
ref={addEditExchangeEl}
></UseExchangeAddEdit>
) : (
<UseCouponAddEdit
couponType={1}
editData={state.rowCouponData}
isAuditButton={false}
ref="addEditCouponEl"
ref={addEditCouponEl}
direct_reseller_id={state.direct_reseller_id}
></UseCouponAddEdit>
)}