fix: key批次增加商品类型

This commit is contained in:
zhangds 2022-10-25 13:39:11 +08:00
parent 60f1adc2d0
commit 57e0cc6dfe
4 changed files with 385 additions and 244 deletions

View File

@ -35,3 +35,24 @@
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
## 组件函数存放
```js
// 函数名 名字+类型
//#region data ******************************/
//#endRegion data ***************************/
//#region init ******************************/
//#endRegion init ***************************/
//#region event handler **********************/
//#endRegion event handler *******************/
//#region hooks ******************************/
//#endRegion hooks ***************************/
//#region submit ***************************/
//#endRegion submit ************************/
```

View File

@ -34,10 +34,20 @@ import {
} from "@/assets/api.js";
const formRules = {
quantity: [
{ type: "required", message: "key数量不能为0" },
{
type: "regExp",
message: "请输入正整数",
reg: "^([1-9][0-9]*){1,3}$",
},
],
bind_object: [{ type: "required", message: "请选择绑定类型" }],
batch_name: [{ type: "required", message: "请输入key批次名称" }],
};
const UseKeyAddEdit = () => {
//#region data ******************************/
const [state, setState] = useSetState({
pageTitle: "编辑key",
isEdit: false,
@ -46,8 +56,7 @@ const UseKeyAddEdit = () => {
isCancel: false,
recall_visible: false,
audit_visible: false,
key_status: 1,
payType: 3,
key_status: -1,
keyType: 1,
rowIndex: -1,
distdata: [],
@ -164,6 +173,11 @@ const UseKeyAddEdit = () => {
draw_title: "",
drawerVisible: false,
direct_reseller_id: 0,
plan_id: "",
id: "",
reseller: {},
payment_direction: ["对私账户", "对公账户", "预付款扣除"],
payType: 3,
});
const keyFormEl = useRef(null);
const bindObjEl = useRef(null);
@ -173,15 +187,37 @@ const UseKeyAddEdit = () => {
plan_title: "",
batch_name: "",
style: 1,
allow_repetition: 1,
allow_loss: 1,
quantity: "",
allow_repetition: 0,
allow_loss: 0,
quantity: "1",
stock: "",
merge_stock: 1,
mobile_excel: "",
});
//#endRegion data ***************************/
//#region init ******************************/
useEffect(() => {
init();
}, []);
// id
const getResellerFun = (id) => {
getReseller(id).then((res) => {
handelResponse(
res,
(req, msg) => {
setState({ direct_reseller_id: req.direct_reseller_id });
setState({
reseller: req,
});
},
(err) => {
Notify.error(err);
}
);
});
};
const init = () => {
// KeyPcType 1 2 3
if (state.KeyPcType === "3") {
@ -191,9 +227,13 @@ const UseKeyAddEdit = () => {
let planItem = sessionStorage.getItem("plan_item");
if (planItem) {
let obj = JSON.parse(planItem);
console.log("plan item =>", obj);
setModel({
plan_title: obj.title,
});
setState({
plan_id: obj.plan_id,
});
getResellerFun(obj.reseller_id);
}
} else if (state.KeyPcType === "1") {
@ -206,22 +246,15 @@ 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 = () => {};
//#endRegion init ***************************/
//#region event handler **********************/
//
const styleChange = () => {};
//
const importWhiteNameList = () => {};
//
const planAddExchangeCoupon = (type) => {
if (type === 0) {
setState({ draw_title: "新建兑换码" });
@ -237,7 +270,8 @@ const UseKeyAddEdit = () => {
setState({ rowIndex: -1 });
setState({ drawerVisible: true });
};
const pageChange = () => {};
//
const onBindNum = (e, rowData, rowIndex) => {
if (state.keyType === 1) {
state.distdata[rowIndex].restrict = e.target.value;
@ -248,178 +282,34 @@ const UseKeyAddEdit = () => {
}
};
//
const coupon_range = (product) => {
const goodsRange = (product) => {
let arr_legal = product.legal.map((item) => item.product_name);
let arr_reduce = product.reduce.map((item) => item.batch_goods_name);
let arr = arr_legal.concat(arr_reduce);
arr = arr.join(",");
return <span>{arr}</span>;
};
const rowItemClick = () => {};
const onRepetitionChange = () => {};
const onLossChange = () => {};
const Cancel = () => {
Sweetalert.confirm({
type: "warning",
closeBtn: true,
title: "确认操作",
content: <p>是否取消本次操作</p>,
onConfirm: () => {
window.history.back();
},
onCancel: () => {},
className: "questModal",
parentComponent: this,
});
};
const onReCall = () => {};
/**
*
* @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 rowEditClick = () => {};
//
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 repeatGoodsCheck = () => {};
//
const exchangeSubmit = () => {
//
let editExchangeData = state.distdata.filter(
(item) =>
item.checked === true &&
(item.status === -1 || item.status === 7 || item.id === "" || !item.id)
);
//
const lossCheck = () => {};
//
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 cancelExamineBtn = () => {};
const onConfirm = () => {
// keyType 1 2
if (state.keyType === 1) {
exchangeSubmit();
} else {
couponSubmit();
}
};
const onPayTypeChange = () => {};
const onCheckChange = () => {};
const codeSubmit = () => {
//
const payCheck = () => {};
//
const bindObjectCheck = () => {};
//
const exchangeCouponBtnPop = () => {
//
if (state.keyType === 2) {
let validator = addEditCouponEl.current.submit();
@ -464,13 +354,14 @@ const UseKeyAddEdit = () => {
return;
}
};
const closeDraw = () => {
//
const exchangeCouponCloseBtnPop = () => {
if (state.keyType === 2) {
setTimeout(() => {
addEditCouponEl.current.clearCouponForm();
}, 300);
}
if (state.keyType === 1) {
setTimeout(() => {
addEditExchangeEl.current.clearExchangeForm();
@ -478,6 +369,216 @@ const UseKeyAddEdit = () => {
}
setState({ drawerVisible: false });
};
//
const examineBtn = () => {
if (keyFormEl.current.validator()) {
//
if (state.keyType === 1) {
// bindObjEl
if (state.distdata.length <= 0) {
Notify.error("请添加绑定对象");
return;
}
} else {
if (state.couponData.length <= 0) {
Notify.error("请添加绑定对象");
return;
}
}
let arr = bindObjEl.current.getSelectData();
if (arr.length <= 0) {
Notify.error("请勾选绑定对象");
return;
}
let arr_restrict = arr.filter((item) => item.restrict === "");
if (arr_restrict.length > 0) {
Notify.error("绑定数不能为空");
return;
}
setState({
audit_visible: true,
});
}
};
//
const examineBackBtn = () => {
Sweetalert.confirm({
type: "warning",
closeBtn: true,
title: "确认操作",
content: <p>是否取消本次操作</p>,
onConfirm: () => {
window.history.back();
},
onCancel: () => {},
className: "questModal",
parentComponent: this,
});
};
//#endRegion event handler *******************/
//#region submit ***************************/
/**
*
* @param {0新增addKeysBatchInfo1编辑keyEditApproval} apiType
* @param {*} data
*/
const couponExchangeSubmit = (apiType, data) => {
console.log("apiType =>", apiType);
console.log("data =>", data);
let keyBatch_id = sessionStorage.getItem("keybatch_id");
if (apiType === 0) {
let create_param = {
id: state.id,
batch_name: model.batch_name,
style: model.style,
quantity: model.quantity,
bind_object: [state.keyType],
allow_repetition: model.allow_repetition,
allow_loss: model.allow_loss,
merge_stock: model.merge_stock,
mobile_excel: model.mobile_excel,
mobile_repeat: model.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;
}
console.log("大提交 =>", create_param);
return;
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 couponTools = () => {
//
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) {
//
couponExchangeSubmit(1, editCouponData);
} else {
//
let addCouponData = state.couponData.filter(
(item) => item.checked === true && !item.id
);
couponExchangeSubmit(0, addCouponData);
}
} else {
//
couponExchangeSubmit(1, editCouponData);
}
};
//
const exchangeTools = () => {
//
let editExchangeData = state.distdata.filter(
(item) =>
item.checked === true &&
(item.status === -1 || item.status === 7 || item.id === "" || !item.id)
);
// KeyPcType 1 2 3
if (state.KeyPcType === "3" || state.KeyPcType === "2") {
couponExchangeSubmit(0, editExchangeData);
} else {
// 2.1
if (state.key_status === 1) {
// 2.2
let arr = editExchangeData.filter((item) => item.id && item.id !== "");
if (arr.length > 0) {
// 2.3
couponExchangeSubmit(1, editExchangeData);
} else {
// 2.4
let addArr = state.distdata.filter(
(item) => item.checked === true && !item.id
);
couponExchangeSubmit(0, addArr);
}
} else {
// 2.5
couponExchangeSubmit(1, editExchangeData);
}
}
};
//
const bigSubmit = () => {
// keyType 1 2
if (state.keyType === 1) {
exchangeTools();
} else {
couponTools();
}
};
//#endRegion submit ************************/
return (
<div id="addkey" className="addkey">
<Card
@ -513,7 +614,7 @@ const UseKeyAddEdit = () => {
<FormItem labelname=" key样式" prop="style" id="style">
<RadioGroup
onChange={(e) => {
onStyleChange(e);
styleChange(e);
}}
value={model.style}
disabled={state.isEdit}
@ -533,50 +634,46 @@ const UseKeyAddEdit = () => {
</RadioGroup>
</FormItem>
{state.white_visible ? (
<Button
type="primary"
onClick={(e) => {
initUpload();
setState({
import_visible: true,
});
}}
>
导入白名单
</Button>
) : null}
<FormItem labelname="key数量" prop="quantity" id="quantity">
<div className="key_number">
<Ipt
onChange={(e) => {
setModel({
quantity: e,
});
}}
value={model.quantity}
disabled={model.style === 6}
placeholder={"请输入"}
labelWidth={"0px"}
maxLength={5}
height={"36px"}
width={"400px"}
alignment={"left"}
/>
<FormItem labelname="key发放" prop="quantity" id="quantity">
<Ipt
onChange={(e) => {
setModel({
quantity: e,
});
}}
value={model.quantity}
disabled={model.style == 6}
placeholder={"请输入"}
labelWidth={"0px"}
maxLength={5}
height={"36px"}
width={"400px"}
alignment={"left"}
/>
{state.white_visible ? (
<Button
type="primary"
onClick={(e) => {
importWhiteNameList();
setState({
import_visible: true,
});
}}
>
导入白名单
</Button>
) : null}
</div>
</FormItem>
{state.key_status === 1 ? null : (
<FormItem labelname="key剩余" prop="quantity" id="quantity">
<div className="line-value">{model.stock}</div>
</FormItem>
)}
<FormItem labelname="绑定类型" prop="bind_object" id="bind_object">
<Radio.Group
value={state.keyType}
disabled={true}
onChange={(e) => {
onCheckChange(e);
bindObjectCheck(e);
}}
>
<Radio value={1}>兑换码</Radio>
@ -617,9 +714,7 @@ const UseKeyAddEdit = () => {
countbarVisible={false}
isBorder={true}
isSwitch={false}
pageChange={(e) => {
pageChange(e);
}}
pageChange={(e) => {}}
checkChange={(selection) => {}}
ComponentHandler={(com, rowData, rowIndex) => {
if (com == "restrict") {
@ -636,13 +731,13 @@ const UseKeyAddEdit = () => {
}
//
if (com === "product") {
return coupon_range(rowData.product);
return goodsRange(rowData.product);
}
if (com == "edit") {
let str = (
<span
onClick={(e) => {
rowItemClick(rowData, rowIndex);
rowEditClick(rowData, rowIndex);
}}
style={{ color: "#2B66F2" }}
>
@ -662,7 +757,7 @@ const UseKeyAddEdit = () => {
>
<RadioGroup
disabled={state.isEdit}
onChange={(e) => onRepetitionChange(e)}
onChange={(e) => repeatGoodsCheck(e)}
value={model.allow_repetition}
>
<RadioButton value={1}></RadioButton>
@ -673,7 +768,7 @@ const UseKeyAddEdit = () => {
<FormItem labelname="是否允许亏损" id="allow_loss" prop="allow_loss">
<RadioGroup
disabled={state.isEdit}
onChange={(e) => onLossChange(e)}
onChange={(e) => lossCheck(e)}
value={model.allow_loss}
>
<RadioButton value={1}></RadioButton>
@ -684,19 +779,12 @@ const UseKeyAddEdit = () => {
</Card>
<div className="addkey-btn-group">
{state.isCancel ? null : (
<Button
type="primary"
onClick={() =>
setState({
audit_visible: true,
})
}
>
<Button type="primary" onClick={() => examineBtn()}>
提交审核
</Button>
)}
<Button type="normal" onClick={() => Cancel()}>
<Button type="normal" onClick={() => examineBackBtn()}>
取消
</Button>
</div>
@ -709,14 +797,14 @@ const UseKeyAddEdit = () => {
<Button
type="primary"
onClick={(e) => {
codeSubmit(e);
exchangeCouponBtnPop();
}}
>
提交
</Button>
<Button
onClick={(e) => {
closeDraw();
exchangeCouponCloseBtnPop();
}}
>
取消
@ -725,7 +813,7 @@ const UseKeyAddEdit = () => {
}
visible={state.drawerVisible}
onClose={(e) => {
closeDraw();
exchangeCouponCloseBtnPop();
}}
maskClosable={false}
>
@ -763,7 +851,7 @@ const UseKeyAddEdit = () => {
<div className="payType">
<RadioGroup
onChange={(e) => {
onPayTypeChange(e);
payCheck(e);
}}
value={state.payType}
className="audit-obj"
@ -786,7 +874,7 @@ const UseKeyAddEdit = () => {
<Button
type="primary"
onClick={(e) => {
onConfirm(e);
bigSubmit(e);
}}
>
确定
@ -826,7 +914,7 @@ const UseKeyAddEdit = () => {
<Button
type="primary"
onClick={(e) => {
onReCall(e);
cancelExamineBtn(e);
}}
>
确定

View File

@ -784,6 +784,7 @@ export default class acclist extends React.Component {
item.checked === true &&
(item.status === -1 || item.status === 7 || item.id === "" || !item.id)
);
// 第一步:判断是否是新增还是编辑
// 第二步:是否是 创建中或者驳回
if (this.state.key_status === 1) {

View File

@ -339,6 +339,37 @@ export default class acclist extends React.Component {
// this.getKeyList();
}
clickFn2222() {
this.props.history.push("/home/exchangecode-add");
sessionStorage.setItem("pathname2", "/home/exchangecode-add");
let activerou = [
{
pagetitle: "新建",
items: [
{
path: "/home/exchangecode-list",
name: "key列表管理",
},
{
path: "/home/exchangecode-add",
name: "新建key",
},
],
},
];
sessionStorage.setItem("keybatch_id", "");
sessionStorage.setItem("copyOpearo", 0);
//白名单状态为6
if (this.state.distdata.length > 0 && this.state.distdata[0].style == 6) {
sessionStorage.setItem("keyStyle", 1);
} else {
sessionStorage.setItem("keyStyle", 0);
}
sessionStorage.setItem("breakchangenav", JSON.stringify(activerou));
}
clickFn() {
sessionStorage.setItem("pathname2", "/home/key-addEdit");
let activerou = [