Commit d07b4f3301af0a9957493aa774313ba8dc4436c9
1 parent
95eae081
fix logic for multiple picker
Showing
1 changed file
with
14 additions
and
6 deletions
Show diff stats
src/components/date-picker/picker.vue
... | ... | @@ -265,8 +265,12 @@ |
265 | 265 | }, |
266 | 266 | computed: { |
267 | 267 | publicValue(){ |
268 | - const isRange = this.type.includes('range'); | |
269 | - return isRange ? this.formatDate(this.internalValue) : this.formatDate(this.internalValue[0]); | |
268 | + if (this.multiple){ | |
269 | + return this.internalValue.map(date => this.formatDate(date)); | |
270 | + } else { | |
271 | + const isRange = this.type.includes('range'); | |
272 | + return isRange ? this.formatDate(this.internalValue) : this.formatDate(this.internalValue[0]); | |
273 | + } | |
270 | 274 | }, |
271 | 275 | |
272 | 276 | opened () { |
... | ... | @@ -284,8 +288,10 @@ |
284 | 288 | }, |
285 | 289 | visualValue() { |
286 | 290 | const value = this.internalValue; |
287 | - | |
288 | 291 | if (!value) return; |
292 | + | |
293 | + if (this.multiple) return value.map(date => this.formatDate(date)).join(', '); | |
294 | + | |
289 | 295 | const formatter = ( |
290 | 296 | TYPE_VALUE_RESOLVER_MAP[this.type] || |
291 | 297 | TYPE_VALUE_RESOLVER_MAP['default'] |
... | ... | @@ -294,7 +300,7 @@ |
294 | 300 | return formatter(value, this.format || format); |
295 | 301 | }, |
296 | 302 | isConfirm(){ |
297 | - return this.confirm || this.type === 'datetime' || this.type === 'datetimerange'; | |
303 | + return this.confirm || this.type === 'datetime' || this.type === 'datetimerange' || this.multiple; | |
298 | 304 | } |
299 | 305 | }, |
300 | 306 | methods: { |
... | ... | @@ -393,8 +399,10 @@ |
393 | 399 | }, |
394 | 400 | onPick(dates, visible = false) { |
395 | 401 | |
396 | - if (this.type === 'multiple'){ | |
397 | - this.internalValue = [...this.internalValue, dates]; // TODO: filter multiple date duplicates | |
402 | + if (this.multiple){ | |
403 | + const allDates = [...this.internalValue, dates].filter(Boolean); | |
404 | + const timeStamps = allDates.map(date => date.getTime()).filter((ts, i, arr) => arr.indexOf(ts) === i); // filter away duplicates | |
405 | + this.internalValue = timeStamps.map(ts => new Date(ts)); | |
398 | 406 | } else { |
399 | 407 | this.internalValue = Array.isArray(dates) ? dates : [dates]; |
400 | 408 | } | ... | ... |