<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>{{supplyDemand.productType}}</p>
          <p>服务</p>
        </div>

        <div class="main_content_right_list_center">
          <template v-if="supplyDemand.supplyDemand!=null">
            <img v-if="supplyDemand.supplyDemand.supplyMasterMap" :src="supplyDemand.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">{{supplyDemand.contractionName}}</p>
            <div class="tab">
              <p>￥<span>{{supplyDemand.unitPrice}}</span>.00/{{supplyDemand.unit}}</p>
            </div>
          </div>
        </div>
        <van-cell title="买方名称" :border="false" :value="supplyDemand.bookName" />
        <van-cell title="联系人" :border="false" :value="supplyDemand.linkera" />
        <van-cell @click="showDialog" :border="false" >
          <template #title>
            <div style="display: flex;align-items: center;">
              <p style="margin-right: 5px;">联系电话</p>
              <img src="../../../../static/images/agriculturalTrusteeship/insurance/insurance_list_iphone.png">
            </div>
          </template>
          <template #default>
            <p style="color: #336699">{{supplyDemand.phone}}</p>
          </template>
        </van-cell>
        <van-dialog
          v-model="show"
          title="联系卖家"
          :message="`确认拨打`+supplyDemand.phone+`联系电话？`"
          show-cancel-button
          @cancel="show=false"
          @confirm="contact"
        >
        </van-dialog>
      </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="supplyDemand.linkera" />
        <van-cell title="联系电话" :border="false" :value="supplyDemand.phonea" />
        <van-cell title="服务地点" :border="false" :value="supplyDemand.serviceAddress" />
      </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="supplyDemand.contractionName" />
        <van-cell title="服务作物" :border="false" :value="supplyDemand.cropType" />
        <van-cell title="下单时间" :border="false" :value="supplyDemand.orderAt" />
        <van-cell title="服务时间" :border="false" :value="supplyDemand.serviceAt" />
        <van-cell title="服务数量" :border="false" :value="supplyDemand.serviceNum" />
        <van-cell title="订单金额（元）" :border="false" :value="supplyDemand.realityServiceMoney == null ? supplyDemand.countMoney:supplyDemand.realityServiceMoney" />
        <van-cell title="数量单位" :border="false" :value="supplyDemand.numUnit" />
        <van-cell title="备注" :border="false" :value="supplyDemand.serviceRemark" />
      </div>

    </div>

    <div class="main_btn">
      <p @click="clickYes">接单</p>
      <p @click="clickNo">拒单</p>
    </div>
    <!--  内容结束  -->
  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import {productTypes, supplyorderGet , supplyorderFinish , supplyorderReject} from "@/api/agriculturalTrusteeship";

  export default {
    name: "agriculturalTrusteeshipIndex",
    data() {
      return {
        activeKey: 0,
        active: 0,
        loading: false,
        finished: false,
        show:false,
        activeNames:[],
        cropTypeOptions:[],
        orderStatusOptions:[],
        productList:[],
        supplyDemand:{}
      };
    },
    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;
      });
      this.getDetail();
    },
    methods: {
      showDialog() {
        this.show = true;// 显示确认对话框
      },
      contact() {
        const a = document.createElement("a");
        a.href = "tel:8888410"
        a.click();
        this.show = false;
      },
      getDetail(){
        supplyorderGet(this.$route.query.id).then(response => {
          response.data.cropType = this.selectDictLabel(this.cropTypeOptions, response.data.cropType);
          response.data.orderStatus = this.selectDictLabel(this.orderStatusOptions, response.data.orderStatus);
          var that = this ;
          setTimeout(function () {
            response.data.productType = that.productList.filter(function (e) { return e.id == response.data.productType; })[0].dictName;
          },1000)


          response.data.countMoney = response.data.unitPrice*response.data.serviceNum;

          if (response.data.supplyDemand!=null){
            if (response.data.supplyDemand.supplyMasterMap){
              var attachement = response.data.supplyDemand.supplyMasterMap.split( "," );
              response.data.supplyDemand.supplyMasterMap = '/api' + attachement[0];
            }
          }
          this.supplyDemand = response.data;
        });
      },
      clickYes(){
        supplyorderFinish(this.$route.query.id).then(response => {
          this.$notify({ type: 'success', message: '接单成功' });
          setTimeout(function(){
            history.back(-1);
          },2000)
        });
      },
      clickNo(){
        supplyorderReject(this.$route.query.id).then(response => {
          this.$notify({ type: 'success', message: '拒单成功' });
          setTimeout(function(){
            history.back(-1);
          },2000)
        });
      }
    },
  }
</script>
<style scoped lang="scss">
  .home_wrapper{

  }
  /*头部*/
  .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: 8PX;
      }
      .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>
