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

    /**
     * 页面的初始数据
     */
    data: {
        deptId:"",
        loginName:"",
        userName:"",
        projectId:"",
        projectData:{},
        projectNameArgs:"",
        initData: {},
        show:false,
        listData:[],
        trainType:"",
        title:"",
        minTitle:"",
        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}&trainType=`+this.data.trainType,
        })
    },

    getInfo(e){
        let {id} = e.currentTarget.dataset.set
        wx.redirectTo({
          url: `../info/index?id=${id}&trainType=`+this.data.trainType,
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      let {trainType} = options
     //获取缓存数据
      wx.getStorage({
        key: 'userinfo',
        success:res=>{
          let title="";
          let minTitle="";
          if(trainType==0){
            title="教育培训管理";
            minTitle="培训";
          }else{
            title="应急演练管理";
            minTitle="演练";
          }
          this.setData({
            title,
            minTitle,
            trainType,
            deptId:res.data.deptId,
            loginName:res.data.loginName,
            userName:res.data.userName,
            projectId:app.globalData.projectId,
            projectNameArgs:app.globalData.projectName,
            minRoleId:res.data.minRoleId,
            initData:{text:app.globalData.projectName,id:app.globalData.projectId}
          })  
          this.getListData(app.globalData.projectId,res.data.deptId,trainType);
        }
      })
    },

  /**
    * 查询项目举牌验收数据
    */
   getListData(projectId,deptId,trainType) {
    var that = this;
    //判断角色,
    if(this.data.minRoleId==2||this.data.minRoleId==3||this.data.minRoleId==4){
      deptId=0;
    }
    wx.request({
      url: app.globalData.reqUrl + '/wechat/projectTrain/list',
      
      data: {
        "deptId":deptId,
        "trainType":trainType,
        "projectId": projectId
      },
      method: "get",
      success: function (res) {
        that.setData({
            listData:res.data.data
        })
      }
    })
    },

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

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

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})