hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<template>
  <div class='map_poi'>
    <el-select
      v-model="value"
      filterable
      remote
      default-first-option
      placeholder="请输入关键词"
      :remote-method="remoteMethod"
      :loading="loading"
      size="small"
      @change="onChange"
    >
      <el-option
        v-for="item in options"
        :key="item.id"
        :label="item.name"
        :value="item.id"
      >
      </el-option>
    </el-select>
  </div>
</template>
 
<script>
export default {
  props: {
    map: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  components: {},
  data() {
    return {
      options: [],
      value: "",
      list: [],
      loading: false,
    };
  },
  watch: {},
  computed: {
    isMap() {
      return this.map && this.map.version;
    },
  },
  methods: {
    remoteMethod(query) {
      if (query !== "") {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          this.options = [];
          if (this.isMap) {
            this.map.poi({ search: query, code: "攀枝花" }, (e) => {
              if (e.code) {
                this.options = e.data.list || [];
              }
            });
          }
        }, 200);
      } else {
        this.options = [];
      }
    },
    onChange(e) {
      let val =
        this.options.filter((r) => {
          return r.id === e;
        })[0] || {};
      this.map.center(val.lng, val.lat);
    },
  },
  mounted() {},
};
</script>
<style lang='less' scoped>
.map_poi {
  position: absolute;
  left: 20px;
  top: 20px;
  z-index: 500;
}
</style>