纸通宝SAAS仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

103 lines
3.9 KiB

// 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: {
focus: 0,
fileList: []
},
methods: {
setValues: function(value){
if(value && 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})
}
},
bindInput: function (e) {
this.data.item[e.currentTarget.id] = e.detail.value
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.value) || Number(e.detail.value) <= 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.value)), 100).toFixed(2)
}
this.statAmount()
} else if(e.currentTarget.id == 'deductWeight'){
if(util.isEmpty(e.detail.value) || Number(e.detail.value) <= 0){
this.data.item.deductWeight = null
this.data.item.deductPercent = null
} else {
this.data.item.deductPercent = math.times(math.divide(Number(e.detail.value), this.data.item.netWeight), 100).toFixed(2)
}
this.statAmount()
} else if(e.currentTarget.id == 'settleUnitPrice'){
this.statAmount()
}
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.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){
this.setData({ ['item.sign']: e.currentTarget.dataset.type, focus: e.currentTarget.dataset.type })
},
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.weightNoteImage = imageUrls
wx.nextTick(() => {
this.triggerEvent('change', {index: this.data.index, item: this.data.item});
})
}
}
})