<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 typeList" :key="index" @click="clickTypeLabels(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="date">
                <div style="margin: 10px 10px 0 10px;">
                  <van-tag type="primary" v-for="(item, index) in dateList" :key="index" @click="clickDateLabels(item, index)" :color="dateName == item.condition?'#E9F1FD':'#F2F3F5'" :text-color="dateName == 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="dateConfirmCancel">
                    重置
                </van-button>
                <van-button class="br-6" style="width: 45%;float: right;" type="info" @click="dateConfirmSure">
                    确认
                </van-button>
                </div>
            </van-dropdown-item>
            <van-dropdown-item title="省份地区" ref="city">
                <div style="margin: 10px 10px 0 10px;">
<!--                    <van-area title="" :area-list="areaList" />-->
                  <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-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 biddingList" :key="index">
        <div class="fw-bold mg-lt-16">{{ item.doctitle }}</div>
        <van-cell-group>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">招投标类型：{{ item.tendertype }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">发布日期：{{ item.timerelease }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">招采单位：{{ item.tenderee }}</div>
          <div class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">中标单位：{{ item.wintenderer }}</div>
          <div style="padding-bottom: 10px" class="fs-14 mg-lt-16 mg-bt-5 mg-tp-8">中标金额：{{ item.winbidprice }}元</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, Area } from 'vant';
  import { areaList } from '@vant/area-data';
  
  // 3. 引入接口
  import {postBiddingBaseinfo, postDocchannel, postBaseinfoYear, postBiddingCity} from "@/service/api/customerDashboard";

  
  export default {
    name: "BiddingInfo",

    data() {
      return {
        pageLoading: true,
        areaList,
        biddingList: [],
        total: '',
        typeList: [],
        dateList: [],
        cityList: [],
        typeValue: '',
        typeName: '',
        dateValue: '',
        dateName: '',
        cityValue: '',
        cityName: '',
        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.postChannel();
      this.posttBaseinfo();
      this.postCity();
    },
    mounted() {
      window.addEventListener('scroll', this.scrollBottom);
      this.postBidding();
    },
    destroyed() {
      window.removeEventListener('scroll', this.scrollBottom)
    },
    methods: {
      // 获取招投标信息
      async postBidding(){
        let params = {
          // companyId: '65376e48de72d81dee2c1723309dc178',
          companyId: sessionStorage.getItem('companyId'),
          city: this.cityValue,
          docchannel: this.typeValue,
          timeRelease: this.dateValue,
          pageNum: this.currentPage,
          pageSize: 10,
        }
        let result = await postBiddingBaseinfo(params);
        // this.biddingList = result.records;
        if (result) {
          this.pageLoading = true;
          this.total = result.total;
          if (this.loading) {
            this.biddingList = this.biddingList.concat(result.records);
          } else {
            this.biddingList = result.records;
          }
          if (this.biddingList.length < result.total) {
            this.isEndLoading = false;
          } else {
            this.isEndLoading = true;
          }
          this.loading = false;
        }
      },
      // 获取公告类型
      async postChannel(){
        let result = await postDocchannel({companyId: sessionStorage.getItem('companyId')});
        this.typeList = result;
      },
      // 获取发布日期
      async posttBaseinfo(){
        let result = await postBaseinfoYear({companyId: sessionStorage.getItem('companyId')});
        this.dateList = result;
      },
      // 获取省份地区
      async postCity(){
        let result = await postBiddingCity({companyId: sessionStorage.getItem('companyId')});
        this.cityList = result;
      },

      // 根据公告类型查询
      clickTypeLabels(tag, i) {
        this.typeName = tag.condition;
      },
      // 公告类型点击重置
      typeConfirmCancel() {
        this.typeName = '';
        this.typeValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postBidding();
      },
      // 公告类型点击确定
      typeConfirmSure() {
        this.$refs.type.toggle(false);
        this.typeValue = this.typeName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postBidding();
      },

      // 根据发布日期查询
      clickDateLabels(tag, i) {
        this.dateName = tag.condition;
      },
      // 发布日期点击重置
      dateConfirmCancel() {
        this.dateName = '';
        this.dateValue = '';
        this.currentPage = 1;
        this.pageLoading = false;
        this.postBidding();
      },
      // 发布日期点击确定
      dateConfirmSure() {
        this.$refs.date.toggle(false);
        this.dateValue = this.dateName;
        this.currentPage = 1;
        this.pageLoading = false;
        this.postBidding();
      },

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

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

      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: 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