From 915055614b5f6ab4758eb2b322f962c1a6894548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Tue, 27 Dec 2016 16:14:45 +0800 Subject: [PATCH] TimePicker TimePicker --- .../date-picker/base/time-spinner.vue | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/components/date-picker/base/time-spinner.vue b/src/components/date-picker/base/time-spinner.vue index cc5555d4..185f2b1a 100644 --- a/src/components/date-picker/base/time-spinner.vue +++ b/src/components/date-picker/base/time-spinner.vue @@ -156,20 +156,33 @@ this.$emit('on-change', data); const from = this.$els[type].scrollTop; - - let index = cell.text; - const Type = firstUpperCase(type); - const disabled = this[`disabled${Type}`]; - if (disabled.length && this.hideDisabledOptions) { - let _count = 0; - disabled.forEach(item => item <= index ? _count++ : ''); - index -= _count; - } - - const to = 24 * index; + const to = 24 * this.getScrollIndex(type, cell.text); scrollTop(this.$els[type], from, to, 500); } + }, + getScrollIndex (type, index) { + const Type = firstUpperCase(type); + const disabled = this[`disabled${Type}`]; + if (disabled.length && this.hideDisabledOptions) { + let _count = 0; + disabled.forEach(item => item <= index ? _count++ : ''); + index -= _count; + } + return index; + }, + updateScroll () { + const times = ['hours', 'minutes', 'seconds']; + times.forEach(type => this.$els[type].style.overflow = 'hidden'); + this.$nextTick(() => { + times.forEach(type => { + this.$els[type].scrollTop = 24 * this.getScrollIndex(type, this[type]); + }); + this.$nextTick(() => times.forEach(type => this.$els[type].style.overflow = 'auto')); + }); } + }, + compiled () { + this.updateScroll(); } }; \ No newline at end of file