Blame view

node_modules/vue-baidu-map/components/others/AutoComplete.vue 1.43 KB
290144e9   易尊强   第一次
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
  <template>
  <span>
    <slot>
      <input>
    </slot>
  </span>
  </template>
  
  <script>
  import commonMixin from '../base/mixins/common.js'
  import bindEvents from '../base/bindEvent.js'
  
  export default {
    name: 'bm-autocomplete',
    mixins: [commonMixin()],
    props: {
      types: {
        type: String
      },
      location: {
        type: String
      },
      sugStyle: {
        type: Object,
        default () {
          return {}
        }
      }
    },
    watch: {
      types () {
        this.reload()
      },
      location () {
        this.reload()
      }
    },
    methods: {
      load () {
        const {BMap, map, $el, types, location, sugStyle} = this
        const input = $el.querySelector('input')
        if (!input) {
          return
        }
        this.originInstance = new BMap.Autocomplete({
          input,
          types,
          location: location || map,
          onSearchComplete: e => {
            const $sugs = document.querySelectorAll('.tangram-suggestion-main')
            for (const $sug of $sugs) {
              for (const name in sugStyle) {
                $sug.style[name] = sugStyle[name].toString()
              }
            }
            this.$emit('searchcomplete', e)
          }
        })
  
        // Support v-model
        this.originInstance.addEventListener('onconfirm', e => {
          const val = e.item.value
          this.$emit('input', val.province + val.city + val.district + val.street + val.business)
        })
  
        bindEvents.call(this, this.originInstance)
      }
    }
  }
  </script>