optimized time picker

master v2.0.1
A1Gard 3 weeks ago
parent 178f851f4f
commit b6019d821e

@ -247,12 +247,12 @@ export default {
methods: { methods: {
showModal(i){ showModal(i){
console.log('ii',i); // console.log('ii',i);
this.qOnEdit = i; this.qOnEdit = i;
this.modal = true; this.modal = true;
}, },
changeImgIndex(i){ changeImgIndex(i){
console.log('jjj',i); // console.log('jjj',i);
this.quantities[this.qOnEdit].image = i; this.quantities[this.qOnEdit].image = i;
}, },
remQ(i){ remQ(i){
@ -309,7 +309,7 @@ export default {
}, },
watch: { watch: {
category_id: function (old,n) { category_id: function (old,n) {
console.log(old,n,'x'); // console.log(old,n,'x');
// if (this.lastCat != this.category_id){ // if (this.lastCat != this.category_id){
// this.lastCat = this.category_id; // this.lastCat = this.category_id;
this.updateProps(); this.updateProps();

@ -16,6 +16,7 @@
<div class="col" <div class="col"
@touchstart="startDrag('minute', $event)" @touchstart="startDrag('minute', $event)"
@mousedown="startDrag('minute', $event)" @mousedown="startDrag('minute', $event)"
@wheel="handleScroll('minute',$event)"
> >
<div> <div>
<ul :style="mTop"> <ul :style="mTop">
@ -28,6 +29,7 @@
<div class="col" <div class="col"
@touchstart="startDrag('hour', $event)" @touchstart="startDrag('hour', $event)"
@mousedown="startDrag('hour', $event)" @mousedown="startDrag('hour', $event)"
@wheel="handleScroll('hour',$event)"
> >
<div> <div>
<ul :style="hTop"> <ul :style="hTop">
@ -40,6 +42,7 @@
<div class="col" v-if="amPm" <div class="col" v-if="amPm"
@touchstart="startDrag('ampm', $event)" @touchstart="startDrag('ampm', $event)"
@mousedown="startDrag('ampm', $event)" @mousedown="startDrag('ampm', $event)"
@wheel="handleScroll('ampm',$event)"
> >
<div> <div>
<ul :style="amTop" @click="ap = Math.abs(ap - 1)"> <ul :style="amTop" @click="ap = Math.abs(ap - 1)">
@ -135,6 +138,49 @@ export default {
} }
}, },
methods: { methods: {
handleScroll(column,e){
e.preventDefault();
let change = -1;
if (e.deltaY > 0){
change = 1;
}
this.changeHandle(column,change);
},
changeHandle(column, change){
if (column == 'ampm'){
if (change == 1) {
this.ap = 1;
} else if (change == -1) {
this.ap = 0;
}
}else if (column === 'minute') {
this.m += change;
if (this.m < 0) {
this.m = 0;
}
if (this.m > 59) {
this.m = 59;
}
} else if (column === 'hour') {
this.h += change;
if (this.amPm) {
if (this.h < 1) {
this.h = 1;
}
if (this.h > this.maxHour) {
this.h = this.maxHour;
}
} else {
if (this.h < 0) {
this.h = 0;
}
if (this.h > this.maxHour - 1) {
this.h = this.maxHour - 1;
}
}
}
},
modalShow() { modalShow() {
this.modal = true; this.modal = true;
document.addEventListener('click', this.handleModal); document.addEventListener('click', this.handleModal);
@ -189,39 +235,7 @@ export default {
let change = Math.round(deltaY / this.tolerance); let change = Math.round(deltaY / this.tolerance);
// console.log(change,currentY); // console.log(change,currentY);
if (column === 'minute') { this.changeHandle(column,change);
this.m += change;
if (this.m < 0) {
this.m = 0;
}
if (this.m > 59) {
this.m = 59;
}
} else if (column === 'hour') {
this.h += change;
if (this.amPm) {
if (this.h < 1) {
this.h = 1;
}
if (this.h > this.maxHour) {
this.h = this.maxHour;
}
} else {
if (this.h < 0) {
this.h = 0;
}
if (this.h > this.maxHour - 1) {
this.h = this.maxHour - 1;
}
}
} else if (column === 'ampm' && this.amPm) {
if (change == 1) {
this.ap = 1;
} else if (change == -1) {
this.ap = 0;
}
}
if (change != 0) { if (change != 0) {
this.startY = currentY; this.startY = currentY;
@ -263,6 +277,8 @@ export default {
x = this.xvalue; x = this.xvalue;
} }
this.calc(x); this.calc(x);
// window.addEventListener('scroll', this.handleScroll);
} }
}; };
</script> </script>

Loading…
Cancel
Save