// import API from "../../../../../api";
import axios from 'axios';
import { Utils } from "../../../../../lib/cesium";
import { zoomTo } from "./zoomTo";
import pngAisu from '../assets/images/aisu.png';
import pngAier from '../assets/images/aier.png';
import pngAiing from '../assets/images/aiing.png';

// 识别类型 2 车牌（公安） 3:人流 4:火焰烟雾 5:漏油识别6.裸土识别8.车牌（共达地）
let urlList = {
  2: "http://183.62.225.251:9090/api/inflet/v1/tasks/e01d1d01-52e2-4883-a5de-0ae268764db0/predict",
  3: "http://183.62.225.251:9090/api/inflet/v1/tasks/18493235-4dd0-4f54-ab55-c1856ca7e3a5/predict",
  4: "http://183.62.225.251:9090/api/inflet/v1/tasks/fca2eb65-8b99-4109-9f9e-a9f7fd06ac1f/predict",
  5: "http://183.62.225.251:9002/detect/image",
  6: "http://183.62.225.251:9090/api/inflet/v1/tasks/05a9d657-8339-4575-bced-04b60b74c690/predict",
  8: "http://183.62.225.251:9090/api/inflet/v1/tasks/e01d1d01-52e2-4883-a5de-0ae268764db0/predict",
}
export default {
  // 人脸车牌识别
  async getcanvasFaceCar(command, deviceHardId, id) {
    /**
     * command人脸or车牌，a人脸，b车牌
     * id代表设备id
     * deviceHardId代表无人机序列号
     */
    let blob = this.screenShot();
    let fd = new FormData();
    fd.append("uploadFiles", blob, `下载.jpeg`);
    let res = await API.MAPMANAGE.fileUpload(fd);
    if (command == "a") {
      this.aiuse(res[0].storage, deviceHardId, id);
    } else {
      this.plate(res[0].storage, deviceHardId, id);
    }
  },
  getPopup(flag, val) {
    let scene = viewer.scene
    this.aiPopup = new Cesium.BillboardCollection({
      scene,
      show: true,
    });
    this.aiPopup.add({
      position: Utils.transformWGS842Cartesian({
        lng: Number(this.uavData.locationCoordinate3D.longitude),
        lat: Number(this.uavData.locationCoordinate3D.latitude),
        alt: Number(this.uavData.locationCoordinate3D.altitude),
      }),
      image: flag ? pngAisu : pngAier,
      scale: 1,
      width: 54,
      height: 89,
      verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
      horizontalOrigin: Cesium.VerticalOrigin.CENTER,
      id: 258,//字444444
      distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
        0,
        2.2e5
      ),
      scaleByDistance: new Cesium.NearFarScalar(2.5e4, 0.7, 2.2e7, 0),
      disableDepthTestDistance: Number.POSITIVE_INFINITY,
    });
    scene.primitives.add(this.aiPopup);
  },
  // 人脸
  async aiuseV2(url, deviceHardId, single, aiData) {
    let data = {
      imageUrl: url,
      deviceHardId: deviceHardId,
    };
    if (aiData) {
      //区域识别
      let res = await API.AIUSE.aiphoto(data);
      if (res.code == 200) {


        let datapid = {
          aiFacePid: res.pid,
        };
        let resFace = await API.AIUSE.getFaceuavvideoMsg(datapid);
        for (let i = 0; i < resFace.length; i++) {
          if (resFace[i].idCard == aiData.faceData.id) {
            this.$emit("fn", {
              data: "POSITION",
              type: 513
            });
            // this.$emit("AIDialog", true, "当前位置识别到人");
            this.getPopup(true)
            this.pid = res.pid;
            this.faceAiShow = true;

          }
        }
      } else {
        if (single) {
          this.getPopup(false)
        }
      }
    } else {
      let res = await API.AIUSE.aiphoto(data);
      if (res.code == 200) {
        this.$emit("fn", {
          data: "POSITION",
          type: 513
        });
        this.$emit("AIDialog", true, "当前位置识别到人");
        this.getPopup(true)

        this.pid = res.pid;
        this.faceAiShow = true;
      } else {
        if (single) {
          this.getPopup(false)

        }
      }
    }
  },
  // 车牌
  async plateV2(url, deviceHardId, single, aiData) {
    let data = {
      imgUrl: url,
      deviceHardId: deviceHardId,
    };
    if (aiData) {
      //区域识别
      let res = await API.AIUSE.palteId(data);
      if (res.code == 200) {
        res.data.forEach(val => {
          if (val.plateNum == aiData.carData.carnum) {
            this.$emit("fn", {
              data: "POSITION",
              type: 513
            });
            // this.$emit("AIDialog", true, "当前位置识别到车辆");
            this.getPopup(true)
            this.carList = res.data;
            this.carAiShow = true;
          }
        })
      } else {
        if (single) {
          this.getPopup(false)
        }
      }
    } else {

      let res = await API.AIUSE.palteId(data);
      if (res.code == 200) {
        this.$emit("fn", {
          data: "POSITION",
          type: 513
        });
        this.$emit("AIDialog", true, "当前位置识别到车辆");
        this.getPopup(true)
        this.carList = res.data;
        this.carAiShow = true;
      } else {
        if (single) {
          this.getPopup(false)
        }
      }
    }
  },
  //人流识别
  async flowV2(url, deviceHardId, single) {
    let data = {
      imageUrl: url,
      deviceHardId: deviceHardId,
    };
    let res2 = await API.FCKERNEL.crowdDensity(data);
    if (res2 && res2.total) {
      this.$emit("fn", {
        data: "POSITION",
        type: 513
      });
      this.$emit("AIDialog", true, "当前位置识别到人群");
      this.getPopup(true)
      this.trafficShow = true;
      this.trafficData = res2;
    } else {
      if (single) {
        this.getPopup(false)

      }
    }
  },
  //ai识别
  async aiIdentify(aiData, flag, single) {
    let {
      mqttType, //发送数据类型 true 代表无人机 false 代表机库
      deviceHardId,
      id,
      aiType, // 识别类型 2 车牌（公安） 3:人流 4:火焰烟雾 5:漏油识别6.裸土识别8.车牌（共达地）
    } = aiData
    let blob = this.screenShot();
    let data = {
      image: null,
    };
    if (aiType > 1 && aiType != 5 && aiType != 2 && aiType != 10) {
      blobToBase64(blob, async (base64DataUrl) => {
        data.image = base64DataUrl;
        let res = await axios.post(
          urlList[aiType],
          data
        );
        if (res.data.data.targets && res.data.data.targets.length > 0) {
          this.timerList.forEach(v => {
            clearInterval(v)
          })
          this.timerList = []
          if (flag) {
            if (aiType != 10) {
              this.$message.success("识别成功！")
            }
          } else {
            if (this.uav.network == 2) {
              this.$store.dispatch("MMCMQTT/publish", {
                topic: "PX4/OBTAIN/" + this.uav.deviceId,
                data: {
                  type: window.$mmc.$store.state.MMCMQTT.orders.无人机模式切换,
                  data: "HOLD",
                },
                callback() {
                  
                },
              });
            } else {
            }
            if (aiType == 4) {
              await this.$confirm("当前区域识别到烟雾", "提示", {
                cancelButtonText: "取消",
                confirmButtonText: "继续飞行",
                customClass: "uav_controlPane",
                showClose: false,
              })
              this.$store.dispatch("MMCMQTT/publish", {
                topic: "PX4/OBTAIN/" + this.uav.deviceId,
                data: {
                  type: window.$mmc.$store.state.MMCMQTT.orders.无人机模式切换,
                  data: "AUTO_MISSION",
                },
                callback() {
                  
                },
              });
            } else if (aiType == 5) {
              await this.$confirm("当前识别到有漏油", "提示", {
                cancelButtonText: "取消",
                confirmButtonText: "继续飞行",
                customClass: "uav_controlPane",
                showClose: false,
              })
              this.$store.dispatch("MMCMQTT/publish", {
                topic: "PX4/OBTAIN/" + this.uav.deviceId,
                data: {
                  type: window.$mmc.$store.state.MMCMQTT.orders.无人机模式切换,
                  data: "AUTO_MISSION",
                },
                callback() {
                  
                },
              });
            }
            // else if (aiType == 6) { //
            //   this.$emit("AIDialog", true, "当前区域识别到异物");
            // }
            else if (aiType == 7) { }
            this.getPopup(true)
          }
          // }
          let fd = new FormData();
          fd.append("uploadFiles", blob, `下载.jpeg`);
          let res2 = await API.MAPMANAGE.fileUpload(fd);
          let carJson = res.data.data //出鬼了，无人机识别车辆没用，机库有用，才写的
          if (aiType != 2) {
            let data2 = {
              aiType: aiType,
              imageUrl: res2[0].storage,
              deviceHardId: deviceHardId,
              jsonData: JSON.stringify(res.data.data),
            };
            let swimres = await API.FCKERNEL.insertSwimmingMonitor(data2);
          } else {
            let arr = []
            carJson.targets.forEach(val => {
              let data = {
                plate_detection: null
              }
              data.plate_detection = {
                x: val.bbox.box.left_top_x,
                y: val.bbox.box.left_top_y,
                w: val.bbox.box.right_bottom_x - val.bbox.box.left_top_x,
                h: val.bbox.box.right_bottom_y - val.bbox.box.left_top_y
              }
              data.plate_number = val.bbox.label
              data.imageUrl = res2[0].storage
              data.deviceHardId = deviceHardId
              arr.push(data)
            })
            let resCar = await API.FCKERNEL.addPlateInfoByNumber(arr);
            // console.log(Array.isArray(resCar),"dfsfaf");
            if (Array.isArray(resCar)) {
              this.carList = resCar;
              this.carAiShow = true;
            } else {
              this.$message.error(resCar)
            }
          }
          // process.env.VUE_APP_IMG_URL +
          let imgshowurl = process.env.VUE_APP_IMG_URL + res2[0].url;
          let jsondata = {
            jsonData: JSON.stringify(res.data.data)
          }
          this.$emit("imgUrl", imgshowurl, aiType, jsondata);
        } else {
          if (single) {
            this.getPopup(false)
          }
          // this.$message.error("无识别结果！")
          if (flag) {
            this.photoSelf(deviceHardId, true)
          }
        }
      });
    } else {
      if (aiType == 5) {
        let fds = new FormData();
        fds.append("image", blob, `下载.jpeg`);
        fds.append("iscount", 1);
        let res = await axios.post(
          urlList[aiType],
          fds
        );
        if (res && res.data && res.data.data && res.data.data.data.length > 0) {
          this.timerList.forEach(v => {
            clearInterval(v)
          })
          this.timerList = []
          if (flag) {
            if (aiType != 10) {
              this.$message.success("识别成功！")
            }
          } else {
            if (mqttType) {
              this.$emit("fn", {
                data: "HOLD",
                type: 513
              }, "wrj");
            } else if (!mqttType) {
              // } else {
              this.$emit("fn", {
                data: "POSITION",
                type: 513
              });
            }
            this.getPopup(true)
          }
          // }
          let fd = new FormData();
          fd.append("uploadFiles", blob, `下载.jpeg`);
          let res2 = await API.MAPMANAGE.fileUpload(fd);
          if (aiType != 2) {
            let data2 = {
              aiType: aiType,
              imageUrl: res2[0].storage,
              deviceHardId: deviceHardId,
              jsonData: JSON.stringify(res.data.data),
            };
            let swimres = await API.FCKERNEL.insertSwimmingMonitor(data2);
          }
          // process.env.VUE_APP_IMG_URL +
          let imgshowurl = process.env.VUE_APP_IMG_URL + res2[0].url;
          let jsondata = {
            jsonData: JSON.stringify(res.data.data)
          }
          this.$emit("imgUrl", imgshowurl, aiType, jsondata);
        } else {
          if (single) {
            this.getPopup(false)
          }
          // this.$message.error("无识别结果！")
          if (flag) {
            this.photoSelf(deviceHardId, true)
          }
        }
      } else if(aiType == 10){
        // let token = await API.MAPMANAGE.getToken();
        // console.log(token,"token");
        // let data = {
        //   image_type: "BASE64",
        // }
        let fd = new FormData();
        fd.append("image", blob, `下载.jpeg`);
        let res = await API.MAPMANAGE.detect(fd);
        if (res.code == 0) {
          let fd2 = new FormData();
          fd2.append("uploadFiles", blob, `下载.jpeg`);
          let res2 = await API.MAPMANAGE.fileUpload(fd2);
          let data2 = {
            aiType: aiType,
            imageUrl: res2[0].storage,
            deviceHardId: deviceHardId,
            jsonData: JSON.stringify(res.data),
          };
          let swimres = await API.FCKERNEL.insertSwimmingMonitor(data2);
          let imgshowurl = process.env.VUE_APP_IMG_URL + res2[0].url;
          let jsondata = {
            jsonData: JSON.stringify(res.data)
          }
          this.$emit("imgUrl", imgshowurl, aiType, jsondata);
        } else {
          if (flag) {
            this.photoSelf(deviceHardId, true)
          }
        }
        console.log(res,"baidures");
        // blobToBase64(blob, async (base64DataUrl) => {
        //   data.image = base64DataUrl;
        // })
      } else {
        if (aiType != 0) {
          let fd = new FormData();
          fd.append("uploadFiles", blob, `下载.jpeg`);
          let res = await API.MAPMANAGE.fileUpload(fd);
          if (aiData.spaceFlag) {
            if (aiType == 1) {
              this.aiuseV2(res[0].storage, deviceHardId, single, aiData.spaceFlag)
            }
          } else {
            if (aiType == 1) {
              this.aiuse()
            } else if (aiType == 2) {
              this.plate()
            }
          }
        } 
      }
    }

    function blobToBase64(blob, callback) {
      let reader = new FileReader();
      reader.onload = () => {
        callback(reader.result);
      };
      reader.readAsDataURL(blob);
    }
  },
  async aiIdentify_zd(aiData, flag, single) {
    let flightMode = this.$store.state.shoudong.Mstate
    if (flightMode != '航线模式') {
      return false
    }

    let {
      mqttType, //发送数据类型 true 代表无人机 false 代表鹰巢
      deviceHardId,
      id,
      aiType, // 识别类型 4 代表游泳 5:跌倒检测 6:异物检测7:火焰烟雾8:车辆朝向9:车辆类型检测 10:车道分割线
    } = aiData
    let blob = this.screenShot();
    let data = {
      image: null,
    };
    if (aiType > 3) {
      blobToBase64(blob, async (base64DataUrl) => {
        data.image = base64DataUrl;
        // console.log(aiData.aiType,"aiTypeaiTypev");
        let res = await axios.post(
          urlList[aiType],
          data
        );
        //  if(this.indexswim == 10){
        if (res.data.data.targets && res.data.data.targets.length > 0) {

          // clearInterval(this.AISetInterval);
          // this.AISetInterval = null;
          this.timerList.forEach(v => {
            clearInterval(v)
          })
          this.timerList = []
          // if (aiType == 4) {
          if (flag) {
            if (aiType != 12) {
              this.$message.success("识别成功！")
            }
          } else {
            if (mqttType) {
              this.$emit("fn", {
                data: "HOLD",
                type: 513
              }, "wrj");
            } else if(!mqttType && aiType != 6) {
              this.$emit("fn", {
                data: "POSITION",
                type: 513
              });
            }
            if (aiType == 4) {
              this.$emit("AIDialog", true, "当前识别到有人游泳");
            } else if (aiType == 5) {
              this.$emit("AIDialog", true, "当前识别到有人员跌倒");
            } else if (aiType == 6) { //
              // this.$emit("AIDialog", true, "当前区域识别到异物");
              this.$emit("continue")
              // let deviceTyoe = null
              // if (mqttType) {
              //   deviceTyoe = 0
              // } else {
              //   deviceTyoe = 1
              // }
              // // 识别到异物后机载拍照三张
              // //  stream 视频播放类型  deviceTyoe 代表无人机类型
              // let stream = this.$store.state.fckernel.stream
              // this.photoNX(id, stream, deviceTyoe, true)
              // this.photoNX(id, stream, deviceTyoe, true)
              // this.photoNX(id, stream, deviceTyoe, true)
            } else if (aiType == 7) {
              this.$emit("AIDialog", true, "当前区域识别到烟雾");
            }
            this.getPopup(true)
          }
          // }
          let fd = new FormData();
          fd.append("uploadFiles", blob, `下载.jpeg`);
          let res2 = await API.MAPMANAGE.fileUpload(fd);
          let carJson = res.data.data//出鬼了，无人机识别车辆没用，鹰巢有用，才写的
          if (aiType != 12) {
            let data2 = {
              aiType: aiType,
              imageUrl: res2[0].storage,
              deviceHardId: deviceHardId,
              jsonData: JSON.stringify(res.data.data),
            };
            let swimres = await API.FCKERNEL.insertSwimmingMonitor(data2);
          } else {
            let arr = []
            carJson.targets.forEach(val => {
              let data = {
                plate_detection: null
              }
              data.plate_detection = {
                x: val.bbox.box.left_top_x,
                y: val.bbox.box.left_top_y,
                w: val.bbox.box.right_bottom_x - val.bbox.box.left_top_x,
                h: val.bbox.box.right_bottom_y - val.bbox.box.left_top_y
              }
              data.plate_number = val.bbox.label
              data.imageUrl = res2[0].storage
              data.deviceHardId = deviceHardId
              arr.push(data)
            })
            let resCar = await API.FCKERNEL.addPlateInfoByNumber(arr);
            // console.log(Array.isArray(resCar),"dfsfaf");
            if (Array.isArray(resCar)) {
              this.carList = resCar;
              this.carAiShow = true;
            } else {
              this.$message.error(resCar)
            }
          }
          // process.env.VUE_APP_IMG_URL +
          let imgshowurl = process.env.VUE_APP_IMG_URL + res2[0].url;
          let jsondata = {
            jsonData: JSON.stringify(res.data.data)
          }
          this.$emit("imgUrl", imgshowurl, aiType, jsondata);
        } else {
          if (single) {
            this.getPopup(false)
          }
          // this.$message.error("无识别结果！")
          if (flag) {
            this.photoSelf(deviceHardId, true)
          }
        }
      });
    } else if (aiType <= 3) {
      let fd = new FormData();
      fd.append("uploadFiles", blob, `下载.jpeg`);
      let res = await API.MAPMANAGE.fileUpload(fd);
      if (aiData.spaceFlag) {
        if (aiType == 1) {
          this.aiuseV2(res[0].storage, deviceHardId, single, aiData.spaceFlag)
        } else if (aiType == 2) {
          this.plateV2(res[0].storage, deviceHardId, single, aiData.spaceFlag)
        } else if (aiType == 3) {
          this.flowV2(res[0].storage, deviceHardId, single, aiData.spaceFlag);
        }
      } else {
        if (aiType == 1) {
          this.aiuseV2(res[0].storage, deviceHardId, single)
        } else if (aiType == 2) {
          this.plateV2(res[0].storage, deviceHardId, single)
        } else if (aiType == 3) {
          this.flowV2(res[0].storage, deviceHardId, single);
        }
      }
    }

    function blobToBase64(blob, callback) {
      let reader = new FileReader();
      reader.onload = () => {
        callback(reader.result);
      };
      reader.readAsDataURL(blob);
    }
  },
  // 人脸
  async aiuse(url, deviceHardId, id) {
    let data = {
      imageUrl: url,
      deviceHardId: deviceHardId,
    };
    if (id) {
      this.$el_message("正在识别中...", () => { }, "info", 0);
    }
    let res = await API.AIUSE.aiphoto(data);
    let dataRun = {
      taskId: this.taskId,
      deviceId: id,
    };
    if (res.code == 200) {
      if (this.taskId && id) {
        dataRun.typeId = 5;
        let run = await API.FCKERNEL.saveDeviceRunMonitorLog(dataRun);
      }
      if (id) {
        this.$el_message("识别成功！", () => { }, "success");
      }
      this.pid = res.pid;
      this.faceAiShow = true;
    } else if (res.code == 201) {
      if (id) {
        this.$el_message(res.message, () => { }, "error");
      }
      if (this.taskId && id) {
        dataRun.typeId = 7;
        let run = await API.FCKERNEL.saveDeviceRunMonitorLog(dataRun);
      }
    } else {
      if (id) {
        this.$el_message(res.message, () => { }, "error");
      }
      if (this.taskId && id) {
        dataRun.typeId = 6;
        let run = await API.FCKERNEL.saveDeviceRunMonitorLog(dataRun);
      }
    }
  },
  // 车牌
  async plate(url, deviceHardId, id) {
    let data = {
      imgUrl: url,
      deviceHardId: deviceHardId,
    };
    if (id) {
      this.$el_message("正在识别中...", () => { }, "info", 0);
    }
    let res = await API.AIUSE.palteId(data);
    let dataRun = {
      taskId: this.taskId,
      deviceId: id,
    };
    if (res.code == 200) {
      if (this.taskId && id) {
        dataRun.typeId = 8;
        let run = await API.FCKERNEL.saveDeviceRunMonitorLog(dataRun);
      }
      if (id) {
        this.$el_message("识别完成", () => { }, "success");
      }
      this.carList = res.data;
      this.carAiShow = true;
    } else if (res.code == 201) {
      if (id) {
        this.$el_message(res.message, () => { }, "error");
      }
      if (this.taskId && id) {
        dataRun.typeId = 10;
        let run = await API.FCKERNEL.saveDeviceRunMonitorLog(dataRun);
      }
    } else {
      if (id) {
        this.$el_message(res.message, () => { }, "error");
      }
      if (this.taskId && id) {
        dataRun.typeId = 9;
        let run = await API.FCKERNEL.saveDeviceRunMonitorLog(dataRun);
      }
    }
  },
  //车流识别
  async carFlow(deviceHardId) {
    let blob = this.screenShot();
    let fd = new FormData();
    fd.append("uploadFiles", blob, `下载.jpeg`);
    let res = await API.MAPMANAGE.fileUpload(fd);
    let data = {
      // imageUrl:"http://32.128.6.52:9000/uploads/2023/12/06/16976801912736.png",
      imageUrl: res[0].storage,
      deviceHardId: deviceHardId,
    };
    let res2 = await API.FCKERNEL.carCrowdDensity(data);
    // console.log(res2,"SSSSS");
    // return
    if (res2 && res2.total) {
      this.cartrafficShow = true;
      this.cartrafficData = res2;
      let jsondata = {
        jsonData: JSON.stringify(res2.location)
      }
      this.$emit("imgUrl", process.env.VUE_APP_IMG_URL+res[0].url, 13,jsondata);
    }
    else {
      this.$el_message("识别失败！", () => { }, "error");
    }
  },
  //人流识别
  async flow(deviceHardId) {
    let blob = this.screenShot();
    let fd = new FormData();
    fd.append("uploadFiles", blob, `下载.jpeg`);
    let res = await API.MAPMANAGE.fileUpload(fd);
    let data = {
      // imageUrl:"http://32.128.6.52:9000/uploads/2023/05/26/2f183488-ad62-41c2-bb89-736ade5d8f36.png",
      imageUrl: res[0].storage,
      deviceHardId: deviceHardId,
    };
    let res2 = await API.FCKERNEL.crowdDensity(data);
    // console.log(res2,"SSSSS");
    // return
    if (res2 && res2.total) {
      this.trafficShow = true;
      this.trafficData = res2;
      let jsondata = {
        jsonData: JSON.stringify(res2.data)
      }
      // this.$emit("imgUrl", res[0].storage, 3,jsondata);
    }
    else {
      this.$el_message("识别失败！", () => { }, "error");
    }
  },
  async mount_angle() {
    let mount = this.$store.state.fckernel.mount
    let data = {
      "type": 514,
      "data": {
        "mountId": mount.mountId,//挂载ID
        "payload": [165, 79, 17, 85, 170, 220, 12, 26, 11, 0, 0, 64, 0, 0, 0, 0, 0, 93, 221]
      }
    }
    this.$emit("fn", data, "wrj");
    this.$emit("fn", data, "wrj");
  },
  CAMERA_ZOOM(data) {
    if (data.actions.length > 0) {
      data.actions.forEach(item => {
        if (item.actionType == "CAMERA_ZOOM") {
          let mount = this.$store.state.fckernel.mount
          let buffer = zoomTo(item.param2)
          let data = {
            "type": 514,
            "data": {
              "mountId": mount.mountId,//挂载ID
              "payload": buffer
            }
          }
          this.$emit("fn", data, "wrj");

        }
      });
    }
  },
  async lineAi(val, aiData) {
    let aiDataLine = aiData
    let progress = val.waypointIndex

    // if(val.isFinish){
    if (this.lineInfo.points) {
      let data = this.lineInfo.points[progress - 1]
      console.log(progress, data, '航点');
      // 执行变倍操作
      this.CAMERA_ZOOM(data)
      // 如果是异物识别挂载调整90°
      let yw = data.ailist.filter(item => item.id == 6)
      if (yw && yw[0].switch) {
        this.mount_angle()
        //如果是异物识别挂载调整90°
        val.isFinishAction = true
        console.log('挂载调整90°');
      }
      let timer = null
      if (val.isFinishAction) {
        console.log(data.ailist, 'data.ailist');
        if (data.ailist) {
          console.log(this.aiPopup, 'this.aiPopup-----');
          if (!this.aiPopup) {
            let scene = viewer.scene
            this.aiPopup = new Cesium.BillboardCollection({
              scene,
              show: true,
            });
            this.aiPopup.add({
              position: Utils.transformWGS842Cartesian({
                lng: Number(this.uavData.locationCoordinate3D.longitude),
                lat: Number(this.uavData.locationCoordinate3D.latitude),
                alt: Number(this.uavData.locationCoordinate3D.altitude),
              }),
              image: pngAiing,
              scale: 1,
              width: 54,
              height: 89,
              verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
              horizontalOrigin: Cesium.VerticalOrigin.CENTER,
              id: 258,//字444444
              distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
                0,
                2.2e5
              ),
              scaleByDistance: new Cesium.NearFarScalar(2.5e4, 0.7, 2.2e7, 0),
              disableDepthTestDistance: Number.POSITIVE_INFINITY,
            });
            scene.primitives.add(this.aiPopup);
            this.$emit("getAiPopup", this.aiPopup)
          }
          data.ailist.forEach(item => {
            console.log(item.check, 'item.check');
            if (item.check) {
              aiDataLine.aiType = item.id
              if (this.lineInfo.carData || this.lineInfo.faceData) {
                aiDataLine.spaceFlag = true
                aiDataLine.carData = this.lineInfo.carData
                aiDataLine.faceData = this.lineInfo.faceData
              } else {
                aiDataLine.spaceFlag = false
              }
              this.aiIdentify(aiDataLine, false, true)
            } else if (!item.check && item.switch) {
              if (this.timers.indexOf(item.id) == -1) {
                timer = setInterval(() => {
                  this.aiIdentify_zd(aiDataLine, false)
                }, 300);
                this.timers.push(item.id)
                this.timerList.push(timer)
              } else {
                aiDataLine.aiType = item.id,
                  timer = setInterval(() => {
                    this.aiIdentify_zd(aiDataLine, false)
                  }, 300);
                this.timerList.push(timer)
              }
            } else if (!item.switch && item.history) {
              console.log('结束航点');
              let num = this.timers.indexOf(item.id)
              // console.log(num,"mmmm");
              if (this.timers.indexOf(item.id) > -1) {
                this.timers.splice(num, 1)
                clearInterval(this.timerList[num])
                this.timerList.splice(num, 1)
                // console.log(this.timerList,"222");
              }
            }
          })
        }
      }
    }
  }
  // }
}