<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-col :span="24" class="down">
            <el-tabs v-model="active" type="border-card" @tab-click="change">
              <el-tab-pane label="资质审查中" name="0">
                <data-table :fields="fields" :opera="opera" :data="list" :total="total" @view="toView" @edit="toEdit">
                  <template #selfbtn>
                    <el-button type="primary" size="mini" @click="toAdd">申领创新券服务</el-button>
                  </template>
                </data-table>
              </el-tab-pane>
              <el-tab-pane label="资质审查失败" name="-1">
                <data-table :fields="fields" :opera="opera" :data="list" :total="total" @view="toView" @edit="toEdit"> </data-table>
              </el-tab-pane>
              <el-tab-pane label="企业准备订单" name="1">
                <data-table :fields="fields" :opera="opera" :data="list" :total="total" @view="toView" @edit="toEdit"> </data-table>
              </el-tab-pane>
              <el-tab-pane label="信息资料审查中" name="2">
                <data-table :fields="fields" :opera="opera" :data="list" :total="total" @view="toView" @edit="toEdit"> </data-table>
              </el-tab-pane>
              <el-tab-pane label="信息资料审查失败" name="-3"
                ><data-table :fields="fields" :opera="opera" :data="list" :total="total" @view="toView" @edit="toEdit"> </data-table
              ></el-tab-pane>
              <el-tab-pane label="企业订单入库" name="3">
                <data-table :fields="fields" :opera="opera" :data="list" :total="total" @view="toView" @edit="toEdit"> </data-table>
              </el-tab-pane>
              <el-tab-pane label="创新券领取成功" name="4">
                <data-table :fields="fields" :opera="opera" :data="list" :total="total" @view="toView"> </data-table
              ></el-tab-pane>
            </el-tabs>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const moment = require('moment');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: ticket } = createNamespacedHelpers('ticket');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      active: '0',
      list: [],
      total: 0,
      opera: [
        {
          label: '查看',
          method: 'view',
        },
        {
          label: '编辑申请/上传合同',
          method: 'edit',
          display: (item) => {
            return item.status == '-1' || item.status == '1' || item.status == '-3' || item.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) => {
            if (i == '0') return '资质审查中';
            else if (i == '1') return '企业准备订单';
            else if (i == '-1') return '资质审查失败';
            else if (i == '2') return '信息资料审查中';
            else if (i == '3') return '企业订单入库';
            else if (i == '-3') return '信息资料审查失败';
            else if (i == '4') return '创新券领取成功';
          },
        },
      ],
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...ticket(['query']),
    // 查询
    async search({ skip = 0, limit = 10, ...info } = {}) {
      info.user_id = this.user.id;
      if (this.active) info.status = this.active;
      let res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 选择tabs
    change(tab) {
      this.$set(this, `active`, tab.name);
      this.search();
    },
    // 申领
    toAdd() {
      this.$router.push({ path: '/adminCenter/company/ticket/detail' });
    },
    // 查看资料
    toView({ data }) {
      this.$router.push({ path: '/adminCenter/company/ticket/info', query: { id: data._id, status: data.status } });
    },
    // 修改申请
    toEdit({ data }) {
      this.$router.push({ path: '/adminCenter/company/ticket/update', query: { id: data._id, status: data.status } });
    },
  },
  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;
  .one {
    .top {
      text-align: right;
      margin: 0 0 15px 0;
    }
  }
}
.main:hover {
  box-shadow: 0 0 5px #409eff;
}
</style>
