<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();
  },
  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 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 } });
      }
    },
    // 人才详情
    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 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);
      }
      // 工作
      const resJob = await this.xinxiList({ skip, limit, ...info });
      if (this.$checkRes(resJob)) {
        this.$set(this, `jobsData`, resJob.data);
      }
      // 专家
      const resZhuanjia = await this.zhuanjiaList({ skip, limit, ...info });
      if (this.$checkRes(resZhuanjia)) {
        this.$set(this, `zhuanjiaData`, resZhuanjia.data);
      }
      //找参谋
      const rescanmou = await this.columnList({ ...info });
      for (const val of rescanmou.data) {
        if (val.site === 'jyzd') {
          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);
      }
    },
  },
};
</script>

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