386 lines
16 KiB
Vue
386 lines
16 KiB
Vue
<template>
|
|
<div class="timeslot-container">
|
|
<div class="point-relay">
|
|
<h2 class="title title_xs">1. Votre point de retrait</h2>
|
|
|
|
<!--<div class="point-relay__form form">
|
|
<input class="form__input" type="text" placeholder="Rechercher une adresse">
|
|
<button class="btn btn_blue">OK</button>
|
|
<button class="btn">
|
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="34px" height="34px">
|
|
<path fill-rule="evenodd" stroke="rgb(255, 255, 255)" stroke-width="2px" stroke-linecap="butt" stroke-linejoin="miter" fill="none" d="M16.500,5.000 C22.851,5.000 28.000,10.149 28.000,16.500 C28.000,22.851 22.851,28.000 16.500,28.000 C10.149,28.000 5.000,22.851 5.000,16.500 C5.000,10.149 10.149,5.000 16.500,5.000 Z" />
|
|
<path fill-rule="evenodd" fill="rgb(255, 255, 255)" d="M-0.000,17.000 L-0.000,16.000 L10.000,16.000 L10.000,17.000 L-0.000,17.000 Z" />
|
|
<path fill-rule="evenodd" fill="rgb(255, 255, 255)" d="M23.000,17.000 L23.000,16.000 L33.000,16.000 L33.000,17.000 L23.000,17.000 Z" />
|
|
<path fill-rule="evenodd" fill="rgb(255, 255, 255)" d="M16.000,10.000 L16.000,-0.000 L17.000,-0.000 L17.000,10.000 L16.000,10.000 Z" />
|
|
<path fill-rule="evenodd" fill="rgb(255, 255, 255)" d="M16.000,33.000 L16.000,23.000 L17.000,23.000 L17.000,33.000 L16.000,33.000 Z" />
|
|
<path fill-rule="evenodd" stroke="rgb(255, 255, 255)" stroke-width="1px" stroke-linecap="butt" stroke-linejoin="miter" fill="none" d="M16.000,16.000 L17.000,16.000 L16.000,16.000 Z" />
|
|
</svg>
|
|
</button>
|
|
</div>-->
|
|
<div class="choices">
|
|
<div class="blocks" v-for="magasin in magasins" @click="choosemagasin(magasin.id)" :class="{ active: selectedmagasin == magasin.id }">
|
|
<div class="block">
|
|
<div class="label title title_small">Point de retrait :</div>
|
|
<div class="value title title_small">{{magasin.name}}</div>
|
|
</div>
|
|
<div class="block">
|
|
<div class="label title title_small">Adresse :</div>
|
|
<div class="value">{{magasin.address}}<br>{{magasin.postcode}} {{magasin.city}}</div>
|
|
</div>
|
|
<div class="block">
|
|
<div class="label title title_small">Téléphone : </div>
|
|
<div class="value">{{magasin.phone}}</div>
|
|
</div>
|
|
<div class="map">
|
|
<iframe :src="magasin.gmaps_embed_href" width="100%" height="225" frameborder="0" style="border:0;" allowfullscreen="" loading="lazy" aria-hidden="false" tabindex="0"></iframe>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<input type="hidden" :value="selectedmagasin" name="selectedmagasin">
|
|
</div>
|
|
<div class="datetime-collect">
|
|
<h2 class="title title_xs">2. Choisissez le jour et l'heure du retrait de votre commande</h2>
|
|
<div class="timeslot-pick-wrapper">
|
|
<div class="calendar">
|
|
<h2><span @click="prevMonth()" v-show="canPrevMonth()"><img src="/ldc/img/chevron_prev.svg"></span>{{ months[currentmonth] }} {{ currentyear }}<span @click="nextMonth()"><img src="/ldc/img/chevron_next.svg"></span></h2>
|
|
<header>
|
|
<div v-for="day in days">{{ short(day) }}</div>
|
|
</header>
|
|
<section class="content">
|
|
<div v-for="tile in tiles" :class="style(tile)" @click="showCreneaux(tile)">
|
|
<span>{{ getday(tile.date) }}</span>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
<div class="creneaux">
|
|
<header>Horaires disponibles le {{selectedDay}}</header>
|
|
<section class="creneaux__list" @mousewheel.prevent="wheel">
|
|
<div class="scroll-up"
|
|
@click="scroll('up')"
|
|
@mousedown="scrollStart('up')" @mouseup="scrollStop()"
|
|
@mouseleave="scrollStop()" @touchstart="scrollStart('up')"
|
|
@touchend="scrollStop()" @touchcancel="scrollStop()"
|
|
:class="{active: (this.scrollCounter>0)}"><img src="/ldc/img/chevron_up.svg"></div>
|
|
<section class="creneaux__slots" ref="creneaux__slots" :class="{hasDown: (creneaux.length>3 && this.scrollCounter<(creneaux.length/2)), hasUp: (this.scrollCounter>0)}">
|
|
<div v-for="(creneau,index) in creneaux" :class="styleCren(creneau)" @click="selectSlot(creneau)" ref="cren" :key="index">
|
|
<span>{{creneau.horaire}}</span>
|
|
</div>
|
|
</section>
|
|
<div class="scroll-down"
|
|
@click="scroll('down')"
|
|
@mousedown="scrollStart('down')" @mouseup="scrollStop()"
|
|
@mouseleave="scrollStop()" @touchstart="scrollStart('down')"
|
|
@touchend="scrollStop()" @touchcancel="scrollStop()"
|
|
:class="{active: (creneaux.length>3 && this.scrollCounter<(creneaux.length/2)) }"><img src="/ldc/img/chevron_down.svg"></div>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
<input type="hidden" :value="selectedCreneau" name="selectedcreneau">
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
export default {
|
|
props: {
|
|
day: {
|
|
type: Number,
|
|
default: function() {
|
|
return new Date().getDay();
|
|
}
|
|
},
|
|
month : {
|
|
type: Number,
|
|
default: function() {
|
|
return new Date().getMonth();
|
|
}
|
|
},
|
|
year : {
|
|
type: Number,
|
|
default: function() {
|
|
return new Date().getFullYear();
|
|
}
|
|
},
|
|
weekend: {
|
|
type: Array,
|
|
default: function() {
|
|
return [5,6];
|
|
}
|
|
},
|
|
days: {
|
|
type: Array,
|
|
default : function() {
|
|
return ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'];
|
|
}
|
|
},
|
|
months: {
|
|
type: Array,
|
|
default: function() {
|
|
return ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octore', 'Novembre', 'Décembre'];
|
|
}
|
|
},
|
|
maxtiles: {
|
|
type: Number,
|
|
default : 34 //soit 5 semaines
|
|
},
|
|
// defaultCreneaux: {
|
|
// type: Array,
|
|
// default: function() {
|
|
// var x = 15; //minutes interval
|
|
// var times = []; // time array
|
|
// var tt = 0; // start time
|
|
// var ap = ['AM', 'PM']; // AM-PM
|
|
|
|
// //loop to increment the time and push results in array
|
|
// for (var i=0;tt<24*60; i++) {
|
|
// var hh = Math.floor(tt/60); // getting hours of day in 0-24 format
|
|
// var mm = (tt%60); // getting minutes of the hour in 0-55 format
|
|
// times[i] = ("0" + hh).slice(-2) + ':' + ("0" + mm).slice(-2) //+ ap[Math.floor(hh/12)]; // pushing data in array in [00:00 - 12:00 AM/PM format]
|
|
// tt = tt + x;
|
|
// }
|
|
|
|
// return times;
|
|
// }
|
|
// },
|
|
dbavailablecreneaux: {
|
|
type: String,
|
|
},
|
|
showOnlyAvailables: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
dbmagasin: {
|
|
type: String,
|
|
},
|
|
},
|
|
computed: {
|
|
date() { return new Date(this.currentyear, this.currentmonth, 1);},
|
|
startday() {return this.date.getDay() < 1 ? 6 : this.date.getDay() - 1;},
|
|
dayscount() {return new Date(this.currentyear, this.currentmonth + 1, 0).getDate();},
|
|
tiles() { return this.prepare(); },
|
|
creneaux: {
|
|
get: function(){ return this.listCreneaux(); },
|
|
}
|
|
},
|
|
watch: {
|
|
|
|
},
|
|
data() {
|
|
return {
|
|
currentmonth: null,
|
|
currentyear: this.year,
|
|
selectedDay : new Date().toLocaleDateString(),
|
|
selectedCreneau : null,
|
|
current: new Date(),
|
|
availableCreneaux: [],
|
|
scrollCounter: 0,
|
|
interval:false,
|
|
magasins: [],
|
|
selectedmagasin: null,
|
|
}
|
|
},
|
|
mounted() {
|
|
this.availableCreneaux = JSON.parse(this.dbavailablecreneaux);
|
|
//this.availableCrenaux = this.dbavailablecreneaux;
|
|
this.selectedDay = this.current.toLocaleDateString();
|
|
this.currentmonth = this.month; //this.months.indexOf(this.month);
|
|
this.magasins = JSON.parse(this.dbmagasin);
|
|
this.loadAvailableCreneaux();
|
|
this.choosemagasin(1);
|
|
},
|
|
methods: {
|
|
nextMonth() {
|
|
if(this.currentmonth == 11) {
|
|
this.currentmonth = 0;
|
|
this.currentyear+=1;
|
|
} else {
|
|
this.currentmonth+=1;
|
|
}
|
|
},
|
|
prevMonth() {
|
|
if(this.currentmonth == 0) {
|
|
this.currentmonth = 11;
|
|
this.currentyear-=1;
|
|
} else {
|
|
this.currentmonth-=1;
|
|
}
|
|
},
|
|
canPrevMonth() {
|
|
let lastDayOfPrevMonth = new Date(this.currentyear,this.currentmonth,0);
|
|
if(lastDayOfPrevMonth > this.current) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
},
|
|
short(value) { return value.substring(0, 3) },
|
|
getday(value) { return new Date(value).getDate() },
|
|
style(tile) {
|
|
return {
|
|
'last': tile.last,
|
|
'next': tile.next,
|
|
'current': tile.current,
|
|
'selected' : tile.selected,
|
|
'grey': tile.grey,
|
|
'unavailable': tile.unavailable
|
|
}
|
|
},
|
|
styleCren(creneau) {
|
|
return {
|
|
'dispo' : creneau.dispo,
|
|
'selected' : creneau.selected
|
|
}
|
|
},
|
|
prepare() {
|
|
let before = [];
|
|
let current = [];
|
|
let daycount = 1;
|
|
for (let i = 0; i <= this.maxtiles; i++) {
|
|
let date = new Date(this.currentyear, this.currentmonth, (i < this.startday) ? -i : daycount);
|
|
let day = date.getDay() < 1 ? 6 : date.getDay() - 1;
|
|
let obj = {
|
|
//this day is from lastmonth
|
|
last: (i < this.startday) ? true : false,
|
|
//this day is next month
|
|
next: i >= this.dayscount + this.startday,
|
|
//this is a weekend day
|
|
grey: this.weekend.find((item) => item === day) ? true : false,
|
|
//this is today
|
|
current: (new Date(this.currentyear, this.currentmonth, daycount).toDateString() == this.current.toDateString()) ? true : false,
|
|
//selected
|
|
selected: (date.toLocaleDateString() == this.selectedDay) ? true : false,
|
|
//this tile's date
|
|
date: date,
|
|
//not available
|
|
unavailable: (new Date(this.current.getFullYear(), this.current.getMonth(), this.current.getDate()) > date)? true : false,
|
|
};
|
|
if (i < this.startday)
|
|
before.push(obj);
|
|
else {
|
|
current.push(obj);
|
|
daycount++;
|
|
}
|
|
}
|
|
return before.reverse().concat(current);
|
|
},
|
|
showCreneaux(tile){
|
|
if(!tile.unavailable) {
|
|
this.selectedDay = tile.date.toLocaleDateString();
|
|
if(tile.next) {
|
|
this.nextMonth();
|
|
}
|
|
if(tile.last) {
|
|
this.prevMonth();
|
|
}
|
|
}
|
|
//this.selectedCreneau = null;
|
|
//this.creneaux = this.listCreneaux();
|
|
},
|
|
selectSlot(creneau){
|
|
if(creneau.dispo) {
|
|
this.selectedCreneau = this.selectedDay+"-"+creneau.horaire;
|
|
}
|
|
},
|
|
listCreneaux() {
|
|
let todaysAvailable = [];
|
|
if(this.selectedDay in this.availableCreneaux) {
|
|
todaysAvailable = this.availableCreneaux[""+this.selectedDay];
|
|
}
|
|
let crens = [];
|
|
|
|
todaysAvailable.forEach(element => {
|
|
let obj = {
|
|
//day: index,
|
|
horaire: element[0],
|
|
dispo: element[1],
|
|
selected: (this.selectedCreneau == this.selectedDay+"-"+element[0]) ? true : false
|
|
};
|
|
//option pour ne générer que les créneaux disponibles
|
|
if(this.showOnlyAvailables) {
|
|
if (obj.dispo) {
|
|
crens.push(obj);
|
|
}
|
|
} else {
|
|
crens.push(obj);
|
|
}
|
|
});
|
|
return crens;
|
|
},
|
|
scrollStart(way) {
|
|
this.interval = setInterval(() => {
|
|
this.scroll(way);
|
|
}, 300);
|
|
},
|
|
scrollStop() {
|
|
clearInterval(this.interval);
|
|
this.interval = false;
|
|
},
|
|
//animation
|
|
scroll(way) {
|
|
if (way == 'down') {
|
|
//ici on limite le nombre de click down
|
|
//1 er click on scroll 2 crans
|
|
//2 eme click on scroll 2 crans, etx
|
|
//et on démarre à 0 donc, -1
|
|
if (this.scrollCounter < (this.creneaux.length/2)) {
|
|
this.scrollCounter = this.scrollCounter + 1;
|
|
this.fixScrolling();
|
|
}
|
|
} else if (way == 'up') {
|
|
if (this.scrollCounter > 0) {
|
|
this.scrollCounter = this.scrollCounter - 1;
|
|
this.fixScrolling()
|
|
}
|
|
}
|
|
},
|
|
wheel(event) {
|
|
if ( event.deltaY < 0 )
|
|
{
|
|
this.scroll('up');
|
|
}
|
|
else
|
|
{
|
|
this.scroll('down');
|
|
}
|
|
},
|
|
fixScrolling(){
|
|
const divH = this.$refs.cren[this.scrollCounter].clientHeight;
|
|
if(this.scrollCounter==1) {
|
|
//cas du premier on va faire apparaite le bouton pour remonter, et réduire la taille du viewport de l'element
|
|
this.$refs.creneaux__slots.scrollTop = divH * this.scrollCounter + divH;
|
|
} else {
|
|
this.$refs.creneaux__slots.scrollTop = 2.1 * divH * this.scrollCounter;
|
|
}
|
|
},
|
|
choosemagasin(id) {
|
|
if(this.selectedmagasin != id) {
|
|
//on a changé de magasin
|
|
this.selectedCreneau = null;
|
|
this.selectedmagasin = id;
|
|
this.loadAvailableCreneaux();
|
|
}
|
|
},
|
|
loadAvailableCreneaux() {
|
|
if(this.selectedmagasin != null) {
|
|
$(".datetime-collect").show();
|
|
axios.post('/ajax/get-time-slots', {
|
|
id: this.selectedmagasin,
|
|
}).then(
|
|
(response) => {
|
|
this.availableCreneaux = response.data;
|
|
this.processing = false;
|
|
}
|
|
)
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
alert('Erreur 101');
|
|
this.processing = false;
|
|
});
|
|
} else {
|
|
$(".datetime-collect").hide();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|