diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index 9dbc4c5b..85385656 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -305,6 +305,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }); } else { if (editData && editData !== "") { + console.log("editData =>", editData); setState({ id: editData.id, status: editData.status, diff --git a/src/components/UseExchangeAddEdit/index.jsx b/src/components/UseExchangeAddEdit/index.jsx index 445f2066..65a46ec6 100644 --- a/src/components/UseExchangeAddEdit/index.jsx +++ b/src/components/UseExchangeAddEdit/index.jsx @@ -143,13 +143,6 @@ const UseExchangeAddEdit = forwardRef((props, ref) => { const codeRuleEl = useRef(null); const table_el = useRef(null); - useEffect(() => { - console.log("兑换码编辑数据 =>", editData); - if (editData && editData !== "") { - editFun(); - } - }, []); - const [state, setState] = useSetState({ rankOptions: [], rank: [], @@ -162,6 +155,8 @@ const UseExchangeAddEdit = forwardRef((props, ref) => { scopePopType: "", productData: [], table_index: -1, + id: "", + status: "", }); const [codeInfo, setCodeInfo] = useSetState({ code_name: "", @@ -177,9 +172,81 @@ const UseExchangeAddEdit = forwardRef((props, ref) => { clearCouponForm, })); - const submit = () => {}; - const getModel = () => {}; - const clearCouponForm = () => {}; + useEffect(() => { + console.log("兑换码编辑数据 =>", editData); + if (editData && editData !== "") { + setState({ + id: editData.id, + status: editData.status, + }); + editFun(); + } + }, []); + + const submit = () => { + let validator = false; + + if (codeInfoEl.current.validator()) { + validator = true; + } else { + validator = false; + } + + if (codeRuleEl.current.validator()) { + validator = true; + } else { + validator = false; + } + if (validator) { + if (state.rank.length > 0) { + let arr = state.tableData.filter((item) => item.checked); + // 第二步:最终的校验 + // 所选商品库存和总发行数校验 + let sum = 0; + arr.map((item) => { + sum += parseInt(item.quantity); + }); + if (sum < Number(codeInfo.issued)) { + Notify.error("所选商品库存总数小于发放量"); + return false; + } + } else { + Notify.error(`请选择商品范围`); + return false; + } + } + + return validator; + }; + const getModel = () => { + let param = { + id: state.id, + status: state.status, + title: codeInfo.code_name, + describe: codeInfo.describe, + begin_time: codeInfo.date_time[0], + end_time: codeInfo.date_time[1], + quantity: codeInfo.issued, + restrict: codeInfo.restrict, + range: codeInfo.range, + product: { + legal: [], + reduce: [], + }, + }; + 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, + }; + }); + return param; + }; + const clearCouponForm = () => { + setState({ id: "", status: "" }); + }; const editFun = () => { setCodeInfo({ code_name: editData.title, @@ -610,55 +677,66 @@ const UseExchangeAddEdit = forwardRef((props, ref) => { - - - onPageChange(e)} - emptyText={ - state.lodgingTable - ? "抱歉,暂无相关数据记录" - : "查询 请输入【分销商】或【计划名称】或【key】进行查询" - } - countChange={(e) => onCountChange(e)} - checkChange={(data) => selectionFun(data)} - ComponentHandler={(com, rowData, rowIndex) => { - if (com === "opearo") { - return ( -
- productEditShow(rowData, rowIndex)} - > - 编辑 - -
- ); + + + onPageChange(e)} + emptyText={ + state.lodgingTable + ? "抱歉,暂无相关数据记录" + : "查询 请输入【分销商】或【计划名称】或【key】进行查询" } + countChange={(e) => onCountChange(e)} + checkChange={(data) => selectionFun(data)} + ComponentHandler={(com, rowData, rowIndex) => { + if (com === "opearo") { + return ( +
+ productEditShow(rowData, rowIndex)} + > + 编辑 + +
+ ); + } - if (com === "type") { - return {rowData.type === 1 ? "商品" : "立减金"}; - } - }} - /> -
+ if (com === "type") { + return {rowData.type === 1 ? "商品" : "立减金"}; + } + + if (com === "cost_price") { + return ( + <> + {rowData.type === 2 + ? rowData.official_price + : rowData.cost_price} + + ); + } + }} + /> +
+ ", param); let tempdata = this.state.couponData; // 优惠券编辑 if (this.state.rowIndex > -1) { @@ -644,8 +645,21 @@ export default class acclist extends React.Component { // 兑换码 let ex_validator = this.refs.addEditExChangeEl.submit(); if (ex_validator) { - let param = this.refs.addEditCouponEl.getModel(); + let param = this.refs.addEditExChangeEl.getModel(); console.log("兑换码 param =>", param); + let tempdata = this.state.distdata; + // 优惠券编辑 + if (this.state.rowIndex > -1) { + tempdata[this.state.rowIndex] = param; + this.setState({ distdata: tempdata }); + } else { + // 优惠券新增 + tempdata.push(param); + this.setState({ distdata: tempdata }); + } + this.setState({ + drawerVisible: false, + }); } } } @@ -814,46 +828,29 @@ export default class acclist extends React.Component { // 兑换码 exchangeSubmit() { // 第一步:整理数据 编辑兑换码数据 - // 注意!!!使用 getSelectData 方法获取table不需判断checked 为true !!!!!! - let selection = this.refs.bindObj.getSelectData(); - let formdata = selection.filter( + let editExchangeData = this.state.distdata.filter( (item) => - item.status === -1 || item.status === 7 || item.id === "" || !item.id + item.checked === true && + (item.status === -1 || item.status === 7 || item.id === "" || !item.id) ); - // 转换数据 - let dataCopy = _.cloneDeep(formdata); - dataCopy.map((item) => { - item.products = item.product; - }); - dataCopy.map((item) => - item.products.map(() => { - item.product = { - legal: item.products.filter((item2) => item2.type == 1), - reduce: item.products - .filter((item3) => item3.type === 2) - .map((item4) => item4.origin), - }; - }) - ); - dataCopy.map((item) => { - delete item.products; - }); // 第二步:是否是 创建中或者驳回 if (this.state.key_status === 1) { // 第三步:是否有原数据 - let arr = dataCopy.filter((item) => item.id && item.id !== ""); + let arr = editExchangeData.filter((item) => item.id && item.id !== ""); if (arr.length > 0) { // 编辑接口 - this.couponExchangeSubmitApi(1, dataCopy); + this.couponExchangeSubmitApi(1, editExchangeData); } else { // 新增接口 - let addArr = dataCopy.filter((item) => !item.id); + let addArr = this.state.distdata.filter( + (item) => item.checked === true && !item.id + ); this.couponExchangeSubmitApi(0, addArr); } } else { // 其它状态 - this.couponExchangeSubmitApi(1, dataCopy); + this.couponExchangeSubmitApi(1, editExchangeData); } } @@ -907,6 +904,7 @@ export default class acclist extends React.Component { } rowItemClick(row, rowIndex) { + console.log("row =>", row); // 编辑兑换码 if (this.state.keyType === 1) { this.setState({