<template>
    <div id="category">
      <!--头部-->
      <!-- <Header/> -->
      <div class="header-title">
        <span class="header-title-return" @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="type">
            <div style="margin: 10px 10px 0 10px;">
              <van-tag type="primary" v-for="(item, index) in type" :key="index" @click="clickLabels(item, index)" :color="typeName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="typeName == 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="typeConfirmCancel">
                重置
              </van-button>
              <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="typeConfirmSure">
                确认
              </van-button>
            </div>
          </van-dropdown-item>
          <van-dropdown-item title="案由" ref="reason">
            <div style="margin: 10px 10px 0 10px;">
              <van-tag type="primary" v-for="(item, index) in reason" :key="index" @click="clickReasonLabels(item, index)" :color="reasonName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="reasonName == 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="reasonConfirmCancel">
                重置
              </van-button>
              <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="reasonConfirmSure">
                确认
              </van-button>
            </div>
          </van-dropdown-item>
        </van-dropdown-menu>
      </div>
  
      <div class="manage-body">
        <div v-for="(item, index) in judgementList" :key="index">
<!--          <span class="fw-bold" style="color: #11C95F;">[已结案]</span>-->
        <div @click="jumpDetail(item)" class="fw-bold mg-lt-16 mg-bt-10">{{ item.caseName }}</div>
<!--        <div class="mg-lt-16 mg-bt-10"><van-tag class="mg-lt-5 pd-5 fs-13" color="#FDF3E7" text-color="#EE8C15" size="large">{{ item.caseReason }}</van-tag></div>-->
        <van-cell-group @click="jumpDetail(item)">
<!--            <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">案号：{{ item.caseName }}</div>-->
            <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">案由：{{ item.caseReason }}</div>
            <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">原告/上诉人：{{ item.prosecutor }}</div>
            <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">被告/被上诉人：{{ item.defendant }}</div>
            <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">涉案金额：{{ item.amount }}</div>
            <div style="padding-bottom: 10px" class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">开庭时间：{{ item.courtMonth }}</div>
<!--            <div style="padding-bottom: 10px" class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">判决结果：{{ item.caseName }}</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, Tag, DropdownMenu, DropdownItem } from 'vant';
  
  // 3. 引入接口
  import {postQueryCateGory, postQueryIllegalJudgement, postQueryCaseType, postQueryCaseReson } from "@/service/api/customerDashboard";

  
  export default {
    name: "Judgments",

    data() {
      return {
        pageLoading: true,
        judgementList: [],
        type: [],
        typeName: '',
        typeValue: '',
        reason: [],
        reasonName: '',
        reasonValue: '',
        currentPage: 1,
        loading: false,
        isEndLoading: false,
      }
    },
    components: {
      VanButton: Button,
      VanRow: Row,
      VanCol: Col,
      VanIcon: Icon,
      VanField: Field,
      VanTag: Tag,
      VanDropdownMenu: DropdownMenu,
      VanDropdownItem: DropdownItem,
    },
    created() {
      this.postJudgement();
      this.postCaseType();
      this.postCaseReson();
    },
    mounted() {
      window.addEventListener('scroll', this.scrollBottom);
    },
    destroyed() {
      window.removeEventListener('scroll', this.scrollBottom)
    },
    methods: {
      // 获取裁判文书
      async postJudgement(){
        let params = {
          // companyId: '00334179afa2e99e4d2932c4ae1f738c',
          companyId: sessionStorage.getItem('companyId'),
          caseReasonType: this.reasonValue,
          caseType: this.typeValue,
          pageNum: this.currentPage,
          pageSize: 10,
        }
        let result = await postQueryIllegalJudgement(params);
        // this.judgementList = result.records;
        if (result) {
          this.pageLoading = true;
          if (this.loading) {
            this.judgementList = this.judgementList.concat(result.records);
          } else {
            this.judgementList = result.records;
          }
          if (this.judgementList.length < result.total) {
            this.isEndLoading = false;
          } else {
            this.isEndLoading = true;
          }
          this.loading = false;
        }
      },
      // 获取案件类型
      async postCaseType(){
        let result = await postQueryCaseType({companyId: sessionStorage.getItem('companyId')});
        this.type = result;
      },
      // 获取案由
      async postCaseReson(){
        let result = await postQueryCaseReson({companyId: sessionStorage.getItem('companyId')});
        this.reason = result;
      },


      // 根据类型查询
      clickLabels(tag, i) {
        this.typeName = tag.condition;
      },
      // 类型点击重置
      typeConfirmCancel() {
        this.typeName = '';
        this.typeValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postJudgement();
      },
      // 类型点击确定
      typeConfirmSure() {
        this.$refs.type.toggle(false);
        this.typeValue = this.typeName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postJudgement();
      },
      // 根据案由查询
      clickReasonLabels(tag, i) {
        this.reasonName = tag.condition;
      },
      // 案由查询点击重置
      reasonConfirmCancel() {
        this.reasonName = '';
        this.reasonValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postJudgement();
      },
      // 案由查询点击确定
      reasonConfirmSure() {
        this.$refs.reason.toggle(false);
        this.reasonValue = this.reasonName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postJudgement();
      },

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

      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.loading = true;
          this.currentPage += 1;
          this.postJudgement();
        }
      },


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