From c28ff0b1b358b398a75793dad04cdd2bdb950e49 Mon Sep 17 00:00:00 2001 From: lijuncheng Date: Fri, 5 Jan 2024 10:33:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E9=87=8F=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/basic.js | 4 +++- common/calc.js | 17 +++++++++++++++++ common/detail.js | 3 ++- common/record.js | 3 ++- pages/count/job/countDetail.vue | 5 ++++- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 common/calc.js diff --git a/common/basic.js b/common/basic.js index 83be91dc..4df664c5 100644 --- a/common/basic.js +++ b/common/basic.js @@ -3,6 +3,8 @@ export { maxPageSize } +import { calc } from '@/common/calc' + let jobStatusList = []; let itemStatusList = []; let locationTypeList = []; @@ -943,7 +945,7 @@ export function getDataSource(subList) { item.subList.push(newDetail); items.push(item) } else { - item.qty += Number(detail.qty) + item.qty = calc.add(item.qty,detail.qty) let newDetail = createDetailInfo(detail); // item.subList.push(newDetail); } diff --git a/common/calc.js b/common/calc.js new file mode 100644 index 00000000..358252ee --- /dev/null +++ b/common/calc.js @@ -0,0 +1,17 @@ +/* 解决js计算精度问题 */ +import { Decimal } from 'decimal.js';//引入 +class Calc { + add(num1,num2) { + return new Decimal(num1).add(new Decimal(num2)) + } + sub(num1,num2) { + return new Decimal(num1).sub(new Decimal(num2)) + } + mul(num1,num2) { + return new Decimal(num1).mul(new Decimal(num2)) + } + div(num1,num2) { + return new Decimal(num1).div(new Decimal(num2)) + } +} +export const calc = new Calc(); \ No newline at end of file diff --git a/common/detail.js b/common/detail.js index 1b566ecf..07d28531 100644 --- a/common/detail.js +++ b/common/detail.js @@ -1,3 +1,4 @@ + import { calc } from '@/common/calc' export function getDataSource(subList) { let items = []; subList.forEach(detail => { @@ -9,7 +10,7 @@ export function getDataSource(subList) { item.subList.push(newDetail); items.push(item) } else { - item.qty +=Number(detail.qty) + item.qty = calc.add(item.qty,detail.qty) let newDetail = createDetailInfo(detail); // item.subList.push(newDetail); } diff --git a/common/record.js b/common/record.js index 45490b12..6b310f39 100644 --- a/common/record.js +++ b/common/record.js @@ -5,6 +5,7 @@ import { import { getDirectoryItemArray, } from '@/common/directory.js'; +import { calc } from '@/common/calc' export function createItemInfo(balance, pack) { let item = { @@ -40,7 +41,7 @@ export function calcHandleQty(detailSource) { item.qty = 0; for (let detail of item.subList) { if (detail != undefined && detail.scaned) { - item.qty = item.qty + Number(detail.qty) + item.qty = calc.add(item.qty,detail.qty); } } } diff --git a/pages/count/job/countDetail.vue b/pages/count/job/countDetail.vue index 7d940707..75d50c9c 100644 --- a/pages/count/job/countDetail.vue +++ b/pages/count/job/countDetail.vue @@ -23,6 +23,7 @@ + {{detailSource[0].qty}} @@ -72,6 +73,7 @@ import { getCountStageName } from '@/common/directory.js'; + import { calc } from '@/common/calc' import winScanButton from '@/mycomponents/scan/winScanButton.vue' import winScanPack from '@/mycomponents/scan/winScanPack.vue' @@ -202,7 +204,7 @@ item.subList.push(newDetail); items.push(item) } else { - item.qty += detail.qty + item.qty = calc.add(item.qty,detail.qty) let newDetail = this.createDetailInfo(detail); // item.subList.push(newDetail); } @@ -250,6 +252,7 @@ item.handleQty = 0; for (let detail of item.subList) { if (detail != undefined && detail.scaned) { + console.log("数量",Number(detail.qty)) item.handleQty += Number(detail.qty) } }