diff --git a/README.md b/README.md index a64340fa..56e19645 100644 --- a/README.md +++ b/README.md @@ -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 ************************/ +``` \ No newline at end of file diff --git a/src/pages/plan/key/UseKeyAddEdit.jsx b/src/pages/plan/key/UseKeyAddEdit.jsx index 056f1958..7e3dfcc1 100644 --- a/src/pages/plan/key/UseKeyAddEdit.jsx +++ b/src/pages/plan/key/UseKeyAddEdit.jsx @@ -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 {arr}; }; - const rowItemClick = () => {}; - const onRepetitionChange = () => {}; - const onLossChange = () => {}; - const Cancel = () => { - Sweetalert.confirm({ - type: "warning", - closeBtn: true, - title: "确认操作", - content:

是否取消本次操作?

, - onConfirm: () => { - window.history.back(); - }, - onCancel: () => {}, - className: "questModal", - parentComponent: this, - }); - }; - const onReCall = () => {}; - /** - * - * @param {0新增addKeysBatchInfo,1编辑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:

是否取消本次操作?

, + onConfirm: () => { + window.history.back(); + }, + onCancel: () => {}, + className: "questModal", + parentComponent: this, + }); + }; + //#endRegion event handler *******************/ + + //#region submit ***************************/ + /** + * + * @param {0新增addKeysBatchInfo,1编辑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 (
{ { - onStyleChange(e); + styleChange(e); }} value={model.style} disabled={state.isEdit} @@ -533,50 +634,46 @@ const UseKeyAddEdit = () => { - {state.white_visible ? ( - - ) : null} + +
+ { + setModel({ + quantity: e, + }); + }} + value={model.quantity} + disabled={model.style === 6} + placeholder={"请输入"} + labelWidth={"0px"} + maxLength={5} + height={"36px"} + width={"400px"} + alignment={"left"} + /> - - { - setModel({ - quantity: e, - }); - }} - value={model.quantity} - disabled={model.style == 6} - placeholder={"请输入"} - labelWidth={"0px"} - maxLength={5} - height={"36px"} - width={"400px"} - alignment={"left"} - /> + {state.white_visible ? ( + + ) : null} +
- {state.key_status === 1 ? null : ( - -
{model.stock}
-
- )} - { - onCheckChange(e); + bindObjectCheck(e); }} > 兑换码 @@ -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 = ( { - rowItemClick(rowData, rowIndex); + rowEditClick(rowData, rowIndex); }} style={{ color: "#2B66F2" }} > @@ -662,7 +757,7 @@ const UseKeyAddEdit = () => { > onRepetitionChange(e)} + onChange={(e) => repeatGoodsCheck(e)} value={model.allow_repetition} > @@ -673,7 +768,7 @@ const UseKeyAddEdit = () => { onLossChange(e)} + onChange={(e) => lossCheck(e)} value={model.allow_loss} > @@ -684,19 +779,12 @@ const UseKeyAddEdit = () => {
{state.isCancel ? null : ( - )} -
@@ -709,14 +797,14 @@ const UseKeyAddEdit = () => {