// pages/bidding/index/index.js import { getProxyOrderList } from "../../api/ztb" const util = require('../../../utils/util') const event = require('../../../utils/event.js') const app = getApp() const status = ['', 50, 51, 53, 54, 55] Page({ /** * 页面的初始数据 */ data: { height: app.globalData.fragmentHeight, loading: true, requesting: false, finished: false, tabList: ['全部', '待预约', '待送货', '结算中', '已完成', '已关闭'], tabIndex: 0, top: 0, orderList: [], form: { status: '', pageNum: 1 } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ height: app.globalData.fragmentHeight - 90, CustomBar: app.globalData.CustomBar, // ['form.status']: options.status ? statusList[parseInt(options.status)] : '', ['form.status']: options.status? options.status:'', // tabIndex: options.status ? parseInt(options.status) : 0 tabIndex: options.tabIndex ? parseInt(options.tabIndex) : 0 }) event.on('ProxyMessage', this, this.onEvent) this.fetchOrderList() }, onEvent: function (message) { if (message.what == 400) { this.onRefreshList() } }, onRefreshList: function () { if (this.data.requesting) { return } this.setData({ orderList: [], ['form.status']: this.data.form.status, ['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 }) } getProxyOrderList(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 if (this.data.form.pageNum == 1) { this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), top: 0, finished, requesting: false, loading: false }) } else { 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) }) }, onTabChange: function ({ detail }) { if (this.data.tabIndex == detail.index) { return } this.data.tabIndex = detail.index this.data.form.status = status[this.data.tabIndex] this.onRefreshList() }, onUnload: function () { event.remove('ProxyMessage', this) } })