<template>
  <div id="adviserList">
    <enterprisexuqiu-detail
      :info="info"
      :columnList="columnList"
      :liebiaoList="liebiaoList"
      @onsaves="onsaveClicks"
      :form="form"
      @onsave="onsaveClick"
    ></enterprisexuqiu-detail>
    <!-- @detailcm="clickDetailcm" -->
  </div>
</template>

<script>
import enterprisexuqiuDetail from '@/components/enterprise/enterprisexuqiu.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapSite } = createNamespacedHelpers('site');
const { mapActions: mapRecruit } = createNamespacedHelpers('market');
const { mapActions: marketproduct } = createNamespacedHelpers('marketproduct');
const { mapActions: mapColumn } = createNamespacedHelpers('markettype');
export default {
  name: 'adviserList',
  props: {},
  components: {
    enterprisexuqiuDetail,
  },
  data: () => ({
    info: {},
    liebiaoList: [{ name: '基本信息' }, { name: '消息管理' }, { name: '我的发布' }, { name: '我的订购' }, { name: '注销账号' }],
    columnName: '',
    recruitData: [],
    columnList: [],
    form: {},
  }),
  created() {
    this.search();
    this.searchSite();
    this.searchColumn();
  },
  computed: {
    id() {
      return this.$route.query.id;
    },
    keyWord() {
      let meta = this.$route.meta;
      let main = meta.title || '';
      return main;
    },
  },
  methods: {
    ...mapSite(['showInfo']),

    ...marketproduct({ list: 'query', columnInfo: 'fetch', marketcerate: 'create' }),
    ...mapColumn({ queryList: 'query' }),
    async search() {
      this.loading = false;
      if (this.$route.query.id) {
        const res = await this.columnInfo(this.id);
        this.$set(this, `form`, res.data);
      }
      this.loading = true;
    },

    async searchColumn({ ...info } = {}) {
      const res = await this.queryList({ ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `columnList`, res.data);
      }
    },
    // 查询站点信息
    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 onsaveClick({ id }) {
      console.log(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' });
      }
    },
    async onsaveClicks(form) {
      let data = this.form;
      console.log(data);
      let res;
      let msg;
      if (data.id) {
        res = await this.columnInfo(data);
        msg = `${this.keyWord}修改成功`;
      } else {
        res = await this.marketcerate(data);
        msg = `${this.keyWord}添加成功`;
      }
      if (this.$checkRes(res, msg)) this.$router.push({ path: '/policy/index' });
    },
  },
};
</script>

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