From ad048c6292613288918184990f11580d9cf6d22a Mon Sep 17 00:00:00 2001 From: dengxiongfei Date: Tue, 25 Jan 2022 21:59:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9B=E8=88=8D=E4=BA=94=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/submit-quotation/index.vue | 16 +++++++++------- utils/hook.js | 2 +- utils/index.js | 9 +++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pages/submit-quotation/index.vue b/pages/submit-quotation/index.vue index 77d5d1f..0f03fb7 100644 --- a/pages/submit-quotation/index.vue +++ b/pages/submit-quotation/index.vue @@ -148,7 +148,7 @@ 购买数量(张) - 预估重量:{{ Math.round(addObj.gramWeight * addObj.width * addObj.length * addObj.quantity * 1e-12, 4) }} + 预估重量:{{ round(addObj.gramWeight * addObj.width * addObj.length * addObj.quantity * 1e-12, 4) }} @@ -220,6 +220,7 @@ import { back, go2 } from '@/utils/hook.js' import qnHeader from '@/components/qn-header/qn-header.vue' import uGap from '@/components/u-gap/u-gap.vue' import { updateEnquiryReply, enquiryReplyDetail } from '@/apis/trade' +import { round } from '@/utils/index.js' export default { components: { @@ -274,6 +275,7 @@ export default { }, methods: { back, + round, // 获取详情 getDetail(id) { enquiryReplyDetail(id) @@ -289,7 +291,7 @@ export default { // 计算每个纸品的重量 for (let i = 0; i < this.upDataObj.itemList.length; i++) { let target = this.upDataObj.itemList[i] - target.weight = Math.round(target.gramWeight * target.width * target.length * target.quantity * 1e-12, 4) + target.weight = round(target.gramWeight * target.width * target.length * target.quantity * 1e-12, 4) } } }) @@ -396,7 +398,7 @@ export default { sureModifyPaper() { this.$refs.popup.close() // 同时更改重量 - this.addObj.weight = Math.round(this.addObj.gramWeight * this.addObj.width * this.addObj.length * this.addObj.quantity * 1e-12, 4) + this.addObj.weight = round(this.addObj.gramWeight * this.addObj.width * this.addObj.length * this.addObj.quantity * 1e-12, 4) this.upDataObj.itemList[this.modifyIndex] = JSON.parse(JSON.stringify(this.addObj)) this.upDataObj = JSON.parse(JSON.stringify(this.upDataObj)) @@ -411,8 +413,8 @@ export default { pricesSure() { this.$set(this.upDataObj.itemList[this.pricesIndex], 'otherFee', this.prices.otherFee) this.$set(this.upDataObj.itemList[this.pricesIndex], 'unitFee', this.prices.unitFee) - var abs = Math.round(this.prices.unitFee * this.prices.weight + (this.prices.otherFee - 0), 2) - this.$set(this.upDataObj.itemList[this.pricesIndex], 'totalPrice', Math.round(abs, 2)) + var abs = round(this.prices.unitFee * this.prices.weight + (this.prices.otherFee - 0), 2) + this.$set(this.upDataObj.itemList[this.pricesIndex], 'totalPrice', round(abs, 2)) this.upDataObj = JSON.parse(JSON.stringify(this.upDataObj)) this.$refs.popupPrice.close() console.log(this.upDataObj.itemList) @@ -423,9 +425,9 @@ export default { this.upDataObj.otherFee = 0 for (let i = 0; i < this.upDataObj.itemList.length; i++) { var totalAllPrice = parseFloat(this.upDataObj.totalAllPrice) + parseFloat(this.upDataObj.itemList[i].totalPrice) - this.upDataObj.totalAllPrice = Math.round(totalAllPrice, 2) + this.upDataObj.totalAllPrice = round(totalAllPrice, 2) var otherFee = parseFloat(this.upDataObj.otherFee) + parseFloat(this.upDataObj.itemList[i].otherFee) - this.upDataObj.otherFee = Math.round(otherFee, 2) + this.upDataObj.otherFee = round(otherFee, 2) } }, //提交报价 diff --git a/utils/hook.js b/utils/hook.js index 73ded35..8c3b62e 100644 --- a/utils/hook.js +++ b/utils/hook.js @@ -20,7 +20,7 @@ export function tab2(tabPage) { * @return {null} */ export function back() { - if (getCurrentPages().length > 0) { + if (getCurrentPages().length > 1) { uni.navigateBack({ delta: 1 }) diff --git a/utils/index.js b/utils/index.js index 6cae21e..7d7a828 100644 --- a/utils/index.js +++ b/utils/index.js @@ -151,3 +151,12 @@ export const makeSocket = async ({ pageInfo = '', retry = false }) => { return socket } + +/** + * 正数的四舍五入 + * @value {number} num 需要四舍五入的数字 + * @value {number} precision 小数点后保留的位数 + */ +export function round(number, precision) { + return Math.round(+number + 'e' + precision) / Math.pow(10, precision) +}