<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" @click="showDeptId = true">{{deptName}}</p>
      <van-popup v-model="showDeptId" position="bottom" get-container="body">
        <van-cascader
          v-model="villageValue"
          title="请选择"
          :options="deptOptions"
          @close="showDeptId = false"
          @change="onConfirmDept"
          active-color="#1989fa"
          :field-names="hcAreaInfoFieldName"
        />
      </van-popup>
    </div>
    <!--  头部结束  -->

    <!--  内容开始  -->
    <div class="main">
      <van-tabs v-model="active" sticky animated>
        <van-tab title="服务组织">
          <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="没有更多了"
            :immediate-check="false"
            @load="getServiceList"
          >
            <div class="content" v-for="(item,index) in serviceList" :key="index" @click="$router.push({name:'agriculturalTrusteeshipSocietyProjectList',query:{id:item.id,entityName:item.entityName}})">

              <div class="boxParents" v-if="item.modelSocietyType != '非'">
                <p>{{item.modelSocietyType}}</p>
                <div class='box'></div>
                <div class='box2'></div>
                <div class='box3'></div>
              </div>

              <div class="tt_box">
                <p class="content_tt">{{item.entityName}}</p>
                <div class="tab_box">
                  <div class="tab_left">
                    <p>产品 <span>{{item.supplyDemands.length}}</span></p>
                    <p>订单 <span>{{item.orderNum}}</span></p>
                  </div>
                  <div class="tab_right">
                    <p>{{item.industryClassificationType}}</p>
                  </div>
                </div>
              </div>

              <div class="content_con">
                <div class="content_con_left">
                  <p>{{item.supplyDemands.length}}个产品</p>
                  <p>{{item.principalName}}</p>
                  <p>{{item.tal}}</p>
                </div>
                <div class="content_con_right">
                  <img :src="itemChild" v-for="(itemChild,indexChild) in item.masterMap2" v-if="indexChild < 2" :key="indexChild" style="width: 22vw;height: 22vw;">

                  <img v-if="!item.masterMap2 || item.masterMap2.length < 2" src="../../../../static/images/agriculturalTrusteeship/zwtp.png" style="width: 22vw;height: 22vw;">
                  <img v-if="!item.masterMap2 || item.masterMap2.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="服务项目">
          <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>

          <div class="main_content">
            <div class="main_content_left">
              <van-sidebar v-model="activeKey" @change="onChangeIn">
                <van-sidebar-item title="全套服务" />
                <van-sidebar-item v-for="(item,index) in productList" :key="index" :title="item.dictName" />
              </van-sidebar>
            </div>
            <div class="main_content_right">
              <div class="main_content_right_header">
                <p class="main_content_right_header_tit">{{main_content_right_header_tit}}</p>
                <van-tabs v-model="activePs" animated @change="orderByChange">
                  <van-tab title="评分排序"></van-tab>
                  <van-tab title="销量排序"></van-tab>
                </van-tabs>
              </div>
              <div class="main_content_right_nav" v-if="activeKey!=0">
                <p v-for="(item,index) in productListChildren" :key="index">{{item.dictName}}</p>
              </div>

              <van-list
                v-model="loading"
                :finished="finished"
                finished-text="没有更多了"
                :immediate-check="false"
                @load="getList"
              >
                <!--            @load="onLoad" agriculturalTrusteeshipSocializationProjectDetail-->
                <div class="main_content_right_list" v-for="(item,index) in supplyDemandListYes" :key="index" @click="$router.push({name:'agriculturalTrusteeshipSocietyProjectDetail',query:{id:item.id}})">
                  <img v-if="item.supplyMasterMap" :src="item.supplyMasterMap" style="width: 25vw;height: 25vw;">
                  <img v-else src="../../../../static/images/agriculturalTrusteeship/zwtp.png" style="width: 25vw;height: 25vw;">
                  <div class="main_content_right_list_content">
                    <p class="tt">{{item.supplyDemandName}}</p>
                    <div class="tab">
                      <p>￥<span>{{item.unitPrice}}</span>.00/{{item.unit}}</p>
                      <p><span>销 {{item.orderNum}}</span><span>分 {{item.orderScore}}</span></p>
                    </div>
                    <p class="name">{{item.entityName}}</p>
                  </div>
                </div>
              </van-list>

            </div>
          </div>

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

  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import {supplyDemandList, detailList, productTypes, treeselect} from "@/api/agriculturalTrusteeship";
  export default {
    name: "agriculturalTrusteeshipInsuranceList",
    data() {
      return {
        activeKey: 0,
        active: 0,
        activePs: 0,
        loading: false,
        finished: false,
        loading1: false,
        finished1: false,
        productList:[],
        supplyDemandListYes:[],
        supplyDemandList:[],
        serviceList:[],
        productListYes:[],
        financialTypeOptions:[],
        modelSocietyTypeOptions:[],
        productListChildren:[],
        main_content_right_header_tit:'全套服务',
        query:{
          entityId:'',
          serviceDeptId:'',
          entityName:'',
          productType:''
        },
        query2:{
          supplyDemandName:'',
          serviceDeptId:'',
          orderByColumn:'order_score'
        },
        searchServiceInput:'',
        searchInput:'',
        deptOptions:[],
        deptName:'',
        showDeptId:false,
        villageValue : '',
        hcAreaInfoFieldName: {
          text: "label",
          value: "value",
          children: "children",
        },
      };
    },
    created() {
      this.getDicts("Industrial_classification_type").then(response => {
        this.financialTypeOptions = response.data;
      });
      this.getDicts("model_society_type").then(response => {
        this.modelSocietyTypeOptions = response.data;
      });
      let query = {
        parentId : 0
      }
      productTypes(query).then(response => {
        this.productList = response.data;
      });

      treeselect().then(res=>{
        if (res.code == 200) {
          this.deptOptions = res.data;
          this.query.serviceDeptId = res.data[0].value;
          this.query2.serviceDeptId = res.data[0].value;
          this.deptName = res.data[0].label;
          this.serviceList = [];
          this.supplyDemandListYes = [];
          this.supplyDemandList = [];
          this.getServiceList();
          this.getList();
        }
      })
    },
    methods: {
      getServiceList(){
        detailList(this.query).then(response => {
          response.rows.map(res=>{
            res.industryClassificationType = this.selectDictLabel(this.financialTypeOptions, res.industryClassificationType);
            var modelSocietyType = this.selectDictLabel(this.modelSocietyTypeOptions, res.modelSocietyType);
            res.modelSocietyType = modelSocietyType.substr(0,modelSocietyType.length-3)
            if (res.masterMap){
              let supplyMasterMap = res.masterMap.split( "," )
              res.masterMap2 = []
              supplyMasterMap.map(rr=>{
                res.masterMap2.push('/api'+rr)
              })
            }
            this.serviceList.push(res);
          })
          console.log(this.serviceList)
          if(this.serviceList.length >= response.total){
            this.finished1 = true;
            return;
          }else{
            this.loading1 = false;
            this.query.pageNum += 1 ;
          }
        });
      },
      getList(){
        supplyDemandList(this.query2).then(response => {
          response.rows.map(res=>{
            if(res.publishStatus == 3){
              if (res.supplyMasterMap){
                let supplyMasterMap = res.supplyMasterMap.split( "," )
                res.supplyMasterMap = '/api'+supplyMasterMap[0]
              }
              this.supplyDemandListYes.push(res);
            }
            this.supplyDemandList.push(res);
          })
          if(this.supplyDemandList.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.supplyDemandListYes = [];
        this.query2.supplyDemandName = 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();
      },
      //选择案件属地
      onConfirmDept({ selectedOptions }){
        this.query.serviceDeptId = selectedOptions[selectedOptions.length-1].value;
        this.query2.serviceDeptId = selectedOptions[selectedOptions.length-1].value;
        this.deptName = selectedOptions[selectedOptions.length-1].label;
        // this.showDeptId = false
        this.supplyDemandListYes = [];
        this.serviceList = [];
        this.getServiceList();
        this.getList();
      },
    },
  }
</script>
<style scoped lang="scss">
.home_wrapper{
  height: 100vh;
  background: #ffffff;
}
.boxParents{
  position: absolute;
  top: -21PX;
  transform: rotateZ(45deg);
  right: -58PX;
  p{
    position: absolute;
    top: 37PX;
    left: 54PX;
    color: #fff;
    z-index: 9;
  }
}
.box,.box3
{
  width:0px;
  height:0px;
  display:inline-block;
  border-top:50px solid rgba(0,0,0,0);
  border-right:50px solid  rgba(0,0,0,0);
  border-bottom:50px solid #FF5E00;
  border-left:50px solid  rgba(0,0,0,0);
  margin-bottom:10px;
}
.box2
{
  width:25PX;
  height:25PX;
  background-color:#FF5E00;
  display:inline-block;
}
.box{
  transform: translate(56px,10px);
}
.box3{
  transform: translate(-54px,10px);
}
  /*头部*/
  .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;
    }
    /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%;
      position: relative;
      .content_tt{
        font-size: .35rem;
        margin-bottom: 1vh;
      }
      .tt_box{
        border-bottom: 1PX solid #D1D8EB;
        padding-bottom: 1.5vh;
        .tab_box{
          display: flex;
          justify-content: space-between;
          align-items: center;
          .tab_left{
            display: flex;
            p{
              &:nth-child(1){
                border-right: 1px solid;
                padding-right: 8PX;
                margin-right: 8PX;
              }
              span{
                color: #2B7EEC;
              }
              line-height: 1;
            }

          }
          .tab_right{
            display: flex;
            p{
              background: #F3F6FE;
              padding: 5PX 10PX;
              color: #497CE8;
              line-height: 1;
              border-radius: 5PX;
              margin-left: 10PX;
            }
          }
        }
      }
      .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{
      display: flex;
      width: 96%;
      margin-top: 2vh;
      height: 79.7vh;
      overflow: hidden;
      .van-sidebar-item{
        text-align: center;
      }
      /deep/ .van-sidebar-item--select::before{
        display: none;
      }
      .main_content_left{
        border-top-right-radius: 15PX;
        height: 100%;
        overflow-y: scroll;
      }
      .main_content_right{
        flex: 1;
        padding-left: 4%;
        height: 100%;
        overflow-y: scroll;
        .main_content_right_header{
          display: flex;
          justify-content: space-between;
          align-items: center;
          /deep/ .van-tabs--line .van-tabs__wrap{
            border-radius: 100rem;
            height: 25PX;
          }
          /deep/ .van-tab{
            z-index: 1;
            color: #8F8F8F;
            padding: 5PX 10PX;
          }
          /deep/ .van-tab--active{
            color: #334281;
          }
          /deep/ .van-tabs__nav{
            background: #ECECEC;
            border-radius: 100rem;
          }
          /deep/ .van-tabs__nav--line{
            padding: 0;
          }
          /deep/ .van-tabs__line{
            background: #D6D9E6;
            border-radius: 100rem;
            z-index: 0;
            width: 50%;
            height: 100%;
            bottom: 0;
          }
          /deep/ .van-tabs__content{
            padding: 0;
          }
          .main_content_right_header_tit{
            font-size: .4rem;
            color: #1A1D4A;
          }
        }
        .main_content_right_nav{
          display: flex;
          justify-content: space-between;
          margin-top: 2vh;
          p{
            padding: 5PX 10PX;
            background: #F5F5F5;
            color: #8F8F8F;
            border-radius: 4PX;
          }
        }
        .main_content_right_list{
          display: flex;
          margin-top: 2vh;
          width: 100%;
          img{
            border-radius: 15PX;
            margin-right: 4%;
            width: auto;
          }
          .main_content_right_list_content{
            display: flex;
            flex-direction:column;
            justify-content: space-between;
            flex: 1;
            .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: 14PX;
            }
          }
        }
      }
    }
    .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>
