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.
175 lines
6.7 KiB
175 lines
6.7 KiB
// pages/process/order-check/index.js
|
|
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,
|
|
columns: [],
|
|
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.data.paperList = result.data.records
|
|
this.data.columns = []
|
|
for (let index = 0; index < this.data.paperList.length; index++) {
|
|
this.data.columns.push(this.data.paperList[index].name)
|
|
}
|
|
this.setData({ safeBottom: app.globalData.safeBottom, columns: this.data.columns })
|
|
}).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({detail}){
|
|
this.data.nowItem = this.data.paperList[detail.index]
|
|
this.data.form.productId = this.data.nowItem.id
|
|
this.data.form.unitPrice = this.data.nowItem.defaultUnitPrice
|
|
this.data.form.productName = detail.value
|
|
this.statAmount()
|
|
},
|
|
onHide: function(){
|
|
this.setData({ visible: false })
|
|
},
|
|
changeDeductType: function(e){
|
|
this.setData({ ['form.sign']: e.currentTarget.dataset.type, focus: e.currentTarget.dataset.type })
|
|
},
|
|
bindInput: function (e) {
|
|
this.data.form[e.target.id] = e.detail.value
|
|
if(e.target.id == 'deductPercent'){
|
|
if(util.isEmpty(e.detail.value) || Number(e.detail.value) <= 0){
|
|
this.data.form.deductWeight = null
|
|
this.data.form.deductPercent = null
|
|
} else {
|
|
this.data.form.deductWeight = math.divide(math.times(this.data.form.totalWeight, Number(e.detail.value)), 100).toFixed(2)
|
|
// this.setData({ ['form.deductWeight']: math.divide(math.times(this.data.form.totalWeight, Number(e.detail.value)), 100).toFixed(3) })
|
|
}
|
|
} else if(e.target.id == 'deductWeight'){
|
|
if(util.isEmpty(e.detail.value) || Number(e.detail.value) <= 0){
|
|
this.data.form.deductWeight = null
|
|
this.data.form.deductPercent = null
|
|
} else {
|
|
this.data.form.deductPercent = math.times(math.divide(Number(e.detail.value), this.data.form.totalWeight), 100).toFixed(2)
|
|
// this.setData({ ['form.deductPercent']: math.times(math.divide(Number(e.detail.value), this.data.form.totalWeight), 100).toFixed(2) })
|
|
}
|
|
}
|
|
this.statAmount()
|
|
},
|
|
onChange: function(e) {
|
|
this.data.form.inspectionRemark = e.detail
|
|
},
|
|
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 })
|
|
},
|
|
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(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 })
|
|
}
|
|
}
|
|
})
|