<template>
  <div class="home_wrapper">
    <!--  头部开始  -->
    <div class="header">
      <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>
<!--      <img src="../../../../static/images/agriculturalTrusteeship/socialization/socialization_icon_01.png" alt="" @click="show = true;">-->
    </div>
    <!--  头部结束  -->

    <!--  导航开始  -->
    <div class="nav">
      <div class="date">
        <p @click="startTimeShow = true">{{startOrderAt}}</p>
        <span>-</span>
        <p @click="endTimeShow = true">{{endOrderAt}}</p>
      </div>
      <van-popup v-model="startTimeShow" position="bottom">
        <van-datetime-picker
          v-model="currentDateStar"
          @confirm="onConfirmStar"
          type="year-month"
          title="选择年月"
        />
      </van-popup>
      <van-popup v-model="endTimeShow" position="bottom">
        <van-datetime-picker
          v-model="currentDateEnd"
          @confirm="onConfirmEnd"
          type="year-month"
          title="选择年月"
        />
      </van-popup>
      <div class="nav_list">
        <p :class="{'active':query.orderStatus == ''}" @click="tabChange('')">全部</p>
        <p :class="{'active':query.orderStatus == item.dictValue}" @click="tabChange(item.dictValue)" v-for="(item,index) in orderStatusOptions" :key="index">{{item.dictLabel}}</p>
      </div>
    </div>
    <!--  导航结束  -->

    <!--  内容开始  -->
    <div class="main">

      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList"
      >
  <!--            @load="onLoad"  v-for="item in 10" :key="item"-->
        <div class="main_content_right_list" v-for="(item,index) in supplyDemandList" :key="index">
          <div class="main_content_right_list_header">
            <p>{{item.productType}}</p>
            <p>服务</p>
            <p :class="{'off': item.orderStatus== '已拒单','on': item.orderStatus!= '已拒单'}">{{item.orderStatus}}</p>
          </div>
<!--          $router.push({name:'agriculturalTrusteeshipBillDetail2',query:{id:item.id}})-->
          <div class="main_content_right_list_center" @click="goDetail(item.orderStatus,item.id)">
            <template v-if="item.supplyDemand!=null">
              <img v-if="item.supplyDemand.supplyMasterMap" :src="item.supplyDemand.supplyMasterMap" style="width: 25vw;height: 25vw;">
              <img v-else src="../../../../static/images/agriculturalTrusteeship/zwtp.png" style="width: 25vw;height: 25vw;">
            </template>
            <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.demandName}}</p>
              <div class="tab">
                <p>￥<span>{{item.realityServiceMoney == null ? item.countMoney:item.realityServiceMoney}}</span>.00</p>
              </div>
              <p class="name">
                <span>数量：{{item.serviceNum}}</span>
                <span>作物：{{item.cropType}}</span>
              </p>
            </div>
          </div>
          <van-cell title="卖方名称" :border="false" :value="item.entityName" />
          <van-cell title="联系人" :border="false" :value="item.linker" />
          <van-cell title="联系电话" :border="false" :value="item.supplyDemandTal" />
        </div>
<!--        <div class="main_content_right_list">-->
<!--          <div class="main_content_right_list_header">-->
<!--            <p>灌溉</p>-->
<!--            <p>服务</p>-->
<!--            <p class="on">已评分</p>-->
<!--          </div>-->

<!--          <div class="main_content_right_list_center" @click="$router.push({name:'agriculturalTrusteeshipBillDetail3'})">-->
<!--            <img src="../../../../static/images/agriculturalTrusteeship/index/test.png">-->
<!--            <div class="main_content_right_list_content">-->
<!--              <p class="tt">如果只有一行就空着啊啊啊啊啊啊啊啊啊啊啊啊</p>-->
<!--              <div class="tab">-->
<!--                <p>￥<span>165,836,365</span>.00</p>-->
<!--              </div>-->
<!--              <p class="name">-->
<!--                <span>数量：300</span>-->
<!--                <span>作物：玉米</span>-->
<!--              </p>-->
<!--            </div>-->
<!--          </div>-->
<!--          <van-cell title="买方名称" :border="false" value="张三李四联合合作社" />-->
<!--          <van-cell title="联系人" :border="false" value="林晓春" />-->
<!--          <van-cell title="联系电话" :border="false" value="165 8874 0311" />-->
<!--        </div>-->
<!--        <div class="main_content_right_list">-->
<!--          <div class="main_content_right_list_header">-->
<!--            <p>灌溉</p>-->
<!--            <p>服务</p>-->
<!--            <p class="off">已拒单</p>-->
<!--          </div>-->

