// pages/process/order-check/index.js import Scene from '../../index/scene' import Dialog from '../../../components/dialog/dialog' import { repeatSideOrder, getSideOrderInfo, printOrder} from "../../../api/saas" const event = require('../../../utils/event') const util = require('../../../utils/util') const math = require('../../../utils/math') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { id: null, form: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ this.data.id = options.id this.fetchOrderInfo() } event.on('OrderMessage', this, this.onEvent) }, onEvent: function(message){ if (message.what == 12) { this.fetchOrderInfo() } }, fetchOrderInfo: function(){ wx.showLoading({ title: '正在获取', mask: true }) getSideOrderInfo({id: this.data.id}).then(result => { wx.hideLoading() result.data.settleTotalAmount = 0 result.data.settleTotalWeight = 0 for (let index = 0; index < result.data.productCategoryInfos.length; index++) { const element = result.data.productCategoryInfos[index] element.fileList = [] if(element.weightNoteImages){ for (let k = 0; k < element.weightNoteImages.length; k++) { element.fileList.push({url: element.weightNoteImages[k]}) } } if(element.settleUnitPrice && element.settleWeight){ element.settlePrice = math.times(element.settleWeight, element.settleUnitPrice) result.data.settleTotalAmount = math.plus(result.data.settleTotalAmount, element.settlePrice) result.data.settleTotalWeight = math.plus(result.data.settleTotalWeight, element.settleWeight) } } this.setData({ form: result.data, admin: app.userInfo.type && app.userInfo.type.indexOf('ADMIN') >= 0 }) }).catch(err => { wx.hideLoading() console.log(err) util.showToast(err) }) }, printOrder: 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(){ wx.redirectTo({url: `/pages/process/outside-check/index?id=${this.data.id}` }) }, submitForm: function(){ if(this.data.form.onsideGrossWeight) { this.checkPass() } else { var message = '此订单没有厂内毛重数据,按照正常流程请刷卡过磅,获取厂内毛重数据,如果已经无法获取,请仔细查验纸品,确定没有问题后,进行审核。' Dialog.confirm({ title: '温馨提示', message, confirmButtonText: '确定审核' }).then(() => { this.checkPass() }) } }, checkPass: function(){ wx.showLoading({ title: '处理中', mask: true }) repeatSideOrder({scrapPaperReceiptId: this.data.form.scrapPaperReceiptId }).then(result => { wx.hideLoading() util.showBackToast('订单审核已通过') event.emit('OrderMessage', { what: 12, desc: 'pricingOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, paymentOrder: function(){ let pages = getCurrentPages() //当前页面栈 for (let index = 0; index < pages.length; index++) { if (pages[index].route.indexOf('pages/process/payment/index') >= 0) { wx.navigateBack() return } } wx.navigateTo({ url: `/pages/process/payment/index?id=${this.data.form.scrapPaperReceiptId}` }) }, onUnload: function(){ event.remove('OrderMessage', this) } })