// nurse/pages/orderInfo/index.js
import {
  fhGetOrderList,
  fhCancelOrder
} from '../../api/nursing/index'
const {
  Loading,
  hLoading
} = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    nurseOrder: []
  },
  toPhone(){
    wx.makePhoneCall({
      phoneNumber: '13581887180'
    })
  },
  async getNurseOrders(query) {
    Loading()
    try {
      const {
        results
      } = await fhGetOrderList({
        nurseOrderId: query
      })
      console.log(results)
      this.setData({
        nurseOrder: results.records,
        loading: false
      })
    } catch (e) {
      console.log('debug axios', e)
    }
    hLoading()
  },
  onLoad(options) {
    const {
      query,
      type
    } = options
    this.setData({
      nurseOrderId: query,
      type,
    })
    this.getNurseOrders(query)
  },
  async cancelOrder() {
    Loading()
    const {
      nurseOrderId,
      type
    } = this.data
    try {
      const {
        results
      } = await fhCancelOrder({
        nurseOrderId
      })
      wx.showToast({
        title: '取消成功',
        icon: 'success',
        duration: 5000,
        success: function () {
          console.log(type);
          if(type === 'order'){
            wx.navigateBack({
              delta: 1
            });
          }else if(type=== 'submit'){
            wx.switchTab({
              url: '/pages/home/index',
            })
          }
          
        }
      })
      console.log(results)
    } catch (e) {
      console.log('debug axios', e)
    }
    hLoading()
  },
  onReady() {

  }
})