// healthyService/pages/healthyIntro/healthyIntro.js
import {throttle} from "../../../utils/util"
import {doctorList} from "../../../api/consultExpert"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    blockHeight:"150rpx",
    type:'',
    doctorList:[],
    page:1,
    pageNumber:10,
    isTriggered:false,
    show:false,
    expertise_id:'',
    province_id:'',
    city_id:'',
    keyword:'',
    lock:false,
    is_online:0,
    sort_order:1,
    inquiry_type:'1',
    inquiry_mode:'9',
  },
  handleRefresher(){

    this.setData({
      lock:false,
      page:1,
      doctorList:[]
    });
    this.getDoctorList()
   },
   goExpertDetail:throttle(function(e){
       let {doctorid}=e.currentTarget.dataset;
        app.method.navigateTo({
            url:'/healthyService/pages/visitDetail/visitDetail?doctor_id='+doctorid
        })
   }),
   getDoctorList(){
     let {expertise_id,province_id, city_id,sort_order,keyword,page,pageNumber,is_online,inquiry_type,inquiry_mode}=this.data;
    doctorList({
      expertise_id:expertise_id,
      province_id:province_id,
      city_id:city_id,
      sort_order: sort_order,
      is_first_online:is_online,
      keyword:keyword,
      inquiry_type,
      inquiry_mode,
      page:page,
      per_page:pageNumber
    }).then((res)=>{
      let {doctorList}=this.data;
       if(res.data.length==0){
        this.setData({
          lock:true,
          isTriggered:false
        });
        return false;
       }else{
          this.setData({
            isTriggered:false,
            doctorList:doctorList.concat(res.data)
          })
       }
   

    })
   },
  onfresh(){
    this.setData({
      page:1,
      doctorList:[],
      lock:false
    })
    this.getDoctorList();
  },
  lower(e) {
    let {lock}=this.data;
    let addPage=this.data.page+1;
    if(!lock){
      this.setData({
        page:addPage
      });
      this.getDoctorList();
    }  
  },
  goDetail:throttle(function(){
      let url=this.data.type?'/healthyService/pages/visitDetail/visitDetail':'/healthyService/pages/healthyDetail/healthyDetail'
    app.method.navigateTo({
        url: url
    })
  }),

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      if(options.type){
          this.setData({
              type:'visit'
          })
      }
    this.getDoctorList();
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})