<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="execute">
            <div style="margin: 10px 10px 0 10px;">
              <van-tag type="primary" v-for="(item, index) in executeGov" :key="index" @click="clickLabels(item, index)" :color="executeGovName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="executeGovName == 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="confirmCancel">
                重置
              </van-button>
              <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="confirmSure">
                确认
              </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 v-for="(item, index) in monitorCreditList" :key="index">
        <div class="fw-bold mg-lt-16">{{ item.companyName }}</div>
        <van-cell-group>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">决定文书/许可证名称：{{ item.caseNo }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">决定日期：{{ item.lianDate }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">截止日期：{{ item.expireDate }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">许可机关：{{ item.executeGov }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">许可内容：{{ item.content }}</div>
          <div style="padding-bottom: 10px" class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">来源：{{ item.province }}</div>
        </van-cell-group>
        </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 {postQueryGory, postQueryMonitorCredit} from "@/service/api/customerDashboard";

  
  export default {
    name: "Administrative",

    data() {
      return {
        pageLoading: true,
        monitorCreditList: [],
        executeGov: [],
        executeGovValue: '',
        executeGovName: '',
        total: '',
        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.postGory();
    },
    mounted() {
      window.addEventListener('scroll', this.scrollBottom);
      this.postMonitorCredit();
    },
    destroyed() {
      window.removeEventListener('scroll', this.scrollBottom)
    },
    methods: {
      // 获取行政许可
      async postMonitorCredit(){
        let params = {
          // companyId: '00334179afa2e99e4d2932c4ae1f738c',
          companyId: sessionStorage.getItem('companyId'),
          executeGov: this.executeGovValue,
          pageNum: this.currentPage,
          pageSize: 10,
        }
        let result = await postQueryMonitorCredit(params);
        // this.monitorCreditList = result.records;
        if (result) {
          this.pageLoading = true;
          this.total = result.total;
          if (this.loading) {
            this.monitorCreditList = this.monitorCreditList.concat(result.records);
          } else {
            this.monitorCreditList = result.records;
          }
          if (this.monitorCreditList.length < result.total) {
            this.isEndLoading = false;
          } else {
            this.isEndLoading = true;
          }
          this.loading = false;
        }
      },
      // 获取许可机关
      async postGory(){
        let result = await postQueryGory({companyId: sessionStorage.getItem('companyId')});
        this.executeGov = result;
      },
      // 根据许可机关查询
      clickLabels(tag, i) {
        this.executeGovName = tag.condition;
      },
      // 许可机关点击重置
      confirmCancel() {
        this.executeGovName = '';
        this.executeGovValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postMonitorCredit();
      },
      // 许可机关点击确定
      confirmSure() {
        this.$refs.execute.toggle(false);
        this.executeGovValue = this.executeGovName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postMonitorCredit();
      },

      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是自己的判断条件
        console.log(scrollTop, bottomOfWindow)
        if (scrollTop !== 0 && bottomOfWindow && !this.loading && !this.isEndLoading && this.total > 10) {
          this.loading = true;
          this.currentPage += 1;
          this.postMonitorCredit();
        }
      },

      returnClick() {
        this.$router.go(-1)
      },

    },
  }
  </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;
  }
  /deep/ .van-nav-bar__text {
    color: gray !important;
    font-weight: bold;
  }
  .icon-mg {
    margin-left: 3px;
  }
  /deep/ .van-cell__value {
    bottom: 5px;
  }
  </style>../../service/api/index