diff --git a/src/entities/product/model/use-product-price.ts b/src/entities/product/model/use-product-price.ts index 092c53e..23698d7 100644 --- a/src/entities/product/model/use-product-price.ts +++ b/src/entities/product/model/use-product-price.ts @@ -13,9 +13,7 @@ export function useProductPrice(variants: CrmVariant[], id: string) { count: number }[]>('added-items', []) - const currentPriceForAll = computed(() => currentUnitPrice.value * amount.value) - - const prevUnitPriceForAll = computed(() => prevUnitPrice.value * amount.value) + const storageProduct = computed(() => addedItems.value.find(item => item.id === id)) const setInitCurrentPrice = () => { currentUnitPrice.value = Number(variants[0].price) / 100 @@ -43,27 +41,35 @@ export function useProductPrice(variants: CrmVariant[], id: string) { prevUnitPrice.value = undefined } - if (oldValue === 0 && value > 0) { - addedItems.value.push({ - id, - count: value, - }) - } - - if (oldValue > 0 && value === 0) { + if (value === 0) { addedItems.value = addedItems.value.filter(item => item.id !== id) setInitCurrentPrice() + + return } + + if (storageProduct.value) { + storageProduct.value.count = value + return + } + + addedItems.value.push({ + id, + count: value, + }) }) - setInitCurrentPrice() + if (storageProduct.value) { + amount.value = storageProduct.value.count + } + else { + setInitCurrentPrice() + } return { amount, currentUnitPrice, prevUnitPrice, - currentPriceForAll, - prevUnitPriceForAll, } } diff --git a/src/entities/product/ui/ProductCard.vue b/src/entities/product/ui/ProductCard.vue index cf76561..ed620bf 100644 --- a/src/entities/product/ui/ProductCard.vue +++ b/src/entities/product/ui/ProductCard.vue @@ -8,7 +8,7 @@ const props = defineProps<{ product: CrmProduct }>() -const { amount, currentUnitPrice, prevUnitPriceForAll, prevUnitPrice } = useProductPrice(props.product.variants || [], props.product.id!) +const { amount, currentUnitPrice, prevUnitPrice } = useProductPrice(props.product.variants || [], props.product.id!) function onImageClick() { navigateTo( @@ -32,7 +32,7 @@ function onImageClick() { {{ currentUnitPrice }} ₽