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

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    loadShow:false,
    loginName:'',
    userName:'',
    deptId:'',
    projectName:'',
    projectId:'',
    management:[],
    imgShow:false,
    imgUrl:'',

    initData:{}
  },

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

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

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

  onClickShow() {
    this.setData({ loadShow: true });
  },

  onClickHide() {
    this.setData({ loadShow: false });
  },

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

  /**
   * 车辆管理
   */
  getVehicleManagement:function(){
    wx.request({
      url: app.globalData.reqUrl+'/weixin/video/getVehicleManagement',
      method: 'get',
      data: {
        deptId:this.data.deptId,
        projectId:this.data.projectId
      },
      success: resData => {
          this.onClickHide();
          let management =resData.data.code == 200?resData.data.data:[];
          
          this.setData({
            management:management
          })
      }
    })
  },

  //打开放大的图片
  enlargeImage(e){
    this.setData({
      imgUrl:e.currentTarget.dataset.url,
      imgShow:true
    })
  },
  //关闭放大的图片
  closeImages(){
    this.setData({
      imgShow:false
    })
  },


  /**
   * 视频页面跳转
   */
  videoPageJump(e){
    let index = e.currentTarget.dataset.index
    if(index == 1){
      wx.redirectTo({
        url: '../xiangmushipin/xiangmushipin',
      })
    }else if(index == 2){
      wx.redirectTo({
        url: '../AIvideoAnalysis/index',
      })
    }
  },

  /**
   * 返回到更多功能页面
   */
  goGCLB:function(){
    wx.redirectTo({
      url: '../../pages/gengduogongneng/gengduogongneng'
    })
  },

})