// pages/refundMsgList/refundMsgList.js
const app = getApp()
import {throttle} from "../../../utils/util"
import {
  hasRead,
  getMsg
} from "../../../api/msg"
Page({

  /**
   * 页面的初始数据
   */
  data: {
   list:[],
   isTriggered:false,
   isLock:false,
   navName:"退款消息",
   page:1,
   img_host:'https://oss.prod.applets.igandanyiyuan.com/applet/patient/static',
   notice_system_type:3,
   pageNumber:10
  },
  handleGo:throttle(function(event){
    let link_type=event.currentTarget.dataset.type;
    let index=event.currentTarget.dataset.index;
    let link_params=event.currentTarget.dataset.params;
    let id=event.currentTarget.dataset.id;
    let status=event.currentTarget.dataset.status;
    hasRead(id).then(data=>{
      let currentItem=`list[${index}].read_status`
     if(status==0){
       this.setData({
         [currentItem]:1
       })
     }
       this.goOther(link_type,link_params);
    })
  }),
  lower(){
   if(!this.data.isLock){
     this.setData({
       page:++this.data.page
     })
     this.handleGetMsg();
   }
  },
  goBack(){
    wx.navigateBack({
      delta: 1,
    })
  },
  handleRefresher(){
    this.setData({
      page:1,
      isLock:false,
      list:[]
    })
    this.handleGetMsg()
   },
  handleGetMsg(){
    let {page,pageNumber,notice_system_type}=this.data;
    getMsg({
      page:page,
      per_page:pageNumber,
      notice_system_type:notice_system_type
    }).then(data=>{
      let result=data.data;
      if(result.length==0){
        this.setData({
          isLock:true
        })
      };
      this.setData({
        isTriggered:false,
        list:this.data.list.concat(result)
      })
    })
  },
  goOther(link_type,link_params){
  
    let url='';
    if(link_type==1){
      url= '/TUIService/pages/index?currentConversationID='+link_params.doctor_user_id+'&order_inquiry_id='+link_params.order_inquiry_id+'&inquiry_type='+link_params.inquiry_type;
    }else if(link_type==7){
      url='/patient/pages/myWelfare/myWelfare'
    }else if(link_type==8){
      url='/patient/pages/medinceOrder/medinceOrder'
    }else if(link_type==9){
      url='/patient/pages/expressDetail/expressDetail?logistics_no='+link_params.order_product_id
    }else if(link_type==10){
      url='/patient/pages/orderDetail/orderDetail?order_inquiry_id='+link_params.order_inquiry_id
    }else if(link_type==12){
     
    }else if(link_type==13){
      url='/patient/pages/prescriptDetail/prescriptDetail?order_prescription_id='+link_params.order_prescription_id
    }else if(link_type==15){
        url='/healthyService/pages/healthyOrderDetail/healthyOrderDetail?order_service_id='+link_params.order_no
      };
    app.method.navigateTo({
      url: url,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.type=="express"){
      this.setData({
        notice_system_type:4,
        navName:"物流消息"
      });
      wx.setNavigationBarTitle({
        title: '物流消息',
      })
    }
    this.handleGetMsg();
  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

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