// pages/order/order/index.js
import {
  fhGetOrderList
} from '../../api/nursing/index'
const {
  Loading,
  hLoading
} = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    orderStatus: 1000,
    menu: [{
        label: '全部',
        type: 1000
      },
      {
        label: '待接单',
        type: 1001
      },
      {
        label: '待签约',
        type: 1005
      },
      {
        label: '待结单',
        type: 1006
      },
      {
        label: '已完成',
        type: 1009
      },
      {
        label: '待评价',
        type: 1007
      },
      {
        label: '欠费缴单',
        type: 'arrearage'
      }
    ],
    nurseOrder: []
  },
  switchOrderStatus({
    currentTarget: {
      dataset
    }
  }) {
    const {
      type
    } = dataset
    this.setData({
      orderStatus: type
    })
    this.getNurseOrders(type)
  },
  async getNurseOrders(type) {
    Loading()
    console.log(type);
    if (type === 1000) {
      type = null
    }
    try {
      const {
        results
      } = type === 'arrearage' ? await fhGetOrderList({
        balanceStatus: '-1'
      }) : await fhGetOrderList({
        orderStatuses: type
      })
      // const { results } = await fhGetOrderList({orderStatus: type})
      console.log(results)
      this.setData({
        nurseOrder: results.records,
        loading: false
      })
    } catch (e) {
      console.log('debug axios', e)
    }
    hLoading()
  },
  nav({
    currentTarget: {
      dataset
    }
  }) {
    console.log(dataset);
    const {
      type,
      path,
      query
    } = dataset
    wx.navigateTo({
      url: path + '?query=' + query + '&type='+  type
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getNurseOrders()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getNurseOrders(this.data.orderStatus)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getNurseOrders(this.data.orderStatus)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {}
})