diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index ba1eb643..7c4a3134 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -6,7 +6,6 @@ import React, { } from "react"; import { useSetState } from "ahooks"; import { FixedSizeList } from "react-window"; -import { isAmount } from "@/tools/validate"; import { Card, DateRangePicker, Button, Select, Notify } from "zent"; import moment from "moment"; @@ -14,11 +13,12 @@ import Ipt from "@/components/input/main"; import Form from "@/components/form/main"; import FormItem from "@/components/form-item/main"; import Grid from "@/components/gird/main.js"; - import UseGoodsScopePop from "../UseGoodsScopePop/index"; -import { getProductInfoSelect, handelResponse } from "@/assets/api.js"; +import { isAmount } from "@/tools/validate"; +import { getProductInfoSelect, handelResponse } from "@/assets/api.js"; +import { mulNum } from "@/tools/number"; import "./style.less"; const tableColumn = [ @@ -186,6 +186,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { showScopePop: false, scopePopType: "", productData: [], + selectGoodsScopeData: [], }); // 基础信息 @@ -225,19 +226,22 @@ const UseCouponAddEdit = forwardRef((props, ref) => { const submit = () => { // 基础信息 let el_setup1 = form_info_el.current.validator(); - console.log("el_setup1 =>", el_setup1); - console.log("form_info_data =>", form_info_data); + // console.log("el_setup1 =>", el_setup1); + // console.log("form_info_data =>", form_info_data); // 发放规则 let el_setup2 = form_rule_el.current.validator(); - console.log("el_setup2 =>", el_setup2); - console.log("form_rule_data =>", form_rule_data); + // console.log("el_setup2 =>", el_setup2); + // console.log("发放规则 =>", form_rule_data); // 商品范围 + console.log("用户商品范围 =>", state.selectGoodsScopeData); }; const onReturn = () => {}; - const onChangeCombinedDate = () => {}; + const onChangeCombinedDate = (e) => { + setForm_info_data({ date_time: e }); + }; const onDisabledRange = (date, type) => { let disabled = false; if (type === "end") { @@ -250,7 +254,9 @@ const UseCouponAddEdit = forwardRef((props, ref) => { }; const onPageChange = () => {}; const onCountChange = () => {}; - const selectionFun = () => {}; + const selectionFun = (e) => { + setState({ selectGoodsScopeData: e }); + }; const onRankChange = () => {}; const addProduct = (type) => { // 第一步:获取直连天下的商品数据需要分销商 id @@ -329,7 +335,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { // 计算总预算 const setQuantity = () => { if (isAmount(form_rule_data.reduce) && isAmount(form_rule_data.restrict)) { - let num = Math.mulNum( + let num = mulNum( Number(form_rule_data.reduce), Number(form_rule_data.restrict) ); @@ -352,7 +358,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => { // 优惠券弹窗 提交 const scopePopSubmit = (data) => { - console.log("data =>", data); + console.log("scopePopSubmit =>", data); }; return ( diff --git a/src/components/UseGoodsScopePop/index.jsx b/src/components/UseGoodsScopePop/index.jsx index 01f4321c..a925cd0f 100644 --- a/src/components/UseGoodsScopePop/index.jsx +++ b/src/components/UseGoodsScopePop/index.jsx @@ -20,9 +20,10 @@ const UseGoodsScopePop = forwardRef((props, ref) => { // 提交数据 const submitPop = async () => { - let data = null; + let scope_table_data = []; let temp = null; let concatData = []; + // 第一步:判断是立减金还是新建商品 let visible = false; if (type === "addProduct") { @@ -30,13 +31,16 @@ const UseGoodsScopePop = forwardRef((props, ref) => { } else { visible = await knockGold_el.current.submit(); } - console.log("visible =>", visible); - if (visible) { - if (type === "addProduct") { - data = sessionStorage.getItem("productData"); - console.log("商品data =>", JSON.parse(data)); + + try { + if (visible) { + if (type === "addProduct") { + scope_table_data = sessionStorage.getItem("productData"); + } + submit(JSON.parse(scope_table_data)); } - submit(1); + } catch (err) { + console.log("err =>", err); } }; diff --git a/src/tools/number.js b/src/tools/number.js index 4307f8b7..9f42a3ac 100644 --- a/src/tools/number.js +++ b/src/tools/number.js @@ -4,20 +4,20 @@ * @param {Number} b * @example Math.addNum(0.3 , 0.6) // => 0.9 */ -const addNum = (a, b) => { - var c, d, e +export const addNum = (a, b) => { + var c, d, e; try { - c = a.toString().split('.')[1].length + c = a.toString().split(".")[1].length; } catch (f) { - c = 0 + c = 0; } try { - d = b.toString().split('.')[1].length + d = b.toString().split(".")[1].length; } catch (f) { - d = 0 + d = 0; } - return (e = Math.pow(10, Math.max(c, d))), (mulNum(a, e) + mulNum(b, e)) / e -} + return (e = Math.pow(10, Math.max(c, d))), (mulNum(a, e) + mulNum(b, e)) / e; +}; /** * 减法运算 @@ -25,20 +25,20 @@ const addNum = (a, b) => { * @param {Number} b * @example Math.subNum(0.3 , 0.2) // => 0.1 */ -const subNum = (a, b) => { - var c, d, e +export const subNum = (a, b) => { + var c, d, e; try { - c = a.toString().split('.')[1].length + c = a.toString().split(".")[1].length; } catch (f) { - c = 0 + c = 0; } try { - d = b.toString().split('.')[1].length + d = b.toString().split(".")[1].length; } catch (f) { - d = 0 + d = 0; } - return (e = Math.pow(10, Math.max(c, d))), (mulNum(a, e) - mulNum(b, e)) / e -} + return (e = Math.pow(10, Math.max(c, d))), (mulNum(a, e) - mulNum(b, e)) / e; +}; /** * 乘法运算 @@ -46,18 +46,20 @@ const subNum = (a, b) => { * @param {Number} b * @example Math.mulNum(0.3 , 1.5) // => 0.45 */ -const mulNum = (a, b) => { +export const mulNum = (a, b) => { var c = 0, d = a.toString(), - e = b.toString() + e = b.toString(); try { - c += d.split('.')[1].length + c += d.split(".")[1].length; } catch (f) {} try { - c += e.split('.')[1].length + c += e.split(".")[1].length; } catch (f) {} - return (Number(d.replace('.', '')) * Number(e.replace('.', ''))) / Math.pow(10, c) -} + return ( + (Number(d.replace(".", "")) * Number(e.replace(".", ""))) / Math.pow(10, c) + ); +}; /** * 除法运算 @@ -65,24 +67,20 @@ const mulNum = (a, b) => { * @param {Number} b * @example Math.divNum(0.3 , 0.1) // => 3 */ -const divNum = (a, b) => { +export const divNum = (a, b) => { var c, d, e = 0, - f = 0 + f = 0; try { - e = a.toString().split('.')[1].length + e = a.toString().split(".")[1].length; } catch (g) {} try { - f = b.toString().split('.')[1].length + f = b.toString().split(".")[1].length; } catch (g) {} return ( - (c = Number(a.toString().replace('.', ''))), - (d = Number(b.toString().replace('.', ''))), + (c = Number(a.toString().replace(".", ""))), + (d = Number(b.toString().replace(".", ""))), mulNum(c / d, Math.pow(10, f - e)) - ) -} -Math.divNum = divNum -Math.addNum = addNum -Math.subNum = subNum -Math.mulNum = mulNum + ); +};