<template>
  <el-dialog
    :visible.sync="dialogVisible"
    title="取样详情"
    width="80vw"
    top="10vh"
  >
    <div id="sample-container">
      <div id="sample-map-container"></div>
      <div class="sample-info">
        <div class="sample-title">取样信息</div>
        <div class="sample-description">
          <div>拍摄人：</div>
          <div>样品编号：</div>
          <div>检测项目：</div>
          <div>检测单位：</div>
          <div>施工单位：</div>
          <div>工程部位：</div>
        </div>
        <div class="sample-imgs">
          <div class="sample-img">
            <img src="" alt="" />
            <div class="img-des">自拍照</div>
          </div>
          <div class="sample-img">
            <img src="" alt="" />
            <div class="img-des">自拍照</div>
          </div>
          <div class="sample-img">
            <img src="" alt="" />
            <div class="img-des">自拍照</div>
          </div>
          <div class="sample-img">
            <img src="" alt="" />
            <div class="img-des">自拍照</div>
          </div>
        </div>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { getBaseInfo } from "@/api/index";
import AMapLoader from "@amap/amap-jsapi-loader";
export default {
  name: "MapDialog",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    sampleId: {
      type: [String, Number],
      default: "",
    },
  },
  data() {
    return {
      date: "",
      map: null,
      Amap: null, //高德地图amap方法实例
      mapCenter: [],
      hour: "",
    };
  },
  methods: {
    init() {
      getBaseInfo().then((res) => {
        this.mapCenter = [res.data.longitude, res.data.latitude];
        this.$nextTick(() => {
          this.initMap();
        });
      });
    },
    initMap() {
      AMapLoader.load({
        key: "a7387204aeee9f238b217bad35460ba9",
        version: "1.4.15",
        plugins: ["AMap.MarkerClusterer", "AMap.DistrictSearch"],
      }).then((AMap) => {
        // 初始化地图
        this.AMap = AMap;
        this.map = new AMap.Map("sample-map-container", {
          viewMode: "2D",
          zoom: 20,
          center: this.mapCenter,
          resizeEnable: true,
          mapStyle: "amap://styles/1dda787b3ac1ce28f171d2f153726eb7",
        });
        this.$nextTick(() => {
          var scale = window.screen.height / 1220;
          document.getElementById("sample-map-container").style.zoom =
            1 / scale;
        });
      });
    },
    search() {
      this.map.clearMap();
      //   getSafeCapRoute({
      //     bind_id: this.userId,
      //     start_time: `${this.date} ${this.hour}:00:00`,
      //   }).then((res) => {
      //     const paths = res.data.line.map((point) => {
      //       return [point.longitude, point.latitude];
      //     });
      //     new this.AMap.Polyline({
      //       path: paths,
      //       map: this.map,
      //       showDir: true,
      //       strokeColor: "#3366bb",
      //       strokeWeight: 8,
      //     });
      //   });
    },
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit("changeVisible", val);
      },
    },
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.$nextTick(() => {
          this.init();
        });
      }
    },
  },
  mounted() {
    this.init();
  },
};
</script>
<style lang="less" scoped>
@import "@/assets/common/element.less";
#sample-container {
  display: flex;
  justify-content: space-between;
}
#sample-map-container {
  width: 70%;
  height: 700px;
}
.sample-info {
  width: 29%;
  .sample-title {
    line-height: 40px;
    color: #fff;
    text-align: center;
    background: #02306a;
  }
  .sample-description {
    padding: 20px;
    line-height: 24px;
    font-size: 14px;
    color: #c6def9;
    background: #0e3c75;
  }
  .sample-imgs {
    background: #0e3c75;
    padding: 10px;
    margin-top: 10px;
    height: 446px;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .sample-img {
    width: 48%;
    margin-right: 2%;
    position: relative;
    img {
      vertical-align: top;
      width: 100%;
    }
    .img-des {
      position: absolute;
      background: rgba(0, 0, 0, 0.7);
      line-height: 30px;
      height: 30px;
      text-align: center;
      width: 100%;
      bottom: 0;
      left: 0;
      color: #fff;
    }
  }
}
</style>