This commit is contained in:
@@ -1,13 +1,32 @@
|
||||
import type { PickupPoint } from '~/server/shared/types/yandex_pvz'
|
||||
import { createSharedComposable, useStorage } from '@vueuse/core'
|
||||
|
||||
export const useCheckout = createSharedComposable(() => {
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const contacts = useStorage('checkout-contacts', { name: '', surname: '', phone: '', email: '' })
|
||||
const isPickupPointSelected = ref(false)
|
||||
|
||||
const setContacts = (data: { name: string, surname: string, phone: string, email: string }) => {
|
||||
contacts.value = data
|
||||
const checkoutPickupPoint = useStorage<PickupPoint | undefined>(
|
||||
'checkout-pickupPoint',
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
serializer: {
|
||||
read: (v: string) => v ? JSON.parse(v) : undefined,
|
||||
write: (v: PickupPoint | undefined) => JSON.stringify(v),
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
const setCheckoutPickupPoint = (point: PickupPoint | undefined) => {
|
||||
checkoutPickupPoint.value = point
|
||||
}
|
||||
|
||||
const checkoutContacts = useStorage('checkout-contacts', { name: '', surname: '', phone: '', email: '' })
|
||||
|
||||
const setCheckoutContacts = (data: { name: string, surname: string, phone: string, email: string }) => {
|
||||
checkoutContacts.value = data
|
||||
}
|
||||
|
||||
const checkoutSteps = [
|
||||
@@ -25,9 +44,16 @@ export const useCheckout = createSharedComposable(() => {
|
||||
},
|
||||
]
|
||||
|
||||
const currentCheckoutStep = ref(checkoutSteps.find(value => value.title === route.path.split('/').pop()) || checkoutSteps[0])
|
||||
const currentCheckoutStep
|
||||
= ref(checkoutSteps.find(value => value.title === route.path.split('/').pop()) || checkoutSteps[0])
|
||||
|
||||
function previewStep() {
|
||||
if (isPickupPointSelected.value) {
|
||||
isPickupPointSelected.value = false
|
||||
setCheckoutPickupPoint(undefined)
|
||||
return
|
||||
}
|
||||
|
||||
const findIndex = checkoutSteps.findIndex(value => value.step === currentCheckoutStep.value.step)
|
||||
if (findIndex !== 0) {
|
||||
currentCheckoutStep.value = checkoutSteps[findIndex - 1]
|
||||
@@ -52,8 +78,12 @@ export const useCheckout = createSharedComposable(() => {
|
||||
}
|
||||
|
||||
return {
|
||||
contacts,
|
||||
setContacts,
|
||||
isPickupPointSelected,
|
||||
checkoutPickupPoint,
|
||||
setCheckoutPickupPoint,
|
||||
|
||||
checkoutContacts,
|
||||
setCheckoutContacts,
|
||||
|
||||
checkoutSteps,
|
||||
currentCheckoutStep,
|
||||
|
||||
Reference in New Issue
Block a user