wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<script lang="ts" setup>
import { ref, computed } from 'vue'
import FixedSizeList from 'element-plus-secondary/es/components/virtual-list/src/components/fixed-size-list.mjs'
import VanPopup from 'vant/es/popup'
import 'vant/es/popup/style'
 
const props = defineProps({
  options: {
    type: Array,
    default: () => []
  },
  selectValue: {
    type: Array,
    default: () => []
  },
  multiple: {
    type: Boolean,
    default: false
  }
})
 
const showSelect = ref(false)
let oldCheckList = []
const checkAll = ref(false)
const isIndeterminate = ref(false)
const checkTableList = ref([])
const checkList = ref([])
const keywords = ref('')
const tableListWithSearch = computed(() => {
  if (!keywords.value) return props.options
  return props.options.filter((ele: any) =>
    ele.label.toLowerCase().includes(keywords.value.toLowerCase())
  )
})
const emits = defineEmits(['onClear', 'onConfirm'])
const reset = () => {
  oldCheckList = []
  showSelect.value = false
  checkAll.value = false
  isIndeterminate.value = false
  keywords.value = ''
}
const showPopup = () => {
  reset()
  if (props.multiple) {
    checkList.value = [...props.selectValue]
  } else {
    checkList.value = Array.isArray(props.selectValue)
      ? [...props.selectValue]
      : [props.selectValue]
    oldCheckList = [...checkList.value]
  }
  showSelect.value = true
}
 
const onClear = () => {
  reset()
  emits('onClear')
}
 
const onConfirm = () => {
  showSelect.value = false
  checkAll.value = false
  isIndeterminate.value = false
  keywords.value = ''
  emits('onConfirm', checkList.value)
}
 
const handleCheckedTablesChange = (value: any[]) => {
  if (!props.multiple) {
    if (!oldCheckList.length) {
      oldCheckList = [...value]
    } else {
      checkList.value = value.filter(ele => !oldCheckList.includes(ele))
      oldCheckList = [...checkList.value]
    }
    return
  }
  const checkedCount = value.length
  checkAll.value = checkedCount === tableListWithSearch.value.length
  isIndeterminate.value = checkedCount > 0 && checkedCount < tableListWithSearch.value.length
  const tableNameArr = tableListWithSearch.value.map((ele: any) => ele.label)
  checkTableList.value = [
    ...new Set([...checkTableList.value.filter(ele => !tableNameArr.includes(ele)), ...value])
  ]
}
 
const handleCheckAllChange = (val: any) => {
  checkList.value = val
    ? [...new Set([...tableListWithSearch.value.map((ele: any) => ele.label), ...checkList.value])]
    : []
  isIndeterminate.value = false
  const tableNameArr = tableListWithSearch.value.map((ele: any) => ele.label)
  checkTableList.value = val
    ? [...new Set([...tableNameArr, ...checkTableList.value])]
    : checkTableList.value.filter(ele => !tableNameArr.includes(ele))
}
</script>
 
<template>
  <div class="vant-mobile_select" @click="showPopup" />
  <van-popup teleport="body" position="bottom" v-model:show="showSelect">
    <div class="container-vant_mobile">
      <div class="select-all">
        <el-checkbox
          v-model="checkAll"
          v-if="multiple"
          :indeterminate="isIndeterminate"
          @change="handleCheckAllChange"
        >
          {{ $t('component.allSelect') }}
        </el-checkbox>
 
        <el-input
          style="position: absolute; top: 3px; right: 150px; width: 150px"
          v-model="keywords"
          clearable
        ></el-input>
        <button
          style="position: absolute; top: 0; right: 60px"
          @click="onClear"
          class="van-picker__confirm van-haptics-feedback"
        >
          {{ $t('commons.clear') }}
        </button>
        <button
          style="position: absolute; top: 0; right: 10px"
          @click="onConfirm"
          class="van-picker__confirm van-haptics-feedback"
        >
          {{ $t('commons.confirm') }}
        </button>
      </div>
      <el-checkbox-group
        v-model="checkList"
        style="position: relative"
        @change="handleCheckedTablesChange"
      >
        <FixedSizeList
          :item-size="32"
          :data="tableListWithSearch"
          :total="tableListWithSearch.length"
          :height="460"
          :scrollbar-always-on="true"
          class-name="ed-select-dropdown__list"
          layout="vertical"
        >
          <template #default="{ index, style }">
            <div class="list-item_primary" :style="style">
              <el-checkbox :label="tableListWithSearch[index].value">
                {{ tableListWithSearch[index].label }}</el-checkbox
              >
            </div>
          </template>
        </FixedSizeList>
      </el-checkbox-group>
    </div>
  </van-popup>
</template>
 
<style lang="less">
.vant-mobile_select {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
 
.container-vant_mobile {
  overflow: hidden;
  padding: 0 10px;
 
  .select-all {
    height: 40px;
    padding-left: 12px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #dee0e3;
    position: relative;
 
    .ed-input__wrapper {
      background-color: var(--ed-input-bg-color, var(--ed-fill-color-blank)) !important;
      box-shadow: 0 0 0 1px var(--ed-color-primary) inset !important;
    }
  }
 
  .ed-checkbox__label {
    display: inline-flex;
    align-items: center;
    color: #1f2329 !important;
  }
 
  .ed-vl__window {
    scrollbar-width: none;
  }
}
</style>