window.addEventListener('pageshow', function(event) {
 if(event.persisted) { // ios 有效, android 和 pc 每次都是 false
  // location.reload();
   _this.getCardNumber();
   _this.myVue.$children[0].initData();
 } else { // ios 除外
  if(sessionStorage.getItem('home_refresh') === 'true') {
   // location.reload();
    _this.getCardNumber();
    _this.myVue.$children[0].initData();
  }
 }
 sessionStorage.removeItem('home_refresh');
});
_this.pageinit = function(){
  localeResource = mylocaleResource;
  var storeEid = mbos.getRequestParams().storeEid;
  if(storeEid) {
      storeEid = "&storeEid=" + storeEid
  } else {
      storeEid = ""
  }
  _this.pagePath = location.origin + location.pathname + '?appid='+encodeURIComponent(mbos.getRequestParams().appid)+'&eid='+encodeURIComponent(mbos.getRequestParams().eid)+'&path='+mbos.getRequestParams().path+storeEid+'&name=';
  _this.imgPath = location.origin+'/mbos/store/'+encodeURIComponent(mbos.getRequestParams().storeEid || mbos.getRequestParams().eid)+'/'+mbos.getRequestParams().path;
  $('.img_hi').css({
    'background-image': 'url('+_this.imgPath+'/img-20230510-00.png)'
  })
  var personName = easContext.person.name;
  if(typeof personName == 'object'){
    personName = personName.l2;
  }
  $('.person_name').text(personName);
  _this.getVersion();
  _this.getCardNumber();
  _this.initBannerVue();
}
_this.mbosEasInvokeScript = function(methodName,param,callback){
  mbos.eas.invokeScript({
      name : 'commonOSFservice',
      param : [methodName, JSON.stringify(param)],
      success : function (res) {
          callback(res);
      },
      error:function(e){
          console.log(e);
      }
  })
}
_this.getVersion = function(){
  _this.mbosEasInvokeScript('InterGo_GetCurrUserInfoService',{},function(res){
    _this.version = Number(res.data.version);
    localStorage.InterGo_Version =  _this.version;
    if(_this.version < 2.1 || !_this.version){
      mbos('flexpanel5').hide();
      $('title').text('面试GO')
    }
  });
}
_this.getCardNumber = function(){
  _this.mbosEasInvokeScript('InterGo_GetAllTaskCount',{},function(res){
    var totalInterCount = res.data.totalInterCount;
    var totalJudgeCount =  res.data.totalJudgeCount;
    var totalScreenCount = res.data.totalScreenCount;
    mbos('label5').value(totalInterCount);
    mbos('label7').value(totalJudgeCount);
    mbos('label3').value(totalScreenCount)
  });
}
// 待面试
_this.openTointerview = function(event){
  sessionStorage.toDoListAtciveTab = '';
  // var src = _this.pagePath+'01.navui&tabIndex=0&pageType=interviewResults';
  // location.href = src;
  mbos.ui.open({
    path: mbos.getRequestParams().path,
    name:"01.navui",
    params:{
        tabIndex:0,
        pageType:'interviewResults'
    }
  });
}
// 面试分析
_this.openInterAnalyse = function(){
  var src = _this.pagePath+'00.custom#/inter_analyse';
  location.href = src;
  // mbos.ui.open({
  //   path: mbos.getRequestParams().path,
  //   name:"00.custom#/inter_analyse"
  // });
}
// 创建需求
// _this.createRequirements = function(event){
// 	alert('创建需求')
// }
// // 上传简历
// _this.uploadResume = function(event){
// 	alert('上传简历')
// }
// // 安排面试
// _this.scheduleInterview = function(event){
// 	alert('安排面试')
// }
// // 分享海报
// _this.sharePoster = function(event){
// 	alert('分享海报')
// }
// 待筛选简历
_this.screeningResumes = function(event){
  	sessionStorage.toDoListAtciveTab = '';
    mbos.ui.open({
      path: mbos.getRequestParams().path,
      name:"01.navui",
      params:{
          tabIndex:0,
          pageType:'resumeScreening'
      }
    });
}
// 待录面试结果
_this.recordInterviewResults = function(event){
	sessionStorage.toDoListAtciveTab = '';
  	mbos.ui.open({
      path: mbos.getRequestParams().path,
      name:"01.navui",
      params:{
          tabIndex:1,
          pageType:'interviewResults'
      }
    });
}

