<template>
  <div class="home_wrapper">
    <!--  头部开始  -->
    <div class="header">
      <div class="header_left" @click="onClickLeft">
        <p>{{entityName}}</p>
      </div>
      <p class="header_right">
        <img src="../../../../static/images/agriculturalTrusteeship/socialization/socialization_icon_photo.png" />
      </p>
    </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" 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="activePc" 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 :class="{'active':query.productType == item.id}" @click="tabChange(item.id)" 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">
                    <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" @click="$router.push({name:'agriculturalTrusteeshipSocializationProjectDetail',query:{id:item.id}})">{{item.supplyDemandName}}</p>
                      <div class="tab" @click="$router.push({name:'agriculturalTrusteeshipSocializationProjectDetail',query:{id:item.id}})">
                        <p>￥<span>{{item.unitPrice}}</span>/{{item.unit}}</p>
                        <p><span>销{{item.orderNum}}</span><span>分{{item.orderScore}}</span></p>
                      </div>
                      <div class="btn">
                        <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_02.png" @click="productOut(item.id)" />
                        <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_01.png" @click="$router.push({name:'agriculturalTrusteeshipSocializationProjectEdit',query:{id:item.id}})" />
                      </div>
                    </div>
                  </div>
                </van-list>
              </div>
            </div>
        </van-tab>
        <van-tab title="已下架">
          <div class="search">
            <img src="../../../../static/images/agriculturalTrusteeship/index/search_icon_01.png" />
            <input type="text" placeholder="输入需求进行搜索" v-model="searchInput2" />
            <img src="../../../../static/images/agriculturalTrusteeship/index/search_icon_02.png" @click="goSearch2" />
          </div>

          <div class="main_content">
            <div class="main_content_left">
              <van-sidebar v-model="activeKey2" @change="onChangeIn2">
                <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_tit2}}</p>
                <van-tabs v-model="activePc2" animated @change="orderByChange2">
                  <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="loading2"
                :finished="finished2"
                finished-text="没有更多了"
                @load="getList2"
              >
                <div class="main_content_right_list" v-for="(item,index) in supplyDemandListNo" :key="index">
                  <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.entityName}}</p>
                    <div class="tab">
                      <p>￥<span>{{item.unitPrice}}</span>/{{item.unit}}</p>
                      <p><span>销{{item.orderNum}}</span><span>分{{item.orderScore}}</span></p>
                    </div>
                    <div class="btn">
                      <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_03.png" @click="productIn(item.id)" />
                      <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_01.png" @click="$router.push({name:'agriculturalTrusteeshipSocializationProjectEdit',query:{id:item.id}})" />
                    </div>
                  </div>
                </div>
              </van-list>

            </div>
          </div>

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

    <agr></agr>
    <transition name="van-fade">
      <dialogClose v-show="showDialog"></dialogClose>
    </transition>
  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import agr from "@/components/common/agr_footer";
  import dialogClose from "@/components/agriculturalTrusteeship/dialog";
  import {
    supplyDemandList,
    productTypes,
    supplyDemandProductOut,
    supplyDemandProductIn,
  } from "@/api/agriculturalTrusteeship";
  export default {
    name: "agriculturalTrusteeshipInsuranceList",
    components: {
      agr,
      dialogClose
    },
    data() {
      return {
        activeKey: 0,
        activeKey2: 0,
        active: 0,
        activePc: 0,
        activePc2: 0,
        loading: false,
        finished: false,
        loading2: false,
        finished2: false,
        showDialog:false,
        // query:{
        //   pageNum: 1 ,
        //   pageSize: 10,
        // },
        supplyDemandList:[],
        productStatisticsOptions:[],
        industrialTypeOptions:[],
        supplyDemandListYes:[],
        supplyDemandListNo:[],
        productList:[],
        productListChildren:[],
        main_content_right_header_tit:'全套服务',
        main_content_right_header_tit2:'全套服务',
        query:{
          entityId:Cookies.get('ACCESS-SESSION-ID'),
          productType:''
        },
        query2:{
          entityId:Cookies.get('ACCESS-SESSION-ID'),
          productType:''
        },
        entityName:'',
        searchInput:'',
        searchInput2:'',
      };
    },
    created() {
      this.entityName = JSON.parse(Cookies.get("ServiceInformation")).entityName;
      this.getDicts("publish_status").then(response => {
        for (var i = 0; i < response.data.length; i++) {
          this.productStatisticsOptions.push({text: response.data[i].dictLabel, value: response.data[i].dictValue});
        }
      });
      this.getDicts("Industrial_classification_type").then(response => {
        for (var i = 0; i < response.data.length; i++) {
          this.industrialTypeOptions.push({text: response.data[i].dictLabel, value: response.data[i].dictValue});
        }
      });
      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.supplyMasterMap){
              let supplyMasterMap = res.supplyMasterMap.split( "," )
              res.supplyMasterMap = '/api'+supplyMasterMap[0]
            }
            if(res.publishStatus == 3){
              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 ;
          }
        });
      },
      getList2(){
        supplyDemandList(this.query2).then(response => {
          response.rows.map(res=>{
            if (res.supplyMasterMap){
              let supplyMasterMap = res.supplyMasterMap.split( "," )
              res.supplyMasterMap = '/api'+supplyMasterMap[0]
            }
            if(res.publishStatus == 1){
              this.supplyDemandListNo.push(res);
            }
            this.supplyDemandList.push(res);
          })
          if(this.supplyDemandList.length >= response.total){
            this.finished2 = true;
            return;
          }else{
            this.loading2 = false;
            this.query2.pageNum += 1;
          }
        });
      },
      openDialog(val){
        this.showDialog = val
      },
      productIn(id){
        supplyDemandProductIn(id).then(response => {
          this.$notify({ type: 'success', message: '上架成功' });
          location.reload()
        });
      },
      productOut(id){
        supplyDemandProductOut(id).then(response => {
          this.$notify({ type: 'success', message: '下架成功' });
          location.reload()
        });
      },
      onChangeIn(val){
        this.supplyDemandListYes = [];
        this.supplyDemandListNo = [];
        this.supplyDemandList = [];
        if (val == 0){
          this.main_content_right_header_tit = '全套服务';
          this.query.productType = '';
          console.log("aaaaa")
          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;
          console.log("bbbbb")
          this.getList();
        });
      },
      onChangeIn2(val){
        this.supplyDemandListNo = [];
        this.supplyDemandList = [];
        if (val == 0){
          this.main_content_right_header_tit2 = '全套服务';
          this.query2.productType = '';
          console.log("ccccc")
          this.getList2();
          return;
        }
        this.query2.productType = this.productList[val-1].id;
        let parentId = this.productList[val-1].id;
        this.main_content_right_header_tit2 = this.productList[val-1].dictName
        let query1 = {
          parentId : parentId
        }
        productTypes(query1).then(response => {
          this.productListChildren = response.data;
          console.log("ddddd")
          this.getList2();
        });
      },
      orderByChange(){
        if (this.activePc == 0){
          this.query.orderByColumn = 'order_score'
        }
        if (this.activePc == 1){
          this.query.orderByColumn = 'order_num'
        }
        this.supplyDemandListYes = [];
        this.supplyDemandList = [];
        this.getList();
      },
      orderByChange2(){
        if (this.activePc2 == 0){
          this.query2.orderByColumn = 'order_score'
        }
        if (this.activePc2 == 1){
          this.query2.orderByColumn = 'order_num'
        }
        this.supplyDemandListNo = [];
        this.supplyDemandList = [];
        this.getList2();
      },

      goSearch(){
        this.supplyDemandListYes = [];
        this.supplyDemandList = [];
        this.query.supplyDemandName = this.searchInput;
        this.getList();
      },

      goSearch2(){
        this.supplyDemandListNo = [];
        this.supplyDemandList = [];
        this.query2.supplyDemandName = this.searchInput;
        this.getList();
      },

      tabChange(val){
        this.query.productType = val;
        this.supplyDemandListYes=[];
        this.getList();
      },

    },
  }
