<template>
  <div id="governmentDetail">
    <governmentDetail-layout :info="info" :nativeList="nativeList" :columnTitle="columnTitle" :governmentDetail="governmentDetail"></governmentDetail-layout>
  </div>
</template>

<script>
import governmentDetailLayout from '@/components/government/governmentDetail.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapSite } = createNamespacedHelpers('site');
const { mapActions: mapColumn } = createNamespacedHelpers('affairsColumn');
const { mapActions: mapNews } = createNamespacedHelpers('affairsNews');
export default {
  name: 'governmentDetail',
  props: {},
  components: {
    governmentDetailLayout,
  },
  data: () => ({
    info: {},
    nativeList: [],
    columnTitle: '',
    governmentDetail: {},
  }),
  created() {
    this.searchSite();
    this.searchColumn();
    this.searchInfo();
  },
  computed: {},
  methods: {
    ...mapSite(['showInfo']),
    ...mapColumn({ columnList: 'query', columnInfo: 'fetch' }),
    ...mapNews({ newsList: 'query', newsInfo: 'fetch' }),
    // 查询站点信息
    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 searchColumn({ ...info } = {}) {
      const res = await this.columnList({ ...info });
      this.$set(this, `nativeList`, res.data);
      console.log(res);
      // for (const val of res.data) {
      //   this.tpxwSearch({ column_id: val.id, site: val.site });
      // }
    },
    async searchInfo() {
      let detailId = this.$route.query.id;
      const res = await this.newsInfo(detailId);
      const result = await this.columnInfo(res.data.column_id);
      this.$set(this, `columnTitle`, result.data.name);
      this.$set(this, `governmentDetail`, res.data);
    },
    // // 查询信息列表
    // async tpxwSearch({ skip = 0, limit = 10, column_id, site } = {}) {
    //   const res = await this.newsList({ skip, limit, column_id: column_id });
    //   for (const val of res.data) {
    //     const result = await this.columnInfo(val.column_id);
    //     val.column_name = result.data.name;
    //   }
    //   this.$set(this, `${site}List`, res.data);
    //   console.log(res.data);
    // },
  },
};
</script>

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