<!--          <div class="main_content_right_list_center" @click="$router.push({name:'agriculturalTrusteeshipBillDetail4'})">-->
<!--            <img src="../../../../static/images/agriculturalTrusteeship/index/test.png">-->
<!--            <div class="main_content_right_list_content">-->
<!--              <p class="tt">如果只有一行就空着啊啊啊啊啊啊啊啊啊啊啊啊</p>-->
<!--              <div class="tab">-->
<!--                <p>￥<span>165,836,365</span>.00</p>-->
<!--              </div>-->
<!--              <p class="name">-->
<!--                <span>数量：300</span>-->
<!--                <span>作物：玉米</span>-->
<!--              </p>-->
<!--            </div>-->
<!--          </div>-->
<!--          <van-cell title="买方名称" :border="false" value="张三李四联合合作社" />-->
<!--          <van-cell title="联系人" :border="false" value="林晓春" />-->
<!--          <van-cell title="联系电话" :border="false" value="165 8874 0311" />-->
<!--        </div>-->
      </van-list>

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

    <buyer></buyer>
  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import buyer from "@/components/common/buyer_footer";
  import {productTypes, supplyorderList} from "@/api/agriculturalTrusteeship";

  export default {
    name: "agriculturalTrusteeshipIndex",
    components: {
      buyer,
    },
    data() {
      return {
        activeKey: 0,
        active: 0,
        loading: false,
        finished: false,
        show:true,
        activeNames:[],
        showDialog:false,
        startTimeShow:false,
        endTimeShow:false,
        supplyDemandList:[],
        cropTypeOptions:[],
        orderStatusOptions:[],
        productList:[],
        currentDateStar: new Date(),
        currentDateEnd: new Date(),
        query:{
          orderByColumn:'order_at',
          isAsc:'asc',
          demandName :'',
          startOrderAt :'',
          endOrderAt :'',
          orderStatus :'',
        },
        startOrderAt:this.format(new Date(),'yyyy年MM月'),
        endOrderAt:this.format(new Date(),'yyyy年MM月'),
        params : {
          startOrderAt:this.format(new Date(),'yyyy-MM'),
          endOrderAt:this.format(new Date(),'yyyy-MM'),
        },
        content:'',
        searchInput:''
      };
    },
    created() {
      let query = {
        parentId : null,
        tree:false
      }
      productTypes(query).then(response => {
        this.productList = response.data;
      });
      this.getDicts("crop_type").then(response => {
        this.cropTypeOptions = response.data;
      });
      this.getDicts("service_order_status").then(response => {
        this.orderStatusOptions = response.data;
      });
    },
    methods: {
      getList(){
        supplyorderList(this.query).then(response => {
          response.rows.map(res=>{
            // console.log(res.supplyDemand.supplyMasterMap)
            if (res.supplyDemand!=null){
              let supplyMasterMap = res.supplyDemand.supplyMasterMap.split( "," )
              res.supplyDemand.supplyMasterMap = '/api'+supplyMasterMap[0]
            }
            res.cropType = this.selectDictLabel(this.cropTypeOptions, res.cropType);
            var that = this ;
            setTimeout(function () {
              res.productType = that.productList.filter(function (e) { return e.id == res.productType; })[0].dictName;
              res.orderStatus = that.selectDictLabel(that.orderStatusOptions, res.orderStatus);
            },1000)

            res.countMoney = res.unitPrice*res.serviceNum;
            this.supplyDemandList.push(res);
          })
          if(this.supplyDemandList.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.query.pageNum += 1 ;
          }
        });
      },
      onConfirmStar(data){
        this.supplyDemandList=[];
        this.params.startOrderAt = this.format(data,'yyyy-mm');
        this.query.startOrderAt = this.format(data,'yyyy-mm');
        this.startOrderAt = this.format(data,'yyyy年MM月');
        this.startTimeShow = false;
        // orderStatistics(this.params).then(response => {
        //   this.content = response.data;
        // });
        this.getList();
      },
      onConfirmEnd(data){
        this.supplyDemandList=[];
        this.params.endOrderAt = this.format(data,'yyyy-mm');
        this.query.endOrderAt = this.format(data,'yyyy-mm');
        this.endOrderAt = this.format(data,'yyyy年MM月');
        this.endTimeShow = false;
        // orderStatistics(this.params).then(response => {
        //   this.content = response.data;
        // });
        this.getList();
      },
      goDetail(type,id){
        if (type == '已接单'){
          this.$router.push({name:'agriculturalTrusteeshipBillDetail2',query:{id:id}})
        }
        if (type == '已评价'){
          this.$router.push({name:'agriculturalTrusteeshipBillDetail3',query:{id:id}})
        }
        if (type == '已拒单'){
          this.$router.push({name:'agriculturalTrusteeshipBillDetail4',query:{id:id}})
        }
        if (type == '已下单'){
          this.$router.push({name:'agriculturalTrusteeshipBillDetail',query:{id:id}})
        }
      },
      tabChange(val){
        this.query.orderStatus = val;
        this.supplyDemandList=[];
        this.getList();
      },
      goSearch(){
        this.supplyDemandList = [];
        this.query.demandName = this.searchInput;
        this.getList();
      },
      openDialog(val){
        this.showDialog = val
      },
    },
  }
