<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>
      <img src="../../../../static/images/agriculturalTrusteeship/insurance/head_icon.png" @click="show=true,mapClickLoading()">
    </div>
    <!--  头部结束  -->

    <!--  内容开始  -->
    <div class="main">
      <div class="search">
        <img src="../../../../static/images/agriculturalTrusteeship/index/search_icon_01.png" />
        <input type="text" placeholder="输入需求进行搜索" v-model="searchInput" />
        <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="active" 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="没有更多了"
            @load="getList"
          >
            <!--            @load="onLoad"-->
            <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: 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.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">张三社会服务旗舰店</p>-->
              </div>
            </div>
          </van-list>

        </div>
      </div>
    </div>
    <!--  内容结束  -->
    <van-popup v-model="show" round closeable close-icon="close" style="width: 90%;">
      <div class="tt_box">
        <p class="content_tt">{{entityForm.entityName}}</p>
        <div class="tab_box">
          <div class="tab_left">
            <p>产品 <span>{{entityForm.supplyDemands==null?'0':entityForm.supplyDemands.length}}</span></p>
            <p>订单 <span>{{entityForm.orderNum}}</span></p>
          </div>
          <div class="tab_right">
            <p>{{entityForm.industryClassificationType}}</p>
          </div>
        </div>
      </div>
      <van-field readonly label="主体名称" v-model="entityForm.entityName" :border="false" input-align="right" value="内容" />
      <van-field readonly label="主体类别" v-model="entityForm.statisticsTypeId" :border="false" input-align="right" value="内容" />
      <van-field readonly label="生产种类" v-model="entityForm.industryClassificationType" :border="false" input-align="right" value="内容" />
      <van-field readonly label="成立时间" v-model="entityForm.registerTime" :border="false" input-align="right" value="内容" />
      <van-field readonly label="示范类型" v-model="entityForm.modelSocietyType" :border="false" input-align="right" value="内容" />
      <van-field readonly label="负责人" v-model="entityForm.principalName" :border="false" input-align="right" value="内容" />
      <van-field readonly label="联系电话" v-model="entityForm.tal" :border="false" input-align="right" value="内容" />
      <van-field readonly label="主体地址" v-model="entityForm.entityAddress" :border="false" input-align="right" value="内容" />
      <div style="padding: 0 4% 2vh;">
        <van-uploader v-model="entityForm.masterMapList" :show-upload="false" :deletable="false" />
      </div>
      <div class="main_box" v-show="entityForm.theGeom">
        <MapGisTag ref="clickLoading" :showBtn="false" :message="entityForm.theGeom"></MapGisTag>
      </div>
    </van-popup>
  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import {entityGet, productTypes, serviceGet, supplyDemandList} from "@/api/agriculturalTrusteeship";
  import MapGisTag from "@/components/Map/MapGisTagDTG";
  export default {
    name: "agriculturalTrusteeshipInsuranceList",
    components: {
      MapGisTag
    },
    data() {
      return {
        show:false,
        activeKey: 0,
        active: 0,
        loading: false,
        finished: false,
        productList:[],
        supplyDemandListYes:[],
        supplyDemandList:[],
        serviceList:[],
        productListYes:[],
        financialTypeOptions:[],
        productListChildren:[],
        main_content_right_header_tit:'全套服务',
        query:{
          entityId:'',
          supplyDemandName:'',
          productType:''
        },
        tt:'',
        searchInput:'',
        entityForm:{}
      };
    },
    created() {
      this.query.entityId = this.$route.query.id;
      this.tt = this.$route.query.entityName
      this.getDicts("newBusinessEntity_statistics_project").then(response => {
        this.statisticsTypeIdOptions = response.data;
      });
      this.getDicts("model_society_type").then(response => {
        this.modelSocietyTypeOptions = response.data;
      });
      this.getDicts("Industrial_classification_type").then(response => {
        this.financialTypeOptions = response.data;
        this.industryClassificationTypeOptions = response.data;
      });
      let query = {
        parentId : 0
      }
      productTypes(query).then(response => {
        this.productList = response.data;
      });
      this.getUser();
    },
    methods: {
      //每个查看修改，新增  方法下引用下面方法
      mapClickLoading(){
        setTimeout(() => {
          this.$refs.clickLoading.pointPaceCountryDarw();
        }, 500);
      },
      getUser(){
        entityGet(this.$route.query.id).then(res=>{
          res.data.statisticsTypeId = this.selectDictLabel(this.statisticsTypeIdOptions, res.data.statisticsTypeId);
          res.data.industryClassificationType = this.selectDictLabel(this.industryClassificationTypeOptions, res.data.industryClassificationType);
          res.data.modelSocietyType = this.selectDictLabel(this.modelSocietyTypeOptions, res.data.modelSocietyType);

          if (res.data.masterMap){
            res.data.masterMapList = [];
            var attachement = res.data.masterMap.split( "," );
            this.mainImgArrEntity = res.data.masterMap.split( "," );
            attachement.forEach(responseAttach=>{
              res.data.masterMapList.push({
                url:'/api' + responseAttach,
                isImage: true
              });
            })
          }
          this.entityForm = res.data;
          // this.mapClickLoading();
        })
      },
      getList(){
        supplyDemandList(this.query).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();
        });
      },

      goSearch(){
        this.supplyDemandListYes = [];
        this.query.supplyDemandName = this.searchInput;
        this.getList();
      },
      orderByChange(){
        console.log(this.active)
        if (this.active == 0){
          this.query.orderByColumn = 'order_score'
        }
        if (this.active == 1){
          this.query.orderByColumn = 'order_num'
        }
        this.supplyDemandListYes = [];
        this.getList();
      }
    },
  }
</script>
<style scoped lang="scss">
.home_wrapper{
  background: url("../../../../static/images/agriculturalTrusteeship/insurance/society_list_head.png") no-repeat;
}
.tt_box{
  border-bottom: 1PX solid #D1D8EB;
  padding: 2vh;
  .content_tt{
    font-size: .4rem;
    margin-bottom: 1.5vh;
    color: #334281;
  }
  .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;
      }
    }
  }
}
.main_box{
  width: 92%;
  margin: 2vh auto;
  border-radius: 10PX;
  overflow: hidden;
  background-color: #FFF;
  /deep/ .van-cell{
    padding: 0;
    margin-bottom: 10PX;
    &:last-child{
      margin-bottom: 0;
    }
  }
}
  /*头部*/
  .header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    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: #ffffff;
    padding-top: 2vh;
    border-top-left-radius: 25PX;
    border-top-right-radius: 25PX;

    .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;
       }
    }
    /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;
    }
    /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;
    }
    .main_content{
      display: flex;
      width: 96%;
      margin-top: 2vh;
      height: 85.5vh;
      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;
          .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;
          img{
            border-radius: 15PX;
            margin-right: 4%;
            height: 8vh;
          }
          .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){
                  span{
                    display: inline-block;
                    text-align: center;
                    padding: 2PX 5PX;
                    &: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;
            }
          }
        }
      }
    }
  }
</style>
