  import {
    checkApplyList,
    findGroupCountByStatus
  } from '../../../api/projectApply'
  const app = getApp()
  Page({
  
    /**
     * 页面的初始数据
     */
    data: {
      jxzCount: 0,
      ywcCount: 0,
      activeState: "dys",
      total: 0,
      pageNum: 1,
      pageSize: 10,
      listData: [],
    },
  
    getInfo(e) {
      let {
        id
      } = e.currentTarget.dataset.set
      wx.redirectTo({
        url: `../info/index?businessKey=${id}`,
      })
    },
  
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      //获取缓存数据
      this.getListData();
    },
  
    /**
     * 查询项目举牌验收数据
     */
    getListData() {
      this.queryCount();
      let params = "activeName="+ this.data.activeState +"&pageNum=" + this.data.pageNum + "&pageSize=" + this.data.pageSize;
      checkApplyList(params).then(res =>{
        if (res.code == "200") {
          //这里处理this.data.lastDataSize=this.data.pageSize
          this.setData({
            total: res.total, 
            listData: this.data.listData.concat(res.rows)
          })
        }
      })
    },
  
    /**
     * 加载更多数据
     */
    onScrollToLower() {
        let nal = Math.ceil(this.data.total / this.data.pageSize);
        if (this.data.pageNum < nal) {
          this.setData({
            pageNum: this.data.pageNum + 1
          });
          this.getListData();
        }
    },
  
    //查询统计
    queryCount() {
        let params = "activeName="+ this.data.activeState;
      //查询统计数量
      findGroupCountByStatus(params).then(res =>{
          let dys = 0;
          let yys = 0;
          res.data.forEach(item => {
              if(item.applyStatus==10){
                dys += item.total;
              }else{
                yys += item.total;
              }
          });
        this.setData({
          jxzCount: dys,
          ywcCount: yys
        });
      });
    },
  
    /**
     * 标签切换
     */
    typeJump(e) {
      let index = e.currentTarget.dataset.index;
      let nav = "";
      if (index == 1) {
        nav = 'dys';
      } else if (index == 2) {
        nav = 'yys';
      }
      this.setData({
        activeState: nav,
        pageNum: 1,
        listData: [],
      });
      this.getListData();
    },
  
    returnToPage: function () {
      /*关闭当前页面，跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
      wx.redirectTo({
        url: '../../../pages/index/index',
      })
    },
  
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
  
    },
  
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
  
    },
  
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
  
    },
  
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
  
    },
  
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
  
    },
  
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
  
    },
  
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
  
    }
  })