<template>
  <div class="home_wrapper">
    <!--  头部开始  -->
    <van-nav-bar
      title="确认订单"
      fixed
      placeholder
      left-arrow
      @click-left="onClickLeft"
    />
    <!--  头部结束  -->

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

        <div class="main_content_right_list">
          <div class="main_content_right_list_header">
            <p class="on">商品信息</p>
            <p>{{productType}}</p>
            <p>服务</p>
          </div>

          <div class="main_content_right_list_center">
            <img :src="supplyDemand.supplyMasterMap" style="width: 25vw;height: 25vw;">
            <div class="main_content_right_list_content">
              <p class="tt">{{supplyDemand.supplyDemandName}}</p>
              <div class="tab">
                <p>￥<span>{{supplyDemand.unitPrice}}</span>/{{supplyDemand.unit}}</p>
              </div>
            </div>
          </div>
          <van-cell title="卖方名称" :border="false" :value="supplyDemand.entityName" />
          <van-cell title="联系人" :border="false" :value="supplyDemand.linker" />
          <van-cell title="联系电话" :border="false" :value="supplyDemand.supplyDemandTal" />
        </div>

        <div class="main_content_right_list">
          <div class="main_content_right_list_header">
            <p class="on">买家信息</p>
          </div>

          <van-cell title="联系人" :border="false" :value="user.nickName" />
          <van-cell title="联系电话" :border="false" :value="user.phonenumber" />
          <van-cell title="服务地点" :border="false" :value="user.deptName" />
        </div>

        <div class="main_content_right_list">
          <div class="main_content_right_list_header">
            <p class="on">订单信息</p>
          </div>

          <van-field
            readonly
            clickable
            required
            :border="false"
            :rules="[{ required: true , message:'请选择服务合同'}]"
            v-model="contractionName"
            label="服务合同"
            placeholder="请选择服务合同"
            @click="showfwht = true"
            input-align="right"
            right-icon="arrow-down"
            label-width="auto"
          />
          <van-popup v-model="showfwht" position="bottom">
            <van-picker
              show-toolbar
              :columns="fwhtOptions"
              value-key="contractionName"
              @confirm="onConfirmFwht"
              @cancel="showfwht = false"
            />
          </van-popup>
<!--          <van-field label="服务合同" v-model="supplyDemand.fwhtId" :border="false" input-align="right" placeholder="请输入服务合同" />-->
          <van-field readonly label="服务作物" v-model="cropType" :border="false" input-align="right" placeholder="服务作物" />

