<template>
  <div class="bg-bottom">
    <div class="bg-top">
      <div class="content-1180">
        <div class="d-flex pt-4">
          <LeftNav :code="code" :list="list" class="mr-4" @chanegCode="chanegCode" @resetData="resetData" />
          <div class="flex-1 flex-column">
            <Location :title="defaultTitle" />
            <div class="content-detail p-4" :style="{ 'min-height': list.children.length * 56 + 'px' }">
              <template v-if="code.length === 6 && (code.split('')[5] === '4' || code.split('')[5] === '6')">
                <ListPage :code="code" @changeYear="changeYear" :content="content" @getData="getNumData" />
              </template>
              <RichText v-else :rich-obj="content" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex';
import LeftNav from '@/components/LeftNav/LeftNav.vue';
import RichText from '@/components/RichText/RichText.vue';
import Location from '@/components/Location/Location.vue';
import ListPage from '@/components/ListPage/ListPage.vue';

export default {
  components: { LeftNav, RichText, Location, ListPage },
  data() {
    return {
      code: '0901',
      defaultTitle: '总经理工作部',
      list: {
        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',
              },
            ],
          },
        ],
      },
      year: '2022',
      pageNum: 1,
      content: {},
    };
  },
  watch: {
    '$route.query.code'(val) {
      if (this.$route.path === this.list.url) {
        this.code = val;
        this.getDetault(val);
        if (this.code.length === 6 && (this.code.split('')[5] === '4' || this.code.split('')[5] === '6')) {
          this.getContentData(this.code);
        } else {
          this.getData(this.code);
        }
      }
    },
  },
  created() {
    this.code = this.$route.query.code;
    this.getDetault(this.code);
    if (this.code.length === 6 && (this.code.split('')[5] === '4' || this.code.split('')[5] === '6')) {
      this.getContentData(this.code);
    } else {
      this.getData(this.code);
    }
  },
  methods: {
    ...mapActions('home', ['getDetail', 'getContent']),
    // 获取默认显示标题
    getDetault(val) {
      for (let i = 0; i < this.list.children.length; i++) {
        if (val === this.list.children[i].code) {
          this.defaultTitle = this.list.children[i].title;
        }
      }
    },
    async getData(showPage) {
      try {
        const param = {
          showPage,
          introId: '',
        };
        const data = await this.getDetail(param);
        this.content = data || {};
      } catch (error) {}
    },
    async getContentData() {
      try {
        const params = {
          showPage: this.code,
          year: this.year,
          showType: 0,
          pageNum: this.pageNum,
          pageSize: 10,
        };
        const data = await this.getContent(params);
        console.log('data: ', data);
      } catch (error) {}
    },
    resetData() {
      this.pageNum = 1;
      this.getContentData();
    },
    getNumData(pageNum) {
      console.log('pageNum: ', pageNum);
      this.pageNum = pageNum;
      this.getContentData();
    },
    chanegCode(code) {
      this.code = code;
    },
    changeYear(year, code) {
      this.year = year;
      this.getContentData(code);
    },
  },
};
</script>
<style scoped>
.content-detail {
  background: #fff;
}
</style>
