<template>
  <div id="endtrans-1">
    <van-row>
      <van-col span="24" class="main">
        <van-col span="24" class="one">
          <van-form @submit="onSubmit">
            <van-field v-model="form.id" name="id" label="数据id" readonly style="display: none" />
            <van-field v-model="form.patent_name" name="patent_name" label="专利名称" autosize rows="1" type="textarea" readonly />
            <van-field v-model="form.on_obligee" name="on_obligee" label="变更前权利人" readonly />
            <van-field v-model="form.on_afterobligee" name="on_afterobligee" label="变更后权利人" :rules="[{ required: true, message: '变更后权利人' }]" />
            <van-field name="offine_contract" label="合同" :rules="[{ required: true, message: '合同文件' }]">
              <template #input>
                <van-uploader
                  :fileList="form.offine_contract"
                  :max-count="1"
                  :after-read="(file) => toUpload(file, 'offine_contract')"
                  @delete="(file) => toDelete(file, 'offine_contract')"
                />
              </template>
            </van-field>
            <div style="margin: 16px">
              <van-button round block type="info" native-type="submit">提交合同</van-button>
            </div>
          </van-form>
        </van-col>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: upload } = createNamespacedHelpers('upload');
export default {
  name: 'endtrans-1',
  props: {
    form: { type: Object },
  },
  components: {},
  data: function () {
    return {};
  },
  created() {},
  methods: {
    ...upload(['upload']),
    // 提交合同
    onSubmit(value) {
      if (value) this.$emit('onSubmit', value);
    },
    async toUpload({ file }, model) {
      // 上传,赋值
      const res = await this.upload({ file, dir: 'trans' });
      if (this.$checkRes(res)) {
        this.$set(this.form, model, [{ name: res.name, url: res.uri }]);
      }
    },
    toDelete(file, model) {
      const index = this.form[model].findIndex((f) => _.isEqual(f, file));
      this.form[model].splice(index, 1);
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

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