<template>
  <div id="search-1">
    <van-row>
      <van-col span="24" class="main">
        <van-col :span="24" class="one">
          <van-form label-width="6em">
            <!-- <van-field
              readonly
              clickable
              name="apply_personal"
              :value="searchForm.apply_personal"
              label="申请人"
              placeholder="点击选择"
              @click="twoShow = true"
              type="textarea"
              rows="1"
              autosize
            />
            <van-popup v-model="twoShow" position="bottom">
              <van-picker show-toolbar :columns="apply_personalList" value-key="name" @confirm="personalFim" @cancel="twoShow = false" />
            </van-popup> -->
            <van-field v-model="searchForm.apply_personal" name="apply_personal" label="申请人" placeholder="请输入申请人" />
            <van-field v-model="searchForm.first_apply" name="first_apply" label="第一申请人" placeholder="请输入第一申请人" />
            <van-field v-model="searchForm.on_obligee" name="on_obligee" label="当前权利人" placeholder="请输入当前权利人" />
            <van-field name="term" label="专利有效性">
              <template #input>
                <van-radio-group v-model="searchForm.term" direction="horizontal">
                  <van-radio name="有效">有效</van-radio>
                  <van-radio name="审中">审中</van-radio>
                  <van-radio name="失效">失效</van-radio>
                </van-radio-group>
              </template>
            </van-field>
            <van-field v-model="searchForm.key_word" name="key_word" label="标题或关键词" placeholder="请输入标题或关键词" />
            <van-field name="type" label="专利类型">
              <template #input>
                <van-radio-group v-model="searchForm.type" direction="horizontal">
                  <van-radio name="发明申请">发明申请</van-radio>
                  <!-- <van-radio name="发明授权">发明授权</van-radio> -->
                  <van-radio name="实用新型">实用新型</van-radio>
                  <van-radio name="外观设计">外观设计</van-radio>
                  <van-radio name="PCT国际申请号">PCT国际申请号</van-radio>
                  <van-radio name="PCT国际公布号">PCT国际公布号</van-radio>
                </van-radio-group>
              </template>
            </van-field>
            <van-field name="onlegal_status" label="当前法律状态">
              <template #input>
                <van-radio-group v-model="searchForm.onlegal_status" direction="horizontal">
                  <van-radio name="公开">公开</van-radio>
                  <van-radio name="授权">授权</van-radio>
                  <van-radio name="实质审查">实质审查</van-radio>
                </van-radio-group>
              </template>
            </van-field>
            <van-field v-model="searchForm.inventor" name="inventor" label="发明人" placeholder="请输入发明人" />
            <van-field v-model="searchForm.first_inventor" name="first_inventor" label="第一发明人" placeholder="请输入第一发明人" />
            <van-field v-model="searchForm.apply_city" name="apply_city" label="申请人地市" placeholder="请输入申请人地市" />
            <van-field
              readonly
              clickable
              name="calendar"
              :value="searchForm['create_date@start']"
              label="申请日(开始)"
              placeholder="点击选择"
              @click="changeCreate('create_date@start')"
            />
            <van-field
              readonly
              clickable
              name="calendar"
              :value="searchForm['create_date@end']"
              label="申请日(结束)"
              placeholder="点击选择"
              @click="changeCreate('create_date@end')"
            />
            <van-field
              readonly
              clickable
              name="calendar"
              :value="searchForm['empower_date@start']"
              label="授权公告日(开始)"
              placeholder="点击选择"
              @click="changeCreate('empower_date@start')"
            />
            <van-field
              readonly
              clickable
              name="calendar"
              :value="searchForm['empower_date@end']"
              label="授权公告日(结束)"
              placeholder="点击选择"
              @click="changeCreate('empower_date@end')"
            />
            <van-field v-model="searchForm.create_number" name="create_number" label="申请号" placeholder="请输入申请号" />
            <van-field readonly clickable name="所属管理机构" :value="searchForm.pid" style="display: none" />
            <van-field readonly clickable name="所属管理机构" :value="searchForm.pname" label="所属管理机构" placeholder="点击选择" @click="thrShow = true" />
            <van-popup v-model="thrShow" position="bottom">
              <van-picker show-toolbar :columns="adminList" value-key="name" @confirm="pidFim" @cancel="thrShow = false" />
            </van-popup>
            <van-calendar v-model="oneShow" @confirm="oneChange" position="right" :min-date="minDate" :max-date="maxDate" />
            <div class="btn">
              <van-button type="info" size="small" @click="reseat">重置条件</van-button>
              <van-button type="primary" size="small" @click="onSubmit">提交查询</van-button>
            </div>
          </van-form>
        </van-col>
      </van-col>
    </van-row>
  </div>
</template>

<script>
const { apply_personal } = require('@frame/src/layout/applyCom');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: adminLogin } = createNamespacedHelpers('adminLogin');
const moment = require('moment');
export default {
  name: 'search-1',
  props: {
    searchForm: { type: Object },
  },
  components: {},
  data: function () {
    return {
      // 选择申请日
      oneShow: false,
      minDate: new Date(1900, 1, 1),
      maxDate: new Date(2050, 1, 1),
      type: '',
      // 申请人单位
      twoShow: false,
      apply_personalList: apply_personal,
      // 所属管理机构
      thrShow: false,
      adminList: [],
    };
  },
  created() {
    this.searchOther();
  },
  methods: {
    ...adminLogin(['query']),
    reseat() {
      this.$emit('reseat');
    },
    onSubmit() {
      this.$emit('onSubmit', { data: this.searchForm });
    },
    changeCreate(type) {
      this.$set(this, `type`, type);
      this.oneShow = true;
    },
    // 选择申请日
    oneChange(value) {
      this.$set(this.searchForm, this.type, moment(value).format('YYYY-MM-DD'));
      this.oneShow = false;
    },
    // 选择申请人
    personalFim(value) {
      this.$set(this.searchForm, `apply_personal`, value.name);
      this.twoShow = false;
    },
    // 选择所属管理机构
    pidFim(value) {
      this.$set(this.searchForm, `pid`, value.id);
      this.$set(this.searchForm, `pname`, value.name);

      this.thrShow = false;
    },
    // 查询其他信息
    async searchOther() {
      let res = await this.query({ role: '1' });
      if (this.$checkRes(res)) {
        this.$set(this, `adminList`, res.data);
      }
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

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