<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @view="toView">
            <template #selfbtn>
              <el-button type="primary" size="mini" @click="toAdd">申请政策服务</el-button>
            </template>
            <template #options="{ item }">
              <template v-if="item.prop === 'type'">
                <el-option v-for="(i, index) in typeList" :key="`type-${index}`" :label="i" :value="i"></el-option>
              </template>
            </template>
          </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const { policyType, policyStatus } = require('@common/dict/index');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: policy } = createNamespacedHelpers('policy');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      list: [],
      total: 0,
      opera: [
        {
          label: '查看',
          method: 'view',
        },
      ],
      fields: [
        { label: '申请单位', prop: 'company' },
        { label: '申请类型', prop: 'type', filter: 'select' },
        { label: '申请人', prop: 'apply_personal' },
        { label: '联系电话', prop: 'phone' },
        {
          label: '审核状态',
          prop: 'status',
          format: (i) => {
            const r = policyStatus.find((f) => f.value === i);
            if (r) return r.label;
            else return '';
          },
        },
      ],
      typeList: policyType,
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...policy(['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({ path: '/adminCenter/company/policy/detail' });
    },
    // 查看政策服务
    toView({ data }) {
      this.$router.push({ path: '/adminCenter/company/policy/detail', query: { id: data._id } });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  border-radius: 10px;
  box-shadow: 0 0 5px #cccccc;
  padding: 20px;
}
.main:hover {
  box-shadow: 0 0 5px #409eff;
}
</style>
