<template>
  <div class="content-nav d-flex justify-space-between">
    <div class="content-title">
      <span :class="index < 2 ? 'red' : ''" v-for="(item, index) in title.split('')" :key="index">{{ item }}</span>
    </div>
    <div style="font-size:16px">
      <img src="@/assets/location.png" alt="" />
      您当前位置:
      <span class="title-name ml-4" @click="backFirst"> 首页 </span>
      <template v-if="title !== '关键词'">
        <span class="title-name" @click="backTitleOne"> > {{ titleName }} </span>
        <span v-if="titleTwo" class="title-name" @click="backTitle" :class="titleThree ? '' : 'acitve'"> > {{ titleTwo }} </span>
        <span v-if="titleThree" class="title-name acitve"> > {{ titleThree }} </span>
      </template>
      <template v-else>
        <span class="title-name"> > {{ title }} </span>
      </template>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    title: {
      default: '首页',
      type: String,
    },
  },
  data() {
    return {
      str: '',
      tabList: [
        {
          title: '首页',
          url: '/',
          children: [],
        },
        {
          title: '公司概况',
          url: '/profile',
          children: [
            {
              title: '公司简介',
              code: '0101',
            },
            {
              title: '公司领导',
              code: '0102',
            },
            {
              title: '组织架构',
              code: '0103',
            },
            {
              title: '企业VI',
              code: '0104',
            },
            {
              title: '联系方式',
              code: '0105',
            },
          ],
        },
        {
          title: '新闻中心',
          url: '/news',
          children: [
            {
              title: '集团新闻',
              code: '0201',
            },
            {
              title: '省公司新闻',
              code: '0202',
            },
            {
              title: '公司新闻',
              code: '0203',
            },
            {
              title: '图片新闻',
              code: '0204',
            },
            {
              title: '热点专题',
              code: '0205',
            },
            {
              title: '媒体关注',
              code: '0206',
            },
            {
              title: '视频新闻',
              code: '0207',
            },
            {
              title: '专题片',
              code: '0208',
            },
            {
              title: '企业画册',
              code: '0209',
            },
            {
              title: '现场风采',
              code: '0210',
            },
          ],
        },
        {
          title: '党的建设',
          url: '/building',
          children: [
            {
              title: '中心组学习',
              code: '0301',
            },
            {
              title: '示范党委',
              code: '0302',
            },
            {
              title: '党支部达标',
              code: '0303',
            },
            {
              title: '群团工作',
              code: '0304',
            },
            {
              title: '党建动态',
              code: '0305',
            },
            {
              title: '党风廉政',
              code: '0306',
            },
          ],
        },
        {
          title: '安全生产',
          url: '/production',
          children: [
            {
              title: '安全会议',
              code: '0401',
            },
            {
              title: '安全生产记录',
              code: '0402',
            },
            {
              title: '应急管理',
              code: '0403',
            },
            {
              title: '三讲一落实',
              code: '0404',
            },
            {
              title: '曝光台',
              code: '0405',
            },
          ],
        },
        {
          title: '通知公告',
          url: '/notice',
          children: [
            {
              title: '通知',
              code: '0501',
            },
            {
              title: '通报',
              code: '0502',
            },
            {
              title: '公告',
              code: '0503',
            },
            {
              title: '值班安排',
              code: '0504',
            },
            {
              title: '浮窗',
              code: '0505',
            },
          ],
        },
        {
          title: '信息公开',
          url: '/information',
          children: [
            {
              title: '基本信息',
              code: '0601',
              children: [
                {
                  title: '工商登记信息',
                  code: '060101',
                },
                {
                  title: '重要人事变动',
                  code: '060102',
                },
              ],
            },
            {
              title: '经营管理',
              code: '0602',
              children: [
                {
                  title: '重大改革重组',
                  code: '060201',
                },
              ],
            },
            {
              title: '公司公告',
              code: '0603',
              children: [
                {
                  title: '工作通知',
                  code: '060301',
                },
                {
                  title: '公示公告',
                  code: '060302',
                },
                {
                  title: '人才招聘',
                  code: '060303',
                },
              ],
            },
            {
              title: '社会责任',
              code: '0604',
            },
            {
              title: '关于信息公开',
              code: '0605',
              children: [
                {
                  title: '信息公开实施细则',
                  code: '060501',
                },
                {
                  title: '公司制度',
                  code: '060502',
                },
                {
                  title: '联系我们',
                  code: '060503',
                },
              ],
            },
          ],
        },
        {
          title: '审批事项',
          children: [
            {
              title: '公务用车',
              code: '',
            },
            {
              title: '领导干部外出报备',
              code: '',
            },
            {
              title: '疫情防控',
              code: '',
            },
            {
              title: '用印申请',
              code: '',
            },
            {
              title: '业务招待事项',
              code: '',
            },
            {
              title: '会议室使用',
              code: '',
            },
            {
              title: '办公用品领用',
              code: '',
            },
          ],
        },
        {
          title: '制度资料',
          url: '/system',
          children: [
            {
              title: '集团公司制度',
              code: '0801',
            },
            {
              title: '山西公司制度',
              code: '0802',
            },
            {
              title: '行业标准与制度',
              code: '0803',
            },
            {
              title: '公司制度',
              code: '0804',
            },
            {
              title: '地方规章',
              code: '0805',
            },
            {
              title: '培训课件',
              code: '0806',
            },
            {
              title: '培训影像',
              code: '0807',
            },
            {
              title: '科技创新',
              code: '0808',
            },
          ],
        },
        {
          title: '部门首页',
          url: '/department',
          children: [
            {
              title: '总经理工作部',
              code: '0901',
              children: [
                {
                  title: '部门职责',
                  code: '090101',
                },
                {
                  title: '岗位规范',
                  code: '090102',
                },
                {
                  title: '部门动态',
                  code: '090103',
                },
                {
                  title: '工作计划',
                  code: '090104',
                },
                {
                  title: '管理制度',
                  code: '090105',
                },
                {
                  title: '资料下载',
                  code: '090106',
                },
                {
                  title: '学习园地',
                  code: '090107',
                },
                {
                  title: '常用表格',
                  code: '090108',
                },
              ],
            },
            {
              title: '计划营销部',
              code: '0902',
              children: [
                {
                  title: '部门职责',
                  code: '090201',
                },
                {
                  title: '岗位规范',
                  code: '090202',
                },
                {
                  title: '部门动态',
                  code: '090203',
                },
                {
                  title: '工作计划',
                  code: '090204',
                },
                {
                  title: '管理制度',
                  code: '090205',
                },
                {
                  title: '资料下载',
                  code: '090206',
                },
                {
                  title: '学习园地',
                  code: '090207',
                },
                {
                  title: '常用表格',
                  code: '090208',
                },
              ],
            },
            {
              title: '财务管理部',
              code: '0903',
              children: [
                {
                  title: '部门职责',
                  code: '090301',
                },
                {
                  title: '岗位规范',
                  code: '090302',
                },
                {
                  title: '部门动态',
                  code: '090303',
                },
                {
                  title: '工作计划',
                  code: '090304',
                },
                {
                  title: '管理制度',
                  code: '090305',
                },
                {
                  title: '资料下载',
                  code: '090306',
                },
                {
                  title: '学习园地',
                  code: '090307',
                },
                {
                  title: '常用表格',
                  code: '090308',
                },
              ],
            },
            {
              title: '人力资源部',
              code: '0904',
              children: [
                {
                  title: '部门职责',
                  code: '090401',
                },
                {
                  title: '岗位规范',
                  code: '090402',
                },
                {
                  title: '部门动态',
                  code: '090403',
                },
                {
                  title: '工作计划',
                  code: '090404',
                },
                {
                  title: '管理制度',
                  code: '090405',
                },
                {
                  title: '资料下载',
                  code: '090406',
                },
                {
                  title: '学习园地',
                  code: '090407',
                },
                {
                  title: '常用表格',
                  code: '090408',
                },
              ],
            },
            {
              title: '党群工作部',
              code: '0905',
              children: [
                {
                  title: '部门职责',
                  code: '090501',
                },
                {
                  title: '岗位规范',
                  code: '090502',
                },
                {
                  title: '部门动态',
                  code: '090503',
                },
                {
                  title: '工作计划',
                  code: '090504',
                },
                {
                  title: '管理制度',
                  code: '090505',
                },
                {
                  title: '资料下载',
                  code: '090506',
                },
                {
                  title: '学习园地',
                  code: '090507',
                },
                {
                  title: '常用表格',
                  code: '090508',
                },
              ],
            },
            {
              title: '纪委办公室（审计部）',
              code: '0906',
              children: [
                {
                  title: '部门职责',
                  code: '090601',
                },
                {
                  title: '岗位规范',
                  code: '090602',
                },
                {
                  title: '部门动态',
                  code: '090603',
                },
                {
                  title: '工作计划',
                  code: '090604',
                },
                {
                  title: '管理制度',
                  code: '090605',
                },
                {
                  title: '资料下载',
                  code: '090606',
                },
                {
                  title: '学习园地',
                  code: '090607',
                },
                {
                  title: '常用表格',
                  code: '090608',
                },
              ],
            },
            {
              title: '燃料采购部',
              code: '0907',
              children: [
                {
                  title: '部门职责',
                  code: '090701',
                },
                {
                  title: '岗位规范',
                  code: '090702',
                },
                {
                  title: '部门动态',
                  code: '090703',
                },
                {
                  title: '工作计划',
                  code: '090704',
                },
                {
                  title: '管理制度',
                  code: '090705',
                },
                {
                  title: '资料下载',
                  code: '090706',
                },
                {
                  title: '学习园地',
                  code: '090707',
                },
                {
                  title: '常用表格',
                  code: '090708',
                },
              ],
            },
            {
              title: '物资管理部',
              code: '0908',
              children: [
                {
                  title: '部门职责',
                  code: '090801',
                },
                {
                  title: '岗位规范',
                  code: '090802',
                },
                {
                  title: '部门动态',
                  code: '090803',
                },
                {
                  title: '工作计划',
                  code: '090804',
                },
                {
                  title: '管理制度',
                  code: '090805',
                },
                {
                  title: '资料下载',
                  code: '090806',
                },
                {
                  title: '学习园地',
                  code: '090807',
                },
                {
                  title: '常用表格',
                  code: '090808',
                },
              ],
            },
            {
              title: '项目开发部',
              code: '0909',
              children: [
                {
                  title: '部门职责',
                  code: '090901',
                },
                {
                  title: '岗位规范',
                  code: '090902',
                },
                {
                  title: '部门动态',
                  code: '090903',
                },
                {
                  title: '工作计划',
                  code: '090904',
                },
                {
                  title: '管理制度',
                  code: '090905',
                },
                {
                  title: '资料下载',
                  code: '090906',
                },
                {
                  title: '学习园地',
                  code: '090907',
                },
                {
                  title: '常用表格',
                  code: '090908',
                },
              ],
            },
            {
              title: '燃料质量验收部',
              code: '0910',
              children: [
                {
                  title: '部门职责',
                  code: '091001',
                },
                {
                  title: '岗位规范',
                  code: '091002',
                },
                {
                  title: '部门动态',
                  code: '091003',
                },
                {
                  title: '工作计划',
                  code: '091004',
                },
                {
                  title: '管理制度',
                  code: '091005',
                },
                {
                  title: '资料下载',
                  code: '091006',
                },
                {
                  title: '学习园地',
                  code: '091007',
                },
                {
                  title: '常用表格',
                  code: '091008',
                },
              ],
            },
            {
              title: '安全监督部',
              code: '0911',
              children: [
                {
                  title: '部门职责',
                  code: '091101',
                },
                {
                  title: '岗位规范',
                  code: '091102',
                },
                {
                  title: '部门动态',
                  code: '091103',
                },
                {
                  title: '工作计划',
                  code: '091104',
                },
                {
                  title: '管理制度',
                  code: '091105',
                },
                {
                  title: '资料下载',
                  code: '091106',
                },
                {
                  title: '学习园地',
                  code: '091107',
                },
                {
                  title: '常用表格',
                  code: '091108',
                },
              ],
            },
            {
              title: '设备部',
              code: '0912',
              children: [
                {
                  title: '部门职责',
                  code: '091201',
                },
                {
                  title: '岗位规范',
                  code: '091202',
                },
                {
                  title: '部门动态',
                  code: '091203',
                },
                {
                  title: '工作计划',
                  code: '091204',
                },
                {
                  title: '管理制度',
                  code: '091205',
                },
                {
                  title: '资料下载',
                  code: '091206',
                },
                {
                  title: '学习园地',
                  code: '091207',
                },
                {
                  title: '常用表格',
                  code: '091208',
                },
              ],
            },
            {
              title: '发电部',
              code: '0913',
              children: [
                {
                  title: '部门职责',
                  code: '091301',
                },
                {
                  title: '岗位规范',
                  code: '091302',
                },
                {
                  title: '部门动态',
                  code: '091303',
                },
                {
                  title: '工作计划',
                  code: '091304',
                },
                {
                  title: '管理制度',
                  code: '091305',
                },
                {
                  title: '资料下载',
                  code: '091306',
                },
                {
                  title: '学习园地',
                  code: '091307',
                },
                {
                  title: '常用表格',
                  code: '091308',
                },
              ],
            },
            {
              title: '维护部',
              code: '0914',
              children: [
                {
                  title: '部门职责',
                  code: '091401',
                },
                {
                  title: '岗位规范',
                  code: '091402',
                },
                {
                  title: '部门动态',
                  code: '091403',
                },
                {
                  title: '工作计划',
                  code: '091404',
                },
                {
                  title: '管理制度',
                  code: '091405',
                },
                {
                  title: '资料下载',
                  code: '091406',
                },
                {
                  title: '学习园地',
                  code: '091407',
                },
                {
                  title: '常用表格',
                  code: '091408',
                },
              ],
            },
            {
              title: '热工专业',
              code: '0915',
              children: [
                {
                  title: '部门职责',
                  code: '091501',
                },
                {
                  title: '岗位规范',
                  code: '091502',
                },
                {
                  title: '部门动态',
                  code: '091503',
                },
                {
                  title: '工作计划',
                  code: '091504',
                },
                {
                  title: '管理制度',
                  code: '091505',
                },
                {
                  title: '资料下载',
                  code: '091506',
                },
                {
                  title: '学习园地',
                  code: '091507',
                },
                {
                  title: '常用表格',
                  code: '091508',
                },
              ],
            },
            {
              title: '电气专业',
              code: '0916',
              children: [
                {
                  title: '部门职责',
                  code: '091601',
                },
                {
                  title: '岗位规范',
                  code: '091602',
                },
                {
                  title: '部门动态',
                  code: '091603',
                },
                {
                  title: '工作计划',
                  code: '091604',
                },
                {
                  title: '管理制度',
                  code: '091605',
                },
                {
                  title: '资料下载',
                  code: '091606',
                },
                {
                  title: '学习园地',
                  code: '091607',
                },
                {
                  title: '常用表格',
                  code: '091608',
                },
              ],
            },
          ],
        },
      ],
      titleName: '',
      titleTwo: '',
      titleThree: '',
      code: '',
    };
  },
  watch: {
    '$route.query.code'() {
      this.code = this.$route.query.code;
      this.getLocal();
    },
  },
  created() {
    this.getLocal();
    this.code = this.$route.query.code;
  },
  methods: {
    getLocal() {
      this.titleTwo = '';
      this.titleThree = '';
      const path = this.$route.path;
      const query = this.$route.query;
      for (let i = 0; i < this.tabList.length; i++) {
        const title = this.tabList[i];
        if (title.url === path) {
          this.titleName = title.title;
          for (let k = 0; k < title.children.length; k++) {
            const item = title.children[k];
            if (query.code && query.code === title.children[k].code) {
              this.titleTwo = title.children[k].title;
              return;
            }
            if (item.children && item.children.length) {
              for (let m = 0; m < item.children.length; m++) {
                if (query.code && query.code === item.children[m].code) {
                  this.titleTwo = title.children[k].title;
                  this.titleThree = item.children[m].title;
                }
              }
            }
          }
        }
      }
    },
    backFirst() {
      this.$router.push('/');
    },
    backTitle() {
      for (let i = 0; i < this.tabList.length; i++) {
        const item = this.tabList[i];
        if (item.children && item.children.length) {
          for (let k = 0; k < item.children.length; k++) {
            const itemC = item.children[k];
            if (itemC.children && itemC.children.length) {
              for (let m = 0; m < itemC.children.length; m++) {
                const itemD = itemC.children[m];
                if (itemD.code === this.code && m !== 0) {
                  console.log('itemC: ', itemC);
                  this.$router.push({
                    path: item.url,
                    query: { code: itemC.children[0].code },
                  });
                }
              }
            }
          }
        }
      }
    },
    backTitleOne() {
      const path = this.$route.path;
      let titleObj = {};
      let lists = [];
      for (let i = 0; i < this.tabList.length; i++) {
        console.log('111111111');
        if (this.tabList[i].url === path) {
          titleObj = { ...this.tabList[i] };
          lists = [...this.tabList[i].children];
        }
      }
      if (lists[0].children && lists[0].children.length) {
        console.log('2222222222');
        this.$router.push({
          path: titleObj.url,
          query: { code: lists[0].children[0].code },
        });
        // this.code = lists[0].children[0].code;
      } else {
        console.log('333333333333');
        this.$router.push({
          path: titleObj.url,
          query: { code: lists[0].code },
        });
        // this.code = lists[0].code;
      }
    },
  },
};
</script>
<style scoped>
.title-name {
  cursor: pointer;
}
.acitve {
  color: #b61412;
}
.title-name:hover {
  font-size: 18px;
  color: #b61412;
}
.red {
  color: #b61412;
}
.content-title {
  font-size: 20px !important;
}
.content-nav {
  height: 40px;
  margin-bottom: 16px;
  background: #fff;
  line-height: 40px;
  padding: 0 16px;
}
img {
  width: 28px;
}
</style>
