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

166 lines
6.1 KiB

import Scene from '../../index/scene'
import { checkingOrder, getFactoryOrderInfo, getPaperList} from "../../../api/saas"
const event = require('../../../utils/event')
const util = require('../../../utils/util')
const math = require('../../../utils/math')
const app = getApp()
Scene({
/**
* 页面的初始数据
*/
data: {
safeBottom: app.globalData.safeBottom,
paperList: null,
form: null,
paperList: [],
focus: 0,
visible: false,
amout: 0,
nowItem: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.id){
wx.showLoading({ title: '正在获取', mask: true })
getPaperList({pageNum: 1, pageSize: 100}).then(result => {
this.setData({ safeBottom: app.globalData.safeBottom, paperList: result.data.records })
}).catch(err => {
this.setData({ safeBottom: app.globalData.safeBottom })
util.showToast(err)
})
getFactoryOrderInfo(options.id).then(result => {
wx.hideLoading()
result.data.sign = 1
if(Number(result.data.deductPercent) <= 0){
result.data.deductPercent = null
}
this.data.amout = math.times(result.data.settleWeight, result.data.unitPrice)
this.setData({ form: result.data, amout: this.data.amout })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
},
showPlate: function (e) {
this.keyboard = this.keyboard || this.selectComponent('#wux-keyboard')
this.keyboard.show(this.data.form.plateNumber, 0)
},
onPlatenumber: function({detail}){
if(detail && detail.plateNumber){
this.setData({ ['form.plateNumber']: detail.plateNumber })
}
},
showCategory: function(){
this.setData({ visible: true })
},
onConfirm: function(e){
this.data.cIndex = e.currentTarget.dataset.index
this.data.nowItem = this.data.paperList[this.data.cIndex]
this.data.form.productId = this.data.nowItem.id
this.data.form.unitPrice = this.data.nowItem.defaultUnitPrice
this.data.form.productName = this.data.nowItem.name
this.statAmount()
},
onHide: function(){
this.setData({ visible: false })
},
changeDeductType: function(e){
var type = Number(e.currentTarget.dataset.type)
this.setData({ ['form.sign']: type, focus: type })
},
bindInput: function (e) {
this.data.form[e.target.id] = e.detail
if(e.target.id == 'deductPercent'){
if(util.isEmpty(e.detail)){
this.data.form.deductWeight = null
this.data.form.deductPercent = null
} else {
this.data.form.deductWeight = math.divide(math.times(this.data.form.netWeight, Number(e.detail)), 100).toFixed(2)
}
} else if(e.target.id == 'deductWeight'){
if(util.isEmpty(e.detail)){
this.data.form.deductWeight = null
this.data.form.deductPercent = null
} else {
this.data.form.deductPercent = math.times(math.divide(Number(e.detail), this.data.form.netWeight), 100).toFixed(2)
}
}
this.statAmount()
},
statAmount: function(){
this.data.form.settleWeight = this.data.form.netWeight
if(!util.isEmpty(this.data.form.deductWeight)){
this.data.form.settleWeight = math.minus(this.data.form.netWeight, this.data.form.deductWeight)
}
if(!util.isEmpty(this.data.form.unitPrice) && Number(this.data.form.unitPrice) > 0){
this.data.amout = math.times(this.data.form.settleWeight, this.data.form.unitPrice)
} else {
this.data.amout = null
}
this.setData({ visible: false, form: this.data.form, amout: this.data.amout, cIndex: this.data.cIndex })
},
checkOrder: function(){
if(util.isEmpty(this.data.form.productId) || Number(this.data.form.productId) <= 0){
util.showToast('请选择废纸品类')
return
}
if(util.isEmpty(this.data.form.unitPrice) || Number(this.data.form.unitPrice) <= 0){
util.showToast('请输入单价')
return
}
if(this.data.nowItem){
if(this.data.nowItem.highestUnitPrice && Number(this.data.form.unitPrice) > Number(this.data.nowItem.highestUnitPrice)){
util.showToast('输入单价过高,价格范围:' + this.data.nowItem.lowestUnitPrice + '元/公斤-'+ this.data.nowItem.highestUnitPrice + '元/公斤')
return
}
if(this.data.nowItem.lowestUnitPrice && Number(this.data.form.unitPrice) < Number(this.data.nowItem.lowestUnitPrice)){
util.showToast('输入单价过低,价格范围:' + this.data.nowItem.lowestUnitPrice + '元/公斤-'+ this.data.nowItem.highestUnitPrice + '元/公斤')
return
}
}
if(!util.isEmpty(this.data.form.deductWeight) && Number(this.data.form.deductWeight) >= Number(this.data.form.totalWeight)){
util.showToast('扣重不得超过皮重')
return
}
if(!util.isEmpty(this.data.form.deductPercent) && Number(this.data.form.deductPecent) >= 100){
util.showToast('扣点范围:0-100')
return
}
wx.showLoading({ title: '处理中', mask: true })
var data = {id: this.data.form.id}
if(Number(this.data.form.deductWeight) > 0){
data.deductWeight = Number(this.data.form.deductWeight)
}
if(Number(this.data.form.deductPercent) > 0){
data.deductPercent = Number(this.data.form.deductPercent)
}
data.plateNumber = this.data.form.plateNumber
data.productId = this.data.form.productId
data.sign = this.data.form.sign
data.unitPrice = Number(this.data.form.unitPrice)
checkingOrder({ id: this.data.form.id, editOrderPriceDto: data }).then(result => {
wx.hideLoading()
event.emit('OrderMessage', { what: 12, desc: 'checkingOrder' })
util.showBackToast('订单审核已通过')
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
viewImage: function (e) {
var imgList = []
for (let index = 0; index < this.data.form.totalWeighingPicture.length; index++) {
var url = this.data.form.totalWeighingPicture[index].url
if(!util.isEmpty(url) && 'error' != url){
imgList.push(url)
}
}
if(imgList.length){
wx.previewImage({ urls: imgList, current: e.currentTarget.dataset.url })
}
}
})