<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" @view="toView" @edit="toEdit"></data-table>
        </el-col>
      </el-col>
    </el-row>
    <el-dialog title="评分总结" width="40%" :visible.sync="sumDialog" @closed="handleClose" :destroy-on-close="true">
      <data-form :data="sumForm" :fields="sumfields" :rules="{}" @save="sumSave">
        <template #radios="{item}">
          <template v-if="item.model === 'status'">
            <!-- 因为不需要申请人线上证明缴费,所以跳过缴费等待步骤,直接进入会审步骤 -->
            <el-radio label="3">通过</el-radio>
            <el-radio label="-2">不通过</el-radio>
          </template>
        </template>
      </data-form>
    </el-dialog>
  </div>
</template>

<script>
const _ = require('lodash');
import dataForm from '@common/src/components/frame/form.vue';
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,
    dataForm,
  },
  data: function() {
    return {
      opera: [
        {
          label: '专家指派&评分查看',
          method: 'view',
        },
        {
          label: '评分总结',
          method: 'edit',
        },
      ],
      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,
      // 会审总结
      sumDialog: false,
      sumForm: {},
      sumfields: [
        { label: '总结状态', model: 'status', type: 'radio' },
        { label: '总结意见', model: 'desc', type: 'textarea' },
      ],
    };
  },
  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: '1' });
      if (this.$checkRes(res)) {
        this.$set(this, 'list', res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 专家评分查看
    toView({ data }) {
      this.$router.push({ path: '/adminScore/detail', query: { id: data.id } });
    },
    // 会审总结
    toEdit({ data }) {
      this.$set(this, 'sumForm', _.cloneDeep(data));
      this.sumDialog = true;
    },
    // 会审总结提交
    async sumSave({ data }) {
      let dup = _.pick(data, ['desc', 'status']);
      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.handleClose();
      }
    },
    // 取消选择
    handleClose() {
      this.sumForm = {};
      this.sumDialog = false;
      this.search();
    },
  },
  computed: {
    ...mapState(['user']),
  },
  watch: {},
};
</script>

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