// pageage/safetyManagement/securityCheckGR/index.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        deptId:"",
        loginName:"",
        projectId:"",
        minRoleId:"",
        projectData:{},
        initData: {},
        show:false,
        listData:[],
        activeState:"await",
        dspCount:0,
        ywcCount:0
    },

    getInfo(e){
      let {id,type} = e.currentTarget.dataset.set
      if(type=="1"){
        wx.redirectTo({
          url: `approveCheckDetection/index?id=${id}`,
        })
      }else if(type=="2"){
        wx.redirectTo({
          url: `approveMeasure/index?id=${id}`,
        })
      }else if(type=="3"){
        wx.redirectTo({
          url: `approveChecking/index?id=${id}`,
        })
      }else if(type=="4"){
        wx.redirectTo({
          url: `approveMaterialSeal/index?id=${id}`,
        })
      }else{
        //没有这个类型
      }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
     //获取缓存数据
      wx.getStorage({
        key: 'userinfo',
        success:res=>{
          this.setData({
            deptId:res.data.deptId,
            loginName:res.data.loginName,
            projectId:app.globalData.projectId,
            minRoleId:res.data.minRoleId,
            initData:{text:app.globalData.projectName,id:app.globalData.projectId}
          })  
          this.getListData(res.data.loginName);
        }
      })
    },

  /**
    * 查询项目审批数据
    */
   getListData(loginName) {
    var that = this;
    let param = {
        "nowUserName": loginName,
        "activeName":that.data.activeState
    }
    this.queryCount(param);
    wx.request({
      url: app.globalData.reqUrl + '/wechat/projectAuditinfo/findList',
      data:param,
      method: "get",
      success: function (res) {
        that.setData({
            listData:res.data.data
        })
      }
    });
    },

    //查询统计
    queryCount(param){
      let that = this;
      wx.request({
        url: app.globalData.reqUrl + '/wechat/projectAuditinfo/findAuditCount',
        data: param,
        method: "get",
        success: function (res) {
          that.setData({
            dspCount:res.data.data.await,
            ywcCount:res.data.data.finished
          });
        }
      });
    },

  /**
   * 标签切换
   */
  typeJump(e){
    let index = e.currentTarget.dataset.index;
    let nav = "";
    if(index == 1){
      nav = 'await';
    }else if(index == 2){
      nav = 'finished';
    }
    this.setData({
      activeState:nav
    });
    this.getListData(this.data.loginName);
  },

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

    },

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

    },

    returnToPage: function () {
      /*关闭当前页面，跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
      wx.redirectTo({
        url: '../gengduogongneng/gengduogongneng',
      })
    },

      //项目切换 返回值
  onProjectSelect(e){
    let projectId = e.detail.id;
    let projectName = e.detail.text;
    app.globalData.projectId = projectId;
    app.globalData.projectName = projectName;  
    this.onLoad();
  },

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

    },

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

    },

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

    },

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

    },

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

    }
})