Blame view

src/components/transfer/list.vue 4.97 KB
77f7bb95   梁灏   add Transfer comp...
1
  <template>
f031f465   Rui Ma   `style` cannot be...
2
      <div :class="classes" :style="listStyle">
77f7bb95   梁灏   add Transfer comp...
3
          <div :class="prefixCls + '-header'">
5b19b5f5   梁灏   support Transfer
4
              <Checkbox :value="checkedAll" :disabled="checkedAllDisabled" @on-change="toggleSelectAll"></Checkbox>
122e69ee   梁灏   update Transfer
5
              <span>{{ title }}</span>
77f7bb95   梁灏   add Transfer comp...
6
7
8
9
10
11
              <span :class="prefixCls + '-header-count'">{{ count }}</span>
          </div>
          <div :class="bodyClasses">
              <div :class="prefixCls + '-body-search-wrapper'" v-if="filterable">
                  <Search
                      :prefix-cls="prefixCls + '-search'"
5b19b5f5   梁灏   support Transfer
12
13
14
                      :query="query"
                      @on-query-clear="handleQueryClear"
                      @on-query-change="handleQueryChange"
77f7bb95   梁灏   add Transfer comp...
15
16
                      :placeholder="filterPlaceholder"></Search>
              </div>
37ee1535   梁灏   update Transfer
17
              <ul :class="prefixCls + '-content'">
77f7bb95   梁灏   add Transfer comp...
18
                  <li
5b19b5f5   梁灏   support Transfer
19
                      v-for="item in filterData"
c6f21c2f   jingsam   :bug: fix ie bug
20
                      :class="itemClasses(item)"
122e69ee   梁灏   update Transfer
21
                      @click.prevent="select(item)">
5b19b5f5   梁灏   support Transfer
22
23
                      <Checkbox :value="isCheck(item)" :disabled="item.disabled"></Checkbox>
                      <span v-html="showLabel(item)"></span>
122e69ee   梁灏   update Transfer
24
                  </li>
37ee1535   梁灏   update Transfer
25
                  <li :class="prefixCls + '-content-not-found'">{{ notFoundText }}</li>
77f7bb95   梁灏   add Transfer comp...
26
              </ul>
77f7bb95   梁灏   add Transfer comp...
27
          </div>
5b19b5f5   梁灏   support Transfer
28
          <div :class="prefixCls + '-footer'" v-if="showFooter"><slot></slot></div>
