后台商品管理

This commit is contained in:
yml
2026-05-22 17:54:46 +08:00
parent 8afd94ca35
commit dfe686ce0e
12 changed files with 285 additions and 4 deletions
@@ -0,0 +1,166 @@
<script setup lang="ts">
import { Search } from '@element-plus/icons-vue'
import { computed, onMounted, reactive, ref } from 'vue'
import { fetchAdminListings, type Listing } from '@/api/listings'
const loading = ref(false)
const listings = ref<Listing[]>([])
const filters = reactive({
owner_id: '',
status: '',
review_status: '',
limit: 200,
})
const publishedCount = computed(() => listings.value.filter((item) => item.status === 'published').length)
const rentedCount = computed(() => listings.value.filter((item) => item.status === 'rented').length)
const pendingCount = computed(() => listings.value.filter((item) => item.review_status === 'pending').length)
onMounted(loadListings)
async function loadListings() {
loading.value = true
try {
listings.value = await fetchAdminListings(filters)
} finally {
loading.value = false
}
}
function resetFilters() {
filters.owner_id = ''
filters.status = ''
filters.review_status = ''
filters.limit = 200
void loadListings()
}
function money(value: number) {
return `¥${Number(value || 0).toFixed(2)}`
}
function ownerName(row: Listing) {
return row.owner_phone || row.owner_nickname || `号主 ${row.owner_id}`
}
function statusType(status: string) {
if (status === 'published') return 'success'
if (status === 'rented') return 'warning'
if (status === 'offline') return 'info'
return ''
}
function reviewType(status: string) {
if (status === 'approved') return 'success'
if (status === 'pending') return 'warning'
if (status === 'rejected') return 'danger'
return 'info'
}
</script>
<template>
<section class="page">
<div class="page-header-row">
<div class="page-header">
<p class="eyebrow">Listings</p>
<h1>商品管理</h1>
<p>查看全部租号商品号主区服平台价格押金上架状态和审核状态</p>
</div>
<div class="toolbar-actions">
<el-button @click="resetFilters">重置</el-button>
<el-button type="primary" :icon="Search" :loading="loading" @click="loadListings">查询</el-button>
</div>
</div>
<div class="metric-grid">
<div class="metric-card">
<span>当前结果</span>
<strong>{{ listings.length }} </strong>
</div>
<div class="metric-card">
<span>已上架</span>
<strong>{{ publishedCount }} </strong>
</div>
<div class="metric-card">
<span>租赁中</span>
<strong>{{ rentedCount }} </strong>
</div>
<div class="metric-card">
<span>待审核</span>
<strong>{{ pendingCount }} </strong>
</div>
</div>
<el-form class="filter-panel" label-position="top">
<el-form-item label="号主 ID">
<el-input v-model="filters.owner_id" clearable placeholder="按号主筛选" />
</el-form-item>
<el-form-item label="商品状态">
<el-select v-model="filters.status" clearable placeholder="全部状态" class="full-control">
<el-option label="草稿" value="draft" />
<el-option label="已上架" value="published" />
<el-option label="租赁中" value="rented" />
<el-option label="已下架" value="offline" />
</el-select>
</el-form-item>
<el-form-item label="审核状态">
<el-select v-model="filters.review_status" clearable placeholder="全部审核状态" class="full-control">
<el-option label="未提交" value="none" />
<el-option label="待审核" value="pending" />
<el-option label="已通过" value="approved" />
<el-option label="已拒绝" value="rejected" />
</el-select>
</el-form-item>
<el-form-item label="查询条数">
<el-input-number v-model="filters.limit" :min="20" :max="500" :step="20" class="full-control" />
</el-form-item>
</el-form>
<el-table v-loading="loading" class="table-panel" :data="listings">
<el-table-column prop="id" label="ID" width="80" />
<el-table-column label="商品" min-width="220">
<template #default="{ row }">
<strong>{{ row.title }}</strong>
<span class="table-subtext">账号 ID: {{ row.account_id }}</span>
</template>
</el-table-column>
<el-table-column label="号主" min-width="150">
<template #default="{ row }">
<strong>{{ ownerName(row) }}</strong>
<span class="table-subtext">ID: {{ row.owner_id }}</span>
</template>
</el-table-column>
<el-table-column prop="server_region" label="区服" width="120" />
<el-table-column prop="login_platform" label="平台" width="120" />
<el-table-column prop="rank_level" label="段位" width="110" />
<el-table-column prop="haf_coin_amount" label="哈夫币" width="110" />
<el-table-column label="时租" width="100">
<template #default="{ row }">{{ money(row.price_hourly) }}</template>
</el-table-column>
<el-table-column label="押金" width="100">
<template #default="{ row }">{{ money(row.deposit_amount) }}</template>
</el-table-column>
<el-table-column label="商品状态" width="110">
<template #default="{ row }">
<el-tag :type="statusType(row.status)">{{ row.status }}</el-tag>
</template>
</el-table-column>
<el-table-column label="审核状态" width="110">
<template #default="{ row }">
<el-tag :type="reviewType(row.review_status)">{{ row.review_status }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="published_at" label="上架时间" min-width="180" />
<el-table-column prop="updated_at" label="更新时间" min-width="180" />
<el-table-column label="操作" width="110">
<template #default="{ row }">
<RouterLink v-if="row.status === 'published' && row.review_status === 'approved'" :to="`/listings/${row.id}`">
<el-button size="small">前台详情</el-button>
</RouterLink>
<span v-else>-</span>
</template>
</el-table-column>
</el-table>
</section>
</template>