<!--          <van-field label="下单时间" v-model="supplyDemand.orderAt" :border="false" input-align="right" placeholder="请输入下单时间" />-->

          <van-field
            readonly
            clickable
            required
            :border="false"
            :rules="[{ required: true , message:'请选择下单时间'}]"
            v-model="supplyDemand.orderAt"
            label="下单时间"
            placeholder="请选择下单时间"
            @click="showOrderAt = true"
            input-align="right"
            right-icon="arrow-down"
            label-width="auto"
          />
          <van-popup v-model="showOrderAt" position="bottom">
            <van-datetime-picker
              v-model="orderAt"
              @confirm="onConfirmOrderAt"
              type="date"
              title="选择年月"
            />
          </van-popup>

          <van-field
            readonly
            clickable
            required
            :border="false"
            :rules="[{ required: true , message:'请选择服务时间'}]"
            v-model="supplyDemand.serviceAt"
            label="服务时间"
            placeholder="请选择服务时间"
            @click="showServiceAt = true"
            input-align="right"
            right-icon="arrow-down"
            label-width="auto"
          />
          <van-popup v-model="showServiceAt" position="bottom">
            <van-datetime-picker
              v-model="serviceAt"
              @confirm="onConfirmServiceAt"
              type="date"
              title="选择年月"
            />
          </van-popup>

          <van-field label="服务数量" :border="false" input-align="right" >
            <template #input>
              <van-stepper v-model="supplyDemand.serviceNum" />
            </template>
          </van-field>

          <van-field label="数量单位" v-model="supplyDemand.numUnit" :border="false" input-align="right" placeholder="请输入数量单位" />
          <van-field label="备注" v-model="supplyDemand.serviceRemark" :border="false" input-align="right" placeholder="请输入备注" />
        </div>

    </div>

    <div class="main_btn">
      <p @click="placeOrder">下单</p>
      <p @click="onClickLeft">取消</p>
    </div>
    <!--  内容结束  -->
  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import {productTypes, supplyDemandGet,fwhtList,placeOrder} from "@/api/agriculturalTrusteeship";
  import {getInfo} from "@/api/login";
  import request from "@/utils/request";

  export default {
    name: "agriculturalTrusteeshipIndex",
    data() {
      return {
        activeKey: 0,
        active: 0,
        loading: false,
        finished: false,
        showfwht: false,
        show:true,
        orderAt:new Date(),
        showOrderAt: false,
        serviceAt:new Date(),
        showServiceAt: false,
        activeNames:[],
        supplyDemand:{
        },
        projectTypeOptions:[],
        productList:[],
        productList1:[],
        demandTypeOptions:[],
        productTypeOptions:[],
        supplyMasterMapArr:[],
        bodyTypeOptions:[],
        fwhtOptions:[],
        user:{},
        fwht:'',
        contractionName:'',
        productType:'',
        cropType:''
      };
    },
    created() {
      getInfo().then(response => {
        this.user = response.user;
        fwhtList({deptId: response.user.loginDeptId,bookId:'0', contractionStatus: '1'}).then(response => {
          this.fwhtOptions = response.rows;
        });
      });
      let query = {
        parentId : ''
      }
      let query1 = {
        tree : true
      }
      productTypes(query).then(response => {
        this.productList = response.data;
      });
      productTypes(query1).then(response => {
        this.productList1 = response.data;
      });
      this.getDicts("newBusinessEntity_statistics_project").then(response => {
        for (var i = 0; i < response.data.length; i++) {
          this.projectTypeOptions.push({text: response.data[i].dictLabel, value: response.data[i].dictValue});
        }
        this.bodyTypeOptions = response.data;
      });
      this.getDicts("crop_type").then(response => {
        this.cropTypeOptions = response.data;
      });
      this.getDetail();
    },
    methods: {
      getDetail(){
        supplyDemandGet(this.$route.query.id).then(response => {
          response.data.bodyType = this.selectDictLabel(this.bodyTypeOptions, response.data.bodyType);
          this.productType = this.productList1.filter(function (e) { return e.id == response.data.productType; })[0].dictName;
          if (response.data.supplyMasterMap){
            var attachement = response.data.supplyMasterMap.split( "," );
            response.data.supplyMasterMap = '/api' + attachement[0];
          }
          response.data.serviceNum = 1;
          this.supplyDemand = response.data;
        });
      },
      onConfirmFwht(val){
        this.contractionName = val.contractionName;
        this.supplyDemand.fwhtId = val.id;
        this.cropType = this.selectDictLabel(this.cropTypeOptions, val.cropType);
        this.supplyDemand.cropType = val.cropType;
        this.showfwht = false;
      },
      onConfirmOrderAt(data){
        this.supplyDemand.orderAt = this.format(data,'yyyy-MM-dd');
        this.orderAt = data;
        this.showOrderAt = false;
      },
      onConfirmServiceAt(data){
        console.log(data)
        this.supplyDemand.serviceAt = this.format(data,'yyyy-MM-dd');
        this.serviceAt = data;
        this.showServiceAt = false;
      },
      placeOrder(){
        console.log(this.supplyDemand)
        this.supplyDemand.demandId = this.$route.query.id;
        this.supplyDemand.id = '';
        this.supplyDemand.linkera = this.user.nickName
        this.supplyDemand.phonea = this.user.phonenumber
        this.supplyDemand.serviceAddress = this.user.deptName
        placeOrder(this.supplyDemand).then(response => {
          if(response.code=="200"){
            this.$notify({ type: 'success', message: '发布成功' });
            setTimeout(function(){
              history.back(-1);
            },2000)
          }
        });
      }
    },
  }
</script>
<style scoped lang="scss">
.home_wrapper{

}
/deep/ .van-cell--required::before{
  left: 17vw;
}
  /*头部*/
  .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;
    margin-top: 2vh;
    padding: 1.5vh 3%;
    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;
      }
    }
    .billCount {
      display: flex;
      text-align: center;
      margin-top: 3vh;
      .billCount_left{
        width: 50%;
        color: #1B5DEA;
        p{
          &:nth-child(1){
            font-size: .45rem;
          }
        }
      }
      .billCount_right{
        width: 50%;
        color: #FF5E00;
        p{
          &:nth-child(1){
            font-size: .45rem;
          }
        }
      }
    }
  }

  /*内容*/
  .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: 10PX;
      }
      .main_content_right_list_header{
        display: flex;
        margin-bottom: 1vh;
        align-items: center;
        p{
          padding: 3PX 10PX;
          border-radius: 8PX;
          &:nth-child(2){background: #2B7EEC;color: #ffffff;margin-left: auto;}
          &:nth-child(3){background: #E2E9FD;color: #497CE8;margin-left: 10PX;}
        }
        .on{
          color: #334281;
          border-radius: initial;
          padding:0 0 0 20PX;
          font-size: 0.35rem;
          background: url("../../../../static/images/agriculturalTrusteeship/socialization/bill_icon_01.png") no-repeat left center
        }
        .off{
          color: #E60505;
          border-radius: initial;
          margin-left: auto;
          padding:0 0 0 15PX;
          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;
      }
    }
  }
.main_btn{
  display: flex;
  justify-content: space-around;
  padding: 4vh 0;
  p{
    font-size: .4rem;
    width: 35%;
    text-align: center;
    padding: 10PX 0;
    border-radius: 5rem;
    box-shadow: 0px 3PX 6PX 0px rgba(0,0,0,0.16);
    &:nth-child(1){
      background: #334281;
      color: #ffffff;
    }
    &:nth-child(2){
      background: #D1D5E4;
      color: #334281;
    }
  }
}
</style>
