<template>
    <div class="all-box" :class="isIos ? 'isIos' : ''">
      <div style="height: 100%;">
        <initHome v-if="active_index===0" @activeMenu="activeMenu" ref="initHome"/>
        <department v-if="active_index===1" isHide></department>
        <userCenter v-if="active_index===2" ref="userCenter"></userCenter>
      </div>

      <!-- 导航 -->
      <van-tabbar v-model="active_index" :class="isIos ? 'padding-m' : ''" :fixed="false">
        <van-tabbar-item>
          <icon :name="tabs == 0? 'statistics_checked':'statistics'" :class="tabs == 0? 'active':''"></icon>
          <span>首页</span>
        </van-tabbar-item>
        <van-tabbar-item>
          <icon :name="tabs == 1? 'footer_nav_work_press':'footer_nav_work'" :class="tabs == 1? 'active':''"></icon>
          <span>组织</span>
        </van-tabbar-item>
        <van-tabbar-item>
          <icon :name="tabs == 2? 'footer_nav_me_press':'footer_nav_me'" :class="tabs == 2? 'active':''"></icon>
          <span>我的</span>
        </van-tabbar-item>
      </van-tabbar>

      <van-popup v-model="updateVisible" :close-on-click-overlay="false" style="border-radius: 0.15rem; background: #fff0;">
        <div class="buyPopupBody" style="width: 85vw;">
          <div class="buyPopupContent">
            <div class="buyPopupTitle"> {{announcement.type==1? '版本更新':'系统公告'}}</div>
            <div style="max-height: 400px;overflow-y: auto;font-size: 0.3rem;" v-html="announcement.focus"></div>
            <van-row gutter="20">
              <van-col span="12"><van-button block type="info" @click="updateVisible=false">我知道了</van-button></van-col>
              <van-col span="12"><van-button block type="default" @click="getItemBuyPopupPage">查看详情</van-button></van-col>
            </van-row>
          </div>
        </div>
      </van-popup>
    </div>
</template>

<script>
  import initHome from '@/view/body/initHome';
  import userCenter from '@/view/body/userCenter';
  import department from '@/view/user/department';
  // import management from '@/point/view/body/management';
  // import messageList from '@/point/view/body/messageList';
  import {get_employee_all} from '@/api/login';
  export default {
    components: {userCenter,initHome,department},
    data() {
      return {
        isIos:this.$getCache('iPhone'),
        active_index:0,
        tabs:0,
        manNUm: 0, // 绩效数

        // 公共
        updateVisible:false,
        announcement:'',
      };
    },
    watch: {
      active_index(val){
        this.tabs = val;
      }
    },
    methods: {
      IsPC() {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
          if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
          }
        }
        return flag;
      },
      //系统公告
      noticeList() {
        let params = { page: 1, page_size: 10 };
        this.$axiosUser('get', '/api/pro/announcement/list', params).then(res => {
          if (res.data.code == 1) {
            let list = res.data.data.list[0];
            if(!list){
              return false
            }
            if (localStorage.getItem('noticeId')) {
              if (localStorage.getItem('noticeId') != list.id) {
                this.updateVisible = true;
                localStorage.setItem('noticeId', list.id);
              }
            } else {
              localStorage.setItem('noticeId', list.id);
              this.updateVisible = true;
            }
            this.announcement = list;
          }
        });
      },
      getItemBuyPopupPage() {
        this.updateVisible = false;
        this.$router.push({ path: '/noticeList' });
      },
      setEmployee() {
        get_employee_all().then(res => {
          if (res.data.code == 1) {
            let list = res.data.data.list;
            let data = {};
            list.forEach((item, index) => {
              if (item.status == 2) {
                item.name = item.name + '(已离职)';
              }
              data[item.id] = item;
            });
            if (window.plus) {
              plus.storage.setItem('SET_EMPLOYEE_MAP_JX', JSON.stringify(data));
            } else {
              localStorage.setItem('SET_EMPLOYEE_MAP_JX', JSON.stringify(data));
            }
          }
        });
      },
      activeMenu() {
        this.active_index = 1;
      },
      shwoCunt() {
        this.$axiosUser('get', '/api/pro/notice/number').then(res => {
          this.cuntNum = res.data.data;
        });
      },
    },
    created() {
      if (this.IsPC()&&process.env.NODE_ENV == 'production') {
        this.$router.replace({name: 'error'}); // 提示去APP端
        return false
      }
      this.shwoCunt();
      this.setEmployee();
      this.noticeList();
    },
  };
</script>

<style scoped lang="scss">
  .all-box{
    height: calc(100% - 1rem) !important;
    position: relative;
  }
  .isIos {
    height: calc(100% - 1.4rem) !important;
  }
  .padding-m {
    padding-bottom: 0.4rem;
  }
  /deep/ .shortcut-option-btn .van-icon {
    font-size: 0.6rem;
  }

  .all-box /deep/ .van-tabbar-item {
    text-align: center;
    position: relative;
  }

  .all-box /deep/ .van-tabbar-item .svg-icon {
    color: #606266;
    height: 0.36rem;
    margin-bottom: 0.08rem;
  }

  .all-box .footer_nav_add_press {
    height: 0.8rem !important;
  }

  .all-box /deep/ .van-tabbar-item .active {
    color: #238dfa;
  }

  .all-box /deep/ .van-tabbar-item span {
    display: block;
    font-size: 0.2rem;
    margin-bottom: 0.08rem;
  }

  .buyPopupBody {
    width: 85vw;
  }
  .buyPopupContent{
    background: white;
    padding:0.2rem 0.24rem;
    border-radius: 0.15rem;
  }
  .buyPopupContent /deep/ img,.buyPopupContent /deep/ ul,.buyPopupContent /deep/ li,.buyPopupContent /deep/ p{
    width: 100%;
  }
  .buyPopupTitle{
    background: #1a89fa;
    text-align: center;
    border-radius: 0.1rem;
    font-weight: normal;
    font-size: 0.32rem;
    height: 0.8rem;
    line-height: 0.8rem;
    color: #fff;
    margin-top: 0.24rem;
  }
</style>
