<template>
  <div id="guidanceList">
    <diligenceList-detail
      :info="info"
      :recruitData="recruitData"
      :liebiaoList="liebiaoList"
      @onsave="onsaveClick"
      :columnName="columnName"
      @detailcm="clickDetailcm"
      :total="total"
    ></diligenceList-detail>
  </div>
</template>

<script>
import diligenceListDetail from '@/components/personnel/diligenceList.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapSite } = createNamespacedHelpers('site');
const { mapActions: mapColumn } = createNamespacedHelpers('policiesColumn');
const { mapActions: mapRecruit } = createNamespacedHelpers('policiesjbxx');
export default {
  name: 'guidanceList',
  props: {},
  components: {
    diligenceListDetail,
  },
  data: () => ({
    total: 1,
    info: {},
    liebiaoList: [],
    columnName: '',
    recruitData: [],
  }),
  created() {
    this.searchSite();
    this.searchColumn();
    this.searchName();
    this.searchList();
  },
  computed: {},
  methods: {
    ...mapSite(['showInfo']),
    ...mapColumn({ columnList: 'query', columnInfo: 'fetch' }),
    ...mapRecruit({ recruitList: '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 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.site === 'zpxx') {
        this.$router.push({ path: '/personnel/recruitList', query: { id: res.data.id } });
      } else if (res.data.site === 'gzgw') {
        this.$router.push({ path: '/personnel/guidanceList', query: { id: res.data.id } });
      } else if (res.data.site === 'qgjx') {
        this.$router.push({ path: '/personnel/practiceList', query: { id: res.data.id } });
      } else if (res.data.site === 'xxsj') {
        this.$router.push({ path: '/personnel/diligenceList', query: { id: res.data.id } });
      } else if (res.data.site === 'jyzd') {
        this.$router.push({ path: '/personnel/adviserList', query: { id: res.data.id } });
      }
    },
    async searchName() {
      let nameId = this.$route.query.id;
      const res = await this.columnInfo(nameId);
      this.$set(this, `columnName`, res.data.name);
    },
    async searchList({ skip = 0, limit = 10, column_id } = {}) {
      const res = await this.recruitList({ skip, limit, column_id: this.$route.query.id });
      if (this.$checkRes(res)) {
        this.$set(this, `recruitData`, res.data);
        console.log(res.data);
      }
    },
    clickDetailcm({ data }) {
      this.$router.push({ path: '/personnel/personnelcmdetail', query: { id: data.id } });
    },
  },
};
</script>

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