纸通宝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.
 

90 lines
3.3 KiB

// pages/message/index.js
const util = require('../../../utils/util')
const math = require('../../../utils/math')
Component({
options: {
addGlobalClass: true,
multipleSlots: true
},
properties: {
form: { type: Object, value: null },
item: { type: Object, value: null },
index: { type: Number, value: 0 },
list: { type: Array, value: [] },
status: { type: Number, value: 0 }
},
data: {
visible: false,
focus: 0
},
methods: {
showCategory: function(){
this.setData({ visible: true })
},
onConfirm: function(e){
this.data.cIndex = e.currentTarget.dataset.index
var nowItem = this.data.list[this.data.cIndex]
for (var i = 0; i < this.data.form.productCategoryInfos.length; i++) {
if (this.data.form.productCategoryInfos[i].productId == nowItem.id){
this.setData({ visible: false })
util.showToast('纸品已经存在,请不要重复添加')
return
}
}
this.data.item.productId = nowItem.id
this.data.item.settleUnitPrice = nowItem.defaultUnitPrice
this.data.item.highestUnitPrice = nowItem.highestUnitPrice
this.data.item.lowestUnitPrice = nowItem.lowestUnitPrice
this.data.item.productCategoryName = nowItem.name
this.statAmount()
wx.nextTick(() => {
this.triggerEvent('change', {index: this.data.index, item: this.data.item });
})
},
onHide: function(){
this.setData({ visible: false })
},
bindInput: function (e) {
this.data.item[e.currentTarget.id] = e.detail
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()
}
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, visible: false, cIndex: this.data.cIndex })
},
changeDeductType: function(e){
this.setData({ ['item.sign']: e.currentTarget.dataset.type, focus: e.currentTarget.dataset.type })
}
}
})