<template>
  <div class="orderViews" v-show="showDe">
    <div class="orderText1">
      <div class="orderText1_1">派单信息</div>
      <span
        class="el-icon-message-solid orderText1_img"
        style="color: #00ffff; font-size: 28px"
      ></span>
      <span style="color: #00ffff">请车牌号 {{ carnumber }} 前往</span>
      <span style="color: #e47e1b; font-weight: 600">{{ carDestination }}</span>
      <span style="color: #00ffff">{{ orderClass }}</span>
    </div>
    <div class="orderText2" @click="startPaidanFn()" v-show="btnShow1">
      接受派单
    </div>
    <div class="orderText2" @click="refusePaidanFn()" v-show="btnShow1">
      拒绝派单
    </div>
    <div class="orderText2" @click="navigation()" v-show="btnShow4">
      导航前往
    </div>
    <div class="orderText2" @click="finishPaidanFn()" v-show="btnShow2">
      卸车
    </div>
    <div class="orderText2" @click="finishPaidanFn1()" v-show="btnShow3">
      完成派单
    </div>
    <audio
      controls
      currentTime
      autoplay
      :src="startOrderSrcUrl"
      style="display: none"
      id="audio1"
    ></audio>
  </div>
</template>

<script>
import {
  httpGet,
  httpPostForJson,
  putForJson,
  httpDelForJson,
} from "@/common/httpBean.js";
import {
  manualSchedulingQuery,
  manmadeStatusQuery,
  vehicleInformationQuery,
  vehicleInformationUpdate,
  dingDanBiaoCaoZuo,
  getZhuangCheDingDanQuery,
  getXieCheDingDanQuery,
  screenMapSetUpQuery,
  carRealTimeLocationQuery2,
  creatOrder,
} from "@/axios/api.js";
import newOrder from "@/assets/dingdan.mp3";

