<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" />
          <div class="flex-1 flex-column">
            <Location :title="defaultTitle" />
            <div class="content-detail p-4" :style="{ 'min-height': list.children.length * 56 + 'px' }">
              <RichText :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';

export default {
  components: { LeftNav, RichText, Location },
  data() {
    return {
      code: '0801',
      defaultTitle: '集团公司制度',
      list: {
        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',
          },
        ],
      },
      content: {},
    };
  },
  watch: {
    '$route.query.code'(val) {
      if (this.$route.path === this.list.url) {
        this.code = val;
        this.getDetault(val);
        this.getData(this.code);
      }
    },
  },
  created() {
    this.code = this.$route.query.code;
    this.getDetault(this.code);
    this.getData(this.code);
  },
  methods: {
    ...mapActions('home', ['getDetail']),
    // 获取默认显示标题
    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) {}
    },
    chanegCode(code) {
      this.code = code;
    },
  },
};
</script>
<style scoped>
.content-detail {
  background: #fff;
}
</style>
