<template>
  <div id="detail">
    <data-form v-model="form" @save="toSave" :fields="fields" submitText="审核" :needSave="false" labelWidth="180px">
      <template #status>
        <el-radio v-for="(i, index) in statusList" :key="`status-${index}`" :label="i.value"> {{ i.label }}</el-radio>
      </template>
    </data-form>
  </div>
</template>

<script>
const _ = require('lodash');
import quests from '@common/dict/patent/quests';
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'detail',
  props: {
    form: { type: Object, default: () => {} },
  },
  model: {
    prop: 'form',
    event: 'change',
  },
  components: {},
  data: function () {
    return {
      fields: [
        { label: '发明名称', model: 'name', type: 'text', required: true },
        { label: '申请人', model: 'apply_name', required: true, type: 'text' },
        { label: '申请类型', model: 'type', type: 'text', required: true },
        { label: '发明人', model: 'inventer', type: 'text', required: true },
        { label: '技术联系人', model: 'contact', type: 'text', required: true },
        { label: '联系人电话', model: 'phone', type: 'text', required: true },
        { label: '联系人邮箱', model: 'email', type: 'text', required: true },
        { label: '特殊情况说明', model: 'desc', type: 'text', required: true },
      ],
      typeList: [{ label: '国家发明' }, { label: '国防专利' }, { label: '实用新型' }, { label: '外观' }],
      statusList: [
        { label: '通过', value: '1' },
        { label: '拒绝', value: '-1' },
      ],
    };
  },
  created() {
    this.setQuest();
  },
  methods: {
    async toSave({ data }) {
      this.$emit('submit', data);
    },
    setQuest() {
      let fields = _.cloneDeep(this.fields);
      let qs = _.cloneDeep(quests);
      qs = qs.map((i) => {
        i.type = 'text';
        return i;
      });
      fields.push(...qs);
      fields = fields.map((i) => {
        delete i.required;
        return i;
      });
      // 添加审核
      // const checkField = [
      //   {
      //     label: '预估结果',
      //     model: 'status',
      //     type: 'radio',
      //     required: true,
      //   },
      //   {
      //     label: '意见&建议',
      //     model: 'remark',
      //     type: 'textarea',
      //   },
      // ];
      // fields.push(...checkField);
      this.$set(this, `fields`, fields);
    },
  },
  computed: {
    ...mapState(['user']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

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