fix: price
This commit is contained in:
@@ -238,9 +238,9 @@ const formatFileSize = (bytes) => {
|
|||||||
|
|
||||||
<!-- Price -->
|
<!-- Price -->
|
||||||
<div class="col-span-1">
|
<div class="col-span-1">
|
||||||
<label for="price" class="block text-sm font-medium text-gray-700 mb-1">价格 (¥)</label>
|
<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"
|
<InputNumber id="price" v-model="post.price" :minFractionDigits="0" :maxFractionDigits="0"
|
||||||
class="w-full" />
|
class="w-full" placeholder="输入价格,单位:分" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Discount -->
|
<!-- Discount -->
|
||||||
|
|||||||
@@ -293,8 +293,7 @@ onMounted(() => {
|
|||||||
router.push('/posts');
|
router.push('/posts');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Toast />
|
<Toast />
|
||||||
|
|
||||||
@@ -323,9 +322,9 @@ onMounted(() => {
|
|||||||
|
|
||||||
<!-- Price -->
|
<!-- Price -->
|
||||||
<div class="col-span-1">
|
<div class="col-span-1">
|
||||||
<label for="price" class="block text-sm font-medium text-gray-700 mb-1">价格 (¥)</label>
|
<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"
|
<InputNumber id="price" v-model="post.price" :minFractionDigits="0" :maxFractionDigits="0"
|
||||||
class="w-full" />
|
class="w-full" placeholder="输入价格,单位:分" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Discount -->
|
<!-- Discount -->
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ const formatDateTime = (dateStr) => {
|
|||||||
|
|
||||||
// Calculate price after discount
|
// Calculate price after discount
|
||||||
const calculateDiscountPrice = (price, discount) => {
|
const calculateDiscountPrice = (price, discount) => {
|
||||||
if (!discount) return price;
|
if (!discount || discount >= 100) return price;
|
||||||
return price * (1 - discount / 100);
|
return price * discount / 100;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch posts data with pagination and search
|
// Fetch posts data with pagination and search
|
||||||
@@ -154,6 +154,7 @@ const fetchPosts = async () => {
|
|||||||
mediaTypes: getMediaTypes(post.assets),
|
mediaTypes: getMediaTypes(post.assets),
|
||||||
price: post.price / 100,
|
price: post.price / 100,
|
||||||
publishedAt: formatDateTime(post.created_at),
|
publishedAt: formatDateTime(post.created_at),
|
||||||
|
editedAt: formatDateTime(post.updated_at),
|
||||||
viewCount: post.views,
|
viewCount: post.views,
|
||||||
likes: post.likes
|
likes: post.likes
|
||||||
}));
|
}));
|
||||||
@@ -259,14 +260,14 @@ const formatMediaTypes = (mediaTypes) => {
|
|||||||
<Column field="price" header="价格" sortable>
|
<Column field="price" header="价格" sortable>
|
||||||
<template #body="{ data }">
|
<template #body="{ data }">
|
||||||
<div class="text-sm text-gray-900">
|
<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) }}
|
{{ formatPrice(data.price) }}
|
||||||
</span>
|
</span>
|
||||||
<span :class="{ 'ml-2': data.discount }">
|
<span :class="{ 'ml-2': data.discount != 100 }">
|
||||||
{{ formatPrice(calculateDiscountPrice(data.price, data.discount)) }}
|
{{ formatPrice(calculateDiscountPrice(data.price, data.discount)) }}
|
||||||
</span>
|
</span>
|
||||||
<span v-if="data.discount" class="ml-2 text-red-500">
|
<span v-if="data.discount != 100" class="ml-2 text-red-500">
|
||||||
(-{{ data.discount }}%)
|
({{ data.discount }}%)
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -278,6 +279,12 @@ const formatMediaTypes = (mediaTypes) => {
|
|||||||
</template>
|
</template>
|
||||||
</Column>
|
</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>
|
<Column field="status" header="发布状态" sortable>
|
||||||
<template #body="{ data }">
|
<template #body="{ data }">
|
||||||
<Badge :value="data.status" :severity="getBadgeSeverity(data.status)" />
|
<Badge :value="data.status" :severity="getBadgeSeverity(data.status)" />
|
||||||
|
|||||||
Reference in New Issue
Block a user