2025-09-18 21:04:51 +03:00
|
|
|
<script setup>
|
2025-09-22 19:30:58 +03:00
|
|
|
import { useMerchApi } from '@/api/merch.js'
|
2025-09-18 21:04:51 +03:00
|
|
|
import { onMounted, ref } from 'vue'
|
2025-09-22 19:30:58 +03:00
|
|
|
import router from '@/router/index.js'
|
2025-09-27 19:42:35 +03:00
|
|
|
import PeriodSelector from '@/components/PeriodSelector.vue'
|
|
|
|
|
import ChartBlock from '@/components/ChartBlock.vue'
|
|
|
|
|
import { useChartsApi } from '@/api/charts.js'
|
2025-10-01 11:03:10 +03:00
|
|
|
import EditLink from '@/views/DetailsView/EditLink.vue'
|
2025-09-22 19:30:58 +03:00
|
|
|
|
2025-09-22 19:49:49 +03:00
|
|
|
const { getMerchDetails, deleteMerch } = useMerchApi()
|
2025-09-27 19:42:35 +03:00
|
|
|
const { getDistinctPrices } = useChartsApi()
|
2025-09-16 20:53:52 +03:00
|
|
|
|
2025-09-18 21:04:51 +03:00
|
|
|
const props = defineProps({
|
|
|
|
|
merch_uuid: {
|
|
|
|
|
type: String,
|
2025-09-22 19:49:49 +03:00
|
|
|
required: true,
|
|
|
|
|
},
|
2025-09-18 21:04:51 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const merchDetails = ref(null)
|
|
|
|
|
const loading = ref(true)
|
|
|
|
|
const error = ref(null)
|
|
|
|
|
|
|
|
|
|
const fetchMerch = async () => {
|
|
|
|
|
try {
|
2025-09-22 19:49:49 +03:00
|
|
|
const response = await getMerchDetails(props.merch_uuid)
|
2025-09-18 21:04:51 +03:00
|
|
|
merchDetails.value = response.data
|
2025-09-22 19:30:58 +03:00
|
|
|
|
2025-09-22 19:49:49 +03:00
|
|
|
if (!response.status === 400) {
|
|
|
|
|
router.push({ name: 'collection' })
|
|
|
|
|
}
|
2025-09-18 21:04:51 +03:00
|
|
|
} catch (err) {
|
|
|
|
|
error.value = err.message
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-22 19:30:58 +03:00
|
|
|
const showModal = ref(false)
|
|
|
|
|
const onDelete = () => {
|
|
|
|
|
showModal.value = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const confirmDelete = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await deleteMerch(props.merch_uuid)
|
|
|
|
|
if (!response.status === 200) throw new Error('Network response was not ok')
|
2025-09-22 19:49:49 +03:00
|
|
|
if (!response.status === 400) router.push({ name: 'collection' })
|
|
|
|
|
} catch (error) {
|
2025-09-22 19:30:58 +03:00
|
|
|
console.log(error)
|
|
|
|
|
}
|
|
|
|
|
showModal.value = false
|
2025-09-22 19:49:49 +03:00
|
|
|
router.push({ name: 'collection' })
|
2025-09-22 19:30:58 +03:00
|
|
|
}
|
2025-09-27 19:42:35 +03:00
|
|
|
|
|
|
|
|
const prices = ref(null)
|
|
|
|
|
const loading2 = ref(true)
|
|
|
|
|
const error2 = ref(null)
|
|
|
|
|
|
|
|
|
|
const fetchPrices = async (days = 7) => {
|
|
|
|
|
loading2.value = true
|
|
|
|
|
error2.value = null
|
|
|
|
|
try {
|
|
|
|
|
const response = await getDistinctPrices(props.merch_uuid, days)
|
|
|
|
|
|
|
|
|
|
if (response.status === 400) {
|
|
|
|
|
router.push({ name: 'collection' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prices.value = response.data
|
|
|
|
|
} catch (err) {
|
|
|
|
|
error2.value = err.message || 'Fetch data error'
|
|
|
|
|
} finally {
|
|
|
|
|
loading2.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleSelectDays(days) {
|
|
|
|
|
fetchPrices(days)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
fetchMerch()
|
|
|
|
|
fetchPrices(7)
|
|
|
|
|
})
|
2025-09-16 20:53:52 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-09-18 21:04:51 +03:00
|
|
|
<div v-if="loading">Loading...</div>
|
|
|
|
|
<div v-else-if="error">Error: {{ error }}</div>
|
|
|
|
|
<n-card v-else-if="merchDetails" :title="merchDetails.name">
|
|
|
|
|
<n-divider title-placement="left">Main</n-divider>
|
|
|
|
|
<p><strong>Uuid:</strong> {{ merchDetails.merch_uuid }}</p>
|
|
|
|
|
<p><strong>Name:</strong> {{ merchDetails.name }}</p>
|
|
|
|
|
|
2025-09-27 19:42:35 +03:00
|
|
|
<n-divider title-placement="left">Prices</n-divider>
|
|
|
|
|
<PeriodSelector @days="handleSelectDays" />
|
|
|
|
|
|
|
|
|
|
<div style="height: 400px; position: relative">
|
|
|
|
|
<ChartBlock :charts-data="prices" />
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-09-18 21:04:51 +03:00
|
|
|
<n-divider title-placement="left">Surugaya</n-divider>
|
2025-10-01 11:03:10 +03:00
|
|
|
<EditLink
|
|
|
|
|
:merch-uuid="merch_uuid"
|
|
|
|
|
origin="surugaya"
|
|
|
|
|
:name="merchDetails.name"
|
|
|
|
|
v-model="merchDetails.origin_surugaya.link" />
|
2025-09-18 21:04:51 +03:00
|
|
|
|
|
|
|
|
<n-divider title-placement="left">Mandarake</n-divider>
|
2025-10-01 11:03:10 +03:00
|
|
|
<EditLink
|
|
|
|
|
:merch-uuid="merch_uuid"
|
|
|
|
|
origin="mandarake"
|
|
|
|
|
:name="merchDetails.name"
|
|
|
|
|
v-model="merchDetails.origin_mandarake.link" />
|
|
|
|
|
|
2025-09-18 21:04:51 +03:00
|
|
|
</n-card>
|
|
|
|
|
<div v-else>Not found</div>
|
2025-09-22 19:30:58 +03:00
|
|
|
|
|
|
|
|
<div class="center-button-container">
|
|
|
|
|
<n-button type="error" class="center-button" @click="onDelete">Delete</n-button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<n-modal v-model:show="showModal" preset="dialog" title="Confirmation">
|
|
|
|
|
<template #default>
|
|
|
|
|
<p>Confirm delete</p>
|
|
|
|
|
</template>
|
|
|
|
|
<template #action>
|
|
|
|
|
<n-button @click="confirmDelete" type="error">Ok</n-button>
|
|
|
|
|
<n-button @click="showModal = false">Cancel</n-button>
|
|
|
|
|
</template>
|
|
|
|
|
</n-modal>
|
2025-09-16 20:53:52 +03:00
|
|
|
</template>
|
|
|
|
|
|
2025-09-22 19:49:49 +03:00
|
|
|
<style scoped></style>
|