// pages/order/index.js import http from '../../utils/http' import util from '../../utils/util' import api from '../../utils/api' Page({ /** * 页面的初始数据 */ data: { id: -1, project: null, tabs: ['全部订单', '待审核', '已审核', '已完成', '已驳回'], statuses: ['', 'checking', 'checked', 'pass', 'reject'], list: [ [], [], [], [], [] ], pages: [1, 1, 1, 1, 1], tabIndex: 0, touchBottom: [false, false, false, false, false], work_points: [], pointIndex: -1 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var id = options.id ? options.id : 1 this.setData({ id }) api.getProject(this) api.getByName(this, 'work-points/get', 'work_points'); this.getList(); }, search() { this.setData({ list: [ [], [], [], [], [] ], pages: [1, 1, 1, 1, 1], touchBottom: [false, false, false, false, false], }) this.getList() }, getList: function () { var index = this.data.tabIndex var touchBottom = this.data.touchBottom[index] if (touchBottom) return false; var status = this.data.statuses[index] var page = this.data.pages[index] var that = this var pointIndex = this.data.pointIndex var work_point_id = pointIndex >= 0 ? this.data.work_points[pointIndex].id : 0 http({ url: 'orders/get', data: { project_id: this.data.id, status: status, page: page, work_point_id: work_point_id }, success: function (res) { if (res.code == 0) { var list = that.data.list var touchBottom = that.data.touchBottom list[index] = list[index].concat(res.data); if (res.data.length <= 0) { touchBottom[index] = true; } that.setData({ touchBottom, list }) } } }) }, switchTab: function (e) { var index = e.currentTarget.dataset.index this.setData({ tabIndex: index }) }, onChange: function (e) { var name = e.currentTarget.dataset.name this.setData({ [name]: e.detail.value }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })