// pages/storage/index/index.js import Scene from '../../index/scene' import Dialog from '../../../components/dialog/dialog' import { getOutOrderInfo, getPaperList, receiptOutOrder, backupOutOrder, closeOutOrder, printOrder } 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) } if(result.data.outboundDeliveryOrderSettlementInfo.id){ result.data.outboundDeliveryOrderSettlementInfo.netWeight = math.divide(result.data.outboundDeliveryOrderSettlementInfo.netWeight, 1000) this.data.fileList = [] if(result.data.outboundDeliveryOrderSettlementInfo.weightNoteImageUrlsArr){ for (let index = 0; index < result.data.outboundDeliveryOrderSettlementInfo.weightNoteImageUrlsArr.length; index++) { const element = result.data.outboundDeliveryOrderSettlementInfo.weightNoteImageUrlsArr[index] if(!util.isEmpty(element)){ this.data.fileList.push({ url: element}) } } } if(result.data.outboundDeliveryOrder.productId && result.data.outboundDeliveryOrder.productName){ result.data.outboundDeliveryOrderSettlementInfo.categoryId = result.data.outboundDeliveryOrder.productId result.data.outboundDeliveryOrderSettlementInfo.categoryName = result.data.outboundDeliveryOrder.productName } else { result.data.outboundDeliveryOrderSettlementInfo.categoryId = null result.data.outboundDeliveryOrderSettlementInfo.categoryName = null } if(Number(result.data.outboundDeliveryOrderSettlementInfo.settleUnitPrice) > 0){ result.data.outboundDeliveryOrderSettlementInfo.settleUnitPrice = math.times(result.data.outboundDeliveryOrderSettlementInfo.settleUnitPrice, 1000) } if(Number(result.data.outboundDeliveryOrderSettlementInfo.settleWeight) > 0){ result.data.outboundDeliveryOrderSettlementInfo.settleWeight = math.divide(result.data.outboundDeliveryOrderSettlementInfo.settleWeight, 1000) } this.setData({ safeBottom: app.globalData.safeBottom, poundInfo: result.data.weightNote, orderInfo: result.data.outboundDeliveryOrder, form: result.data.outboundDeliveryOrderSettlementInfo, fileList: this.data.fileList }) this.statAmount() } else { this.data.form.id = result.data.outboundDeliveryOrder.id if(result.data.outboundDeliveryOrder.productId && result.data.outboundDeliveryOrder.productName){ this.data.form.categoryId = result.data.outboundDeliveryOrder.productId this.data.form.categoryName = result.data.outboundDeliveryOrder.productName } this.setData({ safeBottom: app.globalData.safeBottom, form: this.data.form, 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 }) }, onSelect: function({detail}){ if(this.data.form.categoryId == detail.id){ return } this.data.form.categoryId = detail.id if(!util.isEmpty(detail.defaultUnitPrice) && Number(detail.defaultUnitPrice) > 0){ this.setData({ ['form.categoryName']: detail.name, ['form.settleUnitPrice']: '', ['form.konePrice']: '指导价格:' + math.times(detail.defaultUnitPrice, 1000), }) } else { this.setData({ ['form.categoryName']: detail.name }) } }, 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.data.form.deductWeight = deductWeight this.setData({ ['form.settleWeight']: math.minus(this.data.form.netWeight, deductWeight) }) } else { this.data.form.deductWeight = 0 this.setData({ ['form.settleWeight']: e.detail }) } this.statPrice() } 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.data.form.deductWeight = deductWeight this.setData({ ['form.settleWeight']: math.minus(this.data.form.netWeight, deductWeight) }) } else { this.data.form.deductWeight = 0 this.setData({ ['form.settleWeight']: '' }) } } this.statPrice() } 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.data.form.deductWeight = deductWeight this.setData({ ['form.deductPercent']: math.times(math.divide(deductWeight, this.data.form.netWeight), 100).toFixed(2) }) } else { this.data.form.deductWeight = 0 this.setData({ ['form.deductPercent']: '' }) } } else { this.setData({ ['form.netWeight']: e.detail }) } this.statPrice() } else if(e.target.id == 'settleUnitPrice'){ this.statPrice() } this.statAmount() }, statPrice: function(){ if(!util.isEmpty(this.data.form.settleUnitPrice) && !util.isEmpty(this.data.form.settleWeight)){ this.data.form.settlePrice = math.times(this.data.form.settleUnitPrice, this.data.form.settleWeight) } }, statAmount: function(){ var amout = this.data.form.settlePrice if(util.isEmpty(amout) || Number(amout) <= 0){ return } if(!util.isEmpty(this.data.form.freight)){ amout = math.minus(amout, this.data.form.freight) } if(!util.isEmpty(this.data.form.proxyPaySurcharge)){ amout = math.minus(amout, this.data.form.proxyPaySurcharge) } if(!util.isEmpty(this.data.form.otherFee)){ amout = math.minus(amout, this.data.form.otherFee) } if(!util.isEmpty(this.data.form.subsidy)){ amout = math.plus(amout, this.data.form.subsidy) } this.setData({ ['form.settlePrice']: this.data.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.orderInfo.id }).then(result => { wx.hideLoading() event.emit('OrderMessage', { what: 21, desc: 'closeOrder' }) util.showBackToast('出货单已关闭') }).catch(err => { wx.hideLoading() util.showToast(err) }) }) }, printOrderInfo: function(){ wx.showLoading({ title: '正在处理', mask: true }) printOrder({id: this.data.orderInfo.id, printType: 3 }).then(result => { wx.hideLoading() util.showToast('即将打印,请稍后') }).catch(err => { wx.hideLoading() util.showToast(err) }) }, saveForm: function(){ wx.showLoading({ title: '正在处理', mask: true }) var params = { id: this.data.orderInfo.id, categoryId: this.data.form.categoryId } params.otherFee = this.data.form.otherFee params.subsidy = this.data.form.subsidy params.proxyPaySurcharge = this.data.form.proxyPaySurcharge params.freight = this.data.form.freight params.deductPercent = this.data.form.deductPercent if(this.data.form.settleUnitPrice && Number(this.data.form.settleUnitPrice) > 0){ params.settleUnitPrice = math.divide(this.data.form.settleUnitPrice, 1000) } params.settlePrice = this.data.form.settlePrice if(this.data.form.netWeight && Number(this.data.form.netWeight) > 0){ params.netWeight = math.times(this.data.form.netWeight, 1000) } if(this.data.form.deductPercent && Number(this.data.form.deductPercent) > 0){ params.deductPercent = this.data.form.deductPercent } if(this.data.form.deductWeight && Number(this.data.form.deductWeight) > 0){ params.deductWeight = math.times(this.data.form.deductWeight, 1000) } if(this.data.form.settleWeight && Number(this.data.form.settleWeight) > 0){ params.settleWeight = math.times(this.data.form.settleWeight, 1000) } 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 } backupOutOrder(params).then(result => { wx.hideLoading() util.showBackToast('保存成功') event.emit('OrderMessage', { what: 21, desc: 'settlementForm' }) }).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.subsidy = this.data.form.subsidy params.proxyPaySurcharge = this.data.form.proxyPaySurcharge params.freight = this.data.form.freight params.deductPercent = this.data.form.deductPercent 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: 'settlementForm' }) }).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 }) } })