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

      <div v-if="initLoading"
           class="d-row">
        <div class="d-info">
          <div class="d-info-prop">
            <div class="d-title">所属组织：</div>
            <div class="d-content">
              <div class="d-content-in">{{ dataForm.agencyName }}</div>
            </div>
          </div>

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

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

          <div class="d-info-prop ">
            <div class="d-title">小区编码：</div>
            <div class="d-content">
              <div class="d-content-in">{{ dataForm.coding?dataForm.coding:'--'}}</div>
            </div>
          </div>
          <div class="d-info-prop d-info-prop-pic">
            <div class="d-title">小区二维码：</div>
            <div class="d-content">
              <div v-if="dataForm.qrcodeUrl"
                   class="content-pic">
                <img class="d-img"
                     :src="dataForm.qrcodeUrl">
                <a class="pic-btn"
                   style="margin-left: 80px"
                   :href="dataForm.qrcodeUrl"
                   target="_blank">下载</a>
              </div>
            </div>
          </div>

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

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

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

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

            </div>
          </div>

        </div>
      </div>

    </div>
    <div class="div-btn">
      <el-button size="small"
                 class="diy-button--blue"
                 @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";

.content-pic {
  display: flex;
  justify-content: space-between;
  padding: 11px 23px;
  justify-items: center;
}

.pic-btn {
  width: 75px;
  height: 25px;
  background: linear-gradient(0deg, #32adab 0%, #2ad0cc 100%);
  border-radius: 3px;
  font-size: 14px;
  font-family: Source Han Serif CN;
  font-weight: 500;
  color: #ffffff;
  line-height: 23px;
  text-align: center;
}
</style>



