// pages/message/index.js const util = require('../../../utils/util') const math = require('../../../utils/math') Component({ options: { addGlobalClass: true, multipleSlots: true }, properties: { item: { type: Object, value: null, observer(value) { this.setValues(value); }}, index: { type: Number, value: 0 }, status: { type: Number, value: 0 } }, data: { valued: false, focus: 0, fileList: [] }, methods: { setValues: function(value){ if(value && !this.data.valued){ this.data.item.settleUnitPrice = value.unitPrice this.statAmount() wx.nextTick(() => { this.triggerEvent('change', {index: this.data.index, item: this.data.item}); }) if(value.weightNoteImages){ this.data.fileList = [] for (let index = 0; index < value.weightNoteImages.length; index++) { this.data.fileList.push({url: value.weightNoteImages[index]}) } this.setData({fileList: this.data.fileList}) } this.data.valued = true } }, bindInput: function (e) { this.data.item[e.currentTarget.id] = e.detail if(e.currentTarget.id == 'grossWeight' || e.currentTarget.id == 'tareWeight'){ if(Number(this.data.item.grossWeight) > 0){ if(Number(this.data.item.tareWeight) > 0){ if(Number(this.data.item.grossWeight) > Number(this.data.item.tareWeight)){ var netWeight = math.minus(this.data.item.grossWeight, this.data.item.tareWeight) var estimatedAmount = math.times(netWeight, this.data.item.unitPrice).toFixed(2) this.setData({['item.netWeight']: netWeight, ['item.estimatedAmount']: estimatedAmount}) } else { this.setData({['item.netWeight']: null, ['item.estimatedAmount']: null}) } } else { this.setData({['item.netWeight']: Number(this.data.item.grossWeight), ['item.estimatedAmount']: null}) } } else { this.setData({['item.netWeight']: null, ['item.estimatedAmount']: null}) } } else if(e.currentTarget.id == 'deductPercent'){ if(util.isEmpty(e.detail) || Number(e.detail) <= 0){ this.data.item.deductWeight = null this.data.item.deductPercent = null } else { this.data.item.deductWeight = math.divide(math.times(this.data.item.netWeight, Number(e.detail)), 100).toFixed(2) } this.statAmount() } else if(e.currentTarget.id == 'deductWeight'){ if(util.isEmpty(e.detail) || Number(e.detail) <= 0){ this.data.item.deductWeight = null this.data.item.deductPercent = null } else { this.data.item.deductPercent = math.times(math.divide(Number(e.detail), this.data.item.netWeight), 100).toFixed(2) } this.statAmount() } else if(e.currentTarget.id == 'settleUnitPrice'){ this.statAmount() } else if(e.currentTarget.id == 'netWeight'){ var estimatedAmount = math.times(this.data.item.netWeight, this.data.item.unitPrice).toFixed(2) this.setData({['item.estimatedAmount']: estimatedAmount}) } wx.nextTick(() => { this.triggerEvent('change', {index: this.data.index, item: this.data.item}); }) }, statAmount: function(){ this.data.item.settleWeight = this.data.item.netWeight if(util.isEmpty(this.data.item.settleWeight) || Number(this.data.item.settleWeight) <= 0){ return } if(!util.isEmpty(this.data.item.deductWeight)){ this.data.item.settleWeight = math.minus(this.data.item.netWeight, this.data.item.deductWeight) } if(!util.isEmpty(this.data.item.settleUnitPrice) && Number(this.data.item.settleUnitPrice) > 0){ this.data.item.settlePrice = math.times(this.data.item.settleWeight, this.data.item.settleUnitPrice) } else { this.data.item.settlePrice = null } this.setData({ item: this.data.item }) }, changeDeductType: function(e){ var type = Number(e.currentTarget.dataset.type) this.setData({ ['item.sign']: type, focus: type }) console.log(this.data.item) }, fileChange: function({detail}){ this.data.fileList = detail.fileList var imageUrls = [] for (let index = 0; index < this.data.fileList.length; index++) { imageUrls.push(this.data.fileList[index].url) } this.data.item.weightNoteImages = imageUrls wx.nextTick(() => { this.triggerEvent('change', {index: this.data.index, item: this.data.item}); }) } } })