<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="type">
                <div style="margin: 10px 10px 0 10px;">
                  <van-tag type="primary" v-for="(item, index) in paimaiType" :key="index" @click="clickTypeLabels(item, index)" :color="paimaiTypeName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="paimaiTypeName == 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="result">
                <div style="margin: 10px 10px 0 10px;">
                  <van-tag type="primary" v-for="(item, index) in paimaiResult" :key="index" @click="clickResultLabels(item, index)" :color="paimaiResultName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="paimaiResultName == 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="resultConfirmCancel">
                    重置
                </van-button>
                <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="resultConfirmSure">
                    确认
                </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" v-if="auctionList.length !== 0">
        <div v-for="(item, index) in auctionList" :key="index">
        <div class="fw-bold mg-lt-16">{{ item.auctionNotice }}</div>
        <van-cell-group>
<!--          <van-cell :title="'案号：'+item.aaa" value="" />-->
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">起拍价(元)：{{ item.salePrice }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">评估价(元)：{{ item.appraisalPrice }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">成交价(元)：{{ item.turnoverPrice }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">拍卖时间：{{ item.auctionStartTime }}<span v-if="item.auctionStartTime &&item.auctionEndTime">至</span>{{ item.auctionEndTime }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">拍卖结果：{{ item.auctionStatus }}</div>
          <div style="padding-bottom: 10px" class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">处置单位：{{ item.courtName }}</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, Area } from 'vant';
  import { areaList } from '@vant/area-data';

  // 3. 引入接口
  import {
    postQueryAuction,
    postQueryAuctionStatus,
    postQueryAuctionType,
  } from "@/service/api/customerDashboard";


  export default {
    name: "JudicialAuctions",

    data() {
      return {
        pageLoading: true,
        areaList,
        auctionList: [],
        paimaiType: [],
        paimaiTypeName: '',
        paimaiTypeValue: '',
        paimaiResult: [],
        paimaiResultName: '',
        paimaiResultValue: '',
        total: '',
        currentPage: 1,
        loading: false,
        isEndLoading: false,
      }
    },
    components: {
      VanButton: Button,
      VanRow: Row,
      VanCol: Col,
      VanIcon: Icon,
      VanField: Field,
      VanTag: Tag,
      VanDropdownMenu: DropdownMenu,
      VanDropdownItem: DropdownItem,
      VanArea: Area,
    },
    created() {
      window.scrollTo(0, 0)
      this.postAuctionType();
      this.postAuctionStatus();
    },
    mounted() {
      window.addEventListener('scroll', this.scrollBottom);
      this.postAuction();
    },
    destroyed() {
      window.removeEventListener('scroll', this.scrollBottom)
    },
    methods: {
      // 获取司法拍卖
      async postAuction(){
        let params = {
          companyId: sessionStorage.getItem('companyId'),
          // companyId: '00210c33715dbba0ffbd109e598ef209',
          auctionStatus: this.paimaiResultValue,
          markType: this.paimaiTypeValue,
          pageNum: this.currentPage,
          pageSize: 10
        }
        let result = await postQueryAuction(params);
        // this.auctionList = result.records;
        if (result) {
          this.pageLoading = true;
          this.total = result.total;
          if (this.loading) {
            this.auctionList = this.auctionList.concat(result.records);
          } else {
            this.auctionList = result.records;
          }
          if (this.auctionList.length < result.total) {
            this.isEndLoading = false;
          } else {
            this.isEndLoading = true;
          }
          this.loading = false;
        }
      },
      // 获取拍卖类型
      async postAuctionType(){
        let result = await postQueryAuctionType({companyId: sessionStorage.getItem('companyId')});
        this.paimaiType = result;
      },
      // 获取拍卖结果
      async postAuctionStatus(){
        let result = await postQueryAuctionStatus({companyId: sessionStorage.getItem('companyId')});
        this.paimaiResult = result;
      },
      returnClick() {
        this.$router.go(-1)
      },
      // 根据拍卖类型查询
      clickTypeLabels(tag, i) {
        this.paimaiTypeName = tag.condition;
      },
      // 拍卖类型点击重置
      typeConfirmCancel() {
        this.paimaiTypeName = '';
        this.paimaiTypeValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postAuction();
      },
      // 拍卖类型点击确定
      typeConfirmSure() {
        this.$refs.type.toggle(false);
        this.paimaiTypeValue = this.paimaiTypeName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postAuction();
      },
      // 根据拍卖结果查询
      clickResultLabels(tag, i) {
        this.paimaiResultName = tag.condition;
      },
      // 拍卖结果查询点击重置
      resultConfirmCancel() {
        this.paimaiResultName = '';
        this.paimaiResultValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postAuction();
      },
      // 拍卖结果查询点击确定
      resultConfirmSure() {
        this.$refs.result.toggle(false);
        this.paimaiResultValue = this.paimaiResultName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postAuction();
      },

      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.postAuction();
        }
      },

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