<template>
  <Row id="home" class="home">
    <Col span="3" class="aside" style="width:17%;height:100%">
      <img src="https://o7oe0d6qz.qnssl.com/image/homelogo.png" alt="" style="height:60px">
      <Menu style="width: 100%;" ref='subMenu' :active-name="vSubName" :open-names="vName" @on-select="go">
        <template v-for="(menu) in childMenu" >
          <Submenu :name="menu.name" :key="menu.name" v-show='!(isAdmin==false&&menu.item=="账户管理")'>
          <template slot="title">
            <Icon :type="menu.icon" style="font-size:20px;font-weight:bold"/>
            {{menu.item}}
          </template>
          <MenuItem v-for="child in menu.child" :key="child.name" :name="child.name" @click="go" :active-name="vSubName">{{child.item}}</MenuItem>
        </Submenu>
        </template>
      </Menu>
    </Col>
    <Col span="21" class="content" style="width:83%;height:100%">
      <Row class="header" style="height:6%">
        <Col span="20">
          <Menu mode="horizontal" :active-name="hName" @on-select="selectMenu">
            <MenuItem v-for="menu in menuList" :name="menu.name" :key="menu.name" >
              {{menu.item}}
            </MenuItem>
          </Menu>
        </Col>
        <Col span="2" class="account" style="">
         <span style="display:inline-block;line-height:6%;margin-left:30%">{{massage}}</span>
        </Col>
        <Col span="2" class="sign-out" >
          <a @click="loginOut" style="margin-left:38%">退出</a>
        </Col>
      </Row>
      <Row style="height:94%">
          <router-view></router-view>
      </Row>
    </Col>
  </Row>
