2016-12-26 14:50:39 +08:00
|
|
|
<template>
|
|
|
|
<div :class="classes">
|
2016-12-27 12:00:45 +08:00
|
|
|
<div :class="[prefixCls+ '-list']" v-el:hours>
|
|
|
|
<ul @click="handleClickHours">
|
|
|
|
<li :class="getCellCls(item)" v-for="item in hoursList" v-show="!item.hide" :index="$index">{{ item.text < 10 ? '0' + item.text : item.text }}</li>
|
2016-12-26 14:50:39 +08:00
|
|
|
</ul>
|
|
|
|
</div>
|
2016-12-27 12:00:45 +08:00
|
|
|
<div :class="[prefixCls+ '-list']" v-el:minutes>
|
|
|
|
<ul @click="handleClickMinutes">
|
|
|
|
<li :class="getCellCls(item)" v-for="item in minutesList" v-show="!item.hide" :index="$index">{{ item.text < 10 ? '0' + item.text : item.text }}</li>
|
2016-12-26 15:57:12 +08:00
|
|
|
</ul>
|
2016-12-26 14:50:39 +08:00
|
|
|
</div>
|
2016-12-27 12:00:45 +08:00
|
|
|
<div :class="[prefixCls+ '-list']" v-show="showSeconds" v-el:seconds>
|
|
|
|
<ul @click="handleClickSeconds">
|
|
|
|
<li :class="getCellCls(item)" v-for="item in secondsList" v-show="!item.hide" :index="$index">{{ item.text < 10 ? '0' + item.text : item.text }}</li>
|
2016-12-26 15:57:12 +08:00
|
|
|
</ul>
|
2016-12-26 14:50:39 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2016-12-26 15:57:12 +08:00
|
|
|
import Options from '../time-mixins';
|
2016-12-27 15:50:07 +08:00
|
|
|
import { deepCopy, scrollTop, firstUpperCase } from '../../../utils/assist';
|
2016-12-26 15:57:12 +08:00
|
|
|
|
2016-12-26 14:50:39 +08:00
|
|
|
const prefixCls = 'ivu-time-picker-cells';
|
|
|
|
|
|
|
|
export default {
|
2016-12-26 15:57:12 +08:00
|
|
|
mixins: [Options],
|
2016-12-26 14:50:39 +08:00
|
|
|
props: {
|
|
|
|
hours: {
|
2016-12-27 17:16:11 +08:00
|
|
|
type: [Number, String],
|
2016-12-26 14:50:39 +08:00
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
minutes: {
|
2016-12-27 17:16:11 +08:00
|
|
|
type: [Number, String],
|
2016-12-26 14:50:39 +08:00
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
seconds: {
|
2016-12-27 17:16:11 +08:00
|
|
|
type: [Number, String],
|
2016-12-26 14:50:39 +08:00
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
showSeconds: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
prefixCls: prefixCls
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
classes () {
|
|
|
|
return [
|
|
|
|
`${prefixCls}`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-with-seconds`]: this.showSeconds
|
|
|
|
}
|
|
|
|
];
|
|
|
|
},
|
|
|
|
hoursList () {
|
2016-12-26 15:57:12 +08:00
|
|
|
let hours = [];
|
|
|
|
const hour_tmpl = {
|
2016-12-27 12:00:45 +08:00
|
|
|
text: 0,
|
2016-12-26 15:57:12 +08:00
|
|
|
selected: false,
|
|
|
|
disabled: false,
|
|
|
|
hide: false
|
|
|
|
};
|
|
|
|
|
|
|
|
for (let i = 0; i < 24; i++) {
|
|
|
|
const hour = deepCopy(hour_tmpl);
|
|
|
|
hour.text = i;
|
|
|
|
|
2016-12-27 15:50:07 +08:00
|
|
|
if (this.disabledHours.length && this.disabledHours.indexOf(i) > -1) {
|
2016-12-26 15:57:12 +08:00
|
|
|
hour.disabled = true;
|
|
|
|
if (this.hideDisabledOptions) hour.hide = true;
|
|
|
|
}
|
2016-12-27 12:00:45 +08:00
|
|
|
if (this.hours === i) hour.selected = true;
|
2016-12-26 15:57:12 +08:00
|
|
|
hours.push(hour);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hours;
|
2016-12-26 14:50:39 +08:00
|
|
|
},
|
|
|
|
minutesList () {
|
2016-12-26 15:57:12 +08:00
|
|
|
let minutes = [];
|
|
|
|
const minute_tmpl = {
|
2016-12-27 12:00:45 +08:00
|
|
|
text: 0,
|
2016-12-26 15:57:12 +08:00
|
|
|
selected: false,
|
|
|
|
disabled: false,
|
|
|
|
hide: false
|
|
|
|
};
|
|
|
|
|
|
|
|
for (let i = 0; i < 60; i++) {
|
|
|
|
const minute = deepCopy(minute_tmpl);
|
|
|
|
minute.text = i;
|
|
|
|
|
2016-12-27 15:50:07 +08:00
|
|
|
if (this.disabledMinutes.length && this.disabledMinutes.indexOf(i) > -1) {
|
2016-12-26 15:57:12 +08:00
|
|
|
minute.disabled = true;
|
|
|
|
if (this.hideDisabledOptions) minute.hide = true;
|
|
|
|
}
|
2016-12-27 12:00:45 +08:00
|
|
|
if (this.minutes === i) minute.selected = true;
|
2016-12-26 15:57:12 +08:00
|
|
|
minutes.push(minute);
|
|
|
|
}
|
|
|
|
|
|
|
|
return minutes;
|
2016-12-26 14:50:39 +08:00
|
|
|
},
|
|
|
|
secondsList () {
|
2016-12-26 15:57:12 +08:00
|
|
|
let seconds = [];
|
|
|
|
const second_tmpl = {
|
2016-12-27 12:00:45 +08:00
|
|
|
text: 0,
|
2016-12-26 15:57:12 +08:00
|
|
|
selected: false,
|
|
|
|
disabled: false,
|
|
|
|
hide: false
|
|
|
|
};
|
|
|
|
|
|
|
|
for (let i = 0; i < 60; i++) {
|
|
|
|
const second = deepCopy(second_tmpl);
|
|
|
|
second.text = i;
|
|
|
|
|
2016-12-27 15:50:07 +08:00
|
|
|
if (this.disabledSeconds.length && this.disabledSeconds.indexOf(i) > -1) {
|
2016-12-26 15:57:12 +08:00
|
|
|
second.disabled = true;
|
|
|
|
if (this.hideDisabledOptions) second.hide = true;
|
|
|
|
}
|
2016-12-27 12:00:45 +08:00
|
|
|
if (this.seconds === i) second.selected = true;
|
2016-12-26 15:57:12 +08:00
|
|
|
seconds.push(second);
|
|
|
|
}
|
|
|
|
|
|
|
|
return seconds;
|
2016-12-26 14:50:39 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2016-12-26 15:57:12 +08:00
|
|
|
getCellCls (cell) {
|
|
|
|
return [
|
|
|
|
`${prefixCls}-cell`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-cell-selected`]: cell.selected,
|
|
|
|
[`${prefixCls}-cell-disabled`]: cell.disabled
|
|
|
|
}
|
|
|
|
];
|
2016-12-27 12:00:45 +08:00
|
|
|
},
|
|
|
|
handleClickHours (event) {
|
|
|
|
this.handleClick('hours', event);
|
|
|
|
},
|
|
|
|
handleClickMinutes (event) {
|
|
|
|
this.handleClick('minutes', event);
|
|
|
|
},
|
|
|
|
handleClickSeconds (event) {
|
|
|
|
this.handleClick('seconds', event);
|
|
|
|
},
|
|
|
|
handleClick (type, event) {
|
|
|
|
const target = event.target;
|
|
|
|
if (target.tagName === 'LI') {
|
|
|
|
const cell = this[`${type}List`][parseInt(event.target.getAttribute('index'))];
|
|
|
|
if (cell.disabled) return;
|
|
|
|
const data = {};
|
|
|
|
data[type] = cell.text;
|
|
|
|
this.$emit('on-change', data);
|
|
|
|
|
|
|
|
const from = this.$els[type].scrollTop;
|
2016-12-27 16:14:45 +08:00
|
|
|
const to = 24 * this.getScrollIndex(type, cell.text);
|
2016-12-27 12:00:45 +08:00
|
|
|
scrollTop(this.$els[type], from, to, 500);
|
|
|
|
}
|
2016-12-27 16:14:45 +08:00
|
|
|
},
|
|
|
|
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'));
|
|
|
|
});
|
2016-12-26 15:57:12 +08:00
|
|
|
}
|
2016-12-27 16:14:45 +08:00
|
|
|
},
|
|
|
|
compiled () {
|
|
|
|
this.updateScroll();
|
2016-12-26 14:50:39 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|