// 我的需求
// _this.myNeeds = function(event){
// 	alert('我的需求')
// }
	        
mbos('page').bind('afterOnload',function(){
  var videomsgDialog = {
    template: '#videomsgDialog',
    data: function(){
      return {
        videoInterMsg: [],
        showVideoMsgBox: false,
        showLoading: false,
        imgPath: location.origin+'/mbos/store/'+encodeURIComponent(mbos.getRequestParams().storeEid || mbos.getRequestParams().eid)+'/'+mbos.getRequestParams().path,
        pagePath: location.origin + location.pathname + '?appid='+encodeURIComponent(mbos.getRequestParams().appid)+'&eid='+encodeURIComponent(mbos.getRequestParams().eid)+'&path='+mbos.getRequestParams().path+(mbos.getRequestParams().storeEid ? "&storeEid=" + mbos.getRequestParams().storeEid : '')+'&name=',
      }
    },
    props: [],
    created: function(){
      this.localeResource = window.localeResource;
    },
    components: {
      
    },
    methods: {
      // 获取视频面试信息弹框
      getVideoInterviewMsg: function(recordId){
        var that = this;
        try{
          /*判断某条待面试记录所处状态*/
          mbos.eas.invokeScript({
            name:"commonOSFservice",
            param:['GetVideoInterviewServiceOSF',JSON.stringify({recordId: recordId})],
            success:function(res){
              if(res.code=="0"){
              that.videoInterMsg = res.data;
              that.showVideoMsgBox = true
              }else{
                var resJson = JSON.stringify(res);
                  if (resJson.indexOf("请求云之家openauth2服务失败") >= 0) {
                    alert(that.localeResource.common_loginTimeout)
                  }else if (resJson.indexOf("无法连接EAS服务器") >= 0) {
                    alert(that.localeResource.common_EAS500)
                  }else{
                    var tipInfo = that.localeResource.common_errorMsg;
                  if(res.mesg){
                    tipInfo = res.mesg;
                  }
                   mbos.ui.showError({
                    title:tipInfo,
                  })
                  }
                  return false;
              }
            },
            error:function(e){
              return false;
            }
          })
        }catch(e){
          console.log(e)
        }
      },
      openZoomLink: function(){
        this.showLoading = true;
        window.location.href = this.videoInterMsg.startUrl;
      },
      doCopy: function () {
        var that = this;
        this.$copyText(this.videoInterMsg.meetingId || 'abc').then(function (e) {
          var msg;
          that.videoInterMsg.videoType == 'tencent' ?
          msg = that.localeResource.videomsgDialog_info_2 :
          msg = that.localeResource.videomsgDialog_info_3;
          that.$toast(msg);
        }, function (e) {
          that.$toast('Can not copy');
        })
      }
    }
  }
  // 首页
  var cA = {
    template:'#comA',
    data: function(){
      return {
        hasData:false,
        todayNum:'',
        tomorrowNum:'',
        curIndex:0,
        taskList:[],
        curList:{
            taskItemList:[]
        },
        bannerImgBg: [],
        currYear: '<span>'+new Date().getFullYear()+'</span>',
        imgPath: location.origin+'/mbos/store/'+encodeURIComponent(mbos.getRequestParams().storeEid || mbos.getRequestParams().eid)+'/'+mbos.getRequestParams().path,
        pagePath: location.origin + location.pathname + '?appid='+encodeURIComponent(mbos.getRequestParams().appid)+'&eid='+encodeURIComponent(mbos.getRequestParams().eid)+'&path='+mbos.getRequestParams().path+(mbos.getRequestParams().storeEid ? "&storeEid=" + mbos.getRequestParams().storeEid : '')+'&name=',
        currItem: {}
      }
    },
    components: {
      videomsgDialog: videomsgDialog
    },
    created: function(){
      this.localeResource = window.localeResource;
      this.initData();
      
    },
    methods: {
      initData: function(){
          var that = this;
          mbos.eas.invokeScript({
              name:"commonOSFservice",
              param:['InterGo_GetRecentTaskListService',JSON.stringify({daysCount: 2})],
              //needShowLoading: false, 此属性为false时加载数据不会出现mbos自带的loading动画
              success:function(res){
                  if(res.code=="0"){
                      that.taskList = res.data.taskList;
                      that.hasData = ( that.taskList[0].countNum == 0 && that.taskList[1].countNum == 0 ) ? false : true;
                      that.curIndex = ( that.taskList[0].countNum == 0 && that.taskList[1].countNum != 0 ) ? 1 : 0;
                      that.curList = that.taskList[that.curIndex];

                      that.todayNum = that.taskList[0].countNum;
                      that.tomorrowNum = that.taskList[1].countNum;
                  }else{
                      var resJson = JSON.stringify(res);
                      if (resJson.indexOf("请求云之家openauth2服务失败") >= 0) {
                          alert(that.localeResource.common_loginTimeout)
                      }else if (resJson.indexOf("无法连接EAS服务器") >= 0) {
                          alert(that.localeResource.common_EAS500)
                      }else{
                        var tipInfo = that.localeResource.common_errorMsg;
                        if(res.mesg){
                            tipInfo = res.mesg;
                        }
                        mbos.ui.showError({
                          title:tipInfo,
                        })
                      }
                      that.taskList = [{countNum:0,items:[]},{countNum:0,items:[]}];
                      that.hasData = ( that.taskList[0].countNum == 0 && that.taskList[1].countNum == 0 ) ? false : true;
                      that.curIndex = ( that.taskList[0].countNum == 0 && that.taskList[1].countNum != 0 ) ? 1 : 0;
                      that.curList = that.taskList[that.curIndex];
                      that.todayNum = that.taskList[0].countNum;
                      that.tomorrowNum = that.taskList[1].countNum;
                  }
              },
              error:function(e){
                console.log(e);
                that.taskList = [{countNum:0,items:[]},{countNum:0,items:[]}];
                that.hasData = ( that.taskList[0].countNum == 0 && that.taskList[1].countNum == 0 ) ? false : true;
                that.curIndex = ( that.taskList[0].countNum == 0 && that.taskList[1].countNum != 0 ) ? 1 : 0;
                that.curList = that.taskList[that.curIndex] ;
                that.todayNum = that.taskList[0].countNum;
                that.tomorrowNum = that.taskList[1].countNum;
                // mbos.ui.showError({
                //   title:"调用接口失败，请联系管理员",
                // })
              }
          });
        },
      showList: function(index){
          this.curIndex = index;
          this.curList = this.taskList[index];
      },
      linkPage: function(item){
          if(item.state=='待面试'){
            location.href = this.pagePath + '00.custom#/resume_detail?recordId='+encodeURIComponent(item.recordId);
          }else if(item.state==='待评价'){
            location.href = this.pagePath + '00.custom#/judge_page?recordId='+encodeURIComponent(item.recordId);
          }else{
            location.href = this.pagePath + '00.custom#/judge_page?recordId='+encodeURIComponent(item.recordId);
          }
      },
      // 显示视频面试信息弹框
      openVideoInterviewBox: function(item){
          this.$refs.videobox.getVideoInterviewMsg(item.recordId);
      },
    }
  }
  
  var routes = [
    { path: '/', meta: {title:'招聘GO', tab: true}, component:  cA, name: 'a'},
  ]

  var router = new VueRouter({
    routes: routes
  });
  router.beforeEach(function(to, from, next) {
    if (to.meta.title) {//如果设置标题，拦截后设置标题
      document.title = to.meta.title
    }
    next()
  })
  var VueClipboard = VueClipboard;
  // 入口
  setTimeout(function(){
    _this.myVue = new Vue({
      router: router,
      VueClipboard: VueClipboard,
      el: '#app',
      data: function(){
        return {}
      },
      created: function(){
        // this[this.$route.name] = '/mbos/store/4000148/fileLibrary/attendance-'+ this.$route.name +'.png';
      },
      watch: {
        // '$route': function(to, from){
        //   this[to.name] = '/mbos/store/4000148/fileLibrary/attendance-'+ to.name +'.png';
        //   this[from.name] = '/mbos/store/4000148/fileLibrary/attendance-'+ from.name +'1.png';
        //   if(to.meta.tab){
        //     this.tabShow = true;
        //   }else{
        //     this.tabShow = false;
        //   }
        // } 
      },
      components:{
        cA: cA,
      },
      methods: {
        close: function(){
          this.bills = false;
        }
      }
    }).$mount('#app')
  })
})

