// pages/storage/index/index.js import Scene from '../../index/scene' import { getPoundInfo, getPaperList, createOutOrder } from "../../../api/saas" const util = require('../../../utils/util') 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) }) } }, chooseFactory: function(){ var that = this wx.navigateTo({ url: `/pages/home/factory-list/index?type=1`, events: { onCallback: (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.factoryName']: 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(){ 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 }) } }, onConfirm: function({detail}){ this.data.nowItem = this.data.paperList[detail.index] this.data.form.productId = this.data.nowItem.id this.setData({ visible: false, ['form.productName']: detail.value }) }, onChange: function({detail}) { this.setData({ activeNames: detail }) }, submitForm: function(){ if(util.isEmpty(this.data.form.factoryName)){ util.showToast('请选择出货方名称') return } if(util.isEmpty(this.data.form.productId) || Number(this.data.form.productId) <= 0){ 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 }) } })