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

148 lines
5.5 KiB

// pages/process/order-check/index.js
import Dialog from '../../../components/dialog/dialog'
import { pricingOrder, cancelOrder, getFactoryOrderInfo, getPaperList} from "../../../api/saas"
const event = require('../../../utils/event')
const util = require('../../../utils/util')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
safeBottom: app.globalData.safeBottom,
paperList: null,
form: null,
deductType: 1,
columns: [],
focus: 0,
visible: false,
nowItem: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.id){
wx.showLoading({ title: '正在获取', mask: true })
getPaperList().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 => {
wx.hideLoading()
this.setData({ safeBottom: app.globalData.safeBottom })
util.showToast(err)
})
getFactoryOrderInfo(options.id).then(result => {
wx.hideLoading()
this.setData({ form: result.data })
}).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
var unitPrice = this.data.nowItem.defaultUnitPrice
this.setData({ visible: false, ['form.productCategoryName']: detail.value, ['form.unitPrice']: unitPrice })
},
onHide: function(){
this.setData({ visible: false })
},
changeDeductType: function(e){
if(Number(e.currentTarget.dataset.type) == 1){
this.setData({ deductType: e.currentTarget.dataset.type, ['form.deductPercent']: null, focus: e.currentTarget.dataset.type})
} else {
this.setData({ deductType: e.currentTarget.dataset.type, ['form.deductWeight']: null, focus: e.currentTarget.dataset.type })
}
},
bindInput: function (e) {
this.data.form[e.target.id] = e.detail.value
},
paddingOrder: function(){
this.setData({ ['form.isWithoutTare']: !this.data.form.isWithoutTare })
},
cancelOrder: function(e){
Dialog.confirm({ title: '温馨提示', message: '确定取消该订单?' }).then(() => {
wx.showLoading({ title: '处理中', mask: true })
cancelOrder(this.data.form.id).then(result => {
wx.hideLoading()
util.showBackToast('订单已经删除')
event.emit('OrderMessage', { what: 12, desc: 'cancelOrder' })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
})
},
priceOrder: 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.highestUnitPrice && Number(this.data.form.unitPrice) > Number(this.data.nowItem.highestUnitPrice)){
util.showToast('输入单价过高,价格范围:' + this.data.nowItem.lowestUnitPrice + '元/KG-'+ this.data.nowItem.highestUnitPrice + '元/KG')
return
}
if(this.data.nowItem.lowestUnitPrice && Number(this.data.form.unitPrice) < Number(this.data.nowItem.lowestUnitPrice)){
util.showToast('输入单价过低,价格范围:' + this.data.nowItem.lowestUnitPrice + '元/KG-'+ this.data.nowItem.highestUnitPrice + '元/KG')
return
}
// if(this.data.deductType == 1 && (util.isEmpty(this.data.form.deductWeight) || Number(this.data.form.deductWeight) <= 0)){
// util.showToast('请输入扣重')
// return
// }
// if(this.data.deductType == 2 && (util.isEmpty(this.data.form.deductPercent) || Number(this.data.form.deductPercent) <= 0)){
// util.showToast('请输入扣点')
// 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)
} else 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.unitPrice = Number(this.data.form.unitPrice)
data.isWithoutTare = Number(this.data.form.isWithoutTare)
pricingOrder(data).then(result => {
wx.hideLoading()
util.showBackToast('定价成功')
event.emit('OrderMessage', { what: 12, desc: 'pricingOrder' })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
viewImage: function (e) {
var imgList = []
for (let index = 0; index < this.data.form.totalWeighingPicture.length; index++) {
imgList.push(this.data.form.totalWeighingPicture[index].url)
}
wx.previewImage({ urls: imgList, current: e.currentTarget.dataset.url })
}
})