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

221 lines
8.9 KiB

// pages/storage/index/index.js
import Scene from '../../index/scene'
import Dialog from '../../../components/dialog/dialog'
import { getOutOrderInfo, getPaperList, receiptOutOrder, closeOutOrder } from "../../../api/saas"
const util = require('../../../utils/util')
const event = require('../../../utils/event')
const math = require('../../../utils/math')
const app = getApp()
Scene({
/**
* 页面的初始数据
*/
data: {
safeBottom: app.globalData.safeBottom,
form: {},
poundInfo: null,
orderInfo: null,
activeNames: [],
paperList: [],
visible: false,
fileList: []
},
/**
* 生命周期函数--监听页面加载
*/
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 => {
wx.hideLoading()
this.setData({ safeBottom: app.globalData.safeBottom })
util.showToast(err)
})
getOutOrderInfo(options.id).then(result => {
result.data.weightNote.emptyWeighingPicture = []
if(result.data.weightNote.firstWeightImageUrl1){
result.data.weightNote.emptyWeighingPicture.push(result.data.weightNote.firstWeightImageUrl1)
}
if(result.data.weightNote.firstWeightImageUrl2){
result.data.weightNote.emptyWeighingPicture.push(result.data.weightNote.firstWeightImageUrl2)
}
result.data.weightNote.totalWeighingPicture = []
if(result.data.weightNote.secondWeightImageUrl1){
result.data.weightNote.totalWeighingPicture.push(result.data.weightNote.secondWeightImageUrl1)
}
if(result.data.weightNote.secondWeightImageUrl2){
result.data.weightNote.totalWeighingPicture.push(result.data.weightNote.secondWeightImageUrl2)
}
result.data.outboundDeliveryOrderSettlementInfo.netWeight = math.divide(result.data.outboundDeliveryOrderSettlementInfo.netWeight, 1000)
if(result.data.outboundDeliveryOrderSettlementInfo.id){
this.setData({
safeBottom: app.globalData.safeBottom,
poundInfo: result.data.weightNote,
orderInfo: result.data.outboundDeliveryOrder,
form: result.data.outboundDeliveryOrderSettlementInfo
})
} else {
this.data.form.id = result.data.outboundDeliveryOrder.id
this.setData({
safeBottom: app.globalData.safeBottom,
poundInfo: result.data.weightNote,
orderInfo: result.data.outboundDeliveryOrder
})
}
wx.hideLoading()
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
},
onChange: function({detail}) {
this.setData({ activeNames: detail });
},
showCategory: function(){
if(this.data.paperList.length <= 0){
wx.showLoading({ title: '正在获取', mask: true })
getPaperList({pageNum: 1, pageSize: 100}).then(result => {
this.setData({ visible: true, paperList: result.data.records })
}).catch(err => {
util.showToast(err)
})
} else {
this.setData({ visible: true })
}
},
onHide: function() {
this.setData({ visible: false })
},
onConfirm: function(e){
this.data.cIndex = e.currentTarget.dataset.index
this.data.nowItem = this.data.paperList[this.data.cIndex]
this.data.form.categoryId = this.data.nowItem.id
if(!util.isEmpty(this.data.nowItem.defaultUnitPrice) && Number(this.data.nowItem.defaultUnitPrice) > 0){
var price = math.times(this.data.nowItem.defaultUnitPrice, 1000)
this.setData({ visible: false, ['form.categoryName']: this.data.nowItem.categoryName, ['form.settleUnitPrice']: price, cIndex: this.data.cIndex })
} else {
this.setData({ visible: false, ['form.categoryName']: this.data.nowItem.categoryName, cIndex: this.data.cIndex })
}
},
bindInput: function (e) {
this.data.form[e.target.id] = Number(e.detail)
if(e.target.id == 'netWeight'){
if(!util.isEmpty(this.data.form.deductPercent) && Number(this.data.form.deductPercent) > 0){
var deductWeight = math.divide(math.times(this.data.form.netWeight, this.data.form.deductPercent), 100)
this.setData({ ['form.settleWeight']: math.minus(this.data.form.netWeight, deductWeight) })
} else {
this.setData({ ['form.settleWeight']: e.detail })
}
} else if(e.target.id == 'deductPercent'){
if(!util.isEmpty(this.data.form.netWeight) && Number(this.data.form.netWeight) > 0){
if(Number(this.data.form.deductPercent) < 100){
var deductWeight = math.divide(math.times(this.data.form.netWeight, this.data.form.deductPercent), 100)
this.setData({ ['form.settleWeight']: math.minus(this.data.form.netWeight, deductWeight) })
} else {
this.setData({ ['form.settleWeight']: '' })
}
}
} else if(e.target.id == 'settleWeight'){
if(!util.isEmpty(this.data.form.netWeight) && Number(this.data.form.netWeight) > 0){
if(Number(this.data.form.netWeight) > Number(this.data.form.settleWeight)){
var deductWeight = math.minus(this.data.form.netWeight, this.data.form.settleWeight)
this.setData({ ['form.deductPercent']: math.times(math.divide(deductWeight, this.data.form.netWeight), 100).toFixed(2) })
} else {
this.setData({ ['form.deductPercent']: '' })
}
} else {
this.setData({ ['form.netWeight']: e.detail })
}
}
this.statAmount()
},
statAmount: function(){
if(!util.isEmpty(this.data.form.settleUnitPrice) && !util.isEmpty(this.data.form.settleWeight)){
var amout = math.times(this.data.form.settleUnitPrice, this.data.form.settleWeight)
if(!util.isEmpty(this.data.form.otherFee)){
amout = math.minus(amout, this.data.form.otherFee)
}
this.setData({ ['form.settlePrice']: amout })
}
},
fileChange: function({detail}){
this.data.fileList = detail.fileList
},
closeForm: function(){
Dialog.confirm({ title: '温馨提示', message: '确定关闭该出货单?' }).then(() => {
wx.showLoading({ title: '正在处理', mask: true })
closeOutOrder( {id: this.data.form.id }).then(result => {
wx.hideLoading()
util.showBackToast('磅单处理成功')
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
})
},
settlementForm: function(){
if(util.isEmpty(this.data.form.categoryId) || Number(this.data.form.categoryId) <= 0){
util.showToast('请选择废纸品类')
return
}
if(util.isEmpty(this.data.form.settleUnitPrice) || Number(this.data.form.settleUnitPrice) <= 0){
util.showToast('请输入结算单价')
return
}
if(util.isEmpty(this.data.form.netWeight) || Number(this.data.form.netWeight) <= 0){
util.showToast('请输入净重')
return
}
if(util.isEmpty(this.data.form.settleWeight) || Number(this.data.form.settleWeight) <= 0){
util.showToast('请输入结算重量')
return
}
var params = { id: this.data.orderInfo.id, categoryId: this.data.form.categoryId }
params.otherFee = this.data.form.otherFee
params.unitPrice = this.data.form.unitPrice
params.estimatedAmount = this.data.form.estimatedAmount
params.deductPercent = this.data.form.deductPercent
params.factoryId = this.data.form.factoryId
params.settleUnitPrice = math.divide(this.data.form.settleUnitPrice, 1000)
params.settlePrice = this.data.form.settlePrice
params.netWeight = math.times(this.data.form.netWeight, 1000)
params.settleWeight = math.times(this.data.form.settleWeight, 1000)
wx.showLoading({ title: '正在处理', mask: true })
var weightNoteImageUrls = []
for (let index = 0; index < this.data.fileList.length; index++) {
const element = this.data.fileList[index]
if(!util.isEmpty(element.url)){
weightNoteImageUrls.push(element.url)
}
}
if(weightNoteImageUrls.length){
params.weightNoteImageUrls = weightNoteImageUrls
}
receiptOutOrder(params).then(result => {
wx.hideLoading()
util.showBackToast('处理成功')
event.emit('OrderMessage', { what: 21, desc: 'cancelOrder' })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
viewImage: function (e) {
var imgList = []
if(e.currentTarget.dataset.type == 0){
for (let index = 0; index < this.data.poundInfo.totalWeighingPicture.length; index++) {
imgList.push(this.data.poundInfo.totalWeighingPicture[index])
}
} else {
for (let index = 0; index < this.data.poundInfo.emptyWeighingPicture.length; index++) {
imgList.push(this.data.poundInfo.emptyWeighingPicture[index])
}
}
wx.previewImage({ urls: imgList, current: e.currentTarget.dataset.url })
}
})