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

    /**
     * 页面的初始数据
     */
    data: {
        deptId:"",
        userId:"",
        loginName:"",
        projectId:"",
        minRoleId:"",
        projectData:{},
        initData: {},
        show:false,
        listData:[],
        request:app.globalData.reqUrl
    },

    getInfo(e){
        let {deployId,procInsId,taskId,taskName,procDefKey,startDeptName,startUserName,procDefName,businessKeyName} = e.currentTarget.dataset.set
        if(taskName=="提交申请"){
          if(procDefKey=="flow_xmglzdl_qjspb"){
            wx.redirectTo({
              url: `../editLeaveTask/index?deployId=${deployId}&procInsId=${procInsId}&nickName=${startUserName}&deptName=${startDeptName}&procDefName=${procDefName}&taskId=${taskId}&taskName=${taskName}&projectName=${businessKeyName}&ret=await`,
            })
          }else{
            wx.redirectTo({
              url: `../editTask/index?deployId=${deployId}&procInsId=${procInsId}&nickName=${startUserName}&deptName=${startDeptName}&procDefName=${procDefName}&taskId=${taskId}&taskName=${taskName}&projectName=${businessKeyName}&ret=await`,
            })
          }
        }else{
          //根据不同业务跳转不同表单
          if(procDefKey=="flow_xmglzdl_qjspb"){
            wx.redirectTo({
              url: `../approveLeaveTask/index?deployId=${deployId}&procInsId=${procInsId}&nickName=${startUserName}&deptName=${startDeptName}&procDefName=${procDefName}&taskId=${taskId}&taskName=${taskName}&projectName=${businessKeyName}`,
            })
          }else{
            wx.redirectTo({
              url: `../approveTask/index?deployId=${deployId}&procInsId=${procInsId}&nickName=${startUserName}&deptName=${startDeptName}&procDefName=${procDefName}&taskId=${taskId}&taskName=${taskName}&projectName=${businessKeyName}`,
            })
          }
        }
    },

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

  /**
    * 查询项目举牌验收数据
    */
   getListData(loginName,userId,deptId,minRoleId) {
    var that = this;
    //businessKey注解掉可以跨项目审批
    let param = {
        //"businessKey":this.data.projectId,
        "nowRole":minRoleId,
        "nowDept":deptId,
        "nowUserName":loginName,
        "nowUser":userId
    }
    wx.request({
      url: app.globalData.reqUrl + '/wechat/flowTask/myAwaitFlowTaskList',
      data:param,
      method: "post",
      success: function (res) {
        res = res.data;
        if(res.code=="200"){
          that.setData({
            listData:res.rows
          })
        }else{
          app.toast(res.msg);
        }
      }
    });
    },

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

    },

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

    },

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

    goFQLC:function(){
      wx.redirectTo({
        url: '../myFlowDefinition/index',
      })
    },

    goWDSQ:function(){
      wx.redirectTo({
        url: '../myProcessIns/index',
      })
    },

    goBLWC:function(){
      wx.redirectTo({
        url: '../finished/index',
      })
    },

      //项目切换 返回值
  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() {

    }
})