activeLocation.vue 7.14 KB
<template>
  <v-full-layout class="active_location">
    <template slot="breadcrumb">
      <el-breadcrumb-item>激活位置</el-breadcrumb-item>
    </template>
    <template slot="main">
      <div class="device_list" v-if="deviceList && deviceList.length > 1">
        <div class="title">
          <span>设备列表({{ deviceList.length }})</span>
          <!-- <i class="el-icon-close i_close"></i> -->
        </div>
        <div class="list_box">
          <div
            class="cell"
            v-for="(item, index) in deviceList"
            :key="index"
            @click="openMapInfoWindow(item.sn, item.vin)"
          >
            <div class="top">
              <i class="i_circle" :class="item.status == 2 ? 'i_red' : ''"></i>
              <span>{{ item.ownerName || "" }}</span>
              <span>{{ item.sn || "" }}({{ statusList[item.source] }})</span>
            </div>
            <div class="bottom">
              <span>车架号:</span>
              <span>{{ item.vin || "" }}</span>
            </div>
          </div>
        </div>
        <div class="device_footer">
          <i class="i_circle"></i>
          <span>在线</span>
          <i class="i_circle i_red"></i>
          <span>离线</span>
        </div>
      </div>
      <div id="map" class="map-container"></div>
    </template>
  </v-full-layout>
</template>
<script>
import mapService from "@/utils/mapService.js";
import "@/utils/mapEvent.js";
import EventBus from "@/event-bus";
import remoteLoad from "@/utils/remoteLoad.js";
import { CONSTANT } from "@/constant";
import { GET_DEVICEINFO_BYSNS } from "@/api/services/monitor.js";
export default {
  data() {
    return {
      AMap: null,
      mapObj: null,
      checkLoadedTimeoutId: "",
      deviceList: [],
      statusList: {
        1: "有线",
        0: "无线",
      },
    };
  },
  created() {
    console.log(history.state);
    let _this = this;
    _this.$mapInit({ }).then((AMap) => {
      _this.initMap();
    });
  },
  methods: {
    // 初始化地图
    initMap() {
      let check = () => {
        if (this.checkLoadedTimeoutId) {
          window.clearTimeout(this.checkLoadedTimeoutId);
        }
        return setTimeout(() => {
          if (
            "AMap" in window &&
            typeof AMap.Map == "function" &&
            !this.mapObj
          ) {
            window.AMap = AMap;
            this.mapObj = mapService.init("map");
            this.isInitMap = true;
            let query = this.$route.query;
            let o = history.state;

            // 假性离线报警查看位置点
            if (query.sns) {
              this.getLocation(query.sns);
              return false;
            }

            // 兼容其他页面的跳转
            if (query && query.sn) {
              query.elat = query.lat;
              query.elng = query.lng;
              this.addLocation(query, true);
              return false;
            }

            console.log(o);
            if (o.lng || o.bsLng) {
              o.elat = o.lat;
              o.elng = o.lng;
              this.addLocation(o, true);
            }
          } else {
            this.checkLoadedTimeoutId = check();
          }
        }, 100);
      };
      this.checkLoadedTimeoutId = check();
    },

    // 添加位置点
    addLocation(row, showInfoWindow) {
      let drawData = row;
      EventBus.$emit("uiMap.monitor.drawMaker", drawData, showInfoWindow);
    },

    // 获取位置点
    getLocation(sns) {
      let oParams = {};
      oParams.sns = sns;
      oParams.deviceCode = "gps";
      GET_DEVICEINFO_BYSNS(oParams).then((res) => {
        let list = res.data || [];

        // 循环标记车辆
        list.map((k) => {
          let o = this.getMapInfo(k);
          if (o.lng || o.bsLng) {
            o.elat = o.lat;
            o.elng = o.lng;
            this.addLocation(o, false);
          }
        });
        if (list[0]) {
          this.openMapInfoWindow(list[0].sn, list[0].vin);
        }
        this.deviceList = list;
      });
    },

    // 获取地图数据
    getMapInfo(row) {
      let gpsInfo = row.gpsLocation || {};
      let bsInfo = row.bsLocation || {};
      let oParams = {};

      oParams.sn = row.sn || "";
      //oParams.gpsData
      oParams.name = row.ownerName || "";
      oParams.standNo = row.vin || "";
      oParams.source = row.source || "";

      // gps 信息
      oParams.lng = gpsInfo.elng;
      oParams.lat = gpsInfo.elat;
      oParams.address = gpsInfo.address || "";
      oParams.time = gpsInfo.dateTime || "";

      //基站信息
      oParams.bsLng = bsInfo.elng;
      oParams.bsLat = bsInfo.elat;
      oParams.bsAddress = bsInfo.address || "";
      oParams.bsTime = bsInfo.dateTime || "";

      // 定位类型
      oParams.type = 2;

      return oParams;
    },

    // 打开车辆弹框
    openMapInfoWindow(sn, vin) {
      EventBus.$emit("uiMap.monitor.openInfoWindow", `${sn}-${vin}`);
    },
  },
};
</script>
<style lang="scss">
.full-width .main-wrap.full-width {
  left: 0;
  width: 100%;
}
</style>
<style lang="scss" scoped>
.active_location {
  .full-width {
    position: absolute;
    top: 0px;
    height: 100%;
    left: 0;
    width: 100%;
    bottom: 0;
    .map-container {
      width: 100%;
      height: 100%;
      z-index: 100;
      position: absolute;
      top: 0px;
      left: 0;
      bottom: 0;
      overflow: hidden;
    }
    .device_list {
      position: absolute;
      top: 16px;
      left: 16px;
      width: 260px;
      height: 300px;
      background: #fff;
      border-radius: 4px;
      z-index: 101;
      display: flex;
      flex-direction: column;
      border: 1px solid #f2f2f2;
      .title {
        position: relative;
        text-align: center;
        height: 36px;
        line-height: 36px;
        border-bottom: 1px solid #f2f2f2;
        span {
          font-weight: bold;
        }
        .i_close {
          position: absolute;
          right: 10px;
          top: 50%;
          transform: translateY(-50%);
          font-size: 16px;
          cursor: pointer;
        }
        .i_close:hover {
          color: #f00;
        }
      }
      .list_box {
        flex: 1;
        padding: 10px 0;
        .cell {
          position: relative;
          padding: 4px 10px;
          line-height: 2;
          cursor: pointer;
          .bottom {
            padding-left: 12px;
          }
        }
        .cell:hover {
          background: #f2f2f2;
        }
        .cell:after {
          position: absolute;
          display: block;
          content: "";
          height: 1px;
          left: 0;
          right: 0;
          bottom: 0;
          background: #f2f2f2;
        }
      }
      .device_footer {
        height: 30px;
        line-height: 30px;
        border-top: 1px solid #f2f2f2;
        padding: 0 10px;
        display: flex;
        align-items: center;
        span {
          position: relative;
          font-size: 12px;
          color: #333;
          margin: 0 10px 0 0;
        }
        .i_circle {
          margin: 0 4px 0 0;
        }
      }
    }
  }
}
.i_circle {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 100%;
  background: #09bf99;
}
.i_red {
  background: #f00;
}
</style>