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

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    //项目的名称
    projectName: '',
    //视频接入数
    videoAll: '',
    //视频在线数
    videoOnline: '',
    //视频的列表
    videoList: [],
    projectId:'',
    lastTapTime:'',
    loadShow:false,

    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: function (options) {
    var that = this;
      //加载蒙版
      that.onClickShow();
      //获取缓存数据
      wx.getStorage({
        key: 'userinfo',
        success:function(res){
          that.setData({
            loginName:res.data.loginName,
            userName:res.data.userName,
            projectName: app.globalData.projectName,
            projectId:app.globalData.projectId,
            initData:{text:app.globalData.projectName,id:app.globalData.projectId}
          })  
        }
      }) 
    //视频数量
    this.getProjectVideoAll(app.globalData.projectId);
    //视频列表
    this.getProjectVideoList(app.globalData.projectId);
  },

  // 获取项目下的视频数
  getProjectVideoAll:function(even) {
    wx.request({
      url: app.globalData.reqUrl+'/weixin/video/getProjectVideoNum',
      method: 'get',
      data: {
          projectName:even
      },
      success: resData => {
          this.setData({
            videoAll:resData.data.videoAll,
            videoOnline:resData.data.videoOnline
          })
          this.onClickHide();
      }
    })
  },

  //获取项目下的视频的列表
  getProjectVideoList:function(even) {
    wx.request({
      url: app.globalData.reqUrl+'/weixin/video/getProjectVideoList',
      method: 'get',
      data: {
        projectName:even
      },
      success: resData => {
          this.setData({
            videoList:resData.data
          })
          this.onClickHide();
      }
    })
  },

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

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

  //视频全屏
  doubleClick: function (e) {
    var curTime = e.timeStamp
    var lastTime = e.currentTarget.dataset.time 
    if (curTime - lastTime > 0) {
      if (curTime - lastTime < 2000) {//是双击事件
        wx.navigateTo({
          url: '../shipinquanping/shipingquanping?rtmpUrl=' + e.currentTarget.dataset.url + '&videoName=' + e.currentTarget.dataset.name + "&token=" + e.currentTarget.dataset.token
        })
      } 
    }
    this.setData({
      lastTapTime: curTime
    })
  },

  quanping:function(e){
    wx.navigateTo({
      url: '../shipinquanping/shipingquanping?rtmpUrl=' + e.currentTarget.dataset.url + '&videoName=' + e.currentTarget.dataset.name + "&token=" + e.currentTarget.dataset.token
    })
  },

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

  },

})