357 lines
14 KiB
Vue
357 lines
14 KiB
Vue
<template>
|
|
<div class="timeslot-container">
|
|
<p class="d-none d-lg-block title-regular text-center text-uppercase font-Barlow-extra-bold m-3">Choisissez où et quand retirer votre commande</p>
|
|
<h3 class="font-Barlow-extra-bold text-center text-lg-start text-uppercase title-small">
|
|
<span class="text-green">1.</span>
|
|
Votre point de retrait
|
|
</h3>
|
|
<div class="row row-cols-1 row-cols-md-2 g-4">
|
|
<div class="col m-0" @click="choosemagasin(magasin.id)">
|
|
<div class="card card-activate mb-3">
|
|
<div class="row bkg-medium-grey shadow rounded-4 g-0 p-3">
|
|
<div class="col-4 p-3">
|
|
<img src="/sable/img/pointer.svg" class="img-fluid" alt="...">
|
|
</div>
|
|
<div class="col-8 d-flex flex-column justify-content-center align-items-center">
|
|
<div class="card-body">
|
|
<h5 class="card-title title-regular text-uppercase font-Barlow-extra-bold">{{ magasin.name }}</h5>
|
|
<p class="card-text font-Barlow-medium m-0">{{ magasin.address }}</p>
|
|
<p class="card-text font-Barlow-medium m-0">{{ magasin.postcode }} {{ magasin.city }}</p>
|
|
<p class="card-text font-Barlow-medium m-0">{{ magasin.phone }}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<input type="hidden" :value="selectedmagasin" name="selectedmagasin" />
|
|
</div>
|
|
<h3 class="font-Barlow-extra-bold text-center text-lg-start text-uppercase title-small m-3">
|
|
<span class="text-green">2.</span>
|
|
Choisissez le jour du retrait de votre commande
|
|
</h3>
|
|
<div class="datetime-collect">
|
|
<div class="timeslot-pick-wrapper">
|
|
<div class="calendar">
|
|
<h2>
|
|
<span @click="prevMonth()" v-show="canPrevMonth()">
|
|
<img src="/sable/img/chevron_prev.svg">
|
|
</span>
|
|
{{ months[currentmonth] }} {{ currentyear }}
|
|
<span @click="nextMonth()">
|
|
<img src="/sable/img/chevron_next.svg">
|
|
</span>
|
|
</h2>
|
|
<header>
|
|
<div v-for="day in days" :key="day">{{ short(day) }}</div>
|
|
</header>
|
|
<section class="content">
|
|
<div v-for="(tile, tileKey) in tiles" :key="tileKey" :class="style(tile)" @click="showCreneaux(tile)">
|
|
<span>{{ getday(tile.date) }}</span>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
<input type="hidden" :value="selectedCreneau" name="selectedcreneau">
|
|
</div>
|
|
<h3 class="font-Barlow-extra-bold text-center text-lg-start text-uppercase title-small m-3">
|
|
<span class="text-green">3.</span>
|
|
Choisissez l'heure du retrait de votre commande
|
|
</h3>
|
|
<div class="row row-cols-1 row-cols-md-2 g-4">
|
|
<div class="col" v-for="(creneau,index) in creneaux" :class="styleCren(creneau)" @click="selectSlot(creneau)" ref="cren" :key="index">
|
|
<div class="card m-0 mb-lg-3" :class="styleCren(creneau)" role="button">
|
|
<div class="row bkg-medium-grey rounded-4 g-0 p-3">
|
|
<div class="d-flex flex-column justify-content-center align-items-center">
|
|
<div class="card-body">
|
|
<h5 class="card-title title-small font-Barlow-medium">{{ creneau.horaire }}</h5>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</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
|
|
},
|
|
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(); },
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
currentmonth: null,
|
|
currentyear: this.year,
|
|
selectedDay: new Date().toLocaleDateString(),
|
|
selectedCreneau : null,
|
|
current: new Date(),
|
|
availableCreneaux: [],
|
|
scrollCounter: 0,
|
|
interval: false,
|
|
magasin: {},
|
|
selectedmagasin: null,
|
|
}
|
|
},
|
|
mounted() {
|
|
this.availableCreneaux = JSON.parse(this.dbavailablecreneaux);
|
|
this.selectedDay = this.current.toLocaleDateString();
|
|
this.currentmonth = this.month;
|
|
this.magasin = JSON.parse(this.dbmagasin);
|
|
this.loadAvailableCreneaux();
|
|
this.choosemagasin(this.magasin.id);
|
|
},
|
|
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,
|
|
'card-activate' : 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) || this.checkNoCren(date)) ? true : false,
|
|
};
|
|
if (i < this.startday)
|
|
before.push(obj);
|
|
else {
|
|
current.push(obj);
|
|
daycount ++;
|
|
}
|
|
}
|
|
return before.reverse().concat(current);
|
|
},
|
|
checkNoCren(date) {
|
|
if(this.availableCreneaux[date.toLocaleDateString()]) {
|
|
return this.availableCreneaux[date.toLocaleDateString()].length ? false : true;
|
|
}
|
|
return true;
|
|
},
|
|
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 = {
|
|
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) {
|
|
document.querySelector(".datetime-collect").display = "block";
|
|
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 {
|
|
document.querySelector(".datetime-collect").display = "none";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|