77f7bb95   梁灏   add Transfer comp...
29
30
31
32
33
34
35
      </div>
  </template>
  <script>
      import Search from './search.vue';
      import Checkbox from '../checkbox/checkbox.vue';
  
      export default {
5b19b5f5   梁灏   support Transfer
36
          name: 'TransferList',
77f7bb95   梁灏   add Transfer comp...
37
          components: { Search, Checkbox },
77f7bb95   梁灏   add Transfer comp...
38
39
40
41
42
          props: {
              prefixCls: String,
              data: Array,
              renderFormat: Function,
              checkedKeys: Array,
f031f465   Rui Ma   `style` cannot be...
43
              listStyle: Object,
77f7bb95   梁灏   add Transfer comp...
44
45
46
47
48
49
50
51
52
53
              title: [String, Number],
              filterable: Boolean,
              filterPlaceholder: String,
              filterMethod: Function,
              notFoundText: String,
              validKeysCount: Number
          },
          data () {
              return {
                  showItems: [],
dcc06127   梁灏   update Transfer
54
55
                  query: '',
                  showFooter: true
b0893113   jingsam   :art: add eslint
56
              };
77f7bb95   梁灏   add Transfer comp...
57
          },
5b19b5f5   梁灏   support Transfer
58
59
60
61
62
          watch: {
              data () {
                  this.updateFilteredData();
              }
          },
77f7bb95   梁灏   add Transfer comp...
63
          computed: {
bf0203db   梁灏   update Transfer
64
65
66
67
68
69
              classes () {
                  return [
                      `${this.prefixCls}`,
                      {
                          [`${this.prefixCls}-with-footer`]: this.showFooter
                      }
b0893113   jingsam   :art: add eslint
70
                  ];
bf0203db   梁灏   update Transfer
71
              },
77f7bb95   梁灏   add Transfer comp...
72
73
74
75
              bodyClasses () {
                  return [
                      `${this.prefixCls}-body`,
                      {
4997bd42   梁灏   update Transfer
76
77
                          [`${this.prefixCls}-body-with-search`]: this.filterable,
                          [`${this.prefixCls}-body-with-footer`]: this.showFooter
77f7bb95   梁灏   add Transfer comp...
78
                      }
b0893113   jingsam   :art: add eslint
79
                  ];
77f7bb95   梁灏   add Transfer comp...
80
81
82
              },
              count () {
                  const validKeysCount = this.validKeysCount;
c6f21c2f   jingsam   :bug: fix ie bug
83
                  return (validKeysCount > 0 ? `${validKeysCount}/` : '') + `${this.data.length}`;
77f7bb95   梁灏   add Transfer comp...
84
85
86
87
88
89
              },
              checkedAll () {
                  return this.data.filter(data => !data.disabled).length === this.validKeysCount && this.validKeysCount !== 0;
              },
              checkedAllDisabled () {
                  return this.data.filter(data => !data.disabled).length <= 0;
5b19b5f5   梁灏   support Transfer
90
91
92
              },
              filterData () {
                  return this.showItems.filter(item => this.filterMethod(item, this.query));
77f7bb95   梁灏   add Transfer comp...
93
94
95
              }
          },
          methods: {
c6f21c2f   jingsam   :bug: fix ie bug
96
97
98
99
100
101
              itemClasses (item) {
                  return [
                      `${this.prefixCls}-content-item`,
                      {
                          [`${this.prefixCls}-content-item-disabled`]: item.disabled
                      }
b0893113   jingsam   :art: add eslint
102
                  ];
c6f21c2f   jingsam   :bug: fix ie bug
103
              },
77f7bb95   梁灏   add Transfer comp...
104
105
106
107
108
109
110
111
112
113
114
115
              showLabel (item) {
                  return this.renderFormat(item);
              },
              isCheck (item) {
                  return this.checkedKeys.some(key => key === item.key);
              },
              select (item) {
                  if (item.disabled) return;
                  const index = this.checkedKeys.indexOf(item.key);
                  index > -1 ? this.checkedKeys.splice(index, 1) : this.checkedKeys.push(item.key);
              },
              updateFilteredData () {
122e69ee   梁灏   update Transfer
116
                  this.showItems = this.data;
77f7bb95   梁灏   add Transfer comp...
117
118
              },
              toggleSelectAll (status) {
5b19b5f5   梁灏   support Transfer
119
                  const keys = status ?
77f7bb95   梁灏   add Transfer comp...
120
121
                          this.data.filter(data => !data.disabled || this.checkedKeys.indexOf(data.key) > -1).map(data => data.key) :
                          this.data.filter(data => data.disabled && this.checkedKeys.indexOf(data.key) > -1).map(data => data.key);
5b19b5f5   梁灏   support Transfer
122
123
124
125
                  this.$emit('on-checked-keys-change', keys);
              },
              handleQueryClear () {
                  this.query = '';
77f7bb95   梁灏   add Transfer comp...
126
              },
5b19b5f5   梁灏   support Transfer
127
128
              handleQueryChange (val) {
                  this.query = val;
77f7bb95   梁灏   add Transfer comp...
129
130
131
132
              }
          },
          created () {
              this.updateFilteredData();
77f7bb95   梁灏   add Transfer comp...
133
          },
5b19b5f5   梁灏   support Transfer
134
135
          mounted () {
              this.showFooter = this.$slots.default !== undefined;
77f7bb95   梁灏   add Transfer comp...
136
          }
b0893113   jingsam   :art: add eslint
137
      };
c6f21c2f   jingsam   :bug: fix ie bug
138
  </script>