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

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

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

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

    getInfo(e){
      let {id,approveStatus,superviseUser} = e.currentTarget.dataset.set
      if(approveStatus=="1" && superviseUser==this.data.loginName){
        wx.redirectTo({
          url: `../../../pages/project_approve/approveChecking/index?id=${id}`
        })
      }else{
        wx.redirectTo({
          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,
            minRoleId:res.data.minRoleId,
            projectId:app.globalData.projectId,
            projectNameArgs:app.globalData.projectName,
            initData:{text:app.globalData.projectName,id:app.globalData.projectId}
          })  
          this.getProjectCheckingData(app.globalData.projectId,res.data.loginName,res.data.deptId,res.data.minRoleId);
        }
      })
    },

  /**
    * 查询项目举牌验收数据
    */
   getProjectCheckingData(projectId,loginName,deptId,minRoleId) {
    var that = this;
    //判断角色，
    if(minRoleId==2||minRoleId==3||minRoleId==4){
      deptId=0;
    }
    let param = {
      "projectId": projectId,
      "nowUserName":loginName,
      "deptId":deptId,
      "activeName":this.data.activeState
    }
    this.queryCount(param);
    wx.request({
      url: app.globalData.reqUrl + '/wechat/projectchecking/list',
      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/projectchecking/findGroupCountByApprove',
        data: param,
        method: "get",
        success: function (res) {
          that.setData({
            jxzCount:res.data.data.jxz,
            ywcCount:res.data.data.ywc
          });
        }
      });
    },

  /**
   * 标签切换
   */
  typeJump(e){
    let index = e.currentTarget.dataset.index;
    let nav = "";
    if(index == 1){
      nav = 'jxz';
    }else if(index == 2){
      nav = 'ywc';
    }
    this.setData({
      activeState:nav
    });
    this.getProjectCheckingData(this.data.projectId,this.data.loginName,this.data.deptId,this.data.minRoleId)
  },

    returnToPage: function () {
      /*关闭当前页面，跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
      if(wx.getStorageSync('nav-menu')=="gd"){
        wx.redirectTo({
          url: '../../../pages/gengduogongneng/gengduogongneng',
        })
      }else{
        wx.redirectTo({
          url: '../../../pages/quality_manage/index',
        })
      }
    },

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

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})