<template>
  <div id="search-1">
    <van-row>
      <van-col span="24" class="main">
        <van-col :span="24" class="one">
          <van-form label-width="5em" @submit="searchBtn">
            <van-field readonly clickable name="picker" :value="searchForm.empower_date" label="授权年份" placeholder="点击选择" @click="oneShow = true" />
            <van-popup v-model="oneShow" position="bottom">
              <van-picker show-toolbar :columns="yearList" @confirm="oneCon" @cancel="oneShow = false" />
            </van-popup>
            <van-field readonly clickable name="picker" :value="searchForm.create_date" label="申请年份" placeholder="点击选择" @click="twoShow = true" />
            <van-popup v-model="twoShow" position="bottom">
              <van-picker show-toolbar :columns="yearList" @confirm="twoCon" @cancel="twoShow = false" />
            </van-popup>
            <van-field v-model="searchForm.field" name="field" label="所属领域" style="display: none" />
            <van-field readonly clickable name="picker" :value="searchForm.fieldname" label="所属领域" placeholder="点击选择" @click="thrShow = true" />
            <van-popup v-model="thrShow" position="bottom">
              <van-picker show-toolbar value-key="name" :columns="fieldList" @confirm="thrCon" @cancel="thrShow = false" />
            </van-popup>
            <van-field v-model="searchForm.create_number" name="first_inventor" label="申请号" placeholder="申请号" />
            <van-field v-model="searchForm.first_inventor" name="first_inventor" label="第一发明人" placeholder="第一发明人" />
            <van-field v-model="searchForm.apply_personal" name="apply_personal" label="所在学校" placeholder="所在学校" disabled />
            <van-field v-model="searchForm.on_obligee" name="on_obligee" 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-group>
              </template>
            </van-field>
            <van-field name="is_empower" label="是否授权">
              <template #input>
                <van-radio-group v-model="searchForm.is_empower" direction="horizontal">
                  <van-radio name="0">已授权</van-radio>
                  <van-radio name="1">未授权</van-radio>
                </van-radio-group>
              </template>
            </van-field>
            <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-group>
              </template>
            </van-field>
            <van-field name="is_lose" label="是否失效">
              <template #input>
                <van-radio-group v-model="searchForm.is_lose" direction="horizontal">
                  <van-radio name="0">失效</van-radio>
                  <van-radio name="1">未失效</van-radio>
                </van-radio-group>
              </template>
            </van-field>
            <van-field name="empower_sort" label="授权日排序">
              <template #input>
                <van-radio-group v-model="searchForm.empower_sort" direction="horizontal">
                  <van-radio name="0">升序</van-radio>
                  <van-radio name="1">降序</van-radio>
                </van-radio-group>
              </template>
            </van-field>
            <van-col span="24" class="btn">
              <van-button type="danger" size="small" @click="reseatBtn">重置条件</van-button>
              <van-button type="info" size="small" native-type="submit">提交查询</van-button>
            </van-col>
          </van-form>
        </van-col>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'search-1',
  props: {
    searchForm: { type: Object },
  },
  components: {},
  data: function () {
    return {
      // 年份列表
      yearList: [
        '2000',
        '2001',
        '2002',
        '2003',
        '2004',
        '2005',
        '2006',
        '2007',
        '2008',
        '2009',
        '2010',
        '2011',
        '2012',
        '2013',
        '2014',
        '2015',
        '2016',
        '2017',
        '2018',
        '2019',
        '2020',
        '2021',
      ],
      // 选择授权年份
      oneShow: false,
      // 选择授权年份
      twoShow: false,
      // 选择所属领域
      thrShow: false,
      fieldList: [
        { num: 'A', name: '人类生活必需' },
        { num: 'B', name: '作业；运输' },
        { num: 'C', name: '化学；冶金' },
        { num: 'D', name: '纺织；造纸' },
        { num: 'E', name: '固定建筑物' },
        { num: 'F', name: '机械工程；照明；加热；武器；爆破' },
        { num: 'G', name: '物理' },
        { num: 'H', name: '电学' },
      ],
    };
  },
  created() {},
  methods: {
    // 选择授权年份
    oneCon(value) {
      this.$set(this.searchForm, `empower_date`, value);
      this.oneShow = false;
    },
    // 选择申请年份
    twoCon(value) {
      this.$set(this.searchForm, `create_date`, value);
      this.twoShow = false;
    },
    // 选择所属领域
    thrCon(value) {
      this.$set(this.searchForm, `field`, value.num);
      this.$set(this.searchForm, `fieldname`, value.name);
      this.thrShow = false;
    },
    // 重置条件
    reseatBtn() {
      this.$emit('reseatBtn');
    },
    // 提交查询
    searchBtn() {
      this.$emit('search', this.searchForm);
    },
  },
  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 {
    text-align: center;
    .btn {
      text-align: center;
      margin: 8px 0;
      .van-button {
        margin: 0 8px;
      }
    }
  }
}
</style>
