feat: 添加用户购买作品数量统计功能
This commit is contained in:
@@ -3,8 +3,6 @@ import { userService } from '@/api/userService';
|
||||
import { formatDate } from '@/utils/date';
|
||||
import Badge from 'primevue/badge';
|
||||
import Button from 'primevue/button';
|
||||
import Column from 'primevue/column';
|
||||
import DataTable from 'primevue/datatable';
|
||||
import ProgressSpinner from 'primevue/progressspinner';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
@@ -13,12 +11,6 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
const loading = ref(false);
|
||||
const user = ref(null);
|
||||
const userArticles = ref([]);
|
||||
const totalArticles = ref(0);
|
||||
const lazyParams = ref({
|
||||
page: 1,
|
||||
limit: 10
|
||||
});
|
||||
|
||||
const fetchUserDetail = async () => {
|
||||
loading.value = true;
|
||||
@@ -32,42 +24,15 @@ const fetchUserDetail = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const fetchUserArticles = async () => {
|
||||
try {
|
||||
const response = await userService.getUserArticles(
|
||||
route.params.id,
|
||||
lazyParams.value.page,
|
||||
lazyParams.value.limit
|
||||
);
|
||||
userArticles.value = response.data.items;
|
||||
totalArticles.value = response.data.total;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch user articles:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
router.push('/users');
|
||||
};
|
||||
|
||||
const onPage = (event) => {
|
||||
lazyParams.value = {
|
||||
page: event.page + 1,
|
||||
limit: event.rows
|
||||
};
|
||||
fetchUserArticles();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserDetail();
|
||||
fetchUserArticles();
|
||||
});
|
||||
|
||||
|
||||
|
||||
const formatPrice = (price) => {
|
||||
return (price / 100).toFixed(2);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -121,25 +86,6 @@ const formatPrice = (price) => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 用户购买的曲谱列表 -->
|
||||
<div class="card">
|
||||
<h3 class="text-xl font-semibold mb-4">购买的曲谱</h3>
|
||||
<DataTable :value="userArticles" stripedRows class="p-datatable-sm" responsiveLayout="scroll"
|
||||
:lazy="true" :totalRecords="totalArticles" :rows="lazyParams.limit" :loading="loading"
|
||||
@page="onPage" paginator :rows-per-page-options="[10, 20, 50]">
|
||||
<Column field="title" header="标题"></Column>
|
||||
<Column field="price" header="价格">
|
||||
<template #body="{ data }">
|
||||
¥ {{ formatPrice(data.price) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="bought_at" header="购买时间">
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data.bought_at) }}
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user