<template>
  <div id="search-1">
    <van-row>
      <van-col span="24" class="main">
        <van-col span="24" class="one">
          <van-col span="24" class="one_1">
            <van-search v-model="searchName" show-action placeholder="请输入专利名称" @search="search">
              <template #action>
                <div @click="search">搜索</div>
              </template>
            </van-search>
          </van-col>
          <van-col span="24" class="one_2">
            <van-col span="24" class="list" v-for="(item, index) in list" :key="index">
              <van-col span="24" class="name">
                {{ item.name }}
              </van-col>
              <van-col span="24" class="other">
                <van-col span="24" class="otherInfo">
                  申请号：<span>{{ item.create_number }}</span>
                </van-col>
              </van-col>
              <van-col span="24" class="btn">
                <van-button type="info" size="small" @click="conFirm(item)">确定专利</van-button>
              </van-col>
            </van-col>
            <van-col span="24" class="page">
              <page @search="search" :limit="limit" :total="total"></page>
            </van-col>
          </van-col>
        </van-col>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patentinfo } = createNamespacedHelpers('patentinfo');
export default {
  name: 'search-1',
  props: {},
  components: {},
  data: function () {
    return {
      searchName: '',
      list: [],
      limit: 4,
      total: 0,
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...patentinfo(['query']),
    async search({ skip = 0, limit = this.limit, ...info } = {}) {
      info.user_id = this.user._id;
      if (this.searchName) info.name = this.searchName;
      let res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 确认专利
    conFirm(data) {
      this.$emit('conPatent', 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 {
    .one_2 {
      .list {
        background-color: #fff;
        margin: 0 0 8px 0;
        padding: 8px;
        border-radius: 5px;
        .name {
          font-size: 16px;
          font-weight: bold;
          margin: 0 0 5px 0;
        }
        .other {
          margin: 0 0 5px 0;
          .otherInfo {
            font-size: 14px;
            color: #666;
            margin: 0 0 5px 0;
            span {
              color: #000;
            }
          }
        }
        .btn {
          text-align: center;
          .van-button {
            margin: 0 5px;
          }
        }
      }
    }
  }
}
</style>
