<template>
  <div id="detail">
    <admin-frame topType="2" @back="back" :rightArrow="false" :usePage="false" :useNav="false">
      <template v-slot:info>
        <form-1 :form="form" @onSubmit="onSubmit"></form-1>
      </template>
    </admin-frame>
  </div>
</template>

<script>
import form1 from '@/layout/patentInfo/form-1.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patentinfo } = createNamespacedHelpers('patentinfo');
export default {
  name: 'detail',
  props: {},
  components: {
    adminFrame,
    form1,
  },
  data: function () {
    return {
      form: {
        user_id: [],
        // create_number: '申请号',
        // create_date: '2021-11-18',
        // success_number: '公开号',
        // success_date: '2021-11-18',
        // inventor: [{ name: '测试用户', user_id: '6193411fed56cc6f90c753b7' }],
        // agent: '代理机构',
        // agent_personal: '代理人',
        // abstract: '摘要',
        // address: '发明人地址',
        // name: '专利名称',
        // apply_personal: '申请人',
        // term: '有效',
        // type: '发明申请',
        // nationality: '公开国别',
        // ipc_type: 'ipc',
        // onlegal_status: '当前法律状态',
        // legal_status: '法律状态',
        // law_date: '2021-11-18',
        // on_obligee: '变更前权利人',
        // apply_address: '申请人地址(其他)',
        // apply_other: '申请人(其他)',
        // law_num: '法律文书编号',
        // first_opendate: '2021-11-18',
        // empower_date: '2021-11-18',
        // lose_date: '2021-11-18',
        // examine_date: '2021-11-18',
        // invention_design: '发明(设计)人(其他)',
        // incopat_link: '链接',
        // first_ask: '首项权利要求',
        // first_apply: '第一申请人',
        // apply_city: '中国申请人地市',
        // business_code: '工商',
        // business_address: '注册地',
        // first_inventor: '第一发明人',
        // shared_value: '合享价值度',
        // techol_stable: '技术稳定性',
        // techol_advanced: '技术先进性',
        // pct_apply: 'pct申请号',
        // pct_publish: 'pct公布号',
        // img_url: [{ name: '20211118151846.jpg', url: '/files/jlstcompany/file/20211118151846.jpg' }],
      },
    };
  },
  async created() {
    if (this.id) await this.search();
  },
  methods: {
    ...patentinfo(['fetch', 'create', 'update']),
    async search() {
      let res = await this.fetch(this.id);
      if (this.$checkRes(res)) {
        this.$set(this, `form`, res.data);
      }
    },
    async onSubmit() {
      let data = this.form;
      if (data.id) {
        let res = await this.update(data);
        if (this.$checkRes(res)) {
          this.$toast({ type: `success`, message: `操作完成` });
          this.back();
        }
      } else {
        let res = await this.create(data);
        if (this.$checkRes(res)) {
          this.$toast({ type: `success`, message: `操作完成` });
          this.back();
        }
      }
    },
    // 返回
    back() {
      this.$router.push({ path: '/patent/admin/patent/info' });
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

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