<template>
  <div id="adviserList">
    <adviserList-detail :info="info" :liebiaoList="liebiaoList" @onsave="onsaveClick" :columnName="columnName"></adviserList-detail>
  </div>
</template>

<script>
import adviserListDetail from '@/components/personnel/adviserList.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapSite } = createNamespacedHelpers('site');
const { mapActions: mapColumn } = createNamespacedHelpers('policiesColumn');
export default {
  name: 'adviserList',
  props: {},
  components: {
    adviserListDetail,
  },
  data: () => ({
    info: {},
    liebiaoList: [],
    columnName: '',
  }),
  created() {
    this.searchSite();
    this.searchColumn();
    this.searchName();
  },
  computed: {},
  methods: {
    ...mapSite(['showInfo']),
    ...mapColumn({ columnList: 'query', columnInfo: '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, `liebiaoList`, res.data);
    },
    async onsaveClick({ id }) {
      const res = await this.columnInfo(id);
      if (res.data.name === '招聘信息') {
        this.$router.push({ path: '/personnel/recruitList', query: { id: id } });
      } else if (res.data.name === '就业指导') {
        this.$router.push({ path: '/personnel/guidanceList', query: { id: id } });
      } else if (res.data.name === '学习实践') {
        this.$router.push({ path: '/personnel/practiceList', query: { id: id } });
      } else if (res.data.name === '勤工俭学') {
        this.$router.push({ path: '/personnel/diligenceList', query: { id: id } });
      } else if (res.data.name === '工作顾问') {
        this.$router.push({ path: '/personnel/adviserList', query: { id: id } });
      }
    },
    async searchName() {
      let nameId = this.$route.query.id;
      const res = await this.columnInfo(nameId);
      this.$set(this, `columnName`, res.data.name);
    },
  },
};
</script>

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