<template>
    <div id="category">
      <!--头部-->
      <!-- <Header/> -->
      <div class="header-title">
        <span class="header-title-return-back" @click="returnClick"><van-icon name="arrow-left" /></span>
        <span class="header-title-name-bold">专利</span>
      </div>
      <div v-if="pageLoading == true">
      <div>
        <van-dropdown-menu active-color="#1989fa">
            <van-dropdown-item title="类型" ref="desc">
                <div style="margin: 10px 10px 0 10px;">
                  <van-tag type="primary" v-for="(item, index) in descList" :key="index" @click="clickDescLabels(item, index)" :color="descName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="descName == item.condition?'#2372EB':'#6D6F6D'" class="mg-lt-5 pd-5 pd-bt-10 mg-10 fs-13" size="large">{{ item.condition }}</van-tag>
                </div>
                <div style="padding: 10px 16px;margin-bottom: 45px;">
                <van-button class="br-6" style="width: 45%;float: left;"  type="default" @click="descConfirmCancel">
                    重置
                </van-button>
                <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="descConfirmSure">
                    确认
                </van-button>
                </div>
            </van-dropdown-item>
            <van-dropdown-item title="状态" ref="status">
                <div style="margin: 10px 10px 0 10px;">
                  <van-tag type="primary" v-for="(item, index) in statusList" :key="index" @click="clickStatusLabels(item, index)" :color="statusName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="statusName == item.condition?'#2372EB':'#6D6F6D'" class="mg-lt-5 pd-5 pd-bt-10 mg-10 fs-13" size="large">{{ item.condition }}</van-tag>
                </div>
                <div style="padding: 10px 16px;margin-bottom: 45px;">
                <van-button class="br-6" style="width: 45%;float: left;"  type="default" @click="statusConfirmCancel">
                    重置
                </van-button>
                <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="statusConfirmSure">
                    确认
                </van-button>
                </div>
            </van-dropdown-item>
            <van-dropdown-item title="申请日" ref="apply">
                <div style="margin: 10px 10px 0 10px;">
                  <van-tag type="primary" v-for="(item, index) in applyList" :key="index" @click="clickApplyLabels(item, index)" :color="applyName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="applyName == item.condition?'#2372EB':'#6D6F6D'" class="mg-lt-5 pd-5 pd-bt-10 mg-10 fs-13" size="large">{{ item.condition }}</van-tag>
                </div>
                <div style="padding: 10px 16px;margin-bottom: 45px;">
                <van-button class="br-6" style="width: 45%;float: left;"  type="default" @click="applyConfirmCancel">
                    重置
                </van-button>
                <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="applyConfirmSure">
                    确认
                </van-button>
                </div>
            </van-dropdown-item>
            <van-dropdown-item title="公开日" ref="publish">
                <div style="margin: 10px 10px 0 10px;">
                  <van-tag type="primary" v-for="(item, index) in publishList" :key="index" @click="clickPublishLabels(item, index)" :color="publishName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="publishName == item.condition?'#2372EB':'#6D6F6D'" class="mg-lt-5 pd-5 pd-bt-10 mg-10 fs-13" size="large">{{ item.condition }}</van-tag>
                </div>
                <div style="padding: 10px 16px;margin-bottom: 45px;">
                <van-button class="br-6" style="width: 45%;float: left;"  type="default" @click="publishConfirmCancel">
                    重置
                </van-button>
                <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="publishConfirmSure">
                    确认
                </van-button>
                </div>
            </van-dropdown-item>
        </van-dropdown-menu>
      </div>

      <div style="font-size: 13px;margin-top: 10px;margin-left: 5px;">共<span style="color: #DB2C2C;">{{ total }}</span>条专利信息</div>
      <div class="manage-body">
        <div style="height: 250px;" @click="jumpDetail(item)" v-for="(item, index) in patentList" :key="index">
            <div class="ft-left wt-15-per hg-100-per"><div class="mg-lt-5 wt-2-rem firm-icon-body"><van-icon class="firm-icon" color="#fff" size="1.5rem" name="hotel-o" /></div></div>
            <div class="ft-right wt-84-per mg-bt-10"><span class="ft-left fs-16 fw-bold">{{ item.title }}</span></div>
            <div><van-tag style="bottom: 5px;" class="mg-lt-10" color="#E9F1FD" text-color="#2372EB">{{ item.kindCodeDesc }}</van-tag></div>
            <div class="ft-right wt-84-per cl-gray mg-bt-10"><span class="ft-left fs-13">申请号：{{ item.applicationNumber }}</span></div>
            <div class="ft-right wt-84-per cl-gray mg-bt-10"><span class="ft-left fs-13">申请日：{{ item.applicationDate }}</span></div>
            <div class="ft-right wt-84-per cl-gray mg-bt-10"><span class="ft-left fs-13">授权公告号：{{ item.publicationNumber }}</span></div>
            <div class="ft-right wt-84-per cl-gray mg-bt-10"><span class="ft-left fs-13">授权公告日：{{ item.publicationDate }}</span></div>
            <div style="padding-bottom: 10px" class="ft-right wt-84-per cl-gray mg-bt-10"><span class="ft-left fs-13">发明人：{{ item.inventorStringList }}</span></div>
        </div>
      </div>
      </div>
      <van-loading style="text-align: center;margin-top: 50%" v-if="pageLoading == false" />
    </div>

  </template>
  
  <script>
  import { Button, Col, Row, Icon, Field, DropdownMenu, DropdownItem, Tag } from 'vant';
  
  // 3. 引入接口
  import {getCategories, getCategoriesDetail} from "./../../service/api/index"
  import {postKindCodeDesc, postLegalStatus, postApplyDate, postPublishDate, postTPatentPage} from "@/service/api/customerDashboard";

  
  export default {
    name: "Patent",

    data() {
      return {
        pageLoading: true,
        patentList: [],
        total: '',
        descList: [],
        statusList: [],
        publishList: [],
        applyList: [],
        descName: '',
        descValue: '',
        statusName: '',
        statusValue: '',
        applyName: '',
        applyValue: '',
        publishName: '',
        publishValue: '',
        currentPage: 1,
        loading: false,
        isEndLoading: false,
      }
    },
    components: {
      VanButton: Button,
      VanRow: Row,
      VanCol: Col,
      VanIcon: Icon,
      VanField: Field,
      VanTag: Tag,
      VanDropdownMenu: DropdownMenu,
      VanDropdownItem: DropdownItem,
    },
    created() {
      window.scrollTo(0, 0)
      this.postDesc();
      this.postStatus();
      this.postApply();
      this.postPublish();
    },
    mounted() {
      window.addEventListener('scroll', this.scrollBottom);
      this.postPatent();
    },
    destroyed() {
      window.removeEventListener('scroll', this.scrollBottom)
    },
    methods: {
      // 获取商标信息
      async postPatent(){
        let params = {
          // companyId: '15f34bb1dadaa500b0007b8dfd1b9227',
          companyId: sessionStorage.getItem('companyId'),
          applicationDate: this.applyValue,
          kindCodeDesc: this.descValue,
          legalStatusDesc: this.statusValue,
          publicationDate: this.publishValue,
          pageNum: this.currentPage,
          pageSize: 10,
        }
        let result = await postTPatentPage(params);
        // this.patentList = result.records;
        if (result) {
          this.pageLoading = true;
          this.total = result.total;
          if (this.loading) {
            this.patentList = this.patentList.concat(result.records);
          } else {
            this.patentList = result.records;
          }
          if (this.patentList.length < result.total) {
            this.isEndLoading = false;
          } else {
            this.isEndLoading = true;
          }
          this.loading = false;
        }
      },
      // 获取类型
      async postDesc(){
        let result = await postKindCodeDesc({companyId: sessionStorage.getItem('companyId')});
        this.descList = result;
      },
      // 获取状态
      async postStatus(){
        let result = await postLegalStatus({companyId: sessionStorage.getItem('companyId')});
        this.statusList = result;
      },
      // 获取申请日
      async postApply(){
        let result = await postApplyDate({companyId: sessionStorage.getItem('companyId')});
        this.applyList = result;
      },
      // 获取公开日
      async postPublish(){
        let result = await postPublishDate({companyId: sessionStorage.getItem('companyId')});
        this.publishList = result;
      },

      // 根据状态查询
      clickStatusLabels(tag, i) {
        this.statusName = tag.condition;
      },
      // 状态点击重置
      statusConfirmCancel() {
        this.statusName = '';
        this.statusValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postPatent();
      },
      // 状态点击确定
      statusConfirmSure() {
        this.$refs.status.toggle(false);
        this.statusValue = this.statusName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postPatent();
      },

      // 根据分类查询
      clickDescLabels(tag, i) {
        this.descName = tag.condition;
      },
      // 分类点击重置
      descConfirmCancel() {
        this.descName = '';
        this.descValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postPatent();
      },
      // 分类点击确定
      descConfirmSure() {
        this.$refs.desc.toggle(false);
        this.descValue = this.descName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postPatent();
      },

      // 根据申请日查询
      clickApplyLabels(tag, i) {
        this.applyName = tag.condition;
      },
      // 申请日点击重置
      applyConfirmCancel() {
        this.applyName = '';
        this.applyValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postPatent();
      },
      // 申请日点击确定
      applyConfirmSure() {
        this.$refs.apply.toggle(false);
        this.applyValue = this.applyName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postPatent();
      },

      // 根据公开日查询
      clickPublishLabels(tag, i) {
        this.publishName = tag.condition;
      },
      // 公开日点击重置
      publishConfirmCancel() {
        this.publishName = '';
        this.publishValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postPatent();
      },
      // 公开日点击确定
      publishConfirmSure() {
        this.$refs.publish.toggle(false);
        this.publishValue = this.publishName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postPatent();
      },

      // 滚动到页面底部时，请求内容
      scrollBottom() {
        let scrollTop = document.documentElement.scrollTop || document.body.scrollTop  //页面滚动的高度
        let clientHeight = document.documentElement.clientHeight  //可视区域高度
        let scrollHeight = document.documentElement.scrollHeight  //可滚动内容的高度
        let bottomOfWindow = scrollTop + clientHeight + 1000 >= scrollHeight    //是否滚动到底部
        //loading 和 this.tableData.length和this.total是自己的判断条件
        if (scrollTop !== 0 && bottomOfWindow && !this.loading && this.total > 10) {
          this.loading = true;
          this.currentPage += 1;
          this.postPatent();
        }
      },

      returnClick() {
        this.$router.go(-1)
      },
      jumpDetail(data) {
        sessionStorage.setItem('patentData', JSON.stringify(data))
        this.$router.push({path: 'PatentDetail'})
      },

    },
  }
  </script>
  
  <style lang="less" scoped>
  
  .header-title {
    height: 46px;
    width: 100%;
    background-color: #fff;
    text-align: center;
  }
  .header-title-name {
    font-weight: bold;
    line-height: 46px;
    align-items: center;
    justify-content: center;
    display: inline-flex;
  }
  .header-title-return {
    position: absolute;
    top: 13px;
    left: 20px;
    font-size: 15px;
  }
  .manage-body {
    margin-top: 10px;
    background-color: #fff;
    padding: 20px 10px 0px 10px;
  }
  .icon-mg {
    margin-left: 3px;
  }
  .firm-icon-body {
    background-color: #2372EB;
    border-radius: 5px;
}
.firm-icon {
    line-height: 2.5rem;
    margin-left: 0.5rem;
}
  </style>../../service/api/index