// pages/index/repair/repair.js
import HTTP from "../../../../requestFn/Api";
const app = getApp();
Page({
  data: {
    garden_id: null,
    order_list: [],
    status: {
      1: "未派单",
      2: "已派单",
      3: "已完结"
    },
    page: 1,
    page_size: 10,
    hasMore: true,
  },
  onLoad() {
    const that = this;
    const {
      garden_id
    } = app.globalData;
    if (garden_id) {
      that.setData({
        garden_id
      });
    }
  },
  onShow(options) {
    this.init()
  },
  goAddRepair() {
    wx.navigateTo({
      url: './addrepair/addrepair',
    })
  },
  init() {
    this.setData({
      page: 1,
      hasMore: true
    })
    this.getOrder_list(true);
  },
  async getOrder_list(flag = false) {
    const that = this;
    let {
      page,
      page_size,
      order_list,
      garden_id
    } = that.data
    let res = await HTTP.Repair_order({
      garden_id,
      page,
      page_size
    })
    that.setData({
      order_list: flag ? res.list : [...order_list, ...res.list],
      page: ++page,
      hasMore: res.list.length === page_size
    })
  },
  onReachBottom() {
    if (!this.data.hasMore) {
      wx.showToast({
        title: '没有更多数据了',
        icon: 'none'
      })
      return console.log('没有更多数据了');
    }
    this.getOrder_list()
  },
  goDetail(e) {
    const {
      id
    } = e.currentTarget
    wx.navigateTo({
      url: `./detail/detail?id=${id}`,
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */

  onPullDownRefresh: function () {
    app.onRefresh();
    this.init(true);
  },
})