<template>
  <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body destroy-on-close :close-on-click-modal="false">
    <el-row>
      <el-col :span="14">
        <el-form label-width="100px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="设备名称">
                <span>{{ detailInfo.deviceName }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="设备类型">
                <span v-if="detailInfo.deviceType">{{ $parent.deviceTypeFormatter(detailInfo) }}</span>
              </el-form-item>
            </el-col>

          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="设备编号">
                <span>{{ detailInfo.deviceCode }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="设备型号">
                <span>{{ detailInfo.deviceModel }}</span>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="具体地址">
                <span>{{ detailInfo.deviceAddr }}</span>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="设备图片">
            <el-image v-if="detailInfo.iconUrl" :src="detailInfo.iconUrl" :preview-src-list="[detailInfo.iconUrl]" :z-index="9999" style="width: 100px;height: 100px;"></el-image>
          </el-form-item>

          <el-row>
            <el-col :span="12">
              <el-form-item label="联系人">
                <span>{{ detailInfo.linkman }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="电话">
                <span>{{ detailInfo.phone }}</span>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="安装时间">
                <span>{{ detailInfo.installationTime }}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-col>
      <el-col :span="10">
        <div id="dev_map" style="width: 100%;height: 400px;border: 1px solid"></div>
      </el-col>
    </el-row>

  </el-dialog>

</template>

<script>
  import { getInfo } from "@/api/baseinfo/deviceInfo";
  import { EditorMap } from "@/utils/mapClass/map";
  import { mapGetters } from "vuex";
  export default {
    name: "detail-info",
    data(){
      return{
        open: false,
        detailInfo: {},
        title: "",
      }
    },

    methods: {
      getDetailInfo(deviceId){
        getInfo(deviceId).then(response => {
          this.detailInfo = response.data;
          this.title = "设备信息详情";
          this.open = true;
          this.initMap();
        });
      },
      initMap(){
        this.$nextTick(() => {
            const path = eval(this.systemSetting.map_center);
            let map = new EditorMap(
                "dev_map",
                {
                  center: path,
                  //mapStyle: "amap://styles/f71d3a3d73e14f5b2bf5508bf1411758",
                  zoom: 14.5,
                },
                this
             );
            if(this.detailInfo.longitude){
              map.control = 1;
              map.addDevice(this.detailInfo);
              map.map.setCenter([this.detailInfo.longitude,this.detailInfo.latitude])
            }
        });
      }
    },
    computed: {
      ...mapGetters(["systemSetting"]),
    },
  }
</script>

<style scoped>

</style>
