<template>
  <div class="home_wrapper">
    <!--  头部开始  -->
    <div class="header">
      <div class="header_left" @click="onClickLeft">
        <img src="../../../../static/images/agriculturalTrusteeship/return.png">
        <p>贷款需求</p>
      </div>
      <p class="header_right">
        <van-checkbox v-model="checked" checked-color="#ffffff" @change="checkChange">只显示有资金需求</van-checkbox>
      </p>
    </div>
    <!--  头部结束  -->

    <!--  内容开始  -->
    <div class="main">
      <van-tabs v-model="active" sticky animated>
        <van-tab :title="'服务组织（'+depositThirdNum+'）'">
          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="getList"
          >
            <!--           @load="onLoad"-->
            <div class="main_content_right_list" v-for="(item,index) in depositThirdList" :key="index" @click="$router.push({name:'agriculturalTrusteeshipShopOrganizationDetail',query:{id:item.id}})">
              <div class="main_tit">
                <i></i>
                <p>{{item.thirdName}}</p>
              </div>
              <div class="main_money">
                <p><span>￥</span>{{item.financeAmount}}</p>
                <p>查看详情 ></p>
              </div>
            </div>
          </van-list>

        </van-tab>
        <van-tab :title="'托管主体（'+stockBaseNum+'）'" >

          <van-list
            v-model="loading2"
            :finished="finished2"
            finished-text="没有更多了"
            @load="getStockBaseList"
          >
            <!--            @load="onLoad"-->
            <div class="main_content_right_list" v-for="(item,index) in stockBaseList" :key="item.bookId" @click="$router.push({name:'agriculturalTrusteeshipShopDepositDetail',query:{id:item.bookId}})">
              <div class="main_tit">
                <i></i>
                <p>{{item.economicName}}</p>
              </div>
              <div class="main_money">
                <p><span>￥</span>{{item.financeAmount}}</p>
                <p>查看详情 ></p>
              </div>
            </div>
          </van-list>

        </van-tab>
      </van-tabs>
    </div>
    <!--  内容结束  -->

  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import {loanDemandList} from "@/api/agriculturalTrusteeship";
  export default {
    name: "agriculturalTrusteeshipShopNeedsList",
    data() {
      return {
        active: 0,
        depositThirdNum: 0,
        stockBaseNum: 0,
        loading: false,
        finished: false,
        loading2: false,
        finished2: false,
        checked: false,
        depositThirdList: [],
        stockBaseList: [],
        query:{
          financialServiceId:Cookies.get('ACCESS-SESSION-ID'),
          pageNum:1,
          pageSize:'10',
          isFinance:'N'
        },
        query2:{
          financialServiceId:Cookies.get('ACCESS-SESSION-ID'),
          pageNum:1,
          pageSize:'10',
          isFinance:'N'
        },
      };
    },
    created() {

    },
    methods: {
      getList(){
        loanDemandList(this.query).then(response => {
          this.depositThirdNum = response.data.depositThirdList.length;
          this.stockBaseNum = response.data.stockBaseList.length;
          this.depositThirdList = response.data.depositThirdList;
          if(this.depositThirdList.length >= response.data.depositThirdList.length){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.query.pageNum += 1 ;
          }
        });
      },
      getStockBaseList(){
        loanDemandList(this.query2).then(response => {
          this.stockBaseList = response.data.stockBaseList;
          if(this.stockBaseList.length >= response.data.stockBaseList.length){
            this.finished2 = true;
            return;
          }else{
            this.loading2 = false;
            this.query2.pageNum += 1 ;
          }
        });
      },
      checkChange(e){
        console.log(e)
        if (e){
          this.query.isFinance = 'Y'
          this.query2.isFinance = 'Y'
          this.getList();
          this.getStockBaseList();
        }else{
          this.query.isFinance = 'N'
          this.query2.isFinance = 'N'
          this.getList();
          this.getStockBaseList();
        }
      }

    },
  }
