<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" @check="toCheck"> </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const { rewardStatus } = require('@common/dict/couindex');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: reward } = createNamespacedHelpers('reward');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      list: [],
      total: 0,
      opera: [
        {
          label: '审核',
          method: 'check',
          display: (item) => {
            return item.status == '0';
          },
        },
      ],
      fields: [
        { label: '申领类型', prop: 'type' },
        { label: '申领企业', prop: 'company', filter: 'input' },
        { label: '申请人', prop: 'apply_person', filter: 'input' },
        { label: '联系电话', prop: 'phone', filter: 'input' },
        {
          label: '审核状态',
          prop: 'status',
          format: (i) => {
            const r = rewardStatus.find((f) => f.value === i);
            if (r) return r.label;
            return '未知状态';
          },
        },
      ],
    };
  },
  created() {},
  methods: {
    ...reward(['query']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      info.type = this.type;
      const res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 审核
    toCheck({ data }) {
      this.$router.push({ path: '/adminCenter/reward/detail', query: { id: data.id, type: data.type } });
    },
  },
  computed: {
    ...mapState(['user']),
    type() {
      return this.$route.query.type;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    type: {
      deep: true,
      immediate: true,
      handler(val) {
        this.search();
      },
    },
  },
};
</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>
