// pages/process/order-check/index.js import Scene from '../../index/scene' import Dialog from '../../../components/dialog/dialog' import { poundSideOrder, getSideOrderInfo, saveSideOrder, priceSideOrder, cancelOrder } from "../../../api/saas" const event = require('../../../utils/event') const util = require('../../../utils/util') const math = require('../../../utils/math') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { height: app.globalData.fragmentHeight, id: null, form: null, param: { scrapPaperReceiptId: null, offsiteGrossWeight: null, offsiteTareWeight: null, }, intoview: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ this.data.id = options.id this.fetchOrderInfo() } }, fetchOrderInfo: function(){ wx.showLoading({ title: '正在获取', mask: true }) getSideOrderInfo({id: this.data.id}).then(result => { wx.hideLoading() this.data.param.offsiteGrossWeight = result.data.offsiteGrossWeight this.data.param.offsiteTareWeight = result.data.offsiteTareWeight var height = app.globalData.fragmentHeight - app.globalData.safeBottom - 120 this.setData({ form: result.data, admin: app.userInfo.type && app.userInfo.type.indexOf('ADMIN') >= 0, height }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, onProductChange: function({detail}){ this.data.form.productCategoryInfos[detail.index] = detail.item var totalNetWeight = 0 var estimatedAmount = 0 for (let index = 0; index < this.data.form.productCategoryInfos.length; index++) { const element = this.data.form.productCategoryInfos[index] if(this.data.form.orderStatus == 0){ if(!util.isEmpty(element.netWeight) && Number(element.netWeight) > 0){ totalNetWeight = math.plus(totalNetWeight, element.netWeight) } if(!util.isEmpty(element.estimatedAmount) && Number(element.estimatedAmount) > 0){ estimatedAmount = math.plus(estimatedAmount, element.estimatedAmount) } } else { if(!util.isEmpty(element.settleWeight) && Number(element.settleWeight) > 0){ totalNetWeight = math.plus(totalNetWeight, element.settleWeight) } if(!util.isEmpty(element.settlePrice) && Number(element.settlePrice) > 0){ estimatedAmount = math.plus(estimatedAmount, element.settlePrice) } } } if(this.data.form.orderStatus == 0){ this.setData({ ['form.totalNetWeight']: totalNetWeight, ['form.estimatedAmount']: estimatedAmount.toFixed(2) }) } else { this.setData({ ['form.settleTotalWeight']: totalNetWeight, ['form.settleTotalAmount']: estimatedAmount.toFixed(2) }) } }, bindInput: function (e) { this.data.param[e.currentTarget.id] = e.detail }, cancelForm: function(e){ Dialog.confirm({ title: '温馨提示', message: '确定取消该订单?' }).then(() => { wx.showLoading({ title: '处理中', mask: true }) cancelOrder(this.data.form.scrapPaperReceiptId).then(result => { wx.hideLoading() util.showBackToast('订单已经取消') event.emit('OrderMessage', { what: 12, desc: 'cancelOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }) }, eidtForm: function(){ wx.redirectTo({url: `/pages/process/outside-add/index?id=${this.data.id}` }) }, saveForm: function(){ var weightNoteList = [] for (let index = 0; index < this.data.form.productCategoryInfos.length; index++) { const element = this.data.form.productCategoryInfos[index] var item = {grossWeight: element.grossWeight, tareWeight: element.tareWeight,weightNoteImage: element.weightNoteImages } item.netWeight = element.netWeight item.scrapPaperPurchaseOrderId = element.scrapPaperPurchaseOrderId weightNoteList.push(item) } this.data.param.scrapPaperReceiptId = this.data.form.scrapPaperReceiptId this.data.param.weightNoteList = weightNoteList wx.showLoading({ title: '处理中', mask: true }) saveSideOrder(this.data.param).then(result => { wx.hideLoading() util.showBackToast('保存成功') // event.emit('OrderMessage', { what: 12, desc: 'saveSideOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, submitForm: function(){ var weightNoteList = [] for (let index = 0; index < this.data.form.productCategoryInfos.length; index++) { const element = this.data.form.productCategoryInfos[index] if(util.isEmpty(element.netWeight) || Number(element.netWeight) <= 0){ util.showToast('请输入第' + (index + 1) + '项废纸品类净重') return } // if(util.isEmpty(element.tareWeight) || Number(element.tareWeight) < 0){ // util.showToast('请输入第' + (index + 1) + '项废纸品类皮重') // return // } if(util.isEmpty(element.weightNoteImages)){ util.showToast('请上传第' + (index + 1) + '项废纸品类过磅凭证') return } if(element.weightNoteImages.length < 3){ util.showToast('每个品类过磅凭证图片必须3张以上') return } var item = {grossWeight: element.grossWeight, tareWeight: element.tareWeight,weightNoteImage: element.weightNoteImages } item.netWeight = element.netWeight item.scrapPaperPurchaseOrderId = element.scrapPaperPurchaseOrderId weightNoteList.push(item) } if(util.isEmpty(this.data.param.offsiteTareWeight)){ this.setData({ intoview: 'offsiteTareWeight' }) util.showToast('请输入厂外皮重') return } if(util.isEmpty(this.data.param.offsiteGrossWeight)){ this.setData({ intoview: 'offsiteGrossWeight' }) util.showToast('请输入厂外毛重') return } this.data.param.scrapPaperReceiptId = this.data.form.scrapPaperReceiptId this.data.param.weightNoteList = weightNoteList wx.showLoading({ title: '处理中', mask: true }) poundSideOrder(this.data.param).then(result => { wx.hideLoading() util.showBackToast('提交成功') event.emit('OrderMessage', { what: 12, desc: 'pricingOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, repeatForm: function(){ wx.redirectTo({url: `/pages/process/outside-check/index?id=${this.data.id}` }) }, priceForm: function(){ var productCategorySettleInfoDtoList = [] for (let index = 0; index < this.data.form.productCategoryInfos.length; index++) { const element = this.data.form.productCategoryInfos[index] if(util.isEmpty(element.settleUnitPrice) || Number(element.settleUnitPrice) <= 0){ util.showToast('请输入第' + (index + 1) + '项废纸品类结算单价') return } var item = { productId: element.productId, scrapPaperPurchaseOrderId: element.scrapPaperPurchaseOrderId } item.deductWeight = element.deductWeight item.deductPercent = element.deductPercent item.settleUnitPrice = element.settleUnitPrice productCategorySettleInfoDtoList.push(item) } var data = {scrapPaperReceiptId: this.data.form.scrapPaperReceiptId } data.productCategorySettleInfoDtoList = productCategorySettleInfoDtoList wx.showLoading({ title: '处理中', mask: true }) priceSideOrder(data).then(result => { wx.hideLoading() if(this.data.form.onsideGrossWeight) { util.showBackToast('定价成功') } else { Dialog.alert({ title: '温馨提示', message: '定价成功,请过磅刷卡获取厂内毛重!' }).then(() => { wx.navigateBack() }) } event.emit('OrderMessage', { what: 12, desc: 'pricingOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, printOrderInfo: function(){ wx.showLoading({ title: '正在处理', mask: true }) printOrder({id: this.data.id, printType: 2}).then(result => { wx.hideLoading() util.showToast('即将打印,请稍后') }).catch(err => { wx.hideLoading() util.showToast(err) }) }, checkForm: function(){ } })