const app = getApp()

Page({
  data: {
    baseImgUrl: app.FILE_SERVER_URL,
    topBarH: app.globalData.CustomBar,
    typeId:app.publicService,
    // 公告
    notice: [],
    list:[],
    page: 1,
    pageSize: 10,
    tabs: [{
      lab: '云服务',
      val: 0
    }, {
      lab: '云诉求',
      val: 1
    }, {
      lab: '云学习',
      val: 2
    }, {
      lab: '云公开',
      val: 3
    }],
    curTab:0,
    userInfo:{},
    startTime: '',
    endTime: '',
  },

  /**
   * 切换筛选
   */
  tabSelect: function (params) {
    this.data.page = 1;
    const index = params.currentTarget.dataset.index;
    this.data.curTab = index;
    this.data.freshIng = true;
    this.data.startTime = '';
    this.data.endTime = '';
    this.setData(this.data)
  },
  refresh: function (params) {
    this.data.page = 1;
    this.data.list = [];
    this.getList();
  },
  /**
   * 开始时间
   */
  startTimeChange: function (e) {
    this.data.startTime = e.detail.value;
    this.data.page = 1;
    this.data.list = [];
    this.setData(this.data);
    this.getList();
  },
  /**
   * 结束时间
   */
  endTimeChange: function (e) {
    this.data.endTime = e.detail.value;
    this.data.page = 1;
    this.data.list = [];
    this.setData(this.data);
    this.getList();
  },
  //下拉刷新
  dropDown: function (params) {
    this.data.page = this.data.page+1;
    this.setData(this.data);
    this.getList();
  },
 
  getList: function (id) {
    if (this.data.curTab == 0) {
        this.getWkDynamicsPage();
    }
    if (this.data.curTab == 1) {
      this.getDifficultyList();
  }
    
    if (this.data.curTab == 2) {
      this.getBanner();
  }
  if (this.data.curTab == 3) {
    this.getPublicContentPage();
}
  
    
  },
  /**
   * 获取工困难诉求列表
   */
  getDifficultyList: function (id) {
    let params = {
      limit:this.data.pageSize,
      page:this.data.page,
      endTime:this.data.endTime,
      startTime:this.data.startTime,
      userId:this.data.userInfo.userId,
    };
    console.log(params,'params===>');
    app.axios("GET", "app", `/difficultyAppeal/difficultyList`, params).then(res => {
      if (res.code == 1) {
        this.data.freshIng = false;
        this.data.list = [...this.data.list,...res.data.list];
        console.log( this.data.list ,' this.data.list ===>');
        this.setData(this.data);
      }
    })
  },
  /**
   * 上报困难诉求
   */
  escalationDifficulty: function (params) {
    wx.navigateTo({
      url: `/pages/the-masses/escalation/index`,
    })
  },
  /**
   * 困难诉求查看
   */
  toescalationDetail: function (params) {
    console.log(params,'params===>');
    wx.navigateTo({
      url: `/pages/the-masses/escalation/index?difficultyId=${params.currentTarget.dataset.item.difficultyId}`,
    })
  },
   /**
   * 查看服务详情
   */
  toserveDetail: function (params) {
    wx.navigateTo({
      url: `/pages/party-member/serve/index?dynamicsId=${params.currentTarget.dataset.item.dynamicsId}`,
    })
  },
  /**
   * 上报服务
   */
  escalationAppeal: function (params) {
    wx.navigateTo({
      url: `/pages/party-member/serve/index`,
    })
  },
   // 工作动态列表/云服务
  getWkDynamicsPage :function() {
    let params = {
      limit:this.data.pageSize,
      page:this.data.page,
      endTime:this.data.endTime,
      startTime:this.data.startTime,
      typeId:this.data.typeId,
      userId:this.data.userInfo.userId,
    };
    app.axios("GET", "app", `/work/wkDynamicsPage`, params).then(res => {
      if (res.code == 1) {
        this.data.freshIng = false;
        this.data.list = [...this.data.list,...res.data.list];
        this.setData(this.data);
      }
    })
  },
   /**
   * 上报服务
   */
  escalationServe: function (params) {
    wx.navigateTo({
      url: `/pages/party-member/serve/index`,
    })
  },




  /**
   * 获取云学习
   */
  getBanner: function () {
    app.axios("GET", "app", "/partyLearnContent/partyLearnPage", {
      limit:this.data.pageSize,
      page:this.data.page,
      // userId: app.globalData.userInfo.userId
    }, false).then(res => {
      wx.stopPullDownRefresh();
      if (res.code == 1) {
        console.log(res,'res====>');
        this.data.freshIng = false;
        
        if (this.data.page == 1) {
          this.data.notice = [res.data.list[0]];
        }
        this.data.list = [...this.data.list,...res.data.list];
        this.setData(this.data);
      }
    })
  },
   /**
   * 获取云公开
   */
  getPublicContentPage: function () {
    app.axios("GET", "app", "/publicContent/publicContentPage", {
      limit:this.data.pageSize,
      page:this.data.page,
      // userId: app.globalData.userInfo.userId
    }, false).then(res => {
      wx.stopPullDownRefresh();
      if (res.code == 1) {
        console.log(res,'res====>');
        this.data.freshIng = false;
        
        if (this.data.page == 1) {
          this.data.notice = [res.data.list[0]];
        }
        this.data.list = [...this.data.list,...res.data.list];
        this.setData(this.data);
      }
    })
  },

  /**
   * 通知详情
   */
  toMsgDetail: function (params) {
    const item = params.currentTarget.dataset.item;
    wx.navigateTo({
      url: `/pages/the-masses/web/index?id=${item.publicContentId}`,
    })
  },
  
  /**
   * 跳转账户信息
   */
  toSkip: function (params) {
    const item = params.currentTarget.dataset.item;
    const url = params.currentTarget.dataset.url;
    if (url || item?.href) {
      wx.navigateTo({
        url: url || item.href,
      })
    }
  },
  //跳转为民服务
  toAppeal: function () {
    wx.navigateTo({
      url: `/pages/party-member/problem/index`,
    })
  },

  onLoad(option) {
    // this.data.userInfo = app.globalData.userInfo;
    // this.getBanner();
    // this.data.curTab = 0;
    this.data.userInfo = app.globalData.userInfo;
    this.data.freshIng = true;
    this.setData(this.data)
    
  },

  onReady() {

  },

  // onPullDownRefresh() {
  //   this.getBanner();
  // }
})