// _this.openPage = function(event){

// }
_this.initBannerVue = function(){
  // rem --> px
  ; (function (win, doc) {
    function change() {
      var rem = (doc.documentElement.clientWidth * 20) / 375
      doc.documentElement.style.fontSize = rem + 'px'
      var d = document.createElement('div')
      d.style.cssText = 'width:10rem;height:0;overflow: hidden;position:absolute;z-index:-1;visibility: hidden;'
      document.body.appendChild(d)
      var dw = d.offsetWidth // 10rem的实际展示px值

      document.body.removeChild(d)
      realRem = (rem * rem * 10) / dw
      doc.documentElement.style.fontSize = realRem + 'px'
    }
    if ($('body').length >= 1) {
      change()
    }
    win.addEventListener('load', change, false)
    win.addEventListener('resize', change, false)
    win.addEventListener('orientationchange', change, false)
  })(window, document)
  // s-HR设置的banner图
  var bannerBox = {
    template:'#bannerBox',
    data: function(){
      return {
        imgPath: location.origin+'/mbos/store/'+encodeURIComponent(mbos.getRequestParams().eid)+'/'+mbos.getRequestParams().path+'/',
        bannerImgBg: [],
      }
    },
    components: {},
    created: function(){
      this.localeResource = window.localeResource;
      this.getBannerImage();
    },
    methods: {
      // banner图
		getBannerImage: function(){
          var that = this;
          mbos.eas.invokeScript({
            name:"commonOSFservice",
            param:['getLightAppBannerService',JSON.stringify({number:'002'})],
            success:function(res){
              console.log('调用接口成功');
              if(res.code == 0){
                if(res.data.imageSrc.length > 0){
                  var imageSrc = res.data.imageSrc;
                  var easUrl = easContext.easUrl+'/shr';
                  for(var i = 0; i < imageSrc.length; i ++){
                      that.bannerImgBg.push(location.protocol+'//wscloud.kingdee.com/recRegister/recDemand/getSHRImageByURL?serviceURL=' + encodeURIComponent(easUrl) + '&imageURL=' + imageSrc[i]);
                  }
                  $('.glicon').hide();
                  // console.log(that.bannerImgBg)
                }else{
                  $('#bannerBoxHtml').hide();
                  $('.glicon').css('visibility','visible');
                }
              }else{
                var tipInfo = that.localeResource.home_info_3;
                if(res.msg){
                  tipInfo = res.msg;
                }
                $('#bannerBoxHtml').hide();
                $('.glicon').css('visibility','visible');
              }
            },
            error:function(e){
              console.log('调用接口失败');
              console.log(e);
              $('#bannerBoxHtml').hide();
              $('.glicon').css('visibility','visible');
            }
          })
		},
    }
  }
  
  var routes = [
    { path: '/', meta: {title:'', tab: true}, component:  bannerBox, name: 'bannerBox'},
  ]

  var router = new VueRouter({
    routes: routes
  });
  router.beforeEach(function(to, from, next) {
    if (to.meta.title) {//如果设置标题，拦截后设置标题
      document.title = to.meta.title
    }
    next()
  })
  // 入口
  setTimeout(function(){
    _this.myBanerVue = new Vue({
      router: router,
      el: '#customBaner',
      data: function(){
        return {}
      },
      created: function(){
      },
      components:{
        bannerBox: bannerBox,
      },
      methods: {
        close: function(){
          this.bills = false;
        }
      }
    }).$mount('#customBaner')
  })
}
        
