From a4dd454a7354da60d5324a2d00fa4c7dfc141609 Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Tue, 2 Jul 2024 13:33:17 +0300 Subject: [PATCH] add calc --- components/modal.vue | 17 +++++++++++++---- types/index.d.ts | 8 +++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/components/modal.vue b/components/modal.vue index fdf5908..da5d97f 100644 --- a/components/modal.vue +++ b/components/modal.vue @@ -99,16 +99,25 @@ const total_txt = computed(() => { const pillar = parseFloat(calculatorData.value.pillar) const pillar_base = parseFloat(calculatorData.value.pillar_base) const lamelles_block = parseFloat(calculatorData.value.lamelles_block) + const { discount } = calculatorData.value const sections = section_count.value as number const extra_m = extra_section.value as number * 0.001 const length_m = fence_section.value as number const lam_count = lamelles_count.value as number + let discountValue = 1 + discount.forEach(element => { + if (sections >= element.min_quantity) { + if (element.max_quantitt && sections >= element.max_quantitt) return + discountValue -= element.percent * 0.01 + } + }); + const prices = { - pillar_length: pillar, - pillar: (pillar * lam_count * 0.115) + pillar_base, - lam_quad: lamelles_block * lam_count * 0.115, + pillar_length: discountValue * pillar, + pillar: discountValue * ((pillar * lam_count * 0.115) + pillar_base), + lam_quad: discountValue * (lamelles_block * lam_count * 0.115), } const extra = { @@ -131,7 +140,7 @@ const total_txt = computed(() => { txt: `Блок ламелей с направляющей, ${sections} шт`, value: prices.lam_quad * length_m * sections }, - } + }; const total = [extra, regular].map(item => Object.values(item).map(el => el ? el.value : 0)).flat().reduce((a, b) => a + b, 0) diff --git a/types/index.d.ts b/types/index.d.ts index 22fddb1..eea6bba 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -49,11 +49,17 @@ type ApiAdvantageType = { title: string content: string } - +type DiscountType = { + id: number + min_quantity: number + max_quantitt?: number + percent: number +} type ApiCalcType = { id: number title: string pillar: string pillar_base: string lamelles_block: string + discount: DiscountType[] } \ No newline at end of file