Blame view

src/components/transfer/list.vue 5.09 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>
ea9620eb   Aresn   update Transfer
5
              <span :class="prefixCls + '-header-title'" @click="toggleSelectAll(!checkedAll)">{{ 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
              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);
9f5a643a   梁灏   fixed #2019
114
                  this.$parent.handleCheckedKeys();
77f7bb95   梁灏   add Transfer comp...
115
116
              },
              updateFilteredData () {
122e69ee   梁灏   update Transfer
117
                  this.showItems = this.data;
77f7bb95   梁灏   add Transfer comp...
118
119
              },
              toggleSelectAll (status) {
5b19b5f5   梁灏   support Transfer
120
                  const keys = status ?
77f7bb95   梁灏   add Transfer comp...
121
122
                          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
123
124
125
126
                  this.$emit('on-checked-keys-change', keys);
              },
              handleQueryClear () {
                  this.query = '';
77f7bb95   梁灏   add Transfer comp...
127
              },
5b19b5f5   梁灏   support Transfer
128
129
              handleQueryChange (val) {
                  this.query = val;
77f7bb95   梁灏   add Transfer comp...
130
131
132
133
              }
          },
          created () {
              this.updateFilteredData();
77f7bb95   梁灏   add Transfer comp...
134
          },
5b19b5f5   梁灏   support Transfer
135
136
          mounted () {
              this.showFooter = this.$slots.default !== undefined;
77f7bb95   梁灏   add Transfer comp...
137
          }
b0893113   jingsam   :art: add eslint
138
      };
c6f21c2f   jingsam   :bug: fix ie bug
139
  </script>