const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    topBarH: app.globalData.CustomBar,
    curTab: 0,
    tabs: [{
      lab: '待处置',
      val: 1
    }, {
      lab: '已处置',
      val: 2
    }, {
      lab: '已取消',
      val: 3
    }],

    list: [],
    startTime: '',
    endTime: '',
    page: 1,
    pageSize: 10,
    userInfo:{}
  },

  /**
   * 开始时间
   */
  startTimeChange: function (e) {
    this.data.startTime = e.detail.value;
    this.data.page = 1;
    this.data.list = [];
    this.setData(this.data);
    this.getList(this.data.curTab+1);
  },
  /**
   * 开始时间
   */
  endTimeChange: function (e) {
    this.data.endTime = e.detail.value;
    this.data.page = 1;
    this.data.list = [];
    this.setData(this.data);
    this.getList(this.data.curTab+1);
  },
   /**
   * 切换筛选
   */
  tabSelect: function (params) {
    const index = params.currentTarget.dataset.index;
    this.data.curTab = index;
    this.data.freshIng = true;
    this.setData(this.data)
    
  },
  /**
   * 上拉刷新
   */
  refresh: function () {
    this.data.page = 1;
    this.data.list = [];
    this.setData(this.data);
    this.getList(this.data.curTab+1);
  },
  
  /**
   * 下拉加载
   */
  dropDown: function (params) {
    this.data.page = this.data.page+1;
    this.setData(this.data);
    this.getList(this.data.curTab+1);
  },
  /**
   * 上报困难诉求
   */
  push: function (params) {
    wx.navigateTo({
      url: `/pages/the-masses/escalation/index`,
    })
  },

  /**
   * 获取工困难诉求列表
   */
  getList: function (id) {
    let params = {
      limit:this.data.pageSize,
      page:this.data.page,
      endTime:this.data.endTime,
      startTime:this.data.startTime,
      difficultyState:id,
      userId:this.data.userInfo.userId,
    };
    console.log(params,'params===>');
    app.axios("GET", "app", `/difficultyAppeal/difficultyList`, params).then(res => {
      if (res.code == 1) {
        console.log(res,'res===>');
        this.data.freshIng = false;
        this.data.list = [...this.data.list,...res.data.list];
        this.setData(this.data);
      }
    })
  },
  /**
   * 查看详情
   */
  toDetail: function (params) {
    console.log(params,'params===>');
    wx.navigateTo({
      url: `/pages/the-masses/escalation/index?difficultyId=${params.currentTarget.dataset.item.difficultyId}`,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.freshIng = true;
    this.data.userInfo = app.globalData.userInfo;
    this.setData(this.data);
    this.getList(1);
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})