// pages/storage/index/index.js import Scene from '../../index/scene' import { getPoundInfo, getPaperList, createOutOrder, recordOutOrder } from "../../../api/saas" const util = require('../../../utils/util') const math = require('../../../utils/math') const event = require('../../../utils/event') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { safeBottom: app.globalData.safeBottom, form: {}, poundInfo: null, activeNames: ['1'], paperList: [], visible: false, imageList: [] }, /** * 生命周期函数--监听页面加载 */ 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) }) getPoundInfo(options.id).then(result => { wx.hideLoading() result.data.emptyWeighingPicture = [] if(result.data.firstWeightImageUrl1){ result.data.emptyWeighingPicture.push(result.data.firstWeightImageUrl1) } if(result.data.firstWeightImageUrl2){ result.data.emptyWeighingPicture.push(result.data.firstWeightImageUrl2) } result.data.totalWeighingPicture = [] if(result.data.secondWeightImageUrl1){ result.data.totalWeighingPicture.push(result.data.secondWeightImageUrl1) } if(result.data.secondWeightImageUrl2){ result.data.totalWeighingPicture.push(result.data.secondWeightImageUrl2) } this.setData({ poundInfo: result.data }) }).catch(err => { wx.hideLoading() util.showToast(err) }) } else { wx.showLoading({ title: '正在获取', mask: true }) getPaperList({pageNum: 1, pageSize: 100}).then(result => { this.setData({ safeBottom: app.globalData.safeBottom, paperList: result.data.records }) wx.hideLoading() }).catch(err => { wx.hideLoading() this.setData({ safeBottom: app.globalData.safeBottom }) util.showToast(err) }) } }, chooseList: function(e){ var url = '' if(e.currentTarget.id == 'orderId'){ url = `/pages/agent/select-list/index?itemId=${this.data.form.agencySellOrderItemId}` } else if(e.currentTarget.id == 'factoryId'){ url = `/pages/home/factory-list/index?type=1` } var that = this var events = {} events.onCallback = function(data){ if (data.what == 140) { if(data.detail.paperMillId){ that.data.form.deliveryChannelType = 2 that.data.form.factoryDeliveryChannelId = data.detail.paperMillId } else { that.data.form.deliveryChannelType = 1 that.data.form.factoryDeliveryChannelId = data.detail.id } that.setData({ ['form.consigneeName']: data.detail.name }) } else if (data.what == 62) { that.data.form.agencySellOrderItemId = data.detail.id that.data.form.plateNumber = data.detail.plateNumber that.data.form.consigneeName = data.detail.millName that.data.form.factoryDeliveryChannelId = '' that.data.form.deliveryChannelType = 2 that.setData({ form: that.data.form }) } } wx.navigateTo({url, events}) }, 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(){ 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 }) wx.hideLoading() }).catch(err => { wx.hideLoading() util.showToast(err) }) } else { this.setData({ visible: true }) } }, onHide: function() { this.setData({ visible: false }) }, onSelect: function({detail}){ this.data.form.productId = detail.id this.data.form.productName = detail.name this.data.form.konePrice = '指导价格:' + math.times(detail.defaultUnitPrice, 1000) this.data.form.unitPrice = '' this.statAmount() }, onChange: function({detail}) { this.setData({ activeNames: detail }) }, bindInput: function (e) { this.data.form[e.currentTarget.id] = e.detail if(e.target.id == 'totalWeight' || e.target.id == 'emptyWeight'){ if(!util.isEmpty(this.data.form.totalWeight) && !util.isEmpty(this.data.form.emptyWeight)){ this.data.form.netWeight = math.minus(this.data.form.totalWeight, this.data.form.emptyWeight) } } this.statAmount() }, statAmount: function(){ if(util.isEmpty(this.data.form.netWeight) && util.isEmpty(this.data.poundInfo)){ this.setData({ visible: false, form: this.data.form }) return } this.data.form.settleWeight = this.data.form.netWeight if(!util.isEmpty(this.data.form.unitPrice) && Number(this.data.form.unitPrice) > 0 && !util.isEmpty(this.data.form.settleWeight)){ this.data.form.estimatedAmount = math.divide(math.times(this.data.form.unitPrice, this.data.form.settleWeight), 1000) } else if(!util.isEmpty(this.data.form.unitPrice) && Number(this.data.form.unitPrice) > 0 && !util.isEmpty(this.data.poundInfo.netWeight)){ this.data.form.estimatedAmount = math.divide(math.times(this.data.form.unitPrice, this.data.poundInfo.netWeight), 1000) } else { this.data.form.estimatedAmount = null } this.setData({ visible: false, form: this.data.form }) }, onInputChange: function(e){ this.data.form[e.currentTarget.id] = e.detail }, fileChange: function({detail}){ this.data.imageList = detail.fileList var imageUrls = [] for (let index = 0; index < this.data.imageList.length; index++) { imageUrls.push(this.data.imageList[index].url) } this.data.form.weightNoteImageUrls = imageUrls }, submitForm: function(){ if(util.isEmpty(this.data.form.consigneeName)){ util.showToast('请选择出货方名称') return } if(util.isEmpty(this.data.form.productName)){ util.showToast('请选择出货品类') return } if(util.isEmpty(this.data.form.plateNumber)){ util.showToast('请输入车牌号码') return } if(util.isEmpty(this.data.form.unitPrice) || Number(this.data.form.unitPrice) <= 0){ util.showToast('请输入出货单价') return } if(util.isEmpty(this.data.form.netWeight) && !this.data.poundInfo){ util.showToast('请输入净重') return } if(Number(this.data.form.netWeight) <= 0 && !this.data.poundInfo){ util.showToast('净重不能小于零') return } if(this.data.poundInfo){ this.data.form.weightNoteId = this.data.poundInfo.id wx.showLoading({ title: '正在处理', mask: true }) createOutOrder(this.data.form).then(result => { wx.hideLoading() util.showBackToast('处理成功') event.emit('OrderMessage', { what: 21, desc: 'createOutOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) } else { wx.showLoading({ title: '正在处理', mask: true }) recordOutOrder(this.data.form).then(result => { wx.hideLoading() util.showBackToast('处理成功') event.emit('OrderMessage', { what: 21, desc: 'recordOutOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) } }, viewImage: function (e) { var imgList = [] if(e.currentTarget.dataset.type == 1){ 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 }) } })