<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="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.value?'#E9F1FD':'#F2F3F5'" :text-color="statusName == item.value?'#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="cls">
                <div style="margin: 10px 10px 0 10px;">
                  <van-tag type="primary" v-for="(item, index) in clsList" :key="index" @click="clickClsLabels(item, index)" :color="clsName == item.value?'#E9F1FD':'#F2F3F5'" :text-color="clsName == item.value?'#2372EB':'#6D6F6D'" class="mg-lt-5 pd-5 pd-bt-10 mg-10 fs-13" size="large">{{ item.key }}</van-tag>
                </div>
                <div style="padding: 10px 16px;margin-bottom: 45px;">
                <van-button class="br-6" style="width: 45%;float: left;"  type="default" @click="clsConfirmCancel">
                    重置
                </van-button>
                <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="clsConfirmSure">
                    确认
                </van-button>
                </div>
            </van-dropdown-item>
            <van-dropdown-item title="申请日" ref="city">
                <div style="margin: 10px 10px 0 10px;">
                  <van-tag type="primary" v-for="(item, index) in cityList" :key="index" @click="clickCityLabels(item, index)" :color="cityName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="cityName == 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="cityConfirmCancel">
                    重置
                </van-button>
                <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="cityConfirmSure">
                    确认
                </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: 150px;" @click="jumpDetail(item)" v-for="(item, index) in ttmList" :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" size="1.5rem" name="hotel-o" /></div></div>
<!--          <img :src="require(item.imageUrl)" />-->
<!--          <van-tag style="bottom: 5px;" class="mg-lt-10" color="#E9F1FD" text-color="#2372EB">{{ item.flowStatusDesc }}</van-tag>-->
            <div class="ft-right wt-84-per mg-bt-10"><span class="ft-left fs-16 fw-bold">{{ item.name }}</span></div>
<!--            <div class="ft-right wt-84-per cl-gray mg-bt-10"><span class="ft-left fs-13">申请/注册号：12313123123</span></div>-->
<!--            <div class="ft-right wt-84-per cl-gray mg-bt-10"><span class="ft-left fs-13">国际分类：12313123123</span></div>-->
<!--            <div class="ft-right wt-84-per cl-gray mg-bt-10"><span class="ft-left fs-13">申请日期：2024-03-21</span></div>-->
<!--            <div class="ft-right wt-84-per cl-gray mg-bt-10"><span class="ft-left fs-13">注册日期：2024-03-21</span></div>-->
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">申请/注册号：{{ item.regNo }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">国际分类：{{ item.intCls }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">申请日期：{{ item.appDate }}</div>
          <div style="padding-bottom: 10px" class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">注册日期：{{ item.regDate }}</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 {
    postTTmPage,
    postTmStatus,
    postIntCls,
    postApplyYear,
    postPublishYear,
  } from "@/service/api/customerDashboard";

  
  export default {
    name: "TradeMark",

    data() {
      return {
        pageLoading: true,
        ttmList: [],
        total: '',
        clsList: [],
        statusList: [{condition: '有效', value: '1'},{condition: '无效', value: '2'},{condition: '待审', value: '3'},{condition: '不定', value: '4'},{condition: '未知状态', value: '5'}],
        publishList: [],
        cityList: [],
        clsName: '',
        clsValue: '',
        statusName: '',
        statusValue: '',
        cityName: '',
        cityValue: '',
        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.postCls();
      this.postTradeCity();
      this.postPublish();
    },
    mounted() {
      window.addEventListener('scroll', this.scrollBottom);
      this.postTTm();
    },
    destroyed() {
      window.removeEventListener('scroll', this.scrollBottom)
    },
    methods: {
      // 获取商标信息
      async postTTm(){
        let params = {
          // companyId: 'd1e4b5bc79818c7d64197139a9b66625',
          companyId: sessionStorage.getItem('companyId'),
          appDate: this.cityValue,
          intCls: this.clsValue,
          regDate: this.publishValue,
          status: this.statusValue,
          pageNum: this.currentPage,
          pageSize: 10,
        }
        let result = await postTTmPage(params);
        // this.ttmList = result.records;
        if (result) {
          this.pageLoading = true;
          this.total = result.total;
          if (this.loading) {
            this.ttmList = this.ttmList.concat(result.records);
          } else {
            this.ttmList = result.records;
          }
          if (this.ttmList.length < result.total) {
            this.isEndLoading = false;
          } else {
            this.isEndLoading = true;
          }
          this.loading = false;
        }
      },
      // 获取分类
      async postCls(){
        let result = await postIntCls({companyId: sessionStorage.getItem('companyId')});
        this.clsList = result;
      },
      // 获取申请日
      async postTradeCity(){
        let result = await postApplyYear({companyId: sessionStorage.getItem('companyId')});
        this.cityList = result;
      },
      // 获取注册日
      async postPublish(){
        let result = await postPublishYear({companyId: sessionStorage.getItem('companyId')});
        this.publishList = result;
      },

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

      // 根据分类查询
      clickClsLabels(tag, i) {
        this.clsName = tag.value;
      },
      // 分类点击重置
      clsConfirmCancel() {
        this.clsName = '';
        this.clsValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postTTm();
      },
      // 分类点击确定
      clsConfirmSure() {
        this.$refs.cls.toggle(false);
        this.clsValue = this.clsName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postTTm();
      },

      // 根据申请日查询
      clickCityLabels(tag, i) {
        this.cityName = tag.condition;
      },
      // 申请日点击重置
      cityConfirmCancel() {
        this.cityName = '';
        this.cityValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postTTm();
      },
      // 申请日点击确定
      cityConfirmSure() {
        this.$refs.city.toggle(false);
        this.cityValue = this.cityName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postTTm();
      },

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

      // 滚动到页面底部时，请求内容
      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.postTTm();
        }
      },

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

    },
  }
  </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