<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="down">
          <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @cert="toCert"></data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import dataTable from '@common/src/components/frame/filter-page-table.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: achieveApply } = createNamespacedHelpers('achieveApply');
const { mapActions: verifyRecord } = createNamespacedHelpers('verifyRecord');
export default {
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  name: 'index',
  props: {},
  components: {
    dataTable,
  },
  data: function() {
    return {
      opera: [
        {
          label: '发放证书',
          method: 'cert',
        },
      ],
      fields: [
        { label: '成果编号', prop: 'basic.achieve_num', filter: 'input', showTip: true },
        { label: '成果名称', prop: 'basic.achieve_name', showTip: true },
        { label: '成果类别', prop: 'basic.achieve_type', showTip: true },
      ],
      list: [],
      total: 0,
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...achieveApply(['query']),
    ...verifyRecord(['create']),
    // 查询列表
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const res = await this.query({ skip, limit, ...info, status: '5' });
      if (this.$checkRes(res)) {
        this.$set(this, 'list', res.data);
        this.$set(this, `total`, res.total);
      }
    },
    async toCert({ data }) {
      // TODO 发证书
      let dup = { status: '6' };
      dup.apply_id = _.get(data, '_id');
      dup.verify = _.get(this.user, 'name');
      dup.verify_phone = _.get(this.user, 'phone');
      dup.verify_id = _.get(this.user, '_id');
      dup.step = '发证书';
      const res = await this.create(dup);
      if (this.$checkRes(res, '已确定发放证书', res.errmsg || '确定发放失败')) this.search();
    },
  },
  computed: {
    ...mapState(['user']),
  },
  watch: {},
};
</script>

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