<template>
  <div id="index">
    <admin-frame topType="2" :rightArrow="false" :leftArrow="false" :usePage="false" :useNav="false">
      <template v-slot:info>
        <van-col :span="24" class="one">
          <van-form @submit="onSubmit" @reset="onReset" label-width="7em">
            <van-field v-model="form.create_number" name="create_number" label="申请号" placeholder="申请号" :rules="[{ required: true, message: '申请号' }]" />
            <van-field
              v-model="form.patent_name"
              name="patent_name"
              label="专利名称"
              placeholder="专利名称"
              :rules="[{ required: true, message: '专利名称' }]"
            />
            <van-field
              v-model="form.on_obligee"
              name="on_obligee"
              label="变更前专利权人"
              placeholder="变更前专利权人"
              :rules="[{ required: true, message: '变更前专利权人' }]"
            />
            <van-field
              v-model="form.on_afterobligee"
              name="on_afterobligee"
              label="变更后专利权人"
              placeholder="变更后专利权人"
              :rules="[{ required: true, message: '变更后专利权人' }]"
            />
            <van-field
              name="transfer_date"
              :value="form.transfer_date"
              label="专利权转移日期"
              placeholder="点击选择"
              @click="selectDate('transfer_date')"
              :rules="[{ required: true, message: '专利权转移日期' }]"
            />
            <!-- 选择日期公用弹框 -->
            <van-calendar v-model="calendarShow" @confirm="calendarCon" :min-date="minDate" :max-date="maxDate" />
            <div class="btn">
              <van-button type="danger" size="small" native-type="reset">重置信息</van-button>
              <van-button type="info" size="small" native-type="submit">提交信息</van-button>
            </div>
          </van-form>
        </van-col>
        <!-- <van-button @click="createData">添加</van-button> -->
      </template>
    </admin-frame>
  </div>
</template>

<script>
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
import { Toast } from 'vant';
const { mapActions: patenttrans } = createNamespacedHelpers('patenttrans');
var moment = require('moment');
export default {
  name: 'index',
  props: {},
  components: {
    adminFrame,
  },
  data: function () {
    return {
      form: {},
      // 选择日期
      minDate: new Date(2000, 10, 1),
      maxDate: new Date(2050, 10, 1),
      calendarShow: false,
      calendar_type: '',
    };
  },
  created() {},
  methods: {
    ...patenttrans(['create']),
    async onSubmit(value) {
      value.status = '4';
      let res = await this.create(value);
      if (this.$checkRes(res)) {
        this.$toast({ type: `success`, message: `操作成功` });
      }
    },
    onReset() {},
    // 打开选择日期弹框
    selectDate(type) {
      this.$set(this, `calendar_type`, type);
      this.calendarShow = true;
    },
    // 选中日期
    calendarCon(date) {
      this.$set(this.form, this.calendar_type, moment(date).format('YYYY-MM-DD'));
      this.calendarShow = false;
    },
    // 自动添加数据
    async createData() {
      let data = [];
      for (const val of data) {
        let res = await this.create(val);
        if (this.$checkRes(res)) {
          this.$toast({ type: `success`, message: `操作成功` });
        }
      }
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.one {
  .btn {
    text-align: center;
    margin: 10px 0;
    .van-button {
      margin: 0 10px;
    }
  }
  /deep/.van-radio--horizontal {
    margin-right: 5px;
  }
}
</style>
