<template>
  <div id="index">
    <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @edit="toEdit" @delete="toDelete">
      <template #selfbtn>
        <!-- <el-button type="primary" size="mini" @click="toAdd">添加专家</el-button> -->
      </template>
    </data-table>
  </div>
</template>

<script>
const { status } = require('@common/dict/index');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: organization } = createNamespacedHelpers('organization');
export default {
  name: 'organizationIndex',
  props: {},
  components: {},
  data: function () {
    return {
      list: [],
      total: 0,
      opera: [
        {
          label: '查看与审核',
          method: 'edit',
        },
        {
          label: '删除',
          method: 'delete',
          type: 'danger',
        },
      ],
      fields: [
        { label: '企业名称', prop: 'name', filter: true },
        { label: '机构代码', prop: 'institution_code', filter: true },
        { label: '联系电话', prop: 'phone' },
        { label: '邮箱', prop: 'email' },
        { label: '所属行业', prop: 'profession' },
        { label: '注册类型', prop: 'companytype' },
        {
          label: '状态',
          prop: 'status',
          format: (i) => {
            const r = status.find((f) => f.value === i);
            if (r) return r.label;
            return '未知状态';
          },
        },
      ],
      statusList: status,
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...organization(['query', 'delete']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    toAdd() {
      this.$router.push('/adminCenter/organization/detail');
    },
    toEdit({ data }) {
      this.$router.push({ path: '/adminCenter/organization/detail', query: { id: data._id } });
    },
    async toDelete({ data }) {
      const res = await this.delete(data._id);
      if (this.$checkRes(res, '删除成功', '删除失败')) {
        this.search();
      }
    },
  },
  computed: {
    ...mapState(['user', 'menuParams']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

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