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.
118 lines
3.4 KiB
118 lines
3.4 KiB
// pages/process/order-list/index.js
|
|
import Dialog from '../../../components/dialog/dialog'
|
|
import { getFactoryOrderList, cancelOrder } from "../../api/saas"
|
|
const event = require('../../../utils/event')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
// * 页面的初始数据
|
|
data: {
|
|
height: app.globalData.fragmentHeight,
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
top: 0,
|
|
orderList: [],
|
|
form: {
|
|
status: 0,
|
|
pageNum: 1
|
|
},
|
|
title: '全部'
|
|
},
|
|
// * 生命周期函数--监听页面加载
|
|
onLoad: function (options) {
|
|
if(options.status){
|
|
this.data.form.status = Number(options.status)
|
|
if(this.data.form.status == 1){
|
|
this.data.title = '待定价订单'
|
|
} else if(this.data.form.status == 2){
|
|
this.data.title = '待过磅审核订单'
|
|
} else if(this.data.form.status == 3){
|
|
this.data.title = '待付款订单'
|
|
} else if(this.data.form.status == 4){
|
|
this.data.title = '已完成订单'
|
|
} else if(this.data.form.status == 5){
|
|
this.data.title = '已关闭订单'
|
|
}
|
|
}
|
|
event.on('OrderMessage', this, this.onEvent)
|
|
this.setData({ height: app.globalData.fragmentHeight, title: this.data.title })
|
|
this.fetchOrderList()
|
|
},
|
|
onEvent: function(message){
|
|
if (message.what == 12) {
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
onRefreshList: function () {
|
|
this.setData({
|
|
orderList: [],
|
|
['form.pageNum']: 1,
|
|
loading: true,
|
|
finished: false
|
|
})
|
|
this.fetchOrderList()
|
|
},
|
|
fetchOrderList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
if (this.data.loading) {
|
|
this.data.requesting = true
|
|
} else {
|
|
this.setData({ requesting: true })
|
|
}
|
|
getFactoryOrderList(this.data.form.status, this.data.form).then(result => {
|
|
if (result.data && result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `orderList[${this.data.orderList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = ((num - 1) * this.data.form.pageSize + respList.length) >= result.data.total
|
|
if(this.data.form.pageNum == 1){
|
|
this.setData({
|
|
[nowList]: respList,
|
|
['form.pageNum']: (num + 1),
|
|
top: 0,
|
|
finished,
|
|
requesting: false,
|
|
loading: false
|
|
})
|
|
} else {
|
|
this.setData({
|
|
[nowList]: respList,
|
|
['form.pageNum']: (num + 1),
|
|
finished,
|
|
requesting: false,
|
|
loading: false
|
|
})
|
|
}
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
cancelOrder: function(e){
|
|
Dialog.confirm({ title: '温馨提示', message: '确定取消该订单?' }).then(() => {
|
|
wx.showLoading({ title: '正在获取', mask: true })
|
|
cancelOrder({ id: this.data.form.id }).then(result => {
|
|
wx.hideLoading()
|
|
util.showToast('订单已经删除')
|
|
this.onRefreshList()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
})
|
|
},
|
|
priceOrder: function(e){
|
|
wx.navigateTo({ url: '/pages/process/order-info/index?id=' + e.currentTarget.dataset.id })
|
|
},
|
|
onUnload: function(){
|
|
event.remove('OrderMessage', this)
|
|
}
|
|
|
|
})
|