export default {
  data() {
    return {
      showDe: false, //接派单窗口
      carnumber: "",
      carDestination: "",
      orderClass: "",
      btnShow1: false, //开始派单和拒绝派单展示
      btnShow2: false, //完成派单展示
      btnShow3: false, //完成派单展示
      btnShow4: false, //导航显示开关
      sonTimer1: null,
      startOrderSrcUrl: "", //来订单语音路径
      dingDanId: "", //订单id
      dingdanodd: "", //订单odd
      zuizhongdingdanid: "",
      equipmentName: "", //车载设备编号
      xiecheBtnAble: false, //卸车按钮是否能用
      zhinengpaidanBoolan: false, //更改该车是否可接受智能派单
      paidanFlag: 0, //暂存的派单是否是人工或者智能
      zuizhongpaidanFlag: 0,
      //暂存的经纬度
      oldxy: {
        lat: 0, //纬度
        lng: 0, //经度
      },
      //智能调度订单自动接单属性
      zhinengjiedan: 0,
      //人工调度订单自动接单属性
      rengongjiedan: 0,
      //卸车语音计时
      xiecheyuyinTimer: 0,
    };
  },
  mounted() {
    let that = this;
    this.sonTimer1 = setInterval(() => {
      if (this.carnumber == "") {
        return;
      }
      //如果zhinengpaidanBoolan为true，获取人工和智能一起的调度
      if (this.zhinengpaidanBoolan) {
        //先查人工调度
        httpGet(dingDanBiaoCaoZuo, {
          sort: "createTime,desc",
          size: 1,
          carNo: this.carnumber,
          flag: 1,
        }).then((res) => {
          console.log(res, "人工调度");
          //如果没有就获取智能调度
          if (res.data.content.length == 0) {
            httpGet(dingDanBiaoCaoZuo, {
              sort: "createTime,desc",
              size: 1,
              carNo: this.carnumber,
            }).then((res_1) => {
              console.log(res_1, "调度");
              if (res_1.data.content.length == 0) {
                this.showDe = false;
                this.btnShow1 = false;
                this.btnShow2 = false;
                this.btnShow3 = false;
                this.btnShow4 = false;
              } else {
                httpGet(vehicleInformationQuery, {
                  number: this.carnumber,
                  size: 1,
                }).then((resSon1) => {
                  console.log(resSon1, "车辆信息");
                  if (resSon1.code == 200) {
                    this.showDe = true;
                    this.carDestination = res_1.data.content[0].destination;
                    this.dingDanId = res_1.data.content[0].id;
                    this.dingdanodd = res_1.data.content[0].odd;
                    this.equipmentName = resSon1.data.content[0].equipmentName;
                    this.paidanFlag = res_1.data.content[0].flag;
                    this.btnShow4 = true;
                    if (res_1.data.content[0].orderClass == 0) {
                      this.orderClass = "装车";
                    } else {
                      this.orderClass = "卸车";
                      this.btnShow2 = true;
                    }
                    if (
                        resSon1.data.content[0].workStatus == 0 &&
                        this.paidanFlag == 0
                    ) {
                      if (res_1.data.content[0].orderClass == 0) {
                        this.showDe = true;
                        this.btnShow1 = true;
                        this.btnShow2 = false;
                        this.btnShow3 = false;
                        this.btnShow4 = false;
                        this.carDestination = res_1.data.content[0].destination;
                        this.dingDanId = res_1.data.content[0].id;
                        this.dingdanodd = res_1.data.content[0].odd;
                        this.equipmentName =
                            resSon1.data.content[0].equipmentName;
                        this.orderClass = "装车";
                        //启动语音
                        this.startOrderSrcUrl = newOrder;
                        let au = document.getElementById("audio1");
                        au.currentTime = 0;
                        au.play();
                        this.zhinengjiedan = this.zhinengjiedan + 1;
                        if (this.zhinengjiedan >= 7) {
                          this.btnShow1 = false;
                          this.startPaidanFn();
                        }
                      } else {
                        this.showDe = true;
                        this.btnShow1 = false;
                        this.btnShow2 = true;
                        this.btnShow3 = false;
                        this.btnShow4 = true;
                        this.carDestination = res_1.data.content[0].destination;
                        this.dingDanId = res_1.data.content[0].id;
                        this.dingdanodd = res_1.data.content[0].odd;
                        this.equipmentName =
                            resSon1.data.content[0].equipmentName;
                        this.orderClass = "卸车";
                        this.xiecheyuyinTimer = this.xiecheyuyinTimer + 1;
                        if (this.xiecheyuyinTimer <= 3) {
                          //启动语音
                          this.startOrderSrcUrl = newOrder;
                          let au = document.getElementById("audio1");
                          au.currentTime = 0;
                          au.play();
                        }
                      }
                    }
                    //获取车辆坐标计算距离并返回给后台
                    httpGet(carRealTimeLocationQuery2, {
                      name: resSon1.data.content[0].equipmentName,
                    }).then((res2) => {
                      if (res2.data) {
                        if (this.oldxy.lat == 0 || this.oldxy.lng == 0) {
                          this.oldxy.lat = res2.data.location.y;
                          this.oldxy.lng = res2.data.location.x;
                        } else {
                          let distance1 =
                              this.getDistance(
                                  this.oldxy.lat,
                                  this.oldxy.lng,
                                  res2.data.location.y,
                                  res2.data.location.x
                              ) + parseFloat(res_1.data.content[0].mil);
                          putForJson(dingDanBiaoCaoZuo, {
                            id: res_1.data.content[0].id,
                            mil: distance1,
                          }).then((res) => {
                          });
                          this.$nextTick(() => {
                            this.oldxy.lat = res2.data.location.y;
                            this.oldxy.lng = res2.data.location.x;
                          });
                        }
                      }
                    });
                  }
                });
              }
            });
          } else {
            //如果有人工调度
            this.orderClass = "";
            //有人工调度就删除智能调度单子
            httpGet(dingDanBiaoCaoZuo, {
              sort: "createTime,desc",
              carNo: this.carnumber,
              flag: 0,
            }).then((resDel) => {
              if (resDel.code == 200) {
                resDel.data.content.forEach((itemDel, indexDel) => {
                  httpDelForJson(dingDanBiaoCaoZuo, [
                    itemDel.id,
                    this.carnumber,
                    item.odd,
                  ]).then((resDelSon) => {
                  });
                });
              }
            });
            //有人工调度下面展示操作
            httpGet(vehicleInformationQuery, {
              number: this.carnumber,
              size: 1,
            }).then((resSon1) => {
              if (resSon1.code == 200) {
                this.showDe = true;
                this.carDestination = res.data.content[0].destination;
                this.dingDanId = res.data.content[0].id;
                this.dingdanodd = res.data.content[0].odd;
                this.equipmentName = resSon1.data.content[0].equipmentName;
                this.btnShow3 = true;
                this.btnShow4 = true;
                if (resSon1.data.content[0].workStatus == 0) {
                  this.paidanFlag = res.data.content[0].flag;
                  this.showDe = true;
                  this.btnShow1 = true;
                  this.btnShow2 = false;
                  this.btnShow3 = false;
                  this.btnShow4 = false;
                  this.carDestination = res.data.content[0].destination;
                  this.dingDanId = res.data.content[0].id;
                  this.dingdanodd = res.data.content[0].odd;
                  this.equipmentName = resSon1.data.content[0].equipmentName;
                  //启动语音
                  this.startOrderSrcUrl = newOrder;
                  let au = document.getElementById("audio1");
                  au.currentTime = 0;
                  au.play();
                  if (this.rengongjiedan >= 7) {
                    this.btnShow1 = false;
                    this.startPaidanFn();
                  }
                  this.rengongjiedan = this.rengongjiedan + 1;
                } else {
                  if (this.paidanFlag == 0) {
                    this.rengongjiedan = this.rengongjiedan + 1;
                    this.paidanFlag = res.data.content[0].flag;
                    this.showDe = true;
                    this.btnShow1 = true;
                    this.btnShow2 = false;
                    this.btnShow3 = false;
                    this.btnShow4 = false;
                    this.carDestination = res.data.content[0].destination;
                    this.dingDanId = res.data.content[0].id;
                    this.dingdanodd = res.data.content[0].odd;
                    this.equipmentName = resSon1.data.content[0].equipmentName;
                    //启动语音
                    this.startOrderSrcUrl = newOrder;
                    let au = document.getElementById("audio1");
                    au.currentTime = 0;
                    au.play();
                  } else {
                    if (this.zuizhongpaidanFlag == 0) {
                      this.paidanFlag = res.data.content[0].flag;
                      this.showDe = true;
                      this.btnShow1 = true;
                      this.btnShow2 = false;
                      this.btnShow3 = false;
                      this.btnShow4 = false;
                      this.carDestination = res.data.content[0].destination;
                      this.dingDanId = res.data.content[0].id;
                      this.dingdanodd = res.data.content[0].odd;
                      this.equipmentName =
                          resSon1.data.content[0].equipmentName;
                      //启动语音
                      this.startOrderSrcUrl = newOrder;
                      let au = document.getElementById("audio1");
                      au.currentTime = 0;
                      au.play();
                      if (this.rengongjiedan >= 7) {
                        this.btnShow1 = false;
                        this.startPaidanFn();
                      }
                      this.rengongjiedan = this.rengongjiedan + 1;
                    }
                  }
                }
                //获取车辆坐标计算距离并返回给后台
                httpGet(carRealTimeLocationQuery2, {
                  name: resSon1.data.content[0].equipmentName,
                }).then((res2) => {
                  if (res2.data) {
                    if (this.oldxy.lat == 0 || this.oldxy.lng == 0) {
                      this.oldxy.lat = res2.data.location.y;
                      this.oldxy.lng = res2.data.location.x;
                    } else {
                      let distance1 =
                          this.getDistance(
                              this.oldxy.lat,
                              this.oldxy.lng,
                              res2.data.location.y,
                              res2.data.location.x
                          ) + parseFloat(res.data.content[0].mil);
                      putForJson(dingDanBiaoCaoZuo, {
                        id: res.data.content[0].id,
                        mil: distance1,
                      }).then((res) => {
                      });
                      this.$nextTick(() => {
                        this.oldxy.lat = res2.data.location.y;
                        this.oldxy.lng = res2.data.location.x;
                      });
                    }
                  }
                });
              }
            });
          }
        });
      } else {
        //如果zhinengpaidanBoolan为false，获取人工的调度
        this.orderClass = "";
        httpGet(dingDanBiaoCaoZuo, {
          sort: "createTime,desc",
          size: 1,
          carNo: this.carnumber,
          flag: 1,
        }).then((res) => {
          if (res.data.content.length == 0) {
            this.showDe = false;
            this.btnShow1 = false;
            this.btnShow2 = false;
            this.btnShow3 = false;
            this.btnShow4 = false;
          } else {
            //有人工调度就删除智能调度单子
            httpGet(dingDanBiaoCaoZuo, {
              sort: "createTime,desc",
              carNo: this.carnumber,
              flag: 0,
            }).then((resDel) => {
              if (resDel.code == 200) {
                resDel.data.content.forEach((itemDel, indexDel) => {
                  httpDelForJson(dingDanBiaoCaoZuo, [
                    itemDel.id,
                    this.carnumber,
                    item.odd,
                  ]).then((resDelSon) => {
                  });
                });
              }
            });
            //有人工调度下面展示操作
            httpGet(vehicleInformationQuery, {
              number: this.carnumber,
              size: 1,
            }).then((resSon1) => {
              if (resSon1.code == 200) {
                this.showDe = true;
                this.carDestination = res.data.content[0].destination;
                this.dingDanId = res.data.content[0].id;
                this.dingdanodd = res.data.content[0].odd;
                this.equipmentName = resSon1.data.content[0].equipmentName;
                this.btnShow3 = true;
                this.btnShow4 = true;
                if (resSon1.data.content[0].workStatus == 0) {
                  this.paidanFlag = res.data.content[0].flag;
                  this.showDe = true;
                  this.btnShow1 = true;
                  this.btnShow2 = false;
                  this.btnShow3 = false;
                  this.btnShow4 = false;
                  this.carDestination = res.data.content[0].destination;
                  this.dingDanId = res.data.content[0].id;
                  this.dingdanodd = res.data.content[0].odd;
                  this.equipmentName = resSon1.data.content[0].equipmentName;
                  //启动语音
                  this.startOrderSrcUrl = newOrder;
                  let au = document.getElementById("audio1");
                  au.currentTime = 0;
                  au.play();
                  if (this.rengongjiedan >= 7) {
                    this.btnShow1 = false;
                    this.startPaidanFn();
                  }
                  this.rengongjiedan = this.rengongjiedan + 1;
                } else {
                  if (this.paidanFlag == 0) {
                    this.rengongjiedan = this.rengongjiedan + 1;
                    this.paidanFlag = res.data.content[0].flag;
                    this.showDe = true;
                    this.btnShow1 = true;
                    this.btnShow2 = false;
                    this.btnShow3 = false;
                    this.btnShow4 = false;
                    this.carDestination = res.data.content[0].destination;
                    this.dingDanId = res.data.content[0].id;
                    this.dingdanodd = res.data.content[0].odd;
                    this.equipmentName = resSon1.data.content[0].equipmentName;
                    //启动语音
                    this.startOrderSrcUrl = newOrder;
                    let au = document.getElementById("audio1");
                    au.currentTime = 0;
                    au.play();
                  } else {
                    if (this.zuizhongpaidanFlag == 0) {
                      this.paidanFlag = res.data.content[0].flag;
                      this.showDe = true;
                      this.btnShow1 = true;
                      this.btnShow2 = false;
                      this.btnShow3 = false;
                      this.btnShow4 = false;
                      this.carDestination = res.data.content[0].destination;
                      this.dingDanId = res.data.content[0].id;
                      this.dingdanodd = res.data.content[0].odd;
                      this.equipmentName =
                          resSon1.data.content[0].equipmentName;
                      //启动语音
                      this.startOrderSrcUrl = newOrder;
                      let au = document.getElementById("audio1");
                      au.currentTime = 0;
                      au.play();
                      if (this.rengongjiedan >= 7) {
                        this.btnShow1 = false;
                        this.startPaidanFn();
                      }
                      this.rengongjiedan = this.rengongjiedan + 1;
                    }
                  }
                }
                //获取车辆坐标计算距离并返回给后台
                httpGet(carRealTimeLocationQuery2, {
                  name: resSon1.data.content[0].equipmentName,
                }).then((res2) => {
                  if (res2.data) {
                    if (this.oldxy.lat == 0 || this.oldxy.lng == 0) {
                      this.oldxy.lat = res2.data.location.y;
                      this.oldxy.lng = res2.data.location.x;
                    } else {
                      let distance1 = this.getDistance(
                              this.oldxy.lat,
                              this.oldxy.lng,
                              res2.data.location.y,
                              res2.data.location.x
                          ) + parseFloat(res.data.content[0].mil);
                      putForJson(dingDanBiaoCaoZuo, {
                        id: res.data.content[0].id,
                        mil: distance1,
                      }).then((res) => {});
                      this.$nextTick(() => {
                        this.oldxy.lat = res2.data.location.y;
                        this.oldxy.lng = res2.data.location.x;
                      });
                    }
                  }
                });
              }
            });
          }
        });
      }
    }, 5000);
  },
  methods: {
    loadData(carnumber) {
      this.carnumber = carnumber;
      this.orderClass = "";
      this.$nextTick(() => {
        //如果zhinengpaidanBoolan为true，获取人工和智能一起的调度
        if (this.zhinengpaidanBoolan) {
          //先查人工调度
          httpGet(dingDanBiaoCaoZuo, {
            sort: "createTime,desc",
            size: 1,
            carNo: this.carnumber,
            flag: 1,
          }).then((res) => {
            //如果没有就获取智能调度

            if (res.data.content.length == 0) {
              httpGet(dingDanBiaoCaoZuo, {
                sort: "createTime,desc",
                size: 1,
                carNo: this.carnumber,
              }).then((res_1) => {
                console.log(res_1, "res_1");
                if (res_1.data.content.length == 0) {
                  this.showDe = false;
                  this.btnShow1 = false;
                  this.btnShow2 = false;
                  this.btnShow3 = false;
                } else {
                  httpGet(vehicleInformationQuery, {
                    number: this.carnumber,
                    size: 1,
                  }).then((resSon1) => {
                    if (resSon1.code == 200) {
                      if (resSon1.data.content[0].workStatus == 0) {
                        this.paidanFlag = res_1.data.content[0].flag;
                        if (res_1.data.content[0].orderClass == 0) {
                          this.showDe = true;
                          this.btnShow1 = true;
                          this.btnShow2 = false;
                          this.btnShow3 = false;
                          this.carDestination =
                            res_1.data.content[0].destination;
                          this.dingDanId = res_1.data.content[0].id;
                          this.dingdanodd = res_1.data.content[0].odd;
                          this.equipmentName =
                            resSon1.data.content[0].equipmentName;
                          this.orderClass = "装车";
                        } else {
                          this.showDe = true;
                          this.btnShow1 = false;
                          this.btnShow2 = true;
                          this.btnShow3 = false;
                          this.carDestination =
                            res_1.data.content[0].destination;
                          this.dingDanId = res_1.data.content[0].id;
                          this.dingdanodd = res_1.data.content[0].odd;
                          this.equipmentName =
                            resSon1.data.content[0].equipmentName;
                          this.orderClass = "卸车";
                        }
                      }
                      //获取车辆坐标计算距离并返回给后台
                      httpGet(carRealTimeLocationQuery2, {
                        name: resSon1.data.content[0].equipmentName,
                      }).then((res2) => {
                        if (res2.data) {
                          if (this.oldxy.lat == 0 || this.oldxy.lng == 0) {
                            this.oldxy.lat = res2.data.location.y;
                            this.oldxy.lng = res2.data.location.x;
                          } else {
                            let distance1 =
                              this.getDistance(
                                this.oldxy.lat,
                                this.oldxy.lng,
                                res2.data.location.y,
                                res2.data.location.x
                              ) + parseFloat(res_1.data.content[0].mil);
                            putForJson(dingDanBiaoCaoZuo, {
                              id: res_1.data.content[0].id,
                              mil: distance1,
                            }).then((res) => {});
                            this.$nextTick(() => {
                              this.oldxy.lat = res2.data.location.y;
                              this.oldxy.lng = res2.data.location.x;
                            });
                          }
                        }
                      });
                    }
                  });
                }
              });
            } else {
              //如果有人工调度
              //有人工调度就删除智能调度单子
              httpGet(dingDanBiaoCaoZuo, {
                sort: "createTime,desc",
                carNo: this.carnumber,
                flag: 0,
              }).then((resDel) => {
                if (resDel.code == 200) {
                  resDel.data.content.forEach((itemDel, indexDel) => {
                    httpDelForJson(dingDanBiaoCaoZuo, [
                      itemDel.id,
                      this.carnumber,
                      item.odd,
                    ]).then((resDelSon) => {});
                  });
                }
              });
              //有人工调度下面展示操作
              httpGet(vehicleInformationQuery, {
                number: this.carnumber,
                size: 1,
              }).then((resSon1) => {
                if (resSon1.code == 200) {
                  if (resSon1.data.content[0].workStatus == 0) {
                    this.paidanFlag = res.data.content[0].flag;
                    this.showDe = true;
                    this.btnShow1 = true;
                    this.btnShow2 = false;
                    this.btnShow3 = false;
                    this.carDestination = res.data.content[0].destination;
                    this.dingDanId = res.data.content[0].id;
                    this.dingdanodd = res.data.content[0].odd;
                    this.equipmentName = resSon1.data.content[0].equipmentName;
                  }
                  //获取车辆坐标计算距离并返回给后台
                  httpGet(carRealTimeLocationQuery2, {
                    name: resSon1.data.content[0].equipmentName,
                  }).then((res2) => {
                    if (res2.data) {
                      if (this.oldxy.lat == 0 || this.oldxy.lng == 0) {
                        this.oldxy.lat = res2.data.location.y;
                        this.oldxy.lng = res2.data.location.x;
                      } else {
                        let distance1 =
                          this.getDistance(
                            this.oldxy.lat,
                            this.oldxy.lng,
                            res2.data.location.y,
                            res2.data.location.x
                          ) + parseFloat(res.data.content[0].mil);
                        putForJson(dingDanBiaoCaoZuo, {
                          id: res.data.content[0].id,
                          mil: distance1,
                        }).then((res) => {});
                        this.$nextTick(() => {
                          this.oldxy.lat = res2.data.location.y;
                          this.oldxy.lng = res2.data.location.x;
                        });
                      }
                    }
                  });
                }
              });
            }
          });
        } else {
          //如果zhinengpaidanBoolan为false，获取人工的调度
          httpGet(dingDanBiaoCaoZuo, {
            sort: "createTime,desc",
            size: 1,
            carNo: this.carnumber,
            flag: 1,
          }).then((res) => {
            if (res.data.content.length == 0) {
              this.showDe = false;
              this.btnShow1 = false;
              this.btnShow2 = false;
              this.btnShow3 = false;
            } else {
              //有人工调度就删除智能调度单子
              httpGet(dingDanBiaoCaoZuo, {
                sort: "createTime,desc",
                carNo: this.carnumber,
                flag: 0,
              }).then((resDel) => {
                if (resDel.code == 200) {
                  resDel.data.content.forEach((itemDel, indexDel) => {
                    httpDelForJson(dingDanBiaoCaoZuo, [
                      itemDel.id,
                      this.carnumber,
                      item.odd,
                    ]).then((resDelSon) => {});
                  });
                }
              });
              //有人工调度下面操作
              httpGet(vehicleInformationQuery, {
                number: this.carnumber,
                size: 1,
              }).then((resSon1) => {
                if (resSon1.code == 200) {
                  if (resSon1.data.content[0].workStatus == 0) {
                    this.paidanFlag = res.data.content[0].flag;
                    this.showDe = true;
                    this.btnShow1 = true;
                    this.btnShow2 = false;
                    this.btnShow3 = false;
                    this.carDestination = res.data.content[0].destination;
                    this.dingDanId = res.data.content[0].id;
                    this.dingdanodd = res.data.content[0].odd;
                    this.equipmentName = resSon1.data.content[0].equipmentName;
                  }
                  //获取车辆坐标计算距离并返回给后台
                  httpGet(carRealTimeLocationQuery2, {
                    name: resSon1.data.content[0].equipmentName,
                  }).then((res2) => {
                    if (res2.data) {
                      if (this.oldxy.lat == 0 || this.oldxy.lng == 0) {
                        this.oldxy.lat = res2.data.location.y;
                        this.oldxy.lng = res2.data.location.x;
                      } else {
                        let distance1 =
                          this.getDistance(
                            this.oldxy.lat,
                            this.oldxy.lng,
                            res2.data.location.y,
                            res2.data.location.x
                          ) + parseFloat(res.data.content[0].mil);
                        putForJson(dingDanBiaoCaoZuo, {
                          id: res.data.content[0].id,
                          mil: distance1,
                        }).then((res) => {});
                        this.$nextTick(() => {
                          this.oldxy.lat = res2.data.location.y;
                          this.oldxy.lng = res2.data.location.x;
                        });
                      }
                    }
                  });
                }
              });
            }
          });
        }
      });
    },
    //关闭清除定时器
    dingshiqiCloseFn() {
      if (this.sonTimer1) {
        //如果定时器还在运行 或者直接关闭，不用判断
        clearInterval(this.sonTimer1); //关闭
      }
    },
    //开始派单
    startPaidanFn() {
      this.btnShow1 = false;
      this.btnShow4 = true;
      this.zhinengjiedan = 0;
      this.rengongjiedan = 0;
      this.xiecheyuyinTimer = 0;
      this.$notify({
        title: "已开始派单！",
        type: "success",
        duration: 2500,
      });
      if (this.paidanFlag == 0) {
        this.zuizhongpaidanFlag = 0;
        httpGet(vehicleInformationQuery, { number: this.carnumber }).then(
          (res) => {
            if (res.code == 200) {
              if (this.paidanFlag == 0) {
                putForJson(vehicleInformationUpdate, {
                  id: res.data.content[0].id,
                  workStatus: 1,
                  weightStatus: 2,
                  odo: 1, //智能
                  status: 0,
                }).then((res) => {});
              } else if (this.paidanFlag == 1) {
                putForJson(vehicleInformationUpdate, {
                  id: res.data.content[0].id,
                  workStatus: 1,
                  weightStatus: 2,
                  odo: 2, //人工
                  status: 0,
                }).then((res) => {});
              }
            }
          }
        );
        // httpGet(manualSchedulingQuery,{sort:'createTime,desc',size:1,carNo:this.carnumber}).then((res) => {
        //     if(res.code == 200){
        //         if(res.data.totalElements == 0){

        //         }else{
        //             putForJson(manualSchedulingQuery,{id:res.data.content[0].id,status:1}).then((res) => {});
        //         }
        //     }
        // });
      } else if (this.paidanFlag == 1) {
        this.zuizhongpaidanFlag = 1;
        this.btnShow3 = true;
        httpGet(vehicleInformationQuery, { number: this.carnumber }).then(
          (res) => {
            if (res.code == 200) {
              if (this.paidanFlag == 0) {
                putForJson(vehicleInformationUpdate, {
                  id: res.data.content[0].id,
                  workStatus: 1,
                  weightStatus: 2,
                  odo: 1,
                  status: 0,
                }).then((res) => {});
              } else if (this.paidanFlag == 1) {
                putForJson(vehicleInformationUpdate, {
                  id: res.data.content[0].id,
                  workStatus: 1,
                  weightStatus: 2,
                  odo: 2,
                  status: 0,
                }).then((res) => {});
              }
            }
          }
        );
        httpGet(manualSchedulingQuery, {
          sort: "createTime,desc",
          size: 1,
          carNo: this.carnumber,
        }).then((res) => {
          if (res.code == 200) {
            if (res.data.totalElements == 0) {
            } else {
              putForJson(manualSchedulingQuery, {
                id: res.data.content[0].id,
                status: 1,
              }).then((res) => {});
            }
          }
        });
      }
    },
    //拒绝派单
    refusePaidanFn() {
      this.btnShow1 = false;
      this.btnShow4 = false;
      this.showDe = false;
      this.paidanFlag = 0;
      this.zuizhongpaidanFlag = 0;
      this.zhinengjiedan = 0;
      this.rengongjiedan = 0;
      this.xiecheyuyinTimer = 0;
      this.$notify({
        title: "已拒绝派单！",
        type: "success",
        duration: 2500,
      });
      httpGet(vehicleInformationQuery, { number: this.carnumber }).then(
        (res) => {
          if (res.code == 200) {
            putForJson(vehicleInformationUpdate, {
              id: res.data.content[0].id,
              oddStatus: 1,
              workStatus: 0,
              odo: 3,
            }).then((res) => {});
          }
        }
      );
      httpGet(manualSchedulingQuery, {
        sort: "createTime,desc",
        size: 1,
        carNo: this.carnumber,
      }).then((res) => {
        if (res.code == 200) {
          if (res.data.totalElements == 0) {
          } else {
            putForJson(manualSchedulingQuery, {
              id: res.data.content[0].id,
              status: 0,
            }).then((res) => {});
          }
        }
      });
      httpDelForJson(dingDanBiaoCaoZuo, [
        this.dingDanId,
        this.carnumber,
        this.dingdanodd,
      ]).then((res) => {});
      this.$nextTick(() => {
        this.oldxy.lat = 0;
        this.oldxy.lng = 0;
      });
    },
    //卸车
    finishPaidanFn() {
      //查询指定目的地围栏以及判断该车是否在围栏里
      httpGet(screenMapSetUpQuery, {
        size: 9999,
        name: this.carDestination,
      }).then((resSon2) => {
        if (resSon2) {
          let weilanArr1 = [];
          resSon2[this.carDestination].forEach((item, index) => {
            let weilanobj1 = [];
            weilanobj1.push(parseFloat(item.lon));
            weilanobj1.push(parseFloat(item.lat));
            weilanArr1.push(weilanobj1);
          });
          httpGet(carRealTimeLocationQuery2, { name: this.equipmentName }).then(
            (resSon3) => {
              if (resSon3.code == 200) {
                let resSon3Obj1 = [];
                resSon3Obj1.push(resSon3.data.location.x);
                resSon3Obj1.push(resSon3.data.location.y);
                this.xiecheBtnAble = this.isPointInPolygon(
                  resSon3Obj1,
                  weilanArr1
                );

                if (!this.xiecheBtnAble) {
                  this.$notify({
                    title: "未到卸车区域，不可卸车！",
                    type: "warning",
                    duration: 2500,
                  });
                } else {
                  this.btnShow2 = false;
                  this.showDe = false;
                  this.btnShow4 = false;
                  this.paidanFlag = 0;
                  this.zuizhongpaidanFlag = 0;
                  this.zhinengjiedan = 0;
                  this.rengongjiedan = 0;
                  this.xiecheyuyinTimer = 0;
                  this.$nextTick(() => {
                    httpGet(vehicleInformationQuery, {
                      number: this.carnumber,
                    }).then((res) => {
                      if (res.code == 200) {
                        putForJson(vehicleInformationUpdate, {
                          id: res.data.content[0].id,
                          workStatus: 0,
                          weightStatus: 0,
                          oddStatus: 1,
                          odo: 3,
                          status: 0,
                        }).then((res) => {});
                      }
                    });
                    httpGet(manualSchedulingQuery, {
                      sort: "createTime,desc",
                      size: 1,
                      carNo: this.carnumber,
                    }).then((res) => {
                      if (res.code == 200) {
                        if (res.data.totalElements == 0) {
                        } else {
                          putForJson(manualSchedulingQuery, {
                            id: res.data.content[0].id,
                            status: 0,
                          }).then((res) => {});
                        }
                      }
                    });
                    httpDelForJson(dingDanBiaoCaoZuo, [
                      this.dingDanId,
                      this.carnumber,
                      this.dingdanodd,
                    ]).then((res) => {
                      this.$parent.zhixinglujing(
                        false,
                        this.carnumber,
                        this.carDestination
                      );
                    });
                  });
                  this.$nextTick(() => {
                    this.oldxy.lat = 0;
                    this.oldxy.lng = 0;
                    this.$notify({
                      title: "卸车成功！",
                      type: "success",
                      duration: 2500,
                    });
                  });
                }
              }
            }
          );
        }
      });
    },
    //车辆自主完成派单
    finishPaidanFn1() {
      //查询指定目的地围栏以及判断该车是否在围栏里
      let carDestinationText1 = this.carDestination;
      let carDestinationText2 = carDestinationText1.split("/")[0];
      httpGet(screenMapSetUpQuery, {
        size: 9999,
        name: carDestinationText2,
      }).then((resSon2) => {
        if (resSon2) {
          let weilanArr1 = [];
          resSon2[carDestinationText2].forEach((item, index) => {
            let weilanobj1 = [];
            weilanobj1.push(parseFloat(item.lon));
            weilanobj1.push(parseFloat(item.lat));
            weilanArr1.push(weilanobj1);
          });
          httpGet(carRealTimeLocationQuery2, { name: this.equipmentName }).then(
            (resSon3) => {
              if (resSon3.code == 200) {
                let resSon3Obj1 = [];
                resSon3Obj1.push(resSon3.data.location.x);
                resSon3Obj1.push(resSon3.data.location.y);

                if (!this.isPointInPolygon(resSon3Obj1, weilanArr1)) {
                  this.$notify({
                    title: "未到调度区域，不可完成派单！",
                    type: "warning",
                    duration: 2500,
                  });
                } else {
                  this.btnShow3 = false;
                  this.btnShow4 = false;
                  this.showDe = false;
                  this.paidanFlag = 0;
                  this.zuizhongpaidanFlag = 0;
                  this.zhinengjiedan = 0;
                  this.rengongjiedan = 0;
                  this.xiecheyuyinTimer = 0;
                  this.$nextTick(() => {
                    httpGet(vehicleInformationQuery, {
                      number: this.carnumber,
                    }).then((res) => {
                      if (res.code == 200) {
                        putForJson(vehicleInformationUpdate, {
                          id: res.data.content[0].id,
                          workStatus: 0,
                          weightStatus: 0,
                          oddStatus: 1,
                          odo: 3,
                          status: 0,
                        }).then((res) => {});
                      }
                    });
                    httpGet(manualSchedulingQuery, {
                      sort: "createTime,desc",
                      size: 1,
                      carNo: this.carnumber,
                    }).then((res) => {
                      if (res.code == 200) {
                        if (res.data.totalElements == 0) {
                        } else {
                          putForJson(manualSchedulingQuery, {
                            id: res.data.content[0].id,
                            status: 0,
                          }).then((res) => {});
                        }
                      }
                    });
                    httpDelForJson(dingDanBiaoCaoZuo, [
                      this.dingDanId,
                      this.carnumber,
                      this.dingdanodd,
                    ]).then((res) => {
                      this.$parent.zhixinglujing(
                        false,
                        this.carnumber,
                        this.carDestination
                      );
                    });
                  });
                  this.$nextTick(() => {
                    this.oldxy.lat = 0;
                    this.oldxy.lng = 0;
                    this.$notify({
                      title: "完成派单！",
                      type: "success",
                      duration: 2500,
                    });
                  });
                }
              }
            }
          );
        }
      });
    },
    //导航开启
    navigation() {
      this.$parent.zhixinglujing(true, this.carnumber, this.carDestination);
    },
    //获取当前时间
    currentTime() {
      var date = new Date();
      var year = date.getFullYear(); //年 ,从 Date 对象以四位数字返回年份
      var month = date.getMonth() + 1; //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
      var day = date.getDate(); //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
      var hours = date.getHours(); //小时 ,返回 Date 对象的小时 (0 ~ 23)
      var minutes = date.getMinutes(); //分钟 ,返回 Date 对象的分钟 (0 ~ 59)
      var seconds = date.getSeconds(); //秒 ,返回 Date 对象的秒数 (0 ~ 59)
      //修改月份格式
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      //修改日期格式
      if (day >= 0 && day <= 9) {
        day = "0" + day;
      }
      //修改小时格式
      if (hours >= 0 && hours <= 9) {
        hours = "0" + hours;
      }
      //修改分钟格式
      if (minutes >= 0 && minutes <= 9) {
        minutes = "0" + minutes;
      }
      //修改秒格式
      if (seconds >= 0 && seconds <= 9) {
        seconds = "0" + seconds;
      }
      //获取当前系统时间  格式(yyyy-mm-dd hh:mm:ss)
      let currentFormatDate =
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hours +
        ":" +
        minutes +
        ":" +
        seconds;
      return currentFormatDate;
    },
    //判断卸车是车是否到达了卸区
    isPointInPolygon(checkPoint, polygonPoints) {
      var counter = 0;
      var i;
      var xinters;
      var p1, p2;
      var pointCount = polygonPoints.length;
      p1 = polygonPoints[0];

      for (i = 1; i <= pointCount; i++) {
        p2 = polygonPoints[i % pointCount];
        if (
          checkPoint[0] > Math.min(p1[0], p2[0]) &&
          checkPoint[0] <= Math.max(p1[0], p2[0])
        ) {
          if (checkPoint[1] <= Math.max(p1[1], p2[1])) {
            if (p1[0] != p2[0]) {
              xinters =
                ((checkPoint[0] - p1[0]) * (p2[1] - p1[1])) / (p2[0] - p1[0]) +
                p1[1];
              if (p1[1] == p2[1] || checkPoint[1] <= xinters) {
                counter++;
              }
            }
          }
        }
        p1 = p2;
      }
      if (counter % 2 == 0) {
        return false;
      } else {
        return true;
      }
    },
    //根据两个经纬度计算距离
    getDistance(lat1, lng1, lat2, lng2) {
      var radLat1 = (lat1 * Math.PI) / 180.0;
      var radLat2 = (lat2 * Math.PI) / 180.0;
      var a = radLat1 - radLat2;
      var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
      var s =
        2 *
        Math.asin(
          Math.sqrt(
            Math.pow(Math.sin(a / 2), 2) +
              Math.cos(radLat1) *
                Math.cos(radLat2) *
                Math.pow(Math.sin(b / 2), 2)
          )
        );
      s = s * 6378.137; // EARTH_RADIUS;
      s = Math.round(s * 10000) / 10000;
      return s;
    },
    //更改该车是否可接受智能派单
    zhinengpaidanFn(boolan) {
      console.log(boolan, "zhinengpaidanBoolan");
      this.zhinengpaidanBoolan = boolan;
      //智能调度订单自动接单属性
      this.zhinengjiedan = 0;
      //人工调度订单自动接单属性
      this.rengongjiedan = 0;
      //卸车语音计时
      this.xiecheyuyinTimer = 0;
    },
  },
  beforeDestroy() {
    // if(this.sonTimer1) { //如果定时器还在运行 或者直接关闭，不用判断
    //     clearInterval(this.sonTimer1); //关闭
    // }
  },
};
</script>

