纸通宝SAAS仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

168 lines
5.3 KiB

// pages/process/order-check/index.js
import Scene from '../../index/scene'
import Dialog from '../../../components/dialog/dialog'
import { cancelOrder, repeatOrder, getFactoryOrderInfo, checkingOrder, printOrder} from "../../../api/saas"
const event = require('../../../utils/event')
const math = require('../../../utils/math')
const util = require('../../../utils/util')
const app = getApp()
Scene({
/**
* 页面的初始数据
*/
data: {
safeBottom: app.globalData.safeBottom,
status: 0,
form: null,
agent: 0,
title: '过磅详情'
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.agent){
this.data.agent = Number(options.agent)
}
if(options.status){
this.data.status = Number(options.status)
}
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 = '已完成'
}
if(this.data.status || this.data.status == 0){
result.data.paymentOrderInfo.receivableStatus = this.data.status
}
if(result.data.paymentOrderInfo.receivablePrice){
if(result.data.paymentOrderInfo.paidPrice){
result.data.paymentOrderInfo.lessPrice = math.minus(result.data.paymentOrderInfo.receivablePrice, result.data.paymentOrderInfo.paidPrice)
} else {
result.data.paymentOrderInfo.lessPrice = 0.00
}
}
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)
})
},
printOrderInfo: 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)
}
})
},
cancelOrder: function(e){
Dialog.confirm({ title: '温馨提示', message: '确定取消该订单?' }).then(() => {
wx.showLoading({ title: '正在获取', mask: true })
cancelOrder(this.data.form.id).then(result => {
wx.hideLoading()
util.showBackToast('订单已经取消')
event.emit('OrderMessage', { what: 12, desc: 'cancelOrder' })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
})
},
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.redirectTo({ 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 })
},
orderLogger: function(){
wx.navigateTo({url: `/pages/process/order-logger/index?type=1&orderId=${this.data.form.id}` })
},
onUnload: function(){
event.remove('OrderMessage', this)
}
})