// pages/consultAndBuy.js
const app = getApp()
import {
  getConsultTime,
  isReceivepatient
} from "../../../api/consultExpert"
import {throttle} from "../../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: null,
    show: false,
    id: '',
    img_host:'https://oss.prod.applets.igandanyiyuan.com/applet/patient/static',
    navName:"快速问诊",
    inquiry_type:2
    

  },
  handleGetConsultTime() {
    let {inquiry_type}=this.data;
    getConsultTime({
      inquiry_type:inquiry_type,
      inquiry_mode: 1,
    }).then(data => {
      this.setData({
        currentData: data
      })
    })
  },
  confirm(event) {
    let {id}=this.data;
    if (event.detail) {
      app.method.navigateTo({
        url: '/patient/pages/orderDetail/orderDetail?order_inquiry_id=' + id,
      })
    }
  },
  handleIsReceivepatient() {
    let {inquiry_type}=this.data;
    isReceivepatient({
      inquiry_type:inquiry_type,
      inquiry_mode: 1,
      doctor_id: ''
    }).then(data => {
      if (data.status == 1) {
        if(inquiry_type==2){
          app.method.navigateTo({
            url: '/patient/pages/selectPatient/selectPatient?inquiry_type=2',
          })
        }else{
          app.method.navigateTo({
            url: '/patient/pages/applyMedince/applyMedince',
          })
        }
       
     
      } else if (data.status == 2) {
        this.setData({
          show: true,
          id: data.data.order_inquiry_id
        })
      } else if (data.status == 3) {
        wx.showToast({
          title: data.message,
          icon: "none"
        })
      }
    })
  },
  handleThrottle:throttle(function(){

   this.goApplyMedince()
  }),
  goApplyMedince() {
    this.handleIsReceivepatient();

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.inquiry_type){
      this.setData({
        inquiry_type:options.inquiry_type,
        navName:"问诊购药"
      })
      wx.setNavigationBarTitle({
        title: '问诊购药',
      })
    }
    this.handleGetConsultTime()
  },
  goBack(){
    wx.navigateBack({
      delta: 1,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      img_host:app.hostConfig().imghost
    })
  },

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

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

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

  }
})