<style scoped>
@media screen and (max-width: 901px) {
  .orderText1_img {
    color: #00ffff;
    font-size: 16px;
  }
  .orderViews {
    display: flex;
    z-index: 2;
    position: absolute;
    top: 8vh;
    left: 20vw;
  }
  .orderText1 {
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 45vw;
    height: 7vh;
    border-radius: 5px;
    background-color: rgba(26, 39, 83, 0.9);
    border: 1px solid lightskyblue;
    font-size: 13px;
  }
  .orderText1_1 {
    background-image: -webkit-linear-gradient(bottom, #02a2f1, #fafeff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 600;
  }
  .orderText2 {
    margin-left: 1vw;
    width: 10vw;
    line-height: 7vh;
    text-align: center;
    height: 7vh;
    border-radius: 5px;
    background-color: rgba(26, 39, 83, 0.9);
    border: 1px solid lightskyblue;
    font-size: 13px;
    font-weight: 600;
    color: lightskyblue;
    cursor: pointer;
  }
}

@media screen and (min-width: 901px) {
  .orderText1_img {
    color: #00ffff;
    font-size: 28px;
  }
  .orderViews {
    display: flex;
    z-index: 2;
    position: absolute;
    top: 8vh;
    left: 20vw;
  }
  .orderText1 {
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 45vw;
    height: 7vh;
    border-radius: 5px;
    background-color: rgba(26, 39, 83, 0.9);
    border: 1px solid lightskyblue;
    font-size: 20px;
  }
  .orderText1_1 {
    background-image: -webkit-linear-gradient(bottom, #02a2f1, #fafeff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 600;
  }
  .orderText2 {
    margin-left: 20px;
    width: 10vw;
    line-height: 7vh;
    text-align: center;
    height: 7vh;
    border-radius: 5px;
    background-color: rgba(26, 39, 83, 0.9);
    border: 1px solid lightskyblue;
    font-size: 22px;
    font-weight: 600;
    color: lightskyblue;
    cursor: pointer;
  }
}
</style>