Blame view

src/components/select/option.vue 2.64 KB
e355dd49   梁灏   add Select Component
1
  <template>
e4ebd304   梁灏   update Select com...
2
      <li :class="classes" @click.stop="select" @mouseout.stop="blur" v-show="!hidden"><slot>{{ showLabel }}</slot></li>
e355dd49   梁灏   add Select Component
3
4
  </template>
  <script>
4aec6a66   梁灏   support Select
5
      import Emitter from '../../mixins/emitter';
fed3e09d   梁灏   add AutoComplete ...
6
      import { findComponentUpward } from '../../utils/assist';
4aec6a66   梁灏   support Select
7
  
e355dd49   梁灏   add Select Component
8
9
10
      const prefixCls = 'ivu-select-item';
  
      export default {
4aec6a66   梁灏   support Select
11
12
13
          name: 'iOption',
          componentName: 'select-item',
          mixins: [ Emitter ],
e355dd49   梁灏   add Select Component
14
15
16
17
18
19
20
21
22
23
24
25
26
          props: {
              value: {
                  type: [String, Number],
                  required: true
              },
              label: {
                  type: [String, Number]
              },
              disabled: {
                  type: Boolean,
                  default: false
              }
          },
e355dd49   梁灏   add Select Component
27
28
29
30
          data () {
              return {
                  selected: false,
                  index: 0,    // for up and down to focus
e4ebd304   梁灏   update Select com...
31
32
                  isFocus: false,
                  hidden: false,    // for search
fed3e09d   梁灏   add AutoComplete ...
33
34
                  searchLabel: '',    // the value is slot,only for search
                  autoComplete: false
b0893113   jingsam   :art: add eslint
35
              };
e355dd49   梁灏   add Select Component
36
37
38
39
40
41
42
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-disabled`]: this.disabled,
fed3e09d   梁灏   add AutoComplete ...
43
                          [`${prefixCls}-selected`]: this.selected && !this.autoComplete,
e355dd49   梁灏   add Select Component
44
45
                          [`${prefixCls}-focus`]: this.isFocus
                      }
b0893113   jingsam   :art: add eslint
46
                  ];
e355dd49   梁灏   add Select Component
47
48
              },
              showLabel () {
b0893113   jingsam   :art: add eslint
49
                  return (this.label) ? this.label : this.value;
e355dd49   梁灏   add Select Component
50
51
52
53
54
55
56
57
              }
          },
          methods: {
              select () {
                  if (this.disabled) {
                      return false;
                  }
  
4aec6a66   梁灏   support Select
58
                  this.dispatch('iSelect', 'on-select-selected', this.value);
e355dd49   梁灏   add Select Component
59
60
61
              },
              blur () {
                  this.isFocus = false;
e4ebd304   梁灏   update Select com...
62
63
              },
              queryChange (val) {
d94d98c4   梁灏   fixed #215
64
65
                  const parsedQuery = val.replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, '\\$1');
                  this.hidden = !new RegExp(parsedQuery, 'i').test(this.searchLabel);
e355dd49   梁灏   add Select Component
66
67
              }
          },
4aec6a66   梁灏   support Select
68
          mounted () {
e4ebd304   梁灏   update Select com...
69
              this.searchLabel = this.$el.innerHTML;
ed91d9b0   梁灏   update Select
70
              this.dispatch('iSelect', 'append');
4aec6a66   梁灏   support Select
71
              this.$on('on-select-close', () => {
e355dd49   梁灏   add Select Component
72
                  this.isFocus = false;
4aec6a66   梁灏   support Select
73
74
              });
              this.$on('on-query-change', (val) => {
e4ebd304   梁灏   update Select com...
75
                  this.queryChange(val);
4aec6a66   梁灏   support Select
76
              });
fed3e09d   梁灏   add AutoComplete ...
77
78
79
  
              const Select = findComponentUpward(this, 'iSelect');
              if (Select) this.autoComplete = Select.autoComplete;
ed91d9b0   梁灏   update Select
80
81
82
          },
          beforeDestroy () {
              this.dispatch('iSelect', 'remove');
e355dd49   梁灏   add Select Component
83
          }
b0893113   jingsam   :art: add eslint
84
85
      };
  </script>