</template>
<script>
import {getpersonMassage,loginOUT,adoptOneSeeResumeList,getChannelMassage,judeAdmin} from '../api/home.server.js'
import localstorage from '../service/localstorage.service.js'
  export default{
    data() {
      return {
        massage:'',
        isAdmin: false,
        arr:[],
        biaoshi:'',
        channelARR:[],
        isadmin:'',
        pageindex:0,
        pageSize:10,
        condition:'',
        xiabiao:'',
        itemSelect:'',
        type:'',
        hName: '',
        vName: ['1-1', '2-1', '3-1', '4-1'],
        vSubName: '1-1-1',
        menuList: [
          { name: '1', 
            item: '简历管理',
            child: [
             { 
              name: '1-1', 
              item: '全部管理', 
              icon: 'ios-apps-outline',
                child: [
                  { 
                    name: '1-1-1', 
                    item:'全部简历', 
                    route: '/allResume' 
                  }
                ] 
              },
              { name: '1-2', 
                item: '渠道简历',
                icon: 'ios-list',
                child: [] 
              }]
            },
            { name: '2', 
              item: '面试管理', 
              child: [
               { name: '2-1', 
                 item: '面试管理',
                 icon: 'ios-paper-outline',
                 child: [
                  { name: '2-1-1', 
                    item:'全部简历', 
                    route: '/interview' 
                  }] 
                }] 
              },
           {  name: '3', 
              item: '上传简历', 
              child: [{ 
               name: '3-1', 
               item: '上传简历',
               icon: 'ios-cloud-upload-outline',
               child: [
                 { name: '3-1-1', 
                   item:'上传简历', 
                   route: '/upload' 
                 }]
               }] 
             },
           { name: '4', 
             item: '系统管理', 
             child: [{ 
               name: '4-1', 
               item: '账户管理', 
               icon: 'ios-contact-outline',
               child: [{ 
                name: '4-1-1', 
                item:'账户管理', 
                route: '/account' 
               }]
              }, 
               { name: '4-2', 
                item: '邮箱管理', 
                icon:'ios-mail-outline',
                child: [{ 
                  name: '4-2-1', 
                  item:'邮箱管理', 
                  route: '/emailMange' 
                }]},
               { name: '4-3', 
                item: '二维码管理', 
                icon: 'ios-qr-scanner',
                child: [
                 { name: '4-3-1', 
                  item:'二维码管理', 
                  route: '/QRcode' 
                }]}
          
          ] },
        ],
        childMenu: [{ name: '1-1', item: '全部管理', child: [{ name: '1-1-1', item:'全部简历', route: '/allResume' }] },
        { name: '1-2', item: '渠道简历', child: [] }]
      }
    },
    watch:{
      $route(to,from){
        if (to.params.fromInterview){
          this.getActiveName()
        }
        
      }
    },
    methods: {
      go(name) {
        this.vSubName = name
        this.childMenu.map(par => {
          par.child.map(child => {
            if (child.name == name) {
              this.$router.push(child.route)
            }
          })
        })
      },
      selectMenu(name, type) {
        // type是否为刷新页面
        this.hName = name
        const menus = this.menuList.filter(v => name === v.name)
        this.childMenu = menus.length > 0 ? menus[0].child : [{ name: '1-1', item: '全部管理', child: [{ name: '1-1-1', item:'全部简历', route: '/allResume' }] },{ name: '1-2', item: '渠道简历', child: [] }]
        if (!type) { // 点击菜单默认展示第一个菜单
          this.vName = []
          this.vName[0] = ((name == '4') && this.isAdmin && this.childMenu[0].name) || ((name == '4') && !this.isAdmin && this.childMenu[1].name) || this.childMenu[0].name
          this.vSubName = ((name == '4') && this.isAdmin && this.childMenu[0].child[0].name) || ((name == '4') && !this.isAdmin && this.childMenu[1].child[0].name) || this.childMenu[0].child[0].name
        }
        if (name == '1') { // 简历管理模块需要加载渠道简历
          this.getChannelMenu()
        }
        if (type&&this.$route.path.indexOf('channel') > -1) {
          this.vSubName = this.$route.path.split('/')[2]
        }
        this.$nextTick(() => {
          this.$refs.subMenu.updateOpened();
          this.$refs.subMenu.updateActiveName();
        })
        this.go(this.vSubName)
      },
      // 获取个人信息
      getmassage(){
        getpersonMassage().then(res=>{
         this.massage=res.data.body.userName
        })
      },
     // 用户退出
      loginOut(){
        loginOUT().then(res=>{
          if(res.data.success==true){
            localstorage.remove('token')
            localstorage.remove('isADMIN')
            this.$router.push('/login') 
          }
        })
      },
      getChannelMenu(){
        this.menuList[0].child[1].child = []
        getChannelMassage().then(res=>{
          this.channelARR=res.data.body
          this.channelARR.map((item,index) => {
          var obj = {
          name: `${item.sourceName}`,
          item: item.sourceName,
          route: `/channel/${item.sourceCode}`
          }
          this.menuList[0].child[1].child.push(obj)
         })
        })
      },
      getActiveName (change) {
        let pathName = this.$route.path
        if (pathName.indexOf('channel') > -1) {
          this.hName = '1'
          this.vSubName = pathName.split('/')[2]
          this.vName = []
          this.vName.push('1-2')
          this.selectMenu(this.hName, 'refresh')
          return
        }
        this.menuList.map(parent => {
          parent.child.map(child => {
              child.child.map(grandson => {
                if (grandson.route == pathName) {
                  this.vSubName = grandson.name
                  this.hName = parent.name
                  this.vName = []
                  this.vName.push(child.name)
                }
              })
              
          })
        })
        this.selectMenu(this.hName, 'refresh')
      },
      // 判断是否为超级管理员
      judgeadmin(){
        judeAdmin().then(res=>{
          this.isAdmin=res.data.body
        })
      }
    },
    mounted() {
      this.getmassage()
      this.getActiveName()
      this.judgeadmin()
    }
  }
</script>

<style lang="less" scoped>
  .home{
    height: 100%;
    .aside{
      // min-height: 2050px;
      border-right: 1px solid #dcdee2;
      box-shadow: #dcdee2 0 0 6px 1px;
      // width:15%;
      img{
        height: 49px;
        width: 100%;
        padding: 3% 28%;
      }
      .ivu-menu{
        .ivu-menu-item{
          padding-left: 49px !important;
        }
      }
    }
    .content{
      .header{
        display: flex;
        align-items: center;height: 55px;
        border-bottom: 1px solid #dcdee2;
        line-height: 55px;
        border-bottom: 1px solid rgb(220, 222, 226);
        font-size: 14px;
        .sign-out{
          line-height: 6%
        }
        .ivu-menu{
          height: 35px;
          line-height: 35px;
          margin: 0 10px;
          .ivu-menu-item{
            padding: 0 13px;
            margin: 0 49px;
          }
          &:after{
            height: 0;
          }
        }
      }
    }
  }
</style>
