карты пвз
All checks were successful
Deploy / build (push) Successful in 2m37s

This commit is contained in:
alsaze
2025-11-10 16:35:00 +03:00
parent 6cd7bd1dec
commit bff6833781
10 changed files with 372 additions and 100 deletions

View File

@@ -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,