<!--
 * @Description: 坐标定位菜单
 * @Author: 王晓颖
 * @Date: 2022-05-18
 -->
<template>
  <div>
    <transition enter-active-class="animate__animated animate__slideInRight" leave-active-class="animate__animated animate__slideOutRight" :duration="500" mode="out-in">
      <div v-show="show" class="layer-choose-window">
        <div class="window-title">
          <div>坐标定位</div>
          <i class="el-icon-close close-icon" @click="close" />
        </div>
        <div class="window-body">
          <!-- 筛选条件-->
          <el-form ref="selectForm" :model="query" size="small">
            <el-form-item label="经度">
              <el-input v-model="query.lng" />
            </el-form-item>
            <el-form-item label="纬度">
              <el-input v-model="query.lat" />
            </el-form-item>
            <div class="btn-line">
              <el-button class="filter-item" type="primary" size="small" @click="picker">
                图上拾取
              </el-button>
              <el-button class="filter-item" type="default" size="small" @click="search">
                坐标定位
              </el-button>
            </div>
          </el-form>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'PopupLocation',
  props: {
    defaultPosition: {
      type: Array,
      default: () => []
    },
    show: {
      type: Boolean,
      default: true
    } // 是否显示
  },
  data() {
    return {
      query: {
        lng: '', // 经度
        lat: '', // 纬度
        deep: '' // 高程
      } // 筛选条件
    }
  },
  mounted() {
    if (this.position && this.position.length > 1) {
      this.query.lng = this.position[0]
      this.query.lat = this.position[1]
    }
  },
  methods: {
    // 关闭窗口
    close() {
      this.$emit('close')
    },
    // 坐标定位
    search() {
      const position = [this.query.lng, this.query.lat]
      this.$emit('search', position)
    },
    // 图上拾取
    picker() {
      this.$emit('picker')
    },
    // 设置拾取结果, 提供给父组件调用
    setQuery(location) {
      this.query.lng = location[0] ? location[0] : ''
      this.query.lat = location[1] ? location[1] : ''
      this.query.deep = location[2] ? location[2] : ''
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.layer-choose-window{
  position: absolute;
  right: 10px;
  top: 50px;
  width: 270px;
  background-color: rgba(255,255,255,0.9);
  .window-body{
    padding: 10px 30px;
    .btn-line{
      display: flex;
      justify-content: center;
      margin-top: 20px;
      margin-bottom: 20px;
    }
  }
}
.window-title{
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 10px;
  .close-icon:hover{
    cursor: pointer;
    color: #36a3f7;
  }
}
</style>
