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

218 lines
8.2 KiB

// pages/process/order-check/index.js
import Scene from '../../index/scene'
import Dialog from '../../../components/dialog/dialog'
import { pricingOrder, cancelOrder, getFactoryOrderInfo, getPaperList, getPlateList, savePlateNumber} 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,
step: 1,
focus: 0,
visible: false,
plateList: [],
nowItem: null,
konePrice: '请输入单价'
},
/**
* 生命周期函数--监听页面加载
*/
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 => {
result.data.deductType = 1
this.data.step = 1
for (let index = 0; index < 2; index++) {
if(util.isEmpty(result.data.totalWeighingPicture[index])){
result.data.totalWeighingPicture[index] = { url: 'error' }
this.data.step = 2
}
}
wx.hideLoading()
this.setData({ form: result.data, step: this.data.step })
getPlateList({factoryCustomerId: result.data.factoryCustomerId}).then(result => {
var plateList = []
for (let index = 0; index < result.data.records.length; index++) {
plateList.push(result.data.records[index].plateNumber)
}
if(plateList.length > 0){
this.setData({ ['form.plateNumber']: plateList[0], plateList })
}
})
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
},
nextStep: function (e) {
this.setData({ step: 2 })
},
// selectCustomer: function(){
// var that = this
// wx.navigateTo({
// url: `/pages/home/customer-list/index?type=1`,
// events: {
// onCallback: (data) => {
// if (data.what == 130) {
// that.data.form.factoryCustomerId = data.detail.id
// that.setData({ ['form.factoryCustomerName']: data.detail.name })
// }
// }
// }
// })
// },
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
var konePrice = '指导价格:' + this.data.nowItem.defaultUnitPrice
// this.setData({ visible: false, ['form.productName']: this.data.nowItem.name, ['form.unitPrice']: unitPrice, cIndex: this.data.cIndex })
this.setData({ visible: false, ['form.productName']: this.data.nowItem.name, konePrice, cIndex: this.data.cIndex })
},
loop: function(){
return false
},
onHide: function(){
this.setData({ visible: false })
},
changeDeductType: function(e){
var type = Number(e.currentTarget.dataset.type)
this.setData({ ['form.deductType']: 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.setData({ ['form.deductWeight']: null, ['form.deductPercent']: null })
} else {
this.setData({ ['form.deductWeight']: math.divide(math.times(this.data.form.totalWeight, Number(e.detail)), 100).toFixed(3) })
}
} else if(e.target.id == 'deductWeight'){
if(util.isEmpty(e.detail)){
this.setData({ ['form.deductWeight']: null, ['form.deductPercent']: null })
} else {
this.setData({ ['form.deductPercent']: math.times(math.divide(Number(e.detail), this.data.form.totalWeight), 100).toFixed(2) })
}
}
},
onChange: function(e) {
this.data.form.inspectionRemark = e.detail
},
paddingOrder: function(){
if(!this.data.form.isWithoutTare){
Dialog.confirm({ title: '温馨提示', message: '为了防止定价流程异常,请耐心查看货品,是否确定无皮过磅?' }).then(() => {
this.setData({ ['form.isWithoutTare']: !this.data.form.isWithoutTare })
})
} else {
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){
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.deductType = this.data.form.deductType
data.unitPrice = Number(this.data.form.unitPrice)
data.isWithoutTare = Number(this.data.form.isWithoutTare)
pricingOrder(data).then(result => {
wx.hideLoading()
if(!util.isEmpty(data.plateNumber) && data.plateNumber.length >= 7
&& this.data.plateList.indexOf(data.plateNumber) < 0 && this.data.plateList.length <= 5){
var params = {factoryCustomerId: this.data.form.factoryCustomerId, plateNumber: data.plateNumber}
savePlateNumber(params).then(result => {})
}
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++) {
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 })
}
}
})