// pages/stock/index.js import { getOrderList } from "../../api/saas" const util = require('../../../utils/util') const event = require('../../../utils/event') const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, /** * 页面的初始数据 */ data: { height: app.globalData.fragmentHeight - 100, loading: true, requesting: false, finished: false, tabList: [ {id: 1, name: '预约单'}, {id: 2, name: '待确认'}, {id: 3, name: '待结算'}, {id: 4, name: '已完成'}, {id: 5, name: '已取消'} ], orderList: [], form: { status: 1, pageNum: 1 } }, lifetimes: { // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 attached: function () { event.on('EventMessage', this, this.onEvent) }, detached: function () { event.remove('EventMessage', this) } }, methods: { onRestart: function () { if (!this.data.firstShow) { this.setData({userInfo: app.globalData.userInfo, height: app.globalData.fragmentHeight - 100 }) this.fetchOrderList() } this.data.firstShow = true }, onEvent: function (message) { if (message.what == 13) { this.onRefreshList() } else if (message.what == 888) { this.setData({ userInfo: app.globalData.userInfo, orderList: [], loading: false }) } }, onRefreshList: function () { this.setData({ orderList: [], ['form.status']: this.data.form.status, ['form.pageNum']: 1, loading: true, finished: false }) this.fetchOrderList() }, fetchOrderList: function () { if (!app.globalData.userInfo) { this.setData({ requesting: false, loading: false }) return } if (this.data.requesting || this.data.finished) { return } if (this.data.loading) { this.data.requesting = true } else { this.setData({ requesting: true }) } getOrderList(this.data.form).then(result => { if (result.data.records.length) { var respList = result.data.records let nowList = `orderList[${this.data.orderList.length}]` var num = this.data.form.pageNum var finished = this.data.form.pageNum >= result.data.pages this.setData({ [nowList]: respList, total: result.data.total, ['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) }) }, lookItem: function (e) { var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index] wx.navigateTo({ url: '/pages/order/detail/index?id=' + item.id + '&type=' + item.receiveType }) }, onTabChange: function (e) { if (this.data.form.status == e.detail.key) { return } this.data.form.status = e.detail.key this.onRefreshList() } } })