diff --git a/src/components/counter/index.tsx b/src/components/counter/index.tsx index 83de8c9..e28250b 100644 --- a/src/components/counter/index.tsx +++ b/src/components/counter/index.tsx @@ -37,13 +37,21 @@ const Counter = ({ minNum = 0, maxNum = 10000, step = 1, digits = 0, defaultNum return parseFloat(num) } + // 判断是否整数类型 + function isInteger(obj) { + return (obj | 0) === obj + } + // 加号 const onPlus = (event) => { event.stopPropagation() if (disable) { return false } let num_res = Big(value).add(step).toNumber() - num_res = num_res >= maxNum ? maxNum : num_res num_res = formatDigits(num_res) + if (!isInteger(num_res)) { + num_res = Math.trunc(num_res) + } + num_res = num_res >= maxNum ? maxNum : num_res setValue(num_res) onClickBtn?.(parseFloat(num_res)) } @@ -51,7 +59,14 @@ const Counter = ({ minNum = 0, maxNum = 10000, step = 1, digits = 0, defaultNum const minus = (event) => { event.stopPropagation() if (disable) { return false } - let num_res = Big(value).minus(step).toNumber() + let num_res = value + // let num_res = Big(value).minus(step).toNumber() + if (!isInteger(num_res)) { + num_res = Math.trunc(num_res) + } + else { + num_res = Big(value).minus(step).toNumber() + } num_res = num_res < minNum ? minNum : num_res setValue(num_res) onClickBtn?.(parseFloat(num_res)) diff --git a/src/components/goodsItem/index.tsx b/src/components/goodsItem/index.tsx index c7dd541..62a27fe 100644 --- a/src/components/goodsItem/index.tsx +++ b/src/components/goodsItem/index.tsx @@ -44,7 +44,7 @@ const GoodsItem = (props: props) => { } if (props.modeFont == 1) { if (Number(res) < 0) { - setValue({ count: 0.5 }) + setValue({ count: '' }) } } if (props.modeFont == 2) { diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index b1399a6..2f57a9e 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -145,8 +145,8 @@ const Index = () => { item.buyNums = 1 } if (search.modeId == 1) { - item.nums = 0.5 - item.buyNums = 0.5 + item.nums = 0.3 + item.buyNums = 0.3 } if (search.modeId == 2) { item.nums = 3 @@ -185,7 +185,13 @@ const Index = () => { const reduceNums = useCallback((item) => { goodList.map((it) => { if (item.id === it.id) { - item.nums-- + if (isInteger(item.nums)) { + item.nums-- + } + else { + item.nums = Math.trunc(item.nums) + } + if (search.modeId == 0) { if (item.nums < 1) { it.showInput = false @@ -193,9 +199,9 @@ const Index = () => { } } if (search.modeId == 1) { - if (item.nums < 0.5) { + if (item.nums < 0.3) { it.showInput = false - it.nums = 0.5 + it.nums = 0.3 } } if (search.modeId == 2) { @@ -214,7 +220,13 @@ const Index = () => { const handPlus = useCallback((item) => { goodList.map((it) => { if (item.id === it.id) { - it.nums++ + if (isInteger(item.nums)) { + item.nums++ + } + else { + item.nums++ + item.nums = Math.trunc(item.nums) + } } return item }) @@ -289,11 +301,11 @@ const Index = () => { else if (search.modeId == 0 && (e.detail.value != '' || Number(e.detail.value) > 0)) { item.nums = e.detail.value } - if (search.modeId == 1 && Number(e.detail.value) < 0.5) { - item.nums = 0.5 + if (search.modeId == 1 && Number(e.detail.value) < 0.3) { + item.nums = 0.3 item.showInput = false } - else if (search.modeId == 1 && Number(e.detail.value) >= 0.5) { + else if (search.modeId == 1 && Number(e.detail.value) >= 0.3) { if (isInteger(Number(e.detail.value))) { item.nums = Number(e.detail.value) } diff --git a/src/pages/searchPage/index.tsx b/src/pages/searchPage/index.tsx index f87663a..a478c10 100644 --- a/src/pages/searchPage/index.tsx +++ b/src/pages/searchPage/index.tsx @@ -88,8 +88,8 @@ const SearchPage = () => { item.buyNums = 1 } if (search.modeId == 1) { - item.nums = 0.5 - item.buyNums = 0.5 + item.nums = 0.3 + item.buyNums = 0.3 } if (search.modeId == 2) { item.nums = 3 @@ -158,9 +158,13 @@ const SearchPage = () => { const handPlus = useCallback((item) => { goodList.map((it) => { if (item.id === it.id) { - // if (it.nums > item.buyNums) { - it.nums++ - // } + if (isInteger(item.nums)) { + item.nums++ + } + else { + item.nums++ + item.nums = Math.trunc(item.nums) + } } return item }) @@ -197,7 +201,13 @@ const SearchPage = () => { const reduceNums = useCallback((item) => { goodList.map((it) => { if (item.id === it.id) { - item.nums-- + if (isInteger(item.nums)) { + item.nums-- + } + else { + item.nums = Math.trunc(item.nums) + } + if (search.modeId == 0) { if (item.nums < 1) { it.showInput = false @@ -205,9 +215,9 @@ const SearchPage = () => { } } if (search.modeId == 1) { - if (item.nums < 0.5) { + if (item.nums < 0.3) { it.showInput = false - it.nums = 0.5 + it.nums = 0.3 } } if (search.modeId == 2) { @@ -321,11 +331,11 @@ const SearchPage = () => { else if (search.modeId == 0 && (e.detail.value != '' || Number(e.detail.value) > 0)) { item.nums = e.detail.value } - if (search.modeId == 1 && Number(e.detail.value) < 0.5) { - item.nums = 0.5 + if (search.modeId == 1 && Number(e.detail.value) < 0.3) { + item.nums = 0.3 item.showInput = false } - else if (search.modeId == 1 && Number(e.detail.value) >= 0.5) { + else if (search.modeId == 1 && Number(e.detail.value) >= 0.3) { if (isInteger(Number(e.detail.value))) { item.nums = Number(e.detail.value) } diff --git a/src/pages/shopping/config.ts b/src/pages/shopping/config.ts index 39df6bb..6eb79e7 100644 --- a/src/pages/shopping/config.ts +++ b/src/pages/shopping/config.ts @@ -6,8 +6,8 @@ export const selectList = { eunit: 'm', step: 1, digits: 2, - minNum: 0.5, - maxNum: 9.99, + minNum: 0.3, + maxNum: 100000, defaultNum: 1, }, 2: {