// pages/process/order-check/index.js import Scene from '../../index/scene' import Dialog from '../../../components/dialog/dialog' import { repeatOrder, getFactoryOrderInfo, checkingOrder, printOrder} from "../../../api/saas" const event = require('../../../utils/event') const util = require('../../../utils/util') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { safeBottom: app.globalData.safeBottom, form: null, agent: 0, title: '过磅详情' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.agent){ this.data.agent = Number(options.agent) } if(options.id){ this.fetchOrderInfo(options.id) } event.on('OrderMessage', this, this.onEvent) }, onEvent: function(message){ if (message.what == 12 && message.desc == 'PaymentOrder') { wx.navigateBack() } }, fetchOrderInfo(id){ wx.showLoading({ title: '正在获取', mask: true }) getFactoryOrderInfo(id).then(result => { wx.hideLoading() if(result.data.status == 4){ this.data.title = '待付款' } else if(result.data.status == 5){ this.data.title = '已完成' } this.setData({ safeBottom: app.globalData.safeBottom, form: result.data, title: this.data.title, admin: app.userInfo.type && app.userInfo.type.indexOf('ADMIN') >= 0, agent: this.data.agent }) }).catch(err => { wx.hideLoading() this.setData({ safeBottom: app.globalData.safeBottom }) util.showToast(err) }) }, 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 }) } }, bindInput: function (e) { this.data.form[e.target.id] = e.detail.value }, onChange: function({ detail }) { // 需要手动对 checked 状态进行更新 this.setData({ ['form.isDefault']: detail ? 1 : 0 }) }, printOrder: function(){ wx.showLoading({ title: '正在处理', mask: true }) printOrder({id: this.data.form.id, printType: 1}).then(result => { wx.hideLoading() util.showToast('即将打印,请稍后') }).catch(err => { wx.hideLoading() util.showToast(err) }) }, paddingOrder: function(){ this.setData({ ['form.checking']: !this.data.form.checking }) }, 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 } } const that = this wx.navigateTo({ url: `/pages/process/payment/index?channel=1`, events: { onOrderChange: (data) => { if (data.what == 12) { that.fetchOrderInfo(that.data.form.id) } } }, success: function(res) { res.eventChannel.emit('onParam', that.data.form) } }) }, repeatOrder: function(e){ Dialog.confirm({ title: '温馨提示', message: '确定重新过皮重?' }).then(() => { wx.showLoading({ title: '正在处理', mask: true }) repeatOrder(this.data.form.id).then(result => { wx.hideLoading() util.showBackToast('订单已经处理') event.emit('OrderMessage', { what: 12, desc: 'cancelOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }) }, priceOrder: function(e){ wx.navigateTo({ url: `/pages/process/order-check/index?id=${this.data.form.id}` }) }, checkOrder: function(e){ wx.showLoading({ title: '正在处理', mask: true }) checkingOrder({ id: this.data.form.id }).then(result => { wx.hideLoading() util.showBackToast('订单审核已通过') event.emit('OrderMessage', { what: 12, desc: 'checkingOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, viewImage: function (e) { var imgList = [] if(e.currentTarget.dataset.type == 0){ for (let index = 0; index < this.data.form.totalWeighingPicture.length; index++) { imgList.push(this.data.form.totalWeighingPicture[index].url) } } else { for (let index = 0; index < this.data.form.emptyWeighingPicture.length; index++) { imgList.push(this.data.form.emptyWeighingPicture[index].url) } } wx.previewImage({ urls: imgList, current: e.currentTarget.dataset.url }) }, onUnload: function(){ event.remove('OrderMessage', this) } })