<!--
  Description: 地图搜索选点组件
  Author: 李亚光
  Date: 2023-05-19
 -->
<script lang="ts" setup name="SelectLocationMap">
import mapDiv from './map/index.vue'
const $emit = defineEmits(['confirm']) // 确定坐标点
const dialogFormVisible = ref(false) // 对话框是否显示
const init = ref()
const initDialog = (data: any) => {
  // init 为初始坐标
  dialogFormVisible.value = true
  init.value = data
}
// 取消
const cancel = () => {
  dialogFormVisible.value = false
}
// 确认
const confirm = () => {
  dialogFormVisible.value = false
}
const location = (data: number[]) => {
  $emit('confirm', data)
}
defineExpose({
  initDialog,
})
</script>

<template>
  <el-dialog
    v-model="dialogFormVisible" title="选择位置" append-to-body width="1000px" :close-on-click-modal="false"
    top="12vh"
  >
    <map-div v-if="dialogFormVisible" style="height: 500px;" :init="init" @confirm="location" />
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="confirm">
          保存
        </el-button>
        <el-button @click="cancel">
          取消
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
.el-dialog {
  width: 700px;
}
</style>
