<template>
  <div class="home_wrapper">
    <!--  头部开始  -->
    <div class="header">
      <div class="header_left" @click="onClickLeft">
        <img src="../../../../static/images/agriculturalTrusteeship/return.png">
        <p>{{tt}}服务</p>
      </div>
      <p class="header_right">河东河西村</p>
    </div>
    <!--  头部结束  -->

    <!--  内容开始  -->
    <div class="main">
      <van-tabs v-model="active" sticky animated>
        <van-tab :title="tt+'公司'">
          <div class="search">
            <img src="../../../../static/images/agriculturalTrusteeship/index/search_icon_01.png" />
            <input type="text" v-model="searchServiceInput" placeholder="输入需求进行搜索" />
            <img src="../../../../static/images/agriculturalTrusteeship/index/search_icon_02.png" @click="goSearchService" />
          </div>

          <van-list
            v-model="loading1"
            :finished="finished1"
            finished-text="没有更多了"
            @load="getServiceList"
          >
            <div class="content" v-for="(item,index) in serviceList" :key="index" @click="$router.push({name:'agriculturalTrusteeshipInsuranceProjectList',query:{id:item.id,financialName:item.financialName}})">
              <p class="content_tt">{{item.financialName}}</p>
              <div class="content_con">
                <div class="content_con_left">
                  <p>{{item.products.length}}个产品</p>
                  <p>{{item.linker}}</p>
                  <p>{{item.phone}}</p>
                </div>
                <div class="content_con_right">
                  <img :src="itemChild" v-for="(itemChild,indexChild) in item.mainImg2" v-if="indexChild < 2" :key="indexChild" style="width: 22vw;height: 22vw;">

                  <img v-if="!item.mainImg2 || item.mainImg2.length < 2" src="../../../../static/images/agriculturalTrusteeship/zwtp.png" style="width: 22vw;height: 22vw;">
                  <img v-if="!item.mainImg2 || item.mainImg2.length < 1" src="../../../../static/images/agriculturalTrusteeship/zwtp.png" style="width: 22vw;height: 22vw;">

                  <img src="../../../../static/images/agriculturalTrusteeship/insurance/insurance_go.png">
                </div>
              </div>
            </div>
          </van-list>

        </van-tab>
        <van-tab :title="tt+'产品'">
          <div class="search">
            <img src="../../../../static/images/agriculturalTrusteeship/index/search_icon_01.png" />
            <input type="text" v-model="searchInput" placeholder="输入需求进行搜索" />
            <img src="../../../../static/images/agriculturalTrusteeship/index/search_icon_02.png" @click="goSearch" />
          </div>

          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="getList"
          >
            <!--            @load="onLoad"-->
            <div class="main_content_right_list" v-for="(item,index) in productListYes" :key="index" @click="$router.push({name:'agriculturalTrusteeshipSocietyProjectDetail',query:{id:item.id}})">
              <img v-if="item.mainImg" :src="item.mainImg" style="width: 18vw;height: 18vw;">
              <img v-else src="../../../../static/images/agriculturalTrusteeship/zwtp.png" style="width: 18vw;height: 18vw;">
              <div class="main_content_right_list_content">
                <p class="tt">{{item.productName}}</p>
