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

    /**
     * 页面的初始数据
     */
    data: {
        deptId:"",
        loginName:"",
        userName:"",
        projectId:"",
        projectData:{},
        projectNameArgs:"",
        initData: {},
        show:false,
        listData:[],
        activeState:"dzg",
        dzgCount:0,
        yclCount:0,
        zgcsCOunt:0,
        request:app.globalData.reqUrl
    },

    onClose(){
        this.setData({ show: false });  
    },
    showPopup() {
        this.setData({ show: true });
    },

    skipAdd(){
        wx.navigateTo({
            url: `../add/index?projectId=${this.data.initData.id}&projectName=`+this.data.initData.text,
        })
    },

    getInfo(e){
        let {id,checkState,lordSentUser,recheckSendUser} = e.currentTarget.dataset.set
        if((checkState==0 || checkState==3) && lordSentUser==this.data.loginName){
          //整改页面（状态时待整改&&整改人是当前登录人）
          wx.navigateTo({
            url: `../modify/index?id=${id}`,
          })
        }else if(checkState==1 && recheckSendUser==this.data.loginName){
          //复检页面 (状态时待复检&&复检人是当前登录人)
          wx.navigateTo({
            url: `../check/index?id=${id}`,
          })
        }else{
          wx.navigateTo({
            url: `../info/index?id=${id}`,
          })
        }
    },

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

  /**
    * 查询项目举牌验收数据
    */
   getListData() {
    var that = this;
    let param = {
        "infoType":"1",//1质量类，0安全类
        "projectId": that.data.projectId,
        "nowRole":"99",//默认传普通角色，真实角色查看的数据量太大，这里只查看自己相关的数据
        "nowUser":that.data.loginName,
        "activeName":that.data.activeState
    }
    wx.request({
      url: app.globalData.reqUrl + '/wechat/projectProblemmodify/list',
      data:param,
      method: "get",
      success: function (res) {
        that.setData({
            listData:res.data.data
        })
      }
    });
    //查询统计数量
    wx.request({
      url: app.globalData.reqUrl + '/wechat/projectProblemmodify/queryCount',
      data: param,
      method: "get",
      success: function (res) {
        let sum1=0;
        if(res.data.data.check0){
          sum1+=res.data.data.check0;
        }
        if(res.data.data.check1){
          sum1+=res.data.data.check1;
        }
        if(res.data.data.check3){
          sum1+=res.data.data.check3;
        }
        let sum4=0;
        let sum99=0;
        if(res.data.data.check4){
          sum4+=res.data.data.check4;
        }
        if(res.data.data.check99){
          sum99+=res.data.data.check99;
        }
        that.setData({
          dzgCount:sum1,
          yclCount:sum4,
          zgcsCount:sum99
        });
      }
    });
    },

     /**
   * 标签切换
   */
  trainingTypeJump(e){
    let index = e.currentTarget.dataset.index;
    let nav = "";
    if(index == 1){
      nav = 'dzg';
    }else if(index == 2){
      nav = 'ycl';
    }else if(index == 3){
      nav = 'zgcs';
    }

    this.setData({
      activeState:nav
    });
    this.getListData();
  },

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

    },

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

    },

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

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

    },

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

    },

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

    },

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

    },

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

    }
})