// pages/storage/index/index.js import Scene from '../../index/scene' import { getPoundInfo, getPaperList, createOutOrder } 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'], columns: [], visible: false, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ wx.showLoading({ title: '正在获取', mask: true }) getPaperList({pageNum: 1, pageSize: 100}).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) }) 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) }) } }, 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.productName = data.detail.categoryName 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.columns.length <= 0){ wx.showLoading({ title: '正在获取', mask: true }) getPaperList({pageNum: 1, pageSize: 100}).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({ visible: true, columns: this.data.columns }) }).catch(err => { util.showToast(err) }) } else { this.setData({ visible: true }) } }, onHide: function() { this.setData({ visible: false }) }, onConfirm: function({detail}){ this.data.nowItem = this.data.paperList[detail.index] this.data.form.productId = this.data.nowItem.id this.data.form.unitPrice = this.data.nowItem.defaultUnitPrice var amount = '' if(!util.isEmpty(this.data.form.unitPrice) && Number(this.data.form.unitPrice) > 0){ amount = math.times(this.data.form.unitPrice, this.data.poundInfo.netWeight) } this.setData({ visible: false, ['form.productName']: detail.value, ['form.unitPrice']: this.data.form.unitPrice, ['form.estimatedAmount']: amount }) }, onChange: function({detail}) { this.setData({ activeNames: detail }) }, bindInput: function (e) { this.data.form[e.currentTarget.id] = e.detail if(e.currentTarget.id == 'unitPrice'){ var amount = '' if(!util.isEmpty(this.data.form.unitPrice) && Number(this.data.form.unitPrice) > 0){ amount = math.times(this.data.form.unitPrice, this.data.poundInfo.netWeight) } this.setData({ visible: false, ['form.estimatedAmount']: amount }) } }, onInputChange: function(e){ this.data.form[e.currentTarget.id] = e.detail }, 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 } 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: 20, desc: 'cancelOrder' }) }).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 }) } })