</script>
<style scoped lang="scss">
  .home_wrapper{
    background: url("../../../../static/images/agriculturalTrusteeship/insurance/society_list_head.png") no-repeat;
  }
  /*头部*/
  .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;
    }
  }

  /* 内容 */
  .main{
    /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;
        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!important;
            height: 25PX;
          }
          /deep/ .van-tab{
            z-index: 1;
            color: #8F8F8F;
            padding: 5PX 10PX;
          }
          /deep/ .van-tab--active{
            color: #334281!important;
          }
          /deep/ .van-tabs__nav{
            background: #ECECEC!important;
            border-radius: initial;
          }
          /deep/ .van-tabs__nav--line{
            padding: 0;
          }
          /deep/ .van-tabs__content{
            padding: 0;
          }
          /deep/ .van-tabs__line{
            background: #D6D9E6!important;
            border-radius: 100rem!important;
            z-index: 0;
            width: 50%;
            height: 100%;
            bottom: 0;
          }
          .main_content_right_header_tit{
            font-size: .4rem;
            color: #1A1D4A;
          }
        }
        .main_content_right_nav{
          display: flex;
          flex-wrap: wrap;
          margin-top: 2vh;
          p{
            padding: 5PX 10PX;
            background: #F5F5F5;
            color: #8F8F8F;
            border-radius: 4PX;
            margin-right: 10PX;
            margin-bottom: 10PX;
            &.active{
              background: #E2E9FD;
              color: #1B5DEA;
            }
          }
        }
        .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;
            .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;
                    }
                  }
                }
              }
            }
            .btn{
              display: flex;
              align-items: center;
              justify-content: space-between;
              img{
                width: 45%;
                margin: 0;
              }
            }
            .name{
              color: #8F8F8F;
              background: url("../../../../static/images/agriculturalTrusteeship/index/name_icon.png") no-repeat left center;
              padding-left: 14PX;
            }
          }
        }
      }
    }
  }
</style>
