fix: price

This commit is contained in:
yanghao05
2025-04-09 21:28:29 +08:00
parent 500e3e199a
commit 0e037348ee
3 changed files with 20 additions and 14 deletions

View File

@@ -238,9 +238,9 @@ const formatFileSize = (bytes) => {
<!-- Price -->
<div class="col-span-1">
<label for="price" class="block text-sm font-medium text-gray-700 mb-1">价格 (¥)</label>
<InputNumber id="price" v-model="post.price" mode="currency" currency="CNY" :minFractionDigits="2"
class="w-full" />
<label for="price" class="block text-sm font-medium text-gray-700 mb-1">价格 ()</label>
<InputNumber id="price" v-model="post.price" :minFractionDigits="0" :maxFractionDigits="0"
class="w-full" placeholder="输入价格,单位:分" />
</div>
<!-- Discount -->

View File

@@ -293,8 +293,7 @@ onMounted(() => {
router.push('/posts');
}
});
</script>
</
<template>
<Toast />
@@ -323,9 +322,9 @@ onMounted(() => {
<!-- Price -->
<div class="col-span-1">
<label for="price" class="block text-sm font-medium text-gray-700 mb-1">价格 (¥)</label>
<InputNumber id="price" v-model="post.price" mode="currency" currency="CNY" :minFractionDigits="2"
class="w-full" />
<label for="price" class="block text-sm font-medium text-gray-700 mb-1">价格 ()</label>
<InputNumber id="price" v-model="post.price" :minFractionDigits="0" :maxFractionDigits="0"
class="w-full" placeholder="输入价格,单位:分" />
</div>
<!-- Discount -->

View File

@@ -130,8 +130,8 @@ const formatDateTime = (dateStr) => {
// Calculate price after discount
const calculateDiscountPrice = (price, discount) => {
if (!discount) return price;
return price * (1 - discount / 100);
if (!discount || discount >= 100) return price;
return price * discount / 100;
};
// Fetch posts data with pagination and search
@@ -154,6 +154,7 @@ const fetchPosts = async () => {
mediaTypes: getMediaTypes(post.assets),
price: post.price / 100,
publishedAt: formatDateTime(post.created_at),
editedAt: formatDateTime(post.updated_at),
viewCount: post.views,
likes: post.likes
}));
@@ -259,14 +260,14 @@ const formatMediaTypes = (mediaTypes) => {
<Column field="price" header="价格" sortable>
<template #body="{ data }">
<div class="text-sm text-gray-900">
<span class="line-through text-gray-500" v-if="data.discount">
<span class="line-through text-gray-500" v-if="data.discount != 100">
{{ formatPrice(data.price) }}
</span>
<span :class="{ 'ml-2': data.discount }">
<span :class="{ 'ml-2': data.discount != 100 }">
{{ formatPrice(calculateDiscountPrice(data.price, data.discount)) }}
</span>
<span v-if="data.discount" class="ml-2 text-red-500">
(-{{ data.discount }}%)
<span v-if="data.discount != 100" class="ml-2 text-red-500">
({{ data.discount }}%)
</span>
</div>
</template>
@@ -278,6 +279,12 @@ const formatMediaTypes = (mediaTypes) => {
</template>
</Column>
<Column field="editedAt" header="编辑时间" sortable>
<template #body="{ data }">
<div class="text-sm text-gray-900">{{ data.editedAt }}</div>
</template>
</Column>
<Column field="status" header="发布状态" sortable>
<template #body="{ data }">
<Badge :value="data.status" :severity="getBadgeSeverity(data.status)" />