<template>
  <div>
    <div class="dialog-h-content scroll-h">

      <div v-if="initLoading"
           class="m-row m-row-2row">
        <div class="m-info-2row">
          <div class="info-prop">
            <span class="info-title info-title-100">所属组织：</span>
            <span>{{ dataForm.agencyName }}</span>
          </div>

          <div class="info-prop">
            <span class="info-title info-title-100">所属网格：</span>
            <span>{{ dataForm.gridName?dataForm.gridName:'--' }}</span>
          </div>

          <div class="info-prop">
            <span class="info-title info-title-100">小区名称：</span>
            <span>{{ dataForm.neighborHoodName}}</span>
          </div>

          <div class="info-prop">
            <span class="info-title info-title-100">关联物业：</span>
            <span>{{ dataForm.propertyShow?dataForm.propertyShow:'--'}}</span>
          </div>
          <div class="info-prop">
            <span class="info-title info-title-100">实有楼栋：</span>
            <span>{{dataForm.realBuilding?dataForm.realBuilding:0 }}</span>
          </div>

          <div class="info-prop">
            <span class="info-title info-title-100">详细地址：</span>
            <span>{{ dataForm.address }}</span>
          </div>

          <div class="info-prop">
            <span class="info-title info-title-100">地图位置：</span>
            <div class="div_map">

              <div id="app_detail_community"></div>

            </div>
          </div>

        </div>
        <div class="m-info-2row">
          <div class="info-prop">
            <span class="info-title info-title-100">小区编码：</span>
            <span>{{ dataForm.coding?dataForm.coding:'--'}}</span>
          </div>
          <div v-if="dataForm.qrcodeUrl"
               class="info-prop">
            <span class="info-title info-title-100">二维码：</span>
            <div style="display: flex;flex-direction: column;">
              <img style="margin-left: 20px;width: 150px;"
                   :src="dataForm.qrcodeUrl">
              <a style="margin-left: 30px;margin-top:20px"
                 class="div-table-button--blue"
                 :href="dataForm.qrcodeUrl"
                 target="_blank"><i class="el-icon-download"></i>下载</a>
            </div>
          </div>

        </div>
      </div>

    </div>
    <div class="div-btn">
      <el-button size="small"
                 @click="handleCancle">关 闭</el-button>

    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { Loading } from 'element-ui' // 引入Loading服务
import { requestPost } from '@/js/dai/request'
import daiMap from "@/utils/dai-map";
var map
var search
var markers
var infoWindowList
let loading // 加载动画
export default {
  data () {
    return {

      btnDisable: false,
      initLoading: false,

      dataForm: {
        neighborHoodName: '', // 小区名称【不超过50字】
        agencyId: '', // 所属组织ID
        agencyName: '',
        gridId: '', //所属网格ID
        propertyId: '', //关联物业
        address: '', //详细地址
        remark: '', //备注【最大500字】
        location: '', //坐标位置
        longitude: '', //经度
        latitude: '', //纬度
        realBuilding: 0,
        coding: '',
        sysCoding: ''
      },


    }
  },
  components: {},
  mounted () {

  },

  methods: {
    handleCancle () {
      this.diaDestroy()
      this.$emit('diaDetailClose')

    },
    diaDestroy () {
      if (map) {
        // map.destroy()
      }
    },

    async initForm (row) {
      this.dataForm = JSON.parse(JSON.stringify(row))

      let propertyShowList = []
      this.dataForm.propertyList.forEach(element => {
        propertyShowList.push(element.name)
      });

      this.dataForm.propertyShow = propertyShowList.join(',')

      this.initLoading = true
      let { latitude, longitude } = this.$store.state.user;
      console.log('lat' + latitude + ',lon' + longitude)
      if (this.dataForm.latitude && this.dataForm.longitude) {
        latitude = this.dataForm.latitude
        longitude = this.dataForm.longitude
      }
      if (!latitude || latitude == "" || latitude == "0") {
        latitude = 39.9088810666821;
        longitude = 116.39743841556731;
      }

      this.$nextTick(() => {
        if (!map) {
          this.initMap(latitude, longitude)
        } else {
          map.setCenter(latitude, longitude);
          map.setMarker(latitude, longitude);
        }

      })

    },

    // 地图初始化函数，本例取名为init，开发者可根据实际情况定义
    initMap (latitude, longitude) {

      map = new daiMap(
        document.getElementById("app_detail_community"),
        { latitude, longitude },
        {
          zoom: 16.2, // 设置地图缩放级别
          pitch: 43.5, // 设置俯仰角
          rotation: 45, // 设置地图旋转角度
        }
      );

      // // 监听地图平移结束
      // map.on("dragend", (e) => {
      //   this.handleMoveCenter(e);
      // });

      map.setCenter(latitude, longitude);
      map.setMarker(latitude, longitude);

    },



    resetData () {

      this.dataForm = {
        neighborHoodName: '', // 小区名称【不超过50字】
        agencyId: '', // 所属组织ID
        agencyName: '',
        gridId: '', //所属网格ID
        propertyId: '', //关联物业
        address: '', //详细地址
        remark: '', //备注【最大500字】
        location: '', //坐标位置
        longitude: '', //经度
        latitude: '', //纬度
        realBuilding: 0,
        coding: '',
        sysCoding: ''
      }

    },
    // 开启加载动画
    startLoading () {
      loading = Loading.service({
        lock: true, // 是否锁定
        text: '正在加载……', // 加载中需要显示的文字
        background: 'rgba(0,0,0,.7)' // 背景颜色
      })
    },
    // 结束加载动画
    endLoading () {
      // clearTimeout(timer);
      if (loading) {
        loading.close()
      }
    }
  },
  computed: {
    dataRule () {
      return {
        neighborHoodName: [
          { required: true, message: '小区名称不能为空', trigger: 'blur' },
          {
            min: 1,
            max: 50,
            message: '小区名称长度在 1 到 50个字符',
            trigger: 'blur'
          }
        ],
        agencyId: [
          { required: true, message: '所属组织不能为空', trigger: 'blur' }
        ],
        gridId: [
          { required: true, message: '所属网格不能为空', trigger: 'blur' }
        ],
        coding: [
          { required: true, message: '小区编码不能为空', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '详细地址不能为空', trigger: 'blur' }
        ],
        longitude: [
          { required: true, message: '坐标不能为空', trigger: 'blur' }
        ]
      }
    },
    propertyRule () {
      name: [
        { required: true, message: '物业名称不能为空', trigger: 'blur' }
        // { min: 1, max: 50, message: '小区名称长度在 1 到 50个字符', trigger: 'blur' }
      ]
    }
  },
  props: {}
}
</script>
<style lang="scss" scoped >
@import "@/assets/scss/modules/management/detail-main.scss";
</style>



