calculator and other cleaning

This commit is contained in:
2025-07-04 22:39:51 +02:00
parent a2db817133
commit 0bab1d83a1
19 changed files with 420 additions and 93 deletions

View File

@ -21,6 +21,7 @@ export const useCheckoutStore = defineStore('checkoutStore', () => {
const vNote = ref('')
const legalValidation = ref(false)
const termsValidation = ref(false)
const totalNumberOfProducts = ref(0)
// get address list
const addressesList = ref<AddressesList[]>()
@ -265,6 +266,13 @@ export const useCheckoutStore = defineStore('checkoutStore', () => {
},
)
totalNumberOfProducts.value = 0
if (data.cart_items && Array.isArray(data.cart_items)) {
for (const item of data.cart_items) {
totalNumberOfProducts.value = totalNumberOfProducts.value + item.quantity
}
}
products.value = data.cart_items
fullPrice.value = data.total_value
fullProductsPrice.value = data.total_value
@ -551,6 +559,7 @@ export const useCheckoutStore = defineStore('checkoutStore', () => {
paymentMethods,
currentPayment,
fullAddress,
totalNumberOfProducts,
vLegal,
vTerms,

49
stores/investmentStore.ts Normal file
View File

@ -0,0 +1,49 @@
// import { useMyFetch } from '#imports'
import type { CalculatorOutput, GenericResponse } from '~/types'
export const useInvestmentStore = defineStore('investmentStore', () => {
const store = useStore()
// const monthlySavings = ref(store.monthlySavings || 100)
// const yearsNumber = ref(store.storagePeriod || 10)
const calculationResult = ref<CalculatorOutput>({} as CalculatorOutput)
const minYear = 1
const maxYear = 20
const { $session: session } = useNuxtApp()
watch(session.cookieData, async () => {
await getCalculator()
}, { deep: true })
const getCalculator = async () => {
const query = new URLSearchParams({
monthly_deposit: String(store.monthlySavings),
years: String(store.storagePeriod),
format: 'svg',
grid: 'false',
legend: 'false',
title: 'false',
ingots_bought_dots: 'true',
draw_linear: 'true',
annotations: 'false',
show_real_value: 'false',
series_stroke_width: '1',
// colors: '#004f3d,#004f3d,#004f3d,#004f3d,#000',
colors: '#9a7f62,#9a7f62,#9a7f62,#9a7f62,#000',
})
const { data } = await useMyFetch<GenericResponse<CalculatorOutput>>(`/api/public/plan-prediction/easy/chart?${query.toString()}`)
calculationResult.value = data
}
return {
// monthlySavings,
// yearsNumber,
minYear,
maxYear,
calculationResult,
getCalculator,
}
})

View File

@ -171,6 +171,10 @@ export const useMenuStore = defineStore('menuStore', () => {
return menuItems.value?.find(item => item.id === 15)
}
function getInvestmentCalculatorMenu() {
return menuItems.value?.find(item => item.id === 16)
}
const getFirstImage = (size: 'l' | 'm' | 's' = 'm', needbaseurl: boolean) => {
const req = useRequestEvent()
const url = useRequestURL()
@ -273,7 +277,7 @@ export const useMenuStore = defineStore('menuStore', () => {
async () => {
await getLocales()
await loadMenu()
await store.getMinValue()
await store.getMinMaxRange()
await store.getCalculator()
},
{ deep: true },
@ -309,5 +313,6 @@ export const useMenuStore = defineStore('menuStore', () => {
getContactMenu,
getShopMenu,
getRegistrationMenu,
getInvestmentCalculatorMenu,
}
})

View File

@ -5,6 +5,7 @@ import type {
PlanPrediction,
} from '~/types'
import type { FrontPageSection } from '~/types/frontSection'
import type { MinMaxRange } from '~/types/planPrediction'
export const useStore = defineStore('store', () => {
const currentPageID = ref('')
@ -13,7 +14,7 @@ export const useStore = defineStore('store', () => {
const monthlySavings = ref(137)
const storagePeriod = ref(10)
const totalInvestment: Ref<number> = ref(0)
const minValue = ref()
const minMaxRange = ref({} as MinMaxRange)
const components = ref({} as FrontPageSection[])
@ -84,10 +85,10 @@ export const useStore = defineStore('store', () => {
}
}
async function getMinValue() {
async function getMinMaxRange() {
try {
const { data } = await useMyFetch<GenericResponse<number>>(
'/api/public/plan-prediction/free/minimum',
const { data } = await useMyFetch<GenericResponse<MinMaxRange>>(
'/api/public/front/minmaxinvestment',
{
headers: {
'Content-Type': 'application/json',
@ -98,23 +99,32 @@ export const useStore = defineStore('store', () => {
},
)
minValue.value = data
minMaxRange.value = data
}
catch (error) {
console.error('getList error:', error)
}
}
const getMinAmount = computed(() => {
return Math.ceil(minMaxRange.value.min)
})
const getMaxAmount = computed(() => {
return Math.ceil(minMaxRange.value.max)
})
return {
currentPageID,
components,
totalInvestment,
monthlySavings,
storagePeriod,
minValue,
minMaxRange,
getCalculator,
getComponents,
getSections,
getMinValue,
getMinMaxRange,
getMinAmount,
getMaxAmount,
}
})