<template>
  <div id="list">
    <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @edit="toEdit"> </data-table>
  </div>
</template>

<script>
const moment = require('moment');
const { ticketType } = require('@common/dict/index');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: ticket } = createNamespacedHelpers('ticket');
export default {
  name: 'list',
  props: {
    status: { type: String, default: '0' },
  },
  components: {},
  data: function () {
    return {
      list: [],
      total: 0,
      opera: [
        {
          label: '审核',
          method: 'edit',
          display: (i) => i.status === '0' || i.status === '3',
        },
        {
          label: '查看',
          method: 'edit',
          display: (i) => i.status !== '0' && i.status !== '3',
        },
      ],
      fields: [
        { label: '企业', prop: 'name', filter: true },
        { label: '申请时间', prop: 'meta.createdAt', format: (i) => moment(i).format('YYYY-MM-DD HH:mm:ss') },
        {
          label: '状态',
          prop: 'status',
          format: (i) => {
            const r = ticketType.find((f) => f.value === i);
            if (r) return r.label;
            else return '';
          },
        },
      ],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...ticket(['query', 'delete']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const res = await this.query({ skip, limit, ...info, status: this.status });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data || [{}]);
        this.$set(this, `total`, res.total);
      }
      this.loading = false;
    },
    toEdit({ data }) {
      this.$router.push({ path: '/adminCenter/ticket/detail', query: { id: data._id, status: data.status } });
    },
  },
  computed: {
    ...mapState(['user', 'menuParams']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

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