<template>
  <div id="shuju">
    <shuju-detail
      :info="info"
      :liebiaoList="liebiaoList"
      :imageList="imageList"
      :gonggaoList="tzggList"
      :shangbaoList="shangbaoList"
      :tongzhiList="tzggList"
    ></shuju-detail>
  </div>
</template>

<script>
import shujuDetail from '@/components/shuju/shuju.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
import _ from 'loadsh';
const { mapActions: mapSite } = createNamespacedHelpers('site');
const { mapActions: mappolicyColumn } = createNamespacedHelpers('recordColumn');
const { mapActions: mapAffairsColumn } = createNamespacedHelpers('affairsColumn');
const { mapActions: mapAffairsNews } = createNamespacedHelpers('affairsNews');
export default {
  name: 'shuju',
  props: {},
  components: {
    shujuDetail,
  },
  data: () => ({
    info: {},
    // 分类导航
    liebiaoList: {},
    // 数据展示
    imageList: [
      {
        pic: require('@/assets/biao1.png'),
      },
      {
        pic: require('@/assets/biao2.png'),
      },
      {
        pic: require('@/assets/biao3.png'),
      },
      {
        pic: require('@/assets/biao4.png'),
      },
      {
        pic: require('@/assets/biao5.png'),
      },
    ],
    // 通知公告
    tzggList: [],
    // 上报通知
    shangbaoList: [
      {
        title: '标题',
        date: '2019-01-02',
      },
      {
        title: '十条数据',
        date: '2019-01-02',
      },
    ],
  }),
  async created() {
    this.searchSite();
    await this.policyColumn();
    await this.affairsColumn();
  },
  computed: {},
  methods: {
    ...mapSite(['showInfo']),
    ...mappolicyColumn({ policyColumns: 'query', policyfetch: 'fetch' }),
    ...mapAffairsColumn({ affairsColumns: 'query', affairsInfo: 'fetch' }),
    ...mapAffairsNews({ affairsList: 'query' }),
    // 查询站点信息
    async searchSite() {
      let res = await this.showInfo();
      let object = JSON.parse(JSON.stringify(res.data));
      if (object) {
        this.$set(this, `info`, res.data);
      } else {
        this.$message.error(res.errmsg ? res.errmsg : 'error');
      }
    },
    async policyColumn({ ...info } = {}) {
      const res = await this.policyColumns({ ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `liebiaoList`, res.data);
      }
    },
    // 查询科技政务栏目
    async affairsColumn({ ...info } = {}) {
      const res = await this.affairsColumns({ ...info });
      for (const val of res.data) {
        this.kjzwSearch({ column_id: val.id, site: val.site });
      }
    },
    async kjzwSearch({ skip = 0, limit = 10, column_id, site } = {}) {
      console.log(column_id, site);
      const res = await this.affairsList({ skip, limit, column_id: column_id });
      for (const val of res.data) {
        const result = await this.affairsInfo(val.column_id);
        val.column_name = result.data.name;
      }
      this.$set(this, `${site}List`, res.data);
      console.log(res.data);
    },
  },
};
</script>

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