// pages/gengduogongneng/gengduogongneng.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:4,  
    show: false,
    projectId:'',
    projectName:'' ,
    loginName:'',
    nickName:'',
    deptName:'',
    remark:'',
    roleId:'',
    roleName:'',
    menuList:[],
    initData:{},
    hiddenn:true,
    todoDB:0,
    approveDB:0,
    ad:0,
    td:0,
  },
  
    
  //项目切换 返回值
  onProjectSelect(e){
    let projectId = e.detail.id;
    let projectName = e.detail.text;
    app.globalData.projectId = projectId;
    app.globalData.projectName = projectName;
    this.setData({
      projectId:projectId,
      projectName:projectName
    })
  },

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

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

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
      //获取缓存数据
      wx.getStorage({
        key: 'userinfo',
        success:function(res){
          that.setData({
            roleId:res.data.roleId,
            roleName:res.data.roleName,
            remark:res.data.remark,
            loginName:res.data.loginName,
            nickName:res.data.nickName,
            deptName:res.data.deptName,
            projectId:app.globalData.projectId,
            projectName:app.globalData.projectName,
            initData:{text:app.globalData.projectName,id:app.globalData.projectId}
          })
          that.selectMenuList(res.data.loginName);
          that.awaitTask(res.data.minRoleId,res.data.deptId,res.data.loginName,res.data.userId); 
        }
      })
      
  },

  selectMenuList:function(loginName){
    var that = this;
    wx.request({
      url: app.globalData.reqUrl+'/wechat/selectRoleMenuList',
      data:{
        username:loginName
      },
      method:"get",
      success:function(res){
        res=res.data;
        if(res.code =='200'){
            that.setData({
              menuList:res.data
            })
        }
      }
    })
  },

  goMenu:function(event){
    let id = event.currentTarget.dataset.id;
    if(id == 'CLSSQE'){
		//材料实收确认
		wx.getStorage({
			key: 'userinfo',
			success:function(res){
              wx.navigateToMiniProgram({
                appId: 'wxc44b5d588f599758',
                path: `pages/tabbar/order-new/index?type=0&szhUserId=${res.data.userId}&szhUserName=${res.data.loginName}`
              })
            }
		})
    //   wx.navigateToMiniProgram({
    //     appId: 'wx7c39a25db91228f7',
    //     path: 'pages/tabbar/order-new/index?type=0'
    //   })
    }else if(id == 'LSRYSH'){
      //临时人员审核
      wx.navigateTo({
        url: '../temporaryToExamine/index',
      })
    }else if(id == 'FQJPYS'){
      //发起举牌验收
      wx.navigateTo({
        url: '../check_accept_initiate/index',
      })
    }else if(id == 'TJJPYS'){
      //提交举牌验收
      wx.navigateTo({
        url: '../check_accept_list/index',
      })
    }else{
      wx.setStorageSync('nav-menu', "gd");
      wx.redirectTo({
        url: event.currentTarget.dataset.url
      })
    }
  },


   // 底部导航
   onChange(event) {
    // event.detail 的值为当前选中项的索引
    this.setData({ active: event.detail });
  },

  //跳转到项目概况页面
  XMGK:function(){
    wx.redirectTo({
      url: '../xiangmugaikuang/xiangmugaikuang'
    })
  },

  //跳转到安全管理
  AQGL:function(){
    wx.redirectTo({
      url:'../safety_manage/index'
    }) 
  },

  //跳转到质量管理
  ZLGL:function(){
    wx.redirectTo({
      url:'../quality_manage/index'
    }) 
  },
   //跳转到进度管理
   JDGL2:function(){
    app.toast("敬请期待！");
    // wx.redirectTo({
    //   //url: '../deepExcavation/index'
    //   url:'../../pageage/Progress-management/index'
    // }) 
  },

  //退出登录
  TCDL:function(){
    wx.clearStorageSync();
    wx.setStorageSync('isReload', "1")
    wx.redirectTo({
      url: '../login/login',
    })
  },

  //修改密码
  XGMM:function(){
    wx.setStorageSync('nav-menu', "gd");
    wx.redirectTo({
      url: '../updatePassword/updatePassword'
      }) 
  },
  
  //返回到工程列表页面
  goGCLB:function(){
    wx.redirectTo({
      url: '../xiangmugaikuang/xiangmugaikuang'
    })
  },

  onClosePopup() {
    this.setData({ show: false });
  },
  
  //查询当前登录人的代办任务
  awaitTask(minRoleId,deptId,loginName,userId) {
    let param = {
      //"businessKey":this.data.projectId,
      "nowRole":minRoleId,
      "nowDept":deptId,
      "nowUserName":loginName,
      "nowUser":userId,
      "activeName":"await"
    }
    var that = this;
    wx.request({
      url: app.globalData.reqUrl + '/wechat/flowTask/myAwaitFlowTaskListCount',
      data:param,
      method: "post",
      success: function (res) {
        res = res.data;
        if(res.code=="200"){
          that.setData({
            todoDB:res.data.todo,
            td:res.data.todo,
            ad:res.data.approve
          })
          console.log("db");
          console.log(that.data.todoDB)
          console.log(that.data.approveDB) 
        }
      }
    })
  },
})