This commit is contained in:
Jonathan Chevalier
2022-10-14 18:06:57 +02:00
parent f250f65814
commit bc938fa1a4
5 changed files with 108 additions and 29 deletions

View File

@@ -1,5 +1,5 @@
import {defineStore} from 'pinia'
import {add} from "date-fns";
import {add, format} from "date-fns";
const today = new Date();
@@ -13,6 +13,58 @@ const afterTomorrow =
days: 2
})
let date = {collectExpress: null, deliveryExpress: null, collectFacteur: null, deliveryFacteur: null}
const currentDay = format(today, 'e')
//const isWeekEnd = (currentDay === '7' || currentDay === '8')
if (format(today, 'HH') > 17) {
date.collectExpress = date.deliveryExpress = tomorrow
} else {
date.collectExpress = date.deliveryExpress = today
}
date.collectFacteur = tomorrow
date.deliveryFacteur = afterTomorrow
if (currentDay === '5') // jeudi
{
date.deliveryFacteur = add(today, {
days: 4
})
} else if (currentDay === '6') // vendredi
{
date.collectFacteur = add(today, {
days: 3
})
date.deliveryFacteur = add(today, {
days: 4
})
if (format(today, 'HH') > 17) {
date.collectExpress = date.deliveryExpress = add(today, {
days: 3
})
}
} else if (currentDay === '7') // samedi
{
date.collectFacteur = add(today, {
days: 2
})
date.deliveryFacteur = add(today, {
days: 3
})
date.collectExpress = date.deliveryExpress = add(today, {
days: 2
})
} else if (currentDay === '8') // dimanche ou 17
{
date.collectExpress = date.deliveryExpress = tomorrow
}
const timestampConverter = (digit13) => digit13 / 1000
export const useMMCMStore = defineStore('counter', {
@@ -30,9 +82,11 @@ export const useMMCMStore = defineStore('counter', {
fullAddress: (state) => state.street + ' ' + state.zipCode + ' ' + state.city,
deliveryMethod: (state) => state.productList.filter(p => p.id === state.idProduct)[0].name,
dateDeliveryString: (state) => new Date(state.dateDelivery).toLocaleDateString("fr-FR"),
minDateForDelivery: (state) => (state.productList.filter(p => p.id === state.idProduct)[0].ref === 'MMCM_EXPRESS') ? today : tomorrow,
minDateForDelivery: (state) => (state.productList.filter(p => p.id === state.idProduct)[0].ref === 'MMCM_EXPRESS') ? date.deliveryExpress : date.deliveryFacteur,
minDateForCollect: (state) => (state.productList.filter(p => p.id === state.idProduct)[0].ref === 'MMCM_EXPRESS') ? date.collectExpress : date.collectFacteur,
needPrescriptionDateCollect: (state) => !!(state.productList.filter(p => p.id === state.idProduct)[0].ref === 'MMCM_FACTEUR' && state.withPrescription),
dateDeliveryTimestampInSecond: (state) => timestampConverter(state.dateDelivery)
dateDeliveryTimestampInSecond: (state) => timestampConverter(state.dateDelivery),
},
actions: {
setStreet(street) {