<template>
  <div id="personnel">
    <personnel-detail
      :info="info"
      :rencaiData="rencaiData"
      :jobsData="jobsData"
      :zhuanjiaData="zhuanjiaData"
      :canmoData="canmoData"
      :messList="messList"
      :rencaiShowList="rencaiShowList"
      :liebiaoList="liebiaoList"
      @detail="clickDetail"
      @detailgz="clickDetailgz"
      @detailzj="clickDetailzj"
      @detailcm="clickDetailcm"
      @onsave="onsaveClick"
    ></personnel-detail>
  </div>
</template>

<script>
import personnelDetail from '@/components/personnel/personnel.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapSite } = createNamespacedHelpers('site');
const { mapActions: mapColumn } = createNamespacedHelpers('policiesColumn');
const { mapActions: mapNews } = createNamespacedHelpers('policiesNew');
const { mapActions: mapxinxi } = createNamespacedHelpers('policiesxinxi');
const { mapActions: mapzhuanjia } = createNamespacedHelpers('policieszhuanjia');
const { mapActions: mapcanmou } = createNamespacedHelpers('policiesjbxx');

export default {
  name: 'personnel',
  props: {},
  components: {
    personnelDetail,
  },
  data: () => ({
    info: {},
    liebiaoList: [],
    rencaiData: [],
    jobsData: [],
    zhuanjiaData: [],
    canmoData: [],
    messList: [
      {
        pic: require('@/assets/message1.jpg'),
        title: '标题',
      },
      {
        pic: require('@/assets/message2.jpg'),
        title: '标题',
      },
      {
        pic: require('@/assets/message3.jpg'),
        title: '标题',
      },
      {
        pic: require('@/assets/message4.jpg'),
        title: '标题',
      },
      {
        pic: require('@/assets/message5.jpg'),
        title: '标题',
      },
      {
        pic: require('@/assets/message6.jpg'),
        title: '标题',
      },
    ],
    rencaiShowList: [],
    canmouId: '',
  }),
  async created() {
    this.searchSite();
    this.searchColumn();
    this.searchInfo();
    this.searchInfojobs();
    this.searchInfozhuanjia();
    this.searchInfomapcanmou();
  },
  computed: {},
  methods: {
    ...mapSite(['showInfo']),
    ...mapColumn({ columnList: 'query', columnInfo: 'fetch' }),
    ...mapNews({ newsList: 'query', newsInfo: 'fetch' }),
    ...mapxinxi({ xinxiList: 'query', xinxiInfo: 'fetch' }),
    ...mapzhuanjia({ zhuanjiaList: 'query', zhuanjiaInfo: 'fetch' }),
    ...mapcanmou({ canmouList: 'query', canmouInfo: '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 searchInfo({ skip = 0, limit = 10, ...info } = {}) {
      const res = await this.newsList({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `rencaiData`, res.data);
        this.$set(this, `rencaiShowList`, res.data);
      }
    },
    // 查询找工作
    async searchInfojobs({ skip = 0, limit = 10, ...info } = {}) {
      const res = await this.xinxiList({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `jobsData`, res.data);
      }
    },
    // 查询找专家
    async searchInfozhuanjia({ skip = 0, limit = 10, ...info } = {}) {
      const res = await this.zhuanjiaList({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `zhuanjiaData`, res.data);
      }
    },
    // 查询找参谋
    async searchInfomapcanmou({ ...info } = {}) {
      const res = await this.columnList({ ...info });
      for (const val of res.data) {
        if (val.site === 'jyzd') {
          console.log(val.id);
          this.$set(this, `canmouId`, val.id);
          this.searchCanmou();
        }
      }
    },
    async searchCanmou({ skip = 0, limit = 10, column_id } = {}) {
      const res = await this.canmouList({ skip, limit, column_id: this.canmouId });
      if (this.$checkRes(res)) {
        this.$set(this, `canmoData`, res.data);
      }
    },
    // 人才详情
    clickDetail({ data }) {
      this.$router.push({ path: '/personnel/rencai', query: { id: data.id } });
    },
    // 工作详情
    clickDetailgz({ data }) {
      this.$router.push({ path: '/personnel/personnelwork', query: { id: data.id } });
    },
    // 专家详情
    clickDetailzj({ data }) {
      this.$router.push({ path: '/personnel/personnelexpert', query: { id: data.id } });
    },
    // 参谋详情
    clickDetailcm({ data }) {
      this.$router.push({ path: '/personnel/personnelcmdetail', query: { id: data.id } });
    },
    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 } });
      }
    },
  },
};
</script>

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