<template>
  <el-dialog
    v-model="dialogFormVisible"
    :title="title"
    width="500px"
    @close="close"
  >
    <el-form ref="form" :model="keyWords" label-width="100px">
      <el-form-item label="位置信息">
        <el-input v-model="keyWords"></el-input>
      </el-form-item>
      <el-button icon="el-icon-search" type="primary" @click="searchAddress">
        {{ $t('defalult.cx') }}
      </el-button>
      <el-button
        icon="el-icon-del"
        type="danger"
        @click="delAddress"
        style="float: right"
      >
        清空
      </el-button>
      <bd-map
        ref="maps"
        :location="location"
        @tellFatherName="getLatAndLng"
      ></bd-map>
      <div class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="define">确 定</el-button>
      </div>
    </el-form>
  </el-dialog>
</template>

<script>
import bdMap from './bdMap';

export default {
  components: {
    bdMap,
  },
  data() {
    return {
      location: '',
      coordinate: [],
      dialogFormVisible: false,
      title: '选择位置',
      keyWords: '',
    };
  },
  methods: {
    getLatAndLng(coordinate) {
      this.coordinate = coordinate;
    },
    searchAddress() {
      this.$refs['maps'].setPlace(this.keyWords);
    },
    delAddress() {
      this.keyWords = '';
      this.$refs['maps'].removeMarker();
    },
    showMap(location) {
      this.dialogFormVisible = true;
      setTimeout(() => {
        this.$refs['maps'].loadScript(location);
      }, 500);
    },
    close() {
      this.dialogFormVisible = false;
    },
    define() {
      this.$emit('setLatAndLng', this.coordinate);
      this.dialogFormVisible = false;
    },
  },
};
</script>
