<template>
  <div id="adviserList">
    <enterprisefabu-detail
      :info="info"
      :liebiaoList="liebiaoList"
      :recruitData="recruitData"
      @delete="deleteData"
      @onsave="onsaveClick"
      :total="total"
    ></enterprisefabu-detail>
  </div>
</template>

<script>
import enterprisefabuDetail from '@/components/enterprise/enterprisefabu.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapSite } = createNamespacedHelpers('site');
const { mapActions: mapRecruit } = createNamespacedHelpers('market');
const { mapActions: marketproduct } = createNamespacedHelpers('marketproduct');
export default {
  name: 'adviserList',
  props: {},
  components: {
    enterprisefabuDetail,
  },
  data: () => ({
    info: {},
    liebiaoList: [{ name: '基本信息' }, { name: '消息管理' }, { name: '我的发布' }, { name: '我的订购' }, { name: '注销账号' }],
    recruitData: [],
    total: 1,
  }),
  created() {
    this.searchSite();
    this.searchInfo();
  },
  computed: {},
  methods: {
    ...mapSite(['showInfo']),
    ...mapRecruit({ columnList: 'query', columnInfo: 'fetch' }),
    ...marketproduct({ productList: 'query', columnInfo: 'fetch', marketcerate: 'create', productdeltet: 'delete' }),
    // 查询站点信息
    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 searchInfo({ skip = 0, limit = 3, ...info } = {}) {
      const res = await this.productList({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        // for (const val of res.data) {
        //   if (val.gxtype == 0) {
        //     this.$set(this, `recruitData`, res.data);
        //     this.$set(this, `total`, res.total);
        //   } else {
        //     console.log(res.data);
        //     console.log('供给');
        //   }
        // }
        this.$set(this, `recruitData`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 删除信息
    async deleteData({ item }) {
      const res = await this.productdeltet(item.id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.searchInfo();
    },
    async onsaveClick({ id }) {
      if (id === '基本信息') {
        this.$router.push({ path: '/enterprise/enterprisejb' });
      } else if (id === '消息管理') {
        this.$router.push({ path: '/enterprise/enterprisexx' });
      } else if (id === '我的发布') {
        this.$router.push({ path: '/enterprise/enterprisefabu' });
      } else if (id === '我的订购') {
        this.$router.push({ path: '/enterprise/enterprisedg' });
      }
    },
  },
};
</script>

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