<template>
  <div class="home_wrapper">
    <div id="topMain" class="topMain">
      <!--  头部开始  -->
      <div class="header">
  <!--      <img :src="avatar">-->
        <img v-if="avatar" :src="avatar" style="width: 50px;height: 50px;">
        <img v-else src="../../../../static/images/agriculturalTrusteeship/index/header.png" style="width: 50px;height: 50px;">
        <div class="header_box" @click="$router.push({name:'agriculturalTrusteeshipLogin'})">
          <p>{{nickName}}<span>{{phonenumber}}</span><img src="../../../../static/images/agriculturalTrusteeship/buyer/buyer_icon_01.png" alt=""></p>
          <p>{{allDeptName}}</p>
        </div>
      </div>
      <!--  头部结束  -->

      <!--  导航开始  -->
      <div class="nav">
        <van-grid :column-num="4" :border="false">
          <van-grid-item :to="{name:'agriculturalTrusteeshipSocietyList'}">
            <img src="../../../../static/images/agriculturalTrusteeship/index/nav_01.png"/>
            <p>社会化</p>
          </van-grid-item>
          <van-grid-item :to="{name:'agriculturalTrusteeshipInsuranceList',query:{type:3}}">
            <img src="../../../../static/images/agriculturalTrusteeship/index/nav_02.png"/>
            <p>农担</p>
          </van-grid-item>
          <van-grid-item :to="{name:'agriculturalTrusteeshipInsuranceList',query:{type:1}}">
            <img src="../../../../static/images/agriculturalTrusteeship/index/nav_03.png"/>
            <p>贷款</p>
          </van-grid-item>
          <van-grid-item :to="{name:'agriculturalTrusteeshipInsuranceList',query:{type:2}}">
            <img src="../../../../static/images/agriculturalTrusteeship/index/nav_04.png"/>
            <p>保险</p>
          </van-grid-item>
        </van-grid>

        <div class="nav_notice_box">
          <van-notice-bar left-icon="../../../../static/images/agriculturalTrusteeship/index/notice_icon.png" mode="link" :scrollable="false" background="#E2E9FD" color="#334281">
            <van-swipe
              vertical
              class="notice-swipe"
              :autoplay="3000"
              :show-indicators="false"
            >
              <van-swipe-item>12.0版本上线啦！点击查看更改内容~</van-swipe-item>
              <van-swipe-item>12.1版本上线啦！点击查看更改内容~</van-swipe-item>
              <van-swipe-item>12.2版本上线啦！点击查看更改内容~</van-swipe-item>
            </van-swipe>
          </van-notice-bar>
        </div>
      </div>
      <!--  导航结束  -->
    </div>
    <!--  内容开始  -->
    <div class="main">
      <div class="main_header">
        <p>社会化服务产品</p>
        <p>河东河西村</p>
      </div>
      <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="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"  @click="$router.push({name:'agriculturalTrusteeshipPlaceOrder'})"-->
            <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">
              <img v-else src="../../../../static/images/agriculturalTrusteeship/zwtp.png">
              <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>

    </div>
    <!--  内容结束  -->

    <img src="../../../../static/images/agriculturalTrusteeship/index/index_btn_icon_01.png" class="pc" @click="openMain"/>

    <buyer></buyer>
  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import buyer from "@/components/common/buyer_footer";
  import {productTypes, supplyDemandList} from "@/api/agriculturalTrusteeship";
  import {getInfo} from "@/api/login";
  import request from "@/utils/request";
  export default {
    name: "agriculturalTrusteeshipBuyIndex",
    components: {
      buyer,
    },
    data() {
      return {
        activeKey: 0,
        active: 0,
        loading: false,
        finished: false,
        supplyDemandListYes:[],
        supplyDemandList:[],
        productListChildren:[],
        productList:[],
        main_content_right_header_tit:'全套服务',
        query:{
          entityId:Cookies.get('ACCESS-SESSION-ID'),
          productType:'',
          supplyDemandName:''
        },
        nickName:'',
        allDeptName:'',
        userId:'',
        avatar:'',
        phonenumber:'',
        searchInput:'',
      };
    },
    created() {
      getInfo().then(response => {
        this.nickName = response.user.nickName
        this.allDeptName = response.user.allDeptName
        this.userId = response.user.userId
        this.phonenumber = response.user.phonenumber
        this.avatar = location.protocol+"//"+location.host+request.defaults.baseURL+response.user.avatar
      });
      let query = {
        parentId : 0
      }
      productTypes(query).then(response => {
        this.productList = response.data;
      });
    },
    methods: {
      getList(){
        supplyDemandList(this.query).then(response => {
          response.rows.map(res=>{
            if(res.publishStatus == 3){
              // console.log(res.supplyMasterMap.split( "," ))
              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();
      },

      openMain(){
        $('#topMain').attr('none');
      }
    },
  }
</script>
<style scoped lang="scss">
.home_wrapper{

}
  /*头部*/
  .header{
    display: flex;
    align-items: center;
    background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
    padding: 4vh 4% 2vh;
    img{
      border-radius: 100%;
    }
    .header_box{
      margin-left: 4%;
      flex: 1;
      p{
        &:nth-child(1){
          color: #ffffff;
          font-size: .45rem;
          display: flex;
          align-items: center;
          span{
            background: rgba(255,255,255,0.8) url("../../../../static/images/agriculturalTrusteeship/socialization/user_icon_07.png") 10PX center no-repeat;
            background-size: 12PX;
            color: #1E67FF;
            font-size: 0.35rem;
            padding: 0 8PX 0 25PX;
            border-radius: 5PX;
            margin-left: 10PX;
          }
          img{
            margin-left: auto;
          }
        }
        &:nth-child(2){
          color: #E5E5E5;
          margin-top: .5vh;
        }
      }
    }
  }

  /*导航栏目*/
  .nav{
    background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
    .van-grid{
      border-top-left-radius: 25PX;
      border-top-right-radius: 25PX;
      overflow: hidden;
    }
    .nav_notice_box{
      background: #ffffff;
      padding:.5vh 0 1vh;
    }
    /deep/ .van-notice-bar{
      width: 94%;
      margin: 0 auto;
      border-radius: 5PX;
      .notice-swipe {
        height: 40px;
        line-height: 42px;
      }
    }
  }

  /*内容*/
  .main{
    background: #ffffff;
    .main_header{
      display: flex;
      padding: 0 4% 1vh;
      justify-content: space-between;
      align-items: center;
      p{
        color: #334281;
        &:nth-child(1){
          font-size: .4rem;
        }
        &:nth-child(2){
          font-size: .35rem;
          background: url("../../../../static/images/agriculturalTrusteeship/index/address_icon.png") no-repeat left center;
          padding: 5PX 0 5PX 22PX;

        }
      }
    }
    .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: 56.8vh;
      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;
        /deep/ .van-list{
          padding-bottom: 10vh;
        }
        .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%;
            width: 25vw;
            height: 25vw;
          }
          .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;
            }
          }
        }
      }
    }
  }

  /*飘窗*/
  .pc{
    position: absolute;
    bottom: 10vh;
    right: 0;
  }
</style>
