<template>
  <div id="quiet">
    <quiet-detail :menuList="menu" :info="site" :backColor="backColor"></quiet-detail>
  </div>
</template>

<script>
import quietDetail from '@/components/quietDetail.vue';
import { mapActions, mapState } from 'vuex';
import _ from 'lodash';
export default {
  metaInfo() {
    return {
      title: this.siteTitle ? this.siteTitle : '吉林省高等学校毕业生就业信息网',
    };
  },
  name: 'quiet',
  props: {},
  components: {
    quietDetail,
  },
  data: () => ({
    info: {
      title: '吉林省高等学校毕业生就业信息网',
      english: 'Jilin University Graduate Employment Guidance Center',
      banner: require('@/assets/banner.jpg'),
      logo: require('@/assets/logo.png'),
      copyright: '吉ICP备09006292号-1 Copyright 2019 版权所有 吉林省高等学校毕业生就业指导中心 All Rights Reserved',
    },
    site: {}, //站点信息
    siteTitle: '吉林省高等学校毕业生就业信息网', //站点标题
    menu: [], //菜单
    backColor: '#0457c7',
  }),
  async created() {
    await this.toGetSite(); //获取主站信息
    this.loadMenu(); //获取菜单信息
  },
  computed: {
    title() {
      return this.$route.query.title;
    },
  },
  methods: {
    ...mapActions(['getSite', `getMenu`, 'getColumn', 'getAllNews', 'getAllColumn', 'getModule', 'getNews', 'getJobInfo', 'getPosts', 'getLink']),
    //站点信息
    async toGetSite() {
      let site = sessionStorage.getItem('site');
      if (site) {
        this.$set(this, `site`, JSON.parse(site));
        this.$set(this, `siteTitle`, this.site.name);
      } else {
        let result = await this.getSite({ type: 'search' });
        if (result.errcode === 0) {
          sessionStorage.setItem('site', JSON.stringify(result.data));
          if (_.get(result.data, `custom`)) {
            let item = result.custom;
          }
          this.$set(this, `site`, result.data);
          this.$set(this, `siteTitle`, this.site.name);
        }
      }
    },
    //菜单
    async loadMenu() {
      let menu = sessionStorage.getItem('menu');
      if (menu) {
        this.$set(this, `menu`, JSON.parse(menu));
        this.finishedMenu();
        return;
      } else this.toGetMenu();
    },
    async toGetMenu() {
      let result = await this.getMenu({ type: `list` });
      if (result.errcode === 0) {
        this.$set(this, `menu`, result.data);
        this.finishedMenu();
      }
    },
    async finishedMenu() {
      let menus = JSON.parse(JSON.stringify(this.menu));
      for (const item of menus) {
        if (item.type === 'content') {
          item.path = `/detail?id=${item.content_id}`;
        } else if (item.type !== 'url') {
          let res = await this.completeMenu(item);
          item.children = res;
        }
      }
      this.$set(this, `menu`, menus);
    },
  },
};
</script>

<style lang="scss" scoped></style>