</script>
<style scoped lang="scss">
.home_wrapper{
  background: #F9F9F9;
}
  /*头部*/
  .header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2vh 4% 0vh;
  }

  .search{
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #6E93F3;
    padding: 1PX 1PX 1PX 12PX ;
    border-radius: 50PX;
    /*margin-right: 30PX;*/
    flex: 1;
    input{
      flex: 1;
      background: transparent;
      margin-left: 10PX;
    }
  }
  /*导航栏目*/
  .nav{
    width: 94%;
    margin: 0 auto;
    padding: 2vh 0 0;
    /*background: #ffffff;*/
    /*border-radius: 10PX;*/
    /*box-shadow: 0px 3PX 6PX 0px rgba(0,0,0,0.16);*/
    .date{
      display: flex;
      justify-content: space-around;
      align-items: center;
      p{
        border-radius: 1rem;
        padding: 5PX 0PX 5PX 5%;
        width: 40%;
        text-align: center;
        color: #334281;
        box-shadow: 0px 3PX 6PX 0px rgba(0,0,0,0.16);
        background:#D6D9E6 url("../../../../static/images/agriculturalTrusteeship/socialization/socialization_icon_date.png") 20% center no-repeat;
      }
    }
    .nav_list{
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 2vh;
      p{
        background: #F0F0F0;
        padding: 7PX 0;
        width: 18%;
        text-align: center;
        color: #888888;
        border-radius: 7PX;
        &.active{
          background: #E2E9FD;
          color: #1B5DEA;
        }
      }
    }
  }

  /*内容*/
  .main{
    width: 94%;
    margin: 0 auto;
    .main_content_right_list{
      margin-top: 2vh;
      padding: 1.5vh 3%;
      background: #ffffff;
      border-radius: 10PX;
      box-shadow: 0px 3PX 6PX 0px rgba(0,0,0,0.16);
      /deep/ .van-cell{
        padding: 0;
        margin-top: 8PX;
      }
      .main_content_right_list_header{
        display: flex;
        margin-bottom: 1vh;
        align-items: center;
        p{
          padding: 3PX 10PX;
          border-radius: 8PX;
          &:nth-child(1){background: #2B7EEC;color: #ffffff;}
          &:nth-child(2){background: #E2E9FD;color: #497CE8;margin-left: 10PX;}
        }
        .on{
          color: #39BD18;
          border-radius: initial;
          margin-left: auto;
          padding:0 0 0 20PX;
          background: url("../../../../static/images/agriculturalTrusteeship/socialization/socialization_icon_on.png") no-repeat left center
        }
        .off{
          color: #E60505;
          border-radius: initial;
          margin-left: auto;
          padding:0 0 0 20PX;
          background: url("../../../../static/images/agriculturalTrusteeship/socialization/socialization_icon_off.png") no-repeat left center
        }
      }
      .main_content_right_list_center{
        display: flex;
        img{
          border-radius: 15PX;
          margin-right: 4%;
        }
        .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){
                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: #7A7A7A;
            span{
              &:nth-child(2){
                margin-left: 5PX;
              }
            }
          }
        }
      }
    }
  }

  /*弹出层*/
  .popup_header{
    display: flex;
    align-items: center;
    color: #334281;
    font-size: .38rem;
    margin-bottom: 15PX;
    img{
      margin-right: 10PX;
      display: block;
    }
    p{
      line-height: 1;
    }
  }
  .popup_content{
    .selected{
      .on{
        font-size: .35rem;
        padding: 10PX 20PX;
        color: #334281;
        background: url("../../../../static/images/agriculturalTrusteeship/socialization/down.png")left center no-repeat;
      }
      .off{
        font-size: .35rem;
        padding: 10PX 20PX;
        color: #334281;
        background: url("../../../../static/images/agriculturalTrusteeship/socialization/right.png")left center no-repeat;
      }
      .options{
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        p{
          background: #F5F5F5;
          color: #8F8F8F;
          width: 30%;
          padding: 5PX 0;
          border-radius: 5PX;
          text-align: center;
          &.active{
            background: #E2E9FD;
            color: #1B5DEA;
          }
        }
      }
    }
  }
  .popup_date{
    display: flex;
    justify-content: space-around;
    align-items: center;
    p{
      border-radius: 1rem;
      padding: 5PX 0PX 5PX 5%;
      width: 45%;
      text-align: center;
      color: #1B5DEA;
      background:#E2E9FD url("../../../../static/images/agriculturalTrusteeship/socialization/socialization_icon_date.png") 15% center no-repeat;
    }
  }
  .popup_btn{
    position: fixed;
    bottom: 5vh;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 94%;
    left: 3%;
    p{
      width: 30%;
      padding: 7PX 0;
      border-radius: 5rem;
      text-align: center;
      font-size: .35rem;
      box-shadow: 0px 3PX 6PX 0px rgba(0,0,0,0.16);
      &:nth-child(1){
        background: #1B5DEA;
        color: #ffffff;
      }
      &:nth-child(2){
        border: 1PX solid #1B5DEA;
        color: #1B5DEA;
      }
      &:nth-child(3){
        background-image: linear-gradient(to right , #6E93F3 , #54C6E4);
        color: #ffffff;
      }
    }
  }
</style>
