charts with period selection
This commit is contained in:
parent
bc36a670a6
commit
e3a5d306d6
1 changed files with 20 additions and 7 deletions
|
|
@ -1,7 +1,10 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import { useChartsApi } from '@/api/charts.js'
|
import { useChartsApi } from '@/api/charts.js'
|
||||||
|
import PeriodSelector from '@/components/PeriodSelector.vue'
|
||||||
import ChartsCard from '@/views/ChartsView/ChartsCard.vue'
|
import ChartsCard from '@/views/ChartsView/ChartsCard.vue'
|
||||||
|
import router from '@/router/index.js'
|
||||||
|
|
||||||
|
|
||||||
const { getChartsPrices } = useChartsApi()
|
const { getChartsPrices } = useChartsApi()
|
||||||
|
|
||||||
|
|
@ -9,27 +12,37 @@ const pricesList = ref(null)
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const error = ref(null)
|
const error = ref(null)
|
||||||
|
|
||||||
const fetchPrices = async () => {
|
const fetchPrices = async (days = 7) => {
|
||||||
|
loading.value = true
|
||||||
|
error.value = null
|
||||||
try {
|
try {
|
||||||
const response = await getChartsPrices(7)
|
const response = await getChartsPrices(days)
|
||||||
pricesList.value = response.data
|
|
||||||
if (!response.status === 400) {
|
if (response.status === 400) {
|
||||||
router.push({ name: 'collection' })
|
router.push({ name: 'collection' })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pricesList.value = response.data
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error.value = err.message
|
error.value = err.message || 'Fetch data error'
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchPrices()
|
fetchPrices(7)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function handleSelectDays(days) {
|
||||||
|
fetchPrices(days)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-grid responsive="screen" cols="1 s:1 m:2 l:2 xl:2 2xl:2" class="grid-main">
|
<PeriodSelector @days="handleSelectDays" />
|
||||||
|
<n-grid responsive="screen" cols="1 s:1 m:1 l:2 xl:2 2xl:2" class="grid-main">
|
||||||
<n-gi class="grid-item" v-for="item in pricesList" :key="item.merch_uuid">
|
<n-gi class="grid-item" v-for="item in pricesList" :key="item.merch_uuid">
|
||||||
<router-link :to="`/details/${item.merch_uuid}`" class="card-link">
|
<router-link :to="`/details/${item.merch_uuid}`" class="card-link">
|
||||||
<ChartsCard :chartsData="item" />
|
<ChartsCard :chartsData="item" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue