Blame view

src/components/date-picker/picker.vue 20 KB
17e1fcf1   梁灏   init DatePicker
1
  <template>
ecaf8d51   梁灏   Date add transfer...
2
      <div :class="[prefixCls]" v-clickoutside="handleClose">
531cd165   梁灏   support DatePicke...
3
          <div ref="reference" :class="[prefixCls + '-rel']">
e9dd4dab   梁灏   publish 0.9.11-rc-1
4
5
              <slot>
                  <i-input
acb79ba3   梁灏   fixed #433
6
                      :element-id="elementId"
e9dd4dab   梁灏   publish 0.9.11-rc-1
7
8
9
10
11
12
                      :class="[prefixCls + '-editor']"
                      :readonly="!editable || readonly"
                      :disabled="disabled"
                      :size="size"
                      :placeholder="placeholder"
                      :value="visualValue"
0460a1e8   梁灏   fixed #812
13
                      :name="name"
531cd165   梁灏   support DatePicke...
14
                      @on-input-change="handleInputChange"
e9dd4dab   梁灏   publish 0.9.11-rc-1
15
                      @on-focus="handleFocus"
030a522d   Sergio Crisostomo   make picker close...
16
                      @on-blur="handleBlur"
e9dd4dab   梁灏   publish 0.9.11-rc-1
17
                      @on-click="handleIconClick"
531cd165   梁灏   support DatePicke...
18
19
                      @mouseenter.native="handleInputMouseenter"
                      @mouseleave.native="handleInputMouseleave"
e9dd4dab   梁灏   publish 0.9.11-rc-1
20
21
22
                      :icon="iconType"></i-input>
              </slot>
          </div>
531cd165   梁灏   support DatePicke...
23
          <transition :name="transition">
ecaf8d51   梁灏   Date add transfer...
24
25
26
27
28
29
30
31
              <Drop
                  @click.native="handleTransferClick"
                  v-show="opened"
                  :class="{ [prefixCls + '-transfer']: transfer }"
                  :placement="placement"
                  ref="drop"
                  :data-transfer="transfer"
                  v-transfer-dom>
531cd165   梁灏   support DatePicke...
32
33
34
                  <div ref="picker"></div>
              </Drop>
          </transition>
0f677893   梁灏   update DatePicker
35
      </div>
17e1fcf1   梁灏   init DatePicker
36
37
  </template>
  <script>
0f677893   梁灏   update DatePicker
38
39
40
      import iInput from '../../components/input/input.vue';
      import Drop from '../../components/select/dropdown.vue';
      import clickoutside from '../../directives/clickoutside';
ecaf8d51   梁灏   Date add transfer...
41
      import TransferDom from '../../directives/transfer-dom';
0f677893   梁灏   update DatePicker
42
      import { oneOf } from '../../utils/assist';
af713093   梁灏   update TimePicker
43
      import { formatDate, parseDate } from './util';
cd78c9c4   梁灏   some comps suppor...
44
      import Emitter from '../../mixins/emitter';
0f677893   梁灏   update DatePicker
45
46
47
48
49
50
  
      const prefixCls = 'ivu-date-picker';
  
      const DEFAULT_FORMATS = {
          date: 'yyyy-MM-dd',
          month: 'yyyy-MM',
c46f385a   梁灏   update DatePicker
51
          year: 'yyyy',
0f677893   梁灏   update DatePicker
52
53
54
55
56
57
58
          datetime: 'yyyy-MM-dd HH:mm:ss',
          time: 'HH:mm:ss',
          timerange: 'HH:mm:ss',
          daterange: 'yyyy-MM-dd',
          datetimerange: 'yyyy-MM-dd HH:mm:ss'
      };
  
c46f385a   梁灏   update DatePicker
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
      const RANGE_SEPARATOR = ' - ';
  
      const DATE_FORMATTER = function(value, format) {
          return formatDate(value, format);
      };
      const DATE_PARSER = function(text, format) {
          return parseDate(text, format);
      };
      const RANGE_FORMATTER = function(value, format) {
          if (Array.isArray(value) && value.length === 2) {
              const start = value[0];
              const end = value[1];
  
              if (start && end) {
                  return formatDate(start, format) + RANGE_SEPARATOR + formatDate(end, format);
              }
          }
          return '';
      };
      const RANGE_PARSER = function(text, format) {
          const array = text.split(RANGE_SEPARATOR);
          if (array.length === 2) {
              const range1 = array[0];
              const range2 = array[1];
  
              return [parseDate(range1, format), parseDate(range2, format)];
          }
          return [];
      };
  
      const TYPE_VALUE_RESOLVER_MAP = {
          default: {
              formatter(value) {
                  if (!value) return '';
                  return '' + value;
              },
              parser(text) {
                  if (text === undefined || text === '') return null;
                  return text;
              }
          },
          date: {
              formatter: DATE_FORMATTER,
              parser: DATE_PARSER
          },
          datetime: {
              formatter: DATE_FORMATTER,
              parser: DATE_PARSER
          },
          daterange: {
              formatter: RANGE_FORMATTER,
              parser: RANGE_PARSER
          },
          datetimerange: {
              formatter: RANGE_FORMATTER,
              parser: RANGE_PARSER
          },
          timerange: {
              formatter: RANGE_FORMATTER,
              parser: RANGE_PARSER
          },
          time: {
              formatter: DATE_FORMATTER,
              parser: DATE_PARSER
          },
          month: {
              formatter: DATE_FORMATTER,
              parser: DATE_PARSER
          },
          year: {
              formatter: DATE_FORMATTER,
              parser: DATE_PARSER
          },
          number: {
              formatter(value) {
                  if (!value) return '';
                  return '' + value;
              },
              parser(text) {
                  let result = Number(text);
  
                  if (!isNaN(text)) {
                      return result;
                  } else {
                      return null;
                  }
              }
          }
      };
  
17e1fcf1   梁灏   init DatePicker
149
      export default {
21dad188   梁灏   prevent dispatch ...
150
          name: 'CalendarPicker',
cd78c9c4   梁灏   some comps suppor...
151
          mixins: [ Emitter ],
0f677893   梁灏   update DatePicker
152
          components: { iInput, Drop },
ecaf8d51   梁灏   Date add transfer...
153
          directives: { clickoutside, TransferDom },
0f677893   梁灏   update DatePicker
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
          props: {
              format: {
                  type: String
              },
              readonly: {
                  type: Boolean,
                  default: false
              },
              disabled: {
                  type: Boolean,
                  default: false
              },
              editable: {
                  type: Boolean,
                  default: true
              },
fe44201b   梁灏   DatePicker add cl...
170
171
172
173
              clearable: {
                  type: Boolean,
                  default: true
              },
b9041a0d   梁灏   DatePicker add co...
174
175
176
177
              confirm: {
                  type: Boolean,
                  default: false
              },
e9dd4dab   梁灏   publish 0.9.11-rc-1
178
179
180
181
              open: {
                  type: Boolean,
                  default: null
              },
0f677893   梁灏   update DatePicker
182
183
              size: {
                  validator (value) {
f00a037c   梁灏   some Components's...
184
                      return oneOf(value, ['small', 'large', 'default']);
0f677893   梁灏   update DatePicker
185
186
187
188
189
190
                  }
              },
              placeholder: {
                  type: String,
                  default: ''
              },
68e9b100   梁灏   update DatePicker
191
              placement: {
0f677893   梁灏   update DatePicker
192
                  validator (value) {
68e9b100   梁灏   update DatePicker
193
                      return oneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']);
0f677893   梁灏   update DatePicker
194
                  },
68e9b100   梁灏   update DatePicker
195
                  default: 'bottom-start'
0f677893   梁灏   update DatePicker
196
197
198
              },
              options: {
                  type: Object
ecaf8d51   梁灏   Date add transfer...
199
200
201
202
              },
              transfer: {
                  type: Boolean,
                  default: false
0460a1e8   梁灏   fixed #812
203
204
205
              },
              name: {
                  type: String
acb79ba3   梁灏   fixed #433
206
207
208
              },
              elementId: {
                  type: String
0f677893   梁灏   update DatePicker
209
210
              }
          },
17e1fcf1   梁灏   init DatePicker
211
          data () {
0f677893   梁灏   update DatePicker
212
213
214
              return {
                  prefixCls: prefixCls,
                  showClose: false,
0f677893   梁灏   update DatePicker
215
                  visible: false,
50637863   梁灏   update DatePicker
216
                  picker: null,
68e9b100   梁灏   update DatePicker
217
                  internalValue: '',
531cd165   梁灏   support DatePicke...
218
                  disableClickOutSide: false,    // fixed when click a date,trigger clickoutside to close picker
ecaf8d51   梁灏   Date add transfer...
219
                  disableCloseUnderTransfer: false,  // transfer 模式下,点击Drop也会触发关闭
531cd165   梁灏   support DatePicke...
220
                  currentValue: this.value
b0893113   jingsam   :art: add eslint
221
              };
0f677893   梁灏   update DatePicker
222
223
          },
          computed: {
e9dd4dab   梁灏   publish 0.9.11-rc-1
224
225
226
              opened () {
                  return this.open === null ? this.visible : this.open;
              },
0f677893   梁灏   update DatePicker
227
              iconType () {
9d844d53   梁灏   fixed Layout bug
228
                  let icon = 'ios-calendar-outline';
456877a1   梁灏   update TimePicker
229
                  if (this.type === 'time' || this.type === 'timerange') icon = 'ios-clock-outline';
9d844d53   梁灏   fixed Layout bug
230
231
                  if (this.showClose) icon = 'ios-close';
                  return icon;
0f677893   梁灏   update DatePicker
232
              },
d20fe0ee   梁灏   update DatePicker
233
234
235
236
237
238
239
              transition () {
                  if (this.placement === 'bottom-start' || this.placement === 'bottom' || this.placement === 'bottom-end') {
                      return 'slide-up';
                  } else {
                      return 'slide-down';
                  }
              },
c46f385a   梁灏   update DatePicker
240
              selectionMode() {
472b4ff1   梁灏   update DatePicker
241
                  if (this.type === 'month') {
c46f385a   梁灏   update DatePicker
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
                      return 'month';
                  } else if (this.type === 'year') {
                      return 'year';
                  }
  
                  return 'day';
              },
              visualValue: {
                  get () {
                      const value = this.internalValue;
                      if (!value) return;
                      const formatter = (
                          TYPE_VALUE_RESOLVER_MAP[this.type] ||
                          TYPE_VALUE_RESOLVER_MAP['default']
                      ).formatter;
                      const format = DEFAULT_FORMATS[this.type];
  
                      return formatter(value, this.format || format);
                  },
  
                  set (value) {
                      if (value) {
                          const type = this.type;
                          const parser = (
                              TYPE_VALUE_RESOLVER_MAP[type] ||
                              TYPE_VALUE_RESOLVER_MAP['default']
                          ).parser;
                          const parsedValue = parser(value, this.format || DEFAULT_FORMATS[type]);
c46f385a   梁灏   update DatePicker
270
271
272
273
274
275
276
                          if (parsedValue) {
                              if (this.picker) this.picker.value = parsedValue;
                          }
                          return;
                      }
                      if (this.picker) this.picker.value = value;
                  }
0f677893   梁灏   update DatePicker
277
278
279
              }
          },
          methods: {
ecaf8d51   梁灏   Date add transfer...
280
281
282
283
              // 开启 transfer 时,点击 Drop 即会关闭,这里不让其关闭
              handleTransferClick () {
                  if (this.transfer) this.disableCloseUnderTransfer = true;
              },
0f677893   梁灏   update DatePicker
284
              handleClose () {
ecaf8d51   梁灏   Date add transfer...
285
286
287
288
                  if (this.disableCloseUnderTransfer) {
                      this.disableCloseUnderTransfer = false;
                      return false;
                  }
1b7aefea   梁灏   update Picker
289
                  if (this.open !== null) return;
762c8ddf   梁灏   update DatePicker
290
291
  //                if (!this.disableClickOutSide) this.visible = false;
                  this.visible = false;
68e9b100   梁灏   update DatePicker
292
                  this.disableClickOutSide = false;
0f677893   梁灏   update DatePicker
293
294
              },
              handleFocus () {
e1874103   梁灏   update DatePicker
295
                  if (this.readonly) return;
0f677893   梁灏   update DatePicker
296
297
                  this.visible = true;
              },
030a522d   Sergio Crisostomo   make picker close...
298
299
300
              handleBlur () {
                  this.visible = false;
              },
e1874103   梁灏   update DatePicker
301
302
303
304
305
              handleInputChange (event) {
                  const oldValue = this.visualValue;
                  const value = event.target.value;
  
                  let correctValue = '';
7c5ccdab   梁灏   update DatePicker
306
307
308
                  let correctDate = '';
                  const type = this.type;
                  const format = this.format || DEFAULT_FORMATS[type];
e1874103   梁灏   update DatePicker
309
  
7c5ccdab   梁灏   update DatePicker
310
311
312
313
314
315
316
317
318
319
320
321
322
                  if (type === 'daterange' || type === 'timerange' || type === 'datetimerange') {
                      const parser = (
                          TYPE_VALUE_RESOLVER_MAP[type] ||
                          TYPE_VALUE_RESOLVER_MAP['default']
                      ).parser;
  
                      const formatter = (
                          TYPE_VALUE_RESOLVER_MAP[type] ||
                          TYPE_VALUE_RESOLVER_MAP['default']
                      ).formatter;
  
                      const parsedValue = parser(value, format);
  
3602b78d   梁灏   update DatePicker
323
324
325
326
                      if (parsedValue[0] instanceof Date && parsedValue[1] instanceof Date) {
                          if (parsedValue[0].getTime() > parsedValue[1].getTime()) {
                              correctValue = oldValue;
                          } else {
3602b78d   梁灏   update DatePicker
327
328
                              correctValue = formatter(parsedValue, format);
                          }
699a9dc8   梁灏   update DatePicker
329
                          // todo 判断disabledDate
e1874103   梁灏   update DatePicker
330
                      } else {
7c5ccdab   梁灏   update DatePicker
331
                          correctValue = oldValue;
e1874103   梁灏   update DatePicker
332
                      }
7c5ccdab   梁灏   update DatePicker
333
  
3602b78d   梁灏   update DatePicker
334
                      correctDate = parser(correctValue, format);
af713093   梁灏   update TimePicker
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
                  } else if (type === 'time') {
                      const parsedDate = parseDate(value, format);
  
                      if (parsedDate instanceof Date) {
                          if (this.disabledHours.length || this.disabledMinutes.length || this.disabledSeconds.length) {
                              const hours = parsedDate.getHours();
                              const minutes = parsedDate.getMinutes();
                              const seconds = parsedDate.getSeconds();
  
                              if ((this.disabledHours.length && this.disabledHours.indexOf(hours) > -1) ||
                                  (this.disabledMinutes.length && this.disabledMinutes.indexOf(minutes) > -1) ||
                                  (this.disabledSeconds.length && this.disabledSeconds.indexOf(seconds) > -1)) {
                                  correctValue = oldValue;
                              } else {
                                  correctValue = formatDate(parsedDate, format);
                              }
                          } else {
                              correctValue = formatDate(parsedDate, format);
                          }
                      } else {
                          correctValue = oldValue;
                      }
  
                      correctDate = parseDate(correctValue, format);
e1874103   梁灏   update DatePicker
359
                  } else {
7c5ccdab   梁灏   update DatePicker
360
361
362
                      const parsedDate = parseDate(value, format);
  
                      if (parsedDate instanceof Date) {
d31b0801   梁灏   fixed DatePicker bug
363
364
                          const options = this.options || false;
                          if (options && options.disabledDate && typeof options.disabledDate === 'function' && options.disabledDate(new Date(parsedDate))) {
7c5ccdab   梁灏   update DatePicker
365
366
367
368
                              correctValue = oldValue;
                          } else {
                              correctValue = formatDate(parsedDate, format);
                          }
77883b8c   Sergio Crisostomo   Return empty stri...
369
370
                      } else if (!parsedDate) {
                          correctValue = '';
7c5ccdab   梁灏   update DatePicker
371
372
373
                      } else {
                          correctValue = oldValue;
                      }
e1874103   梁灏   update DatePicker
374
  
7c5ccdab   梁灏   update DatePicker
375
376
                      correctDate = parseDate(correctValue, format);
                  }
e1874103   梁灏   update DatePicker
377
378
379
380
  
                  this.visualValue = correctValue;
                  event.target.value = correctValue;
                  this.internalValue = correctDate;
21dad188   梁灏   prevent dispatch ...
381
                  this.currentValue = correctDate;
344131a7   梁灏   update DatePicker
382
383
  
                  if (correctValue !== oldValue) this.emitChange(correctDate);
c46f385a   梁灏   update DatePicker
384
385
              },
              handleInputMouseenter () {
0f677893   梁灏   update DatePicker
386
                  if (this.readonly || this.disabled) return;
fe44201b   梁灏   DatePicker add cl...
387
                  if (this.visualValue && this.clearable) {
0f677893   梁灏   update DatePicker
388
389
390
                      this.showClose = true;
                  }
              },
c46f385a   梁灏   update DatePicker
391
              handleInputMouseleave () {
0f677893   梁灏   update DatePicker
392
393
394
                  this.showClose = false;
              },
              handleIconClick () {
7b7178f1   梁灏   fixed #528
395
396
                  if (this.showClose) {
                      this.handleClear();
f1f0206c   Aresn   fixed Date bug
397
                  } else if (!this.disabled) {
7b7178f1   梁灏   fixed #528
398
399
                      this.handleFocus();
                  }
b9041a0d   梁灏   DatePicker add co...
400
401
              },
              handleClear () {
c46f385a   梁灏   update DatePicker
402
403
                  this.visible = false;
                  this.internalValue = '';
531cd165   梁灏   support DatePicke...
404
                  this.currentValue = '';
d20fe0ee   梁灏   update DatePicker
405
                  this.$emit('on-clear');
cd78c9c4   梁灏   some comps suppor...
406
                  this.dispatch('FormItem', 'on-form-change', '');
0f677893   梁灏   update DatePicker
407
408
409
              },
              showPicker () {
                  if (!this.picker) {
531cd165   梁灏   support DatePicke...
410
                      let isConfirm = this.confirm;
5cc9b892   梁灏   update DateTimePi...
411
412
                      const type = this.type;
  
9b376832   Sergio Crisostomo   Add feature: allo...
413
                      this.picker = this.Panel.$mount(this.$refs.picker);
5cc9b892   梁灏   update DateTimePi...
414
                      if (type === 'datetime' || type === 'datetimerange') {
531cd165   梁灏   support DatePicke...
415
                          isConfirm = true;
5cc9b892   梁灏   update DateTimePi...
416
417
                          this.picker.showTime = true;
                      }
50637863   梁灏   update DatePicker
418
                      this.picker.value = this.internalValue;
531cd165   梁灏   support DatePicke...
419
                      this.picker.confirm = isConfirm;
c46f385a   梁灏   update DatePicker
420
                      this.picker.selectionMode = this.selectionMode;
50637863   梁灏   update DatePicker
421
422
                      if (this.format) this.picker.format = this.format;
  
9d844d53   梁灏   fixed Layout bug
423
424
425
426
427
428
                      // TimePicker
                      if (this.disabledHours) this.picker.disabledHours = this.disabledHours;
                      if (this.disabledMinutes) this.picker.disabledMinutes = this.disabledMinutes;
                      if (this.disabledSeconds) this.picker.disabledSeconds = this.disabledSeconds;
                      if (this.hideDisabledOptions) this.picker.hideDisabledOptions = this.hideDisabledOptions;
  
50637863   梁灏   update DatePicker
429
430
431
432
                      const options = this.options;
                      for (const option in options) {
                          this.picker[option] = options[option];
                      }
c46f385a   梁灏   update DatePicker
433
434
  
                      this.picker.$on('on-pick', (date, visible = false) => {
531cd165   梁灏   support DatePicke...
435
436
                          if (!isConfirm) this.visible = visible;
                          this.currentValue = date;
e1874103   梁灏   update DatePicker
437
                          this.picker.value = date;
c46f385a   梁灏   update DatePicker
438
                          this.picker.resetView && this.picker.resetView();
73d10c28   梁灏   update DatePicker
439
                          this.emitChange(date);
c46f385a   梁灏   update DatePicker
440
441
                      });
  
b9041a0d   梁灏   DatePicker add co...
442
443
444
445
                      this.picker.$on('on-pick-clear', () => {
                          this.handleClear();
                      });
                      this.picker.$on('on-pick-success', () => {
b9041a0d   梁灏   DatePicker add co...
446
                          this.visible = false;
d20fe0ee   梁灏   update DatePicker
447
                          this.$emit('on-ok');
b9041a0d   梁灏   DatePicker add co...
448
                      });
68e9b100   梁灏   update DatePicker
449
                      this.picker.$on('on-pick-click', () => this.disableClickOutSide = true);
0f677893   梁灏   update DatePicker
450
                  }
c46f385a   梁灏   update DatePicker
451
452
453
454
455
456
                  if (this.internalValue instanceof Date) {
                      this.picker.date = new Date(this.internalValue.getTime());
                  } else {
                      this.picker.value = this.internalValue;
                  }
                  this.picker.resetView && this.picker.resetView();
344131a7   梁灏   update DatePicker
457
458
              },
              emitChange (date) {
21dad188   梁灏   prevent dispatch ...
459
460
461
                  const newDate = this.formattingDate(date);
  
                  this.$emit('on-change', newDate);
fc0c4c78   梁灏   fixed #494
462
463
464
                  this.$nextTick(() => {
                      this.dispatch('FormItem', 'on-form-change', newDate);
                  });
21dad188   梁灏   prevent dispatch ...
465
466
              },
              formattingDate (date) {
456877a1   梁灏   update TimePicker
467
468
                  const type = this.type;
                  const format = this.format || DEFAULT_FORMATS[type];
699a9dc8   梁灏   update DatePicker
469
                  const formatter = (
456877a1   梁灏   update TimePicker
470
                      TYPE_VALUE_RESOLVER_MAP[type] ||
699a9dc8   梁灏   update DatePicker
471
472
473
                      TYPE_VALUE_RESOLVER_MAP['default']
                  ).formatter;
  
0fd13696   梁灏   fixed DatePicker ...
474
                  let newDate = formatter(date, format);
61d5d48b   Rijn   return array of f...
475
                  if (type === 'daterange' || type === 'timerange' || type === 'datetimerange') {
0fd13696   梁灏   fixed DatePicker ...
476
477
                      newDate = [newDate.split(RANGE_SEPARATOR)[0], newDate.split(RANGE_SEPARATOR)[1]];
                  }
21dad188   梁灏   prevent dispatch ...
478
                  return newDate;
0f677893   梁灏   update DatePicker
479
480
481
482
483
484
485
              }
          },
          watch: {
              visible (val) {
                  if (val) {
                      this.showPicker();
                      this.$refs.drop.update();
d20fe0ee   梁灏   update DatePicker
486
                      if (this.open === null) this.$emit('on-open-change', true);
0f677893   梁灏   update DatePicker
487
                  } else {
5cc9b892   梁灏   update DateTimePi...
488
                      if (this.picker) this.picker.resetView && this.picker.resetView(true);
0f677893   梁灏   update DatePicker
489
                      this.$refs.drop.destroy();
d20fe0ee   梁灏   update DatePicker
490
                      if (this.open === null) this.$emit('on-open-change', false);
030a522d   Sergio Crisostomo   make picker close...
491
492
493
                      // blur the input
                      const input = this.$el.querySelector('input');
                      if (input) input.blur();
c46f385a   梁灏   update DatePicker
494
495
496
497
498
                  }
              },
              internalValue(val) {
                  if (!val && this.picker && typeof this.picker.handleClear === 'function') {
                      this.picker.handleClear();
0f677893   梁灏   update DatePicker
499
                  }
21dad188   梁灏   prevent dispatch ...
500
  //                this.$emit('input', val);
50637863   梁灏   update DatePicker
501
              },
531cd165   梁灏   support DatePicke...
502
503
504
505
              value (val) {
                  this.currentValue = val;
              },
              currentValue: {
50637863   梁灏   update DatePicker
506
507
                  immediate: true,
                  handler (val) {
2dbbd7de   梁灏   update TimePicker
508
                      const type = this.type;
0dd7b94a   梁灏   update TimePicker
509
510
511
512
                      const parser = (
                          TYPE_VALUE_RESOLVER_MAP[type] ||
                          TYPE_VALUE_RESOLVER_MAP['default']
                      ).parser;
d609ba86   梁灏   update TimePicker
513
  
4db5926d   梁灏   fixed #153
514
                      if (val && type === 'time' && !(val instanceof Date)) {
0dd7b94a   梁灏   update TimePicker
515
                          val = parser(val, this.format || DEFAULT_FORMATS[type]);
65255c96   Sergio Crisostomo   fix date formatti...
516
                      } else if (val && type.match(/range$/) && Array.isArray(val) && val.filter(Boolean).length === 2 && !(val[0] instanceof Date) && !(val[1] instanceof Date)) {
0dd7b94a   梁灏   update TimePicker
517
                          val = val.join(RANGE_SEPARATOR);
2dbbd7de   梁灏   update TimePicker
518
                          val = parser(val, this.format || DEFAULT_FORMATS[type]);
b61002ba   Sergio Crisostomo   force string date...
519
                      } else if (typeof val === 'string' && type.indexOf('time') !== 0 ){
5d1c24c7   Sergio Crisostomo   correct behaviour...
520
                          val = parser(val, this.format || DEFAULT_FORMATS[type]) || val;
2dbbd7de   梁灏   update TimePicker
521
                      }
0dd7b94a   梁灏   update TimePicker
522
  
c46f385a   梁灏   update DatePicker
523
                      this.internalValue = val;
531cd165   梁灏   support DatePicke...
524
                      this.$emit('input', val);
50637863   梁灏   update DatePicker
525
                  }
d20fe0ee   梁灏   update DatePicker
526
527
528
529
530
531
532
533
              },
              open (val) {
                  if (val === true) {
                      this.visible = val;
                      this.$emit('on-open-change', true);
                  } else if (val === false) {
                      this.$emit('on-open-change', false);
                  }
0f677893   梁灏   update DatePicker
534
              }
17e1fcf1   梁灏   init DatePicker
535
          },
0f677893   梁灏   update DatePicker
536
537
538
539
          beforeDestroy () {
              if (this.picker) {
                  this.picker.$destroy();
              }
e9dd4dab   梁灏   publish 0.9.11-rc-1
540
          },
531cd165   梁灏   support DatePicke...
541
          mounted () {
d20fe0ee   梁灏   update DatePicker
542
              if (this.open !== null) this.visible = this.open;
0f677893   梁灏   update DatePicker
543
          }
b0893113   jingsam   :art: add eslint
544
545
      };
  </script>