Browse Source

四舍五入

devlop
邓雄飞 4 years ago
parent
commit
ad048c6292
3 changed files with 19 additions and 8 deletions
  1. 16
      pages/submit-quotation/index.vue
  2. 2
      utils/hook.js
  3. 9
      utils/index.js

16
pages/submit-quotation/index.vue

@ -148,7 +148,7 @@
<view class=""><view class="submit-popup-title">购买数量()</view></view>
<view class="submit-number-line">
<uni-number-box v-model="addObj.quantity"></uni-number-box>
<text class="submit-number-text">预估重量{{ Math.round(addObj.gramWeight * addObj.width * addObj.length * addObj.quantity * 1e-12, 4) }}</text>
<text class="submit-number-text">预估重量{{ round(addObj.gramWeight * addObj.width * addObj.length * addObj.quantity * 1e-12, 4) }}</text>
</view>
</view>
<view class=""><button class="submit-btn submit-number-btn" type="primary" @click="sureModifyPaper()">确认修改纸品</button></view>
@ -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)
}
},
//

2
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
})

9
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)
}
Loading…
Cancel
Save