
const app = getApp()
import {pathographyList,pathographyDelete} from "../../../api/sickRecord"
import {throttle} from "../../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isTriggered:false,
    family_id:'',
    show:false,
    message:'',
    page:1,
    currentId:'',
    showRadio:true,
    isLock:false,
    per_page:10,
    img_host:'https://oss.prod.applets.igandanyiyuan.com/applet/patient/static',
    list:[]
  },
  handleRefresher(){
    this.setData({
      page:1,
      isLock:false,
      list:[]
    })
    this.handleFamily();
  },
  onDel(event) {
    let id=event.currentTarget.dataset.id;
   const {instance } = event.detail;
   instance.close();
   this.setData({
     show:true,
     currentId:id,
     message:"确定删除该病情记录？"
   })
 },
 confirm:throttle(function(event){
  if(event.detail){
    this.handlePathographyListDelte();
  }
}),
  handlePathographyListDelte(){
    let id=this.data.currentId
    pathographyDelete(id).then(data=>{
     wx.showToast({
       title: '删除成功',
       icon:'none'
     })
     this.handleRefresher();
    });

  },
  onChange(event) {
    this.setData({
      radio: event.detail,
    });
    var pages = getCurrentPages(); // 当前页面
 
 var beforePage = pages[pages.length - 2]; // 前一个页面
 beforePage.setData({  //修改上衣页面的参数
  'pathography_id':event.detail,
})
//返回上一个页面之前先处理一下数据或调用一下上个页面的方法
 wx.navigateBack({
     delta: 1,
     success: function() {
    
      }
  });
  },
  lower(e) {
    if(!this.data.isLock){
      this.setData({
        page: ++this.data.page
      })
       this.handleFamily()
    }
   },
  handleFamily(){
    let {family_id,page,per_page}=this.data;
    pathographyList({
      family_id,
      page,
      per_page
    }).then(data=>{
      let result=data.data;
      if(result.length==0){
        this.setData({
          isLock:true,
          isTriggered:false 
        })
        return false
     };
      this.setData({
        isTriggered:false,
        list:this.data.list.concat(result)
      })
    })
  },
  goBack(){
    wx.navigateBack({
      delta: 1,
    })
  },
  goInfo:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/memberDetail/memberDetail',
    })
  }),
  goDetail:throttle(function(event){
    let {id,index}=event.currentTarget.dataset;
    app.method.navigateTo({
      url: '/patient/pages/sickDetail/sickDetail?pathography_id='+id+"&index="+index,
    })
  }),
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
     this.setData({
      family_id:options.family_id
     })
    
     if(options.showRadio){
       this.setData({
         showRadio:false
       })
     }else{
      this.setData({
        showRadio:true
      })
     }
    
  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

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