From 123435487c0013d22c50dd7bdd4352d7b3869648 Mon Sep 17 00:00:00 2001 From: zhangds Date: Thu, 1 Sep 2022 15:03:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1)=20=E5=A2=9E=E5=8A=A0=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UseCouponAddEdit/index.jsx | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index 7d785452..7ec3c489 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -211,6 +211,8 @@ const UseCouponAddEdit = forwardRef((props, ref) => { setQuantity(); }, [form_rule_data.reduce, form_rule_data.restrict]); + const table_el = useRef(null); + useImperativeHandle(ref, () => ({ submit: submit, })); @@ -438,6 +440,75 @@ const UseCouponAddEdit = forwardRef((props, ref) => { + + +
+ - - - { - onRankChange(e); - }} - /> - - -
-
- - onPageChange(e)} - emptyText={ - state.lodgingTable - ? "抱歉,暂无相关数据记录" - : "查询 请输入【分销商】或【计划名称】或【key】进行查询" - } - countChange={(e) => onCountChange(e)} - checkChange={(data) => selectionFun(data)} - ComponentHandler={(com, rowData) => { - if (com == "dates") { - return ( - - {rowData.begin_time} 至 {rowData.end_time} - - ); - } - }} - /> -
- - -
- - -
- - ); -}); - -export default UseCouponAddEdit; diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index 7ec3c489..ab30a791 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -1,17 +1,8 @@ import React, { forwardRef, useImperativeHandle, useRef } from "react"; import { useSetState } from "ahooks"; import { FixedSizeList } from "react-window"; -import * as math from "mathjs"; // https://github.com/josdejong/mathjs -import { isAmount, isPosIntNumber } from "@/tools/validate"; -import { - Card, - DateRangePicker, - Button, - LayoutRow as Row, - LayoutCol as Col, - LayoutGrid as Grids, - Select, -} from "zent"; +import { isAmount } from "@/tools/validate"; +import { Card, DateRangePicker, Button, Select } from "zent"; import moment from "moment"; import Ipt from "@/components/input/main"; @@ -259,11 +250,6 @@ const UseCouponAddEdit = forwardRef((props, ref) => { ); }; - function print(value) { - const precision = 14; - console.log(math.format(value, precision)); - } - // 判断是否可用 const setIsRestrict = () => { if (isAmount(form_rule_data.reduce) && isAmount(form_rule_data.full)) { @@ -275,17 +261,19 @@ const UseCouponAddEdit = forwardRef((props, ref) => { // 计算总预算 const setQuantity = () => { - print(math.multiply(math.bignumber(10), math.bignumber(10000000))); - - // subtract减法 multiply乘法 - let num = math.multiply( - Number(form_rule_data.restrict), - Number(form_rule_data.reduce) - ); - num = math.format(num, { precision: 14 }); - setForm_rule_data({ - quantity: num, - }); + if (isAmount(form_rule_data.reduce) && isAmount(form_rule_data.restrict)) { + let num = Math.mulNum( + Number(form_rule_data.reduce), + Number(form_rule_data.restrict) + ); + setForm_rule_data({ + quantity: num, + }); + } else { + setForm_rule_data({ + quantity: "", + }); + } }; return (
diff --git a/src/tools/number.js b/src/tools/number.js new file mode 100644 index 00000000..4307f8b7 --- /dev/null +++ b/src/tools/number.js @@ -0,0 +1,88 @@ +/** + * 加法运算 + * @param {Number} a + * @param {Number} b + * @example Math.addNum(0.3 , 0.6) // => 0.9 + */ +const addNum = (a, b) => { + var c, d, e + try { + c = a.toString().split('.')[1].length + } catch (f) { + c = 0 + } + try { + d = b.toString().split('.')[1].length + } catch (f) { + d = 0 + } + return (e = Math.pow(10, Math.max(c, d))), (mulNum(a, e) + mulNum(b, e)) / e +} + +/** + * 减法运算 + * @param {Number} a + * @param {Number} b + * @example Math.subNum(0.3 , 0.2) // => 0.1 + */ +const subNum = (a, b) => { + var c, d, e + try { + c = a.toString().split('.')[1].length + } catch (f) { + c = 0 + } + try { + d = b.toString().split('.')[1].length + } catch (f) { + d = 0 + } + return (e = Math.pow(10, Math.max(c, d))), (mulNum(a, e) - mulNum(b, e)) / e +} + +/** + * 乘法运算 + * @param {Number} a + * @param {Number} b + * @example Math.mulNum(0.3 , 1.5) // => 0.45 + */ +const mulNum = (a, b) => { + var c = 0, + d = a.toString(), + e = b.toString() + try { + c += d.split('.')[1].length + } catch (f) {} + try { + c += e.split('.')[1].length + } catch (f) {} + return (Number(d.replace('.', '')) * Number(e.replace('.', ''))) / Math.pow(10, c) +} + +/** + * 除法运算 + * @param {Number} a + * @param {Number} b + * @example Math.divNum(0.3 , 0.1) // => 3 + */ +const divNum = (a, b) => { + var c, + d, + e = 0, + f = 0 + try { + e = a.toString().split('.')[1].length + } catch (g) {} + try { + f = b.toString().split('.')[1].length + } catch (g) {} + return ( + (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