<!--                <div class="tab">-->
<!--                  <p>￥<span>66</span>.00/亩</p>-->
<!--                  <p><span>销 600</span><span>分 4.7</span></p>-->
<!--                </div>-->
                <p class="name">{{item.financialName}}</p>
              </div>
            </div>
          </van-list>

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

  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import {productList, productTypes, serviceList} from "@/api/agriculturalTrusteeship";
  export default {
    name: "agriculturalTrusteeshipInsuranceList",
    data() {
      return {
        activeKey: 0,
        active: 0,
        loading: false,
        finished: false,
        loading1: false,
        finished1: false,
        productListNo:[],
        productList:[],
        supplyDemandListYes:[],
        supplyDemandList:[],
        serviceList:[],
        productListYes:[],
        financialTypeOptions:[],
        productListChildren:[],
        main_content_right_header_tit:'全套服务',
        query:{
          entityId:'',
          entityName:'',
          productType:''
        },
        query2:{
          productName :'',
          orderByColumn:'order_score'
        },
        searchServiceInput:'',
        searchInput:'',
        tt:''
      };
    },
    created() {
      this.query.financialType = this.$route.query.type;
      this.query2.financialType = this.$route.query.type;
      if (this.$route.query.type == 3){this.tt = '农担'}
      if (this.$route.query.type == 2){this.tt = '保险'}
      if (this.$route.query.type == 1){this.tt = '贷款'}
    },
    methods: {
      getServiceList(){
        serviceList(this.query).then(response => {
          response.rows.map(res=>{
            // res.industryClassificationType = this.selectDictLabel(this.financialTypeOptions, res.industryClassificationType);
            if (res.mainImg){
              let supplyMasterMap = res.mainImg.split( "," )
              res.mainImg2 = []
              supplyMasterMap.map(rr=>{
                res.mainImg2.push('/api'+rr)
              })
            }
            this.serviceList.push(res);
          })
          if(this.serviceList.length >= response.total){
            this.finished1 = true;
            return;
          }else{
            this.loading1 = false;
            this.query.pageNum += 1 ;
          }
        });
      },
      getList(){
        productList(this.query2).then(response => {
          response.rows.map(res=>{
            if(res.sysYesNo == 'Y'){
              if (res.mainImg){
                let supplyMasterMap = res.mainImg.split( "," )
                res.mainImg = '/api'+supplyMasterMap[0]
              }
              this.productListYes.push(res);
            }
            if(res.sysYesNo == 'N'){
              this.productListNo.push(res);
            }
            this.productList.push(res);
          })
          if(this.productList.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.query.pageNum += 1 ;
          }
        });
      },
      onChangeIn(val){
        this.supplyDemandListYes = [];
        if (val == 0){
          this.main_content_right_header_tit = '全套服务';
          this.query.productType = '';
          this.getList();
          return;
        }
        this.query.productType = this.productList[val-1].id;
        let parentId = this.productList[val-1].id;
        this.main_content_right_header_tit = this.productList[val-1].dictName
        let query1 = {
          parentId : parentId
        }
        productTypes(query1).then(response => {
          this.productListChildren = response.data;
          this.getList();
        });
      },
      goSearchService(){
        this.serviceList = [];
        this.query.entityName = this.searchServiceInput;
        this.getServiceList();
      },
      goSearch(){
        this.productListYes = [];
        this.query2.productName = this.searchInput;
        this.getList();
      },
      orderByChange(){
        if (this.activePs == 0){
          this.query2.orderByColumn = 'order_score'
        }
        if (this.activePs == 1){
          this.query2.orderByColumn = 'order_num'
        }
        this.supplyDemandListYes = [];
        this.getList();
      }
    },
  }
</script>
<style scoped lang="scss">
.home_wrapper{
  height: 100vh;
  background: #ffffff;
}
  /*头部*/
  .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: #ffffff url("../../../../static/images/agriculturalTrusteeship/address.png") no-repeat 10PX center;
      padding: 2PX 15PX 2PX 25PX;
      border-radius: 50PX;
    }
  }

  /* 内容 */
  .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;
    }
    /deep/ .van-tabs__line{
      background: #334281!important;
    }
    /deep/ .van-tab--active{
      color: #334281;
    }
    /deep/ .van-tabs__content{
      background: #ffffff;
      padding-top: 2vh;
    }
    .search{
       display: flex;
       justify-content: space-between;
       align-items: center;
       width: 92%;
       margin: 0PX auto;
       border: 1px solid #6E93F3;
       padding: 1PX 1PX 1PX 12PX ;
       border-radius: 50PX;
       input{
         flex: 1;
         background: transparent;
         margin-left: 10PX;
       }
    }
    .content{
      width: 92%;
      margin: 0 auto;
      box-shadow: 0px 0px 10PX rgba(0,0,0,0.1);
      border-radius: 10PX;
      margin-top: 2vh;
      padding: 1.5vh 4%;
      .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{
      display: flex;
      margin: 0 auto;
      margin-top: 2vh;
      width: 92%;
      img{
        border-radius: 15PX;
        margin-right: 4%;
        width: 20%;
      }
      .main_content_right_list_content{
        display: flex;
        flex-direction:column;
        justify-content: space-between;
        .tt{
          color: #333333;
          font-size: .35rem;
        }
        .tab{
          display: flex;
          justify-content: space-between;
          p{
            &:nth-child(1){
              flex: 1;
              color: #FF5E00;
              span{
                font-size: .4rem;
              }
            }
            &:nth-child(2){
              flex: 1;
              span{
                width: 50%;
                display: inline-block;
                text-align: center;
                padding: 2PX 2PX;
                &:nth-child(1){
                  color: #497CE8;
                  background: #E2E9FD;
                  border-top-left-radius: 10PX;
                }
                &:nth-child(2){
                  color: #ffffff;
                  background-image: linear-gradient(to right , #5D87FA , #5FD5F5);
                  border-bottom-right-radius: 10PX;
                }
              }
            }
          }
        }
        .name{
          color: #8F8F8F;
          background: url("../../../../static/images/agriculturalTrusteeship/index/name_icon.png") no-repeat left center;
          padding-left: 18PX;
        }
      }
    }
  }
</style>
