// patient/pages/kepuList/kepuList.js
import {kepuList} from "../../../api/common"
import {throttle} from "../../../utils/util"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isTriggered:false,
    page:1,
    title:'科普文章',
    keyword:'',
    basic_class_id:'',
    lock:false,
    list:[]
  },
  handleRefresher(){
    this.setData({
      lock:false,
      page:1,
      list:[]
    });
    this.getList()
   },
  getList(){
   let {page,keyword,basic_class_id}=this.data;
   
    kepuList({
     keyword:keyword,
     page:page,
     basic_class_id,
     per_page:10
   }).then((res)=>{
       console.log(res)
     let {list}=this.data;
      if(res.data.length==0){
       this.setData({
         lock:true,
         isTriggered:false
       });
       return false;
      }else{
         this.setData({
           isTriggered:false,
           list:list.concat(res.data)
         })
      }
  console.log(this.data.list)

   })
  },
  goArticle:throttle(function(event){
    app.method.navigateTo({
        url:"/patient/pages/linkPage/linkPage?url="+encodeURIComponent(event.currentTarget.dataset.url)
      })
  }),
  onScroll(event) {
   
    wx.createSelectorQuery().select('#scroller')
      .boundingClientRect((res) => {
         // console.log(event.detail.scrollTop)
       if(event.detail.scrollTop>1400){
           this.lower();
       }
        
        
      }).exec();
    },
  lower(e) {
    let {lock}=this.data;
    let addPage=this.data.page+1;
    if(!lock){
      this.setData({
        page:addPage
      });
      this.getList();
    }  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      if(options.title){
        this.setData({
            title: decodeURIComponent(options.title)
        });
      }
      if(options.id){
          this.setData({
            basic_class_id:options.id
          })
      }
     
    this.getList()
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})