</script>
<style scoped lang="scss">
.home_wrapper{
  background: #f9f9f9;
  height: 100vh;
  /*overflow: hidden;*/
}
  /*头部*/
  .header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
    padding: 2vh 4% 2vh;
    .header_left{
      display: flex;
      align-items: center;
      p{
        font-size: .4rem;
        color: #ffffff;
        line-height: 1;
        margin-left: 10PX;
      }
    }
    .header_right{
      font-size: .35rem;
      background: #334281;
      padding: 2PX 10PX;
      border-radius: 50PX;
      /deep/ .van-checkbox__icon--checked .van-icon{
        color: #334281;
      }
      /deep/ .van-checkbox__label{
        color: #ffffff;
      }
      /deep/ .van-checkbox__icon .van-icon{
        width: .9em;
        height: .9em;
        line-height: .9em;
      }
      /deep/ .van-icon-success::before{
        width: .9em;
        height: .9em;
      }
      /deep/ .van-checkbox__icon{
        height: auto;
      }
    }
  }

  .main_btn{
    display: flex;
    background: #ffffff;
    border-top-left-radius: 25PX;
    border-top-right-radius: 25PX;
    overflow: hidden;
    padding: 4vw 4% 0;
    justify-content: space-between;
    .btn_box_01{
      width: 48%;
      display: flex;
      justify-content: center;
      align-items: center;
      border: 1Px dashed #4E7FFF;
      color: #4E7FFF;
      font-size: .35rem;
      line-height: 15vw;
      border-radius: 10Px;
      p:first-child{
        font-weight: bold;
        margin-right: 5PX;
      }
    }
    .btn_box_02{
      width: 48%;
      display: flex;
      justify-content: center;
      align-items: center;
      background: rgba(78,127,255,0.17);
      color: #1E49BB;
      font-size: .35rem;
      line-height: 15vw;
      border-radius: 10Px;
      p{
        margin-left: 5PX;
      }
    }
  }

  .serviceName{
    display: flex;
    align-items: center;
    justify-content: space-between;
    span{
      background: #E8E8E8;
      padding: 0 8PX;
      border-radius: 5PX;
      color: #7A7A7A;
      margin-right: 5PX;
    }
    .active{
      background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
      color: #ffffff;
    }
  }

  .nav{
    background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
    padding-bottom: 15PX;
    .tt{
      font-size: .45rem;
      color: #334281;
    }
    .content{
      background: #ffffff;
      width: 92%;
      margin: 0 auto;
      box-shadow: 0px 0px 10PX rgba(0,0,0,0.1);
      border-radius: 25PX;
      padding: 1.5vh 4%;
    }
    /deep/ .van-cell{
      padding: 0;
      margin-bottom: 10PX;
      &:last-child{
        margin: 0;
      }
    }
  }

  /* 内容 */
  .main{
    background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
    /deep/ .van-tabs__nav{
      border-top-left-radius: 25PX;
      border-top-right-radius: 25PX;
      /*overflow: hidden;*/
      background: #f9f9f9;
    }
    /deep/ .van-tabs__line{
      background: #334281!important;
    }
    /deep/ .van-tab--active{
      color: #334281;
    }
    /deep/ .van-tabs__content{
      background: #f9f9f9;
      padding-top: 2vh;
    }
    .content{
      width: 92%;
      margin: 0 auto;
      margin-top: 2vh;
      .content_tt{
        font-size: .35rem;
      }
      .content_con{
        display: flex;
        justify-content: space-between;
        margin-top: 1.5vh;
        .content_con_left{
          display: flex;
          flex-direction:column;
          justify-content: space-between;
          p{
            font-size: .35rem;
            padding-left: 18PX;
            &:nth-child(1){
              background: url("../../../../static/images/agriculturalTrusteeship/insurance/insurance_list_project.png") no-repeat left center;
            }
            &:nth-child(2){
              background: url("../../../../static/images/agriculturalTrusteeship/insurance/insurance_list_name.png") no-repeat left center;
            }
            &:nth-child(3){
              background: url("../../../../static/images/agriculturalTrusteeship/insurance/insurance_list_iphone.png") no-repeat left center;
            }
          }
        }
        .content_con_right{
          display: flex;
          justify-content: end;
          align-items: center;
          img{
            border-radius: 10PX;
            width: 40%;
            margin-left: 5%;
            box-shadow: 0px 5PX 10PX rgba(0,0,0,0.2);
            &:last-child{
              width: auto;
              box-shadow: none;
            }
          }
        }
      }
    }
    .main_content_right_list{
      margin: 0 auto;
      margin-bottom: 2vh;
      width: 92%;
      background: #ffffff;
      padding: 15PX 3%;
      border-radius: 10Px;
      box-shadow: 0px 5PX 10PX rgba(0,0,0,0.1);
      .main_tit{
        font-size: .38rem;
        display: flex;
        align-items: center;
        i{
          display: block;
          width: 16PX;
          height: 16PX;
          margin-right: 5PX;
          flex-shrink: 0;
          background: url("../../../../static/images/agriculturalTrusteeship/insurance/shop_needs_icon.png");
        }
        p{
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
          word-break: break-all;
          overflow: hidden;
        }
      }
      .main_money{
        display: flex;
        justify-content: space-between;
        margin-top: 5PX;
        p{
          &:nth-child(1){
            color: #FF5E00;
            font-size: .4rem;
            span{
              font-size: .3rem;
            }
          }
          &:nth-child(2){
            color: #8B8B8B;
            font-size: .35rem;
          }
        }
      }
    }
  }
</style>
