|
1 | 1 | <template> |
2 | 2 | <view class="uni-filter-dropdown"> |
3 | 3 | <view class="dropdown-btn" @click="onDropdown"> |
4 | | - <view class="icon-select" :class="{active: canReset}" |
5 | | - v-if="filterType == 'select' || filterType == 'range'"></view> |
6 | | - <view class="icon-search" :class="{active: canReset}" v-if="filterType == 'search'"> |
| 4 | + <view class="icon-select" :class="{active: canReset}" v-if="isSelect || isRange"></view> |
| 5 | + <view class="icon-search" :class="{active: canReset}" v-if="isSearch"> |
7 | 6 | <view class="icon-search-0"></view> |
8 | 7 | <view class="icon-search-1"></view> |
9 | 8 | </view> |
| 9 | + <view class="icon-calendar" :class="{active: canReset}" v-if="isDate"> |
| 10 | + <view class="icon-calendar-0"></view> |
| 11 | + <view class="icon-calendar-1"></view> |
| 12 | + </view> |
10 | 13 | </view> |
11 | 14 | <view class="uni-dropdown-cover" v-if="isOpened" @click="handleClose"></view> |
12 | 15 | <view class="dropdown-popup dropdown-popup-right" v-if="isOpened" @click.stop> |
|
47 | 50 | <view class="flex-f btn btn-submit" @click="handleRangeSubmit">{{resource.submit}}</view> |
48 | 51 | </view> |
49 | 52 | <!-- date --> |
| 53 | + <view v-if="isDate"> |
| 54 | + <uni-datetime-picker ref="datetimepicker" :value="dateRange" type="datetimerange" return-type="timestamp" @change="datetimechange" @maskClick="timepickerclose"> |
| 55 | + <view></view> |
| 56 | + </uni-datetime-picker> |
| 57 | + </view> |
50 | 58 | </view> |
51 | 59 | </view> |
52 | 60 | </template> |
|
60 | 68 | "submit": "确定", |
61 | 69 | "filter": "筛选", |
62 | 70 | "gt": "大于等于", |
63 | | - "lt": "小于等于" |
| 71 | + "lt": "小于等于", |
| 72 | + "date": "日期范围" |
64 | 73 | } |
65 | 74 |
|
66 | 75 | const DropdownType = { |
67 | 76 | Select: "select", |
68 | 77 | Search: "search", |
69 | 78 | Range: "range", |
70 | | - Date: "date" |
| 79 | + Date: "date", |
| 80 | + Timestamp: "timestamp" |
71 | 81 | } |
72 | 82 |
|
73 | 83 | export default { |
|
114 | 124 | if (this.isRange) { |
115 | 125 | return (this.gtValue.length > 0 && this.ltValue.length > 0) |
116 | 126 | } |
| 127 | + if (this.isDate) { |
| 128 | + return this.dateSelect.length > 0 |
| 129 | + } |
117 | 130 | return false |
118 | 131 | }, |
119 | 132 | isSelect() { |
|
126 | 139 | return this.filterType === DropdownType.Range |
127 | 140 | }, |
128 | 141 | isDate() { |
129 | | - return this.filterType === DropdownType.Date |
| 142 | + return (this.filterType === DropdownType.Date || this.filterType === DropdownType.Timestamp) |
130 | 143 | } |
131 | 144 | }, |
132 | 145 | watch: { |
|
146 | 159 | filterValue: '', |
147 | 160 | checkedValues: [], |
148 | 161 | gtValue: '', |
149 | | - ltValue: '' |
| 162 | + ltValue: '', |
| 163 | + dateRange: [], |
| 164 | + dateSelect: [] |
150 | 165 | }; |
151 | 166 | }, |
152 | 167 | created() { |
|
164 | 179 | }, |
165 | 180 | openPopup() { |
166 | 181 | this.isOpened = true |
| 182 | + if (this.isDate) { |
| 183 | + this.$nextTick(() => { |
| 184 | + if (!this.dateRange.length) { |
| 185 | + this.resetDate() |
| 186 | + } |
| 187 | + this.$refs.datetimepicker.show() |
| 188 | + }) |
| 189 | + } |
167 | 190 | }, |
168 | 191 | closePopup() { |
169 | 192 | this.isOpened = false |
170 | 193 | }, |
171 | 194 | handleClose(e) { |
172 | 195 | this.closePopup() |
173 | 196 | }, |
| 197 | + resetDate() { |
| 198 | + let date = new Date() |
| 199 | + let dateText = date.toISOString().split('T')[0] |
| 200 | + this.dateRange = [dateText + ' 0:00:00', dateText + ' 23:59:59'] |
| 201 | + }, |
174 | 202 | onDropdown(e) { |
175 | 203 | this.openPopup() |
176 | 204 | }, |
|
192 | 220 | } |
193 | 221 | this.checkedValues = checkvalues |
194 | 222 | }, |
| 223 | + datetimechange(e) { |
| 224 | + this.closePopup() |
| 225 | + this.dateRange = e |
| 226 | + this.dateSelect = e |
| 227 | + this.$emit('change', { |
| 228 | + filterType: this.filterType, |
| 229 | + filter: e |
| 230 | + }) |
| 231 | + }, |
| 232 | + timepickerclose(e) { |
| 233 | + this.closePopup() |
| 234 | + }, |
195 | 235 | handleSelectSubmit() { |
196 | 236 | this.closePopup() |
197 | 237 | this.$emit('change', { |
|
309 | 349 | background-color: #1890ff; |
310 | 350 | } |
311 | 351 |
|
| 352 | + .icon-calendar { |
| 353 | + color: #ddd; |
| 354 | + width: 14px; |
| 355 | + height: 16px; |
| 356 | + } |
| 357 | +
|
| 358 | + .icon-calendar-0 { |
| 359 | + height: 4px; |
| 360 | + margin-top: 3px; |
| 361 | + margin-bottom: 1px; |
| 362 | + background-color: #ddd; |
| 363 | + border-radius: 2px 2px 1px 1px; |
| 364 | + position: relative; |
| 365 | + } |
| 366 | + .icon-calendar-0:before, .icon-calendar-0:after { |
| 367 | + content: ''; |
| 368 | + position: absolute; |
| 369 | + top: -3px; |
| 370 | + width: 4px; |
| 371 | + height: 3px; |
| 372 | + border-radius: 1px; |
| 373 | + background-color: #ddd; |
| 374 | + } |
| 375 | + .icon-calendar-0:before { |
| 376 | + left: 2px; |
| 377 | + } |
| 378 | + .icon-calendar-0:after { |
| 379 | + right: 2px; |
| 380 | + } |
| 381 | +
|
| 382 | + .icon-calendar-1 { |
| 383 | + height: 9px; |
| 384 | + background-color: #ddd; |
| 385 | + border-radius: 1px 1px 2px 2px; |
| 386 | + } |
| 387 | +
|
| 388 | + .icon-calendar.active { |
| 389 | + color: #1890ff; |
| 390 | + } |
| 391 | +
|
| 392 | + .icon-calendar.active .icon-calendar-0, |
| 393 | + .icon-calendar.active .icon-calendar-1, |
| 394 | + .icon-calendar.active .icon-calendar-0:before, |
| 395 | + .icon-calendar.active .icon-calendar-0:after { |
| 396 | + background-color: #1890ff; |
| 397 | + } |
| 398 | +
|
312 | 399 | .uni-filter-dropdown { |
313 | 400 | position: relative; |
314 | 401 | font-weight: normal; |
|
0 commit comments