397 lines
12 KiB
Plaintext
397 lines
12 KiB
Plaintext
<template>
|
|
<view class="product-reply-page">
|
|
<!-- 1. 搜索筛选 -->
|
|
<view class="search-card">
|
|
<view class="search-row">
|
|
<view class="search-item">
|
|
<text class="label">评价时间:</text>
|
|
<AnalyticsDateRangePicker
|
|
:initialStartDate="startDate"
|
|
:initialEndDate="endDate"
|
|
@apply="onApplyRange"
|
|
@clear="onClearRange"
|
|
/>
|
|
</view>
|
|
<view class="search-item">
|
|
<text class="label">评价状态:</text>
|
|
<picker :value="statusIndex" :range="statusOptions" range-key="label" @change="onStatusChange">
|
|
<view class="mock-select">
|
|
<text>{{ statusOptions[statusIndex].label }}</text>
|
|
<text class="arrow">▼</text>
|
|
</view>
|
|
</picker>
|
|
</view>
|
|
</view>
|
|
<view class="search-row mt-16">
|
|
<view class="search-item">
|
|
<text class="label">商品名称:</text>
|
|
<input class="mock-input" v-model="searchProduct" placeholder="请输入商品信息" @confirm="onSearch" />
|
|
</view>
|
|
<view class="search-item">
|
|
<text class="label">用户名称:</text>
|
|
<input class="mock-input" v-model="searchUser" placeholder="请输入" @confirm="onSearch" />
|
|
</view>
|
|
<button class="btn-primary" @click="onSearch">查询</button>
|
|
<button class="btn-white" @click="onReset">重置</button>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 2. 操作行 -->
|
|
<view class="action-bar">
|
|
<button class="btn-primary" @click="onAddSelfReview">添加自评</button>
|
|
</view>
|
|
|
|
<!-- 3. 数据表格 -->
|
|
<view class="list-card">
|
|
<view class="table-v5">
|
|
<view class="th-row">
|
|
<view class="th col-check"><text>□</text></view>
|
|
<view class="th col-id"><text>评论ID</text></view>
|
|
<view class="th col-product"><text>商品信息</text></view>
|
|
<view class="th col-user"><text>用户名称</text></view>
|
|
<view class="th col-score"><text>评分</text></view>
|
|
<view class="th col-content"><text>评价内容</text></view>
|
|
<view class="th col-reply"><text>回复内容</text></view>
|
|
<view class="th col-status"><text>审核状态</text></view>
|
|
<view class="th col-time"><text>评价时间</text></view>
|
|
<view class="th col-op"><text>操作</text></view>
|
|
</view>
|
|
|
|
<view v-if="isLoading" class="table-empty" style="padding: 40px; text-align: center;">
|
|
<text>数据加载中...</text>
|
|
</view>
|
|
<view v-else-if="replyList.length === 0" class="table-empty" style="padding: 40px; text-align: center;">
|
|
<text>暂无评价数据</text>
|
|
</view>
|
|
<view v-else v-for="item in replyList" :key="item.id" class="tr-row">
|
|
<view class="td col-check"><text>□</text></view>
|
|
<view class="td col-id"><text>{{ item.id }}</text></view>
|
|
<view class="td col-product">
|
|
<image class="p-img" :src="item.product_image || '/static/logo.png'" mode="aspectFill" />
|
|
<text class="p-name-txt">{{ item.product_name }}</text>
|
|
</view>
|
|
<view class="td col-user"><text>{{ item.username || '游客' }}</text></view>
|
|
<view class="td col-score"><text>{{ item.rating }}</text></view>
|
|
<view class="td col-content"><text class="blue-link">{{ item.content }}</text></view>
|
|
<view class="td col-reply"><text>{{ item.merchant_reply || '无' }}</text></view>
|
|
<view class="td col-status">
|
|
<text class="status-tag" :class="item.status === 1 ? 'pass' : (item.status === 3 ? 'fail' : 'wait')">
|
|
{{ item.status === 1 ? '通过' : (item.status === 3 ? '已驳回' : '待审核') }}
|
|
</text>
|
|
</view>
|
|
<view class="td col-time"><text>{{ formatDateTime(item.created_at) }}</text></view>
|
|
<view class="td col-op">
|
|
<text v-if="item.status !== 1" class="op-link" @click="handleApprove(item.id)">通过</text>
|
|
<text v-if="item.status !== 3" class="op-link" @click="handleReject(item.id)">驳回</text>
|
|
<text class="op-link" @click="handleReply(item)">回复</text>
|
|
<text class="op-link red" @click="handleDelete(item.id)">删除</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 分页 -->
|
|
<view class="pagination-row">
|
|
<text class="total">共 {{ total }} 条</text>
|
|
<view class="page-ctrl">
|
|
<text class="page-btn" :class="{ disabled: page <= 1 }" @click="onPrevPage">{"<"}</text>
|
|
<text class="page-num active">{{ page }}</text>
|
|
<text class="page-btn" :class="{ disabled: replyList.length < pageSize }" @click="onNextPage">{">"}</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup lang="uts">
|
|
import { ref, onMounted } from 'vue'
|
|
import AnalyticsDateRangePicker from '@/components/analytics/AnalyticsDateRangePicker.uvue'
|
|
import { fetchAdminProductReviews, approveProductReview, rejectProductReview, replyProductReview, deleteProductReview, type ProductReviewItem } from '@/services/admin/productReviewService.uts'
|
|
|
|
const replyList = ref<Array<ProductReviewItem>>([])
|
|
const isLoading = ref(false)
|
|
|
|
const searchProduct = ref('')
|
|
const searchUser = ref('')
|
|
|
|
const statusOptions = ref<Array<{ label: string; value: number | null }>>([
|
|
{ label: '全部', value: null },
|
|
{ label: '通过', value: 1 },
|
|
{ label: '已驳回', value: 3 },
|
|
{ label: '已删除', value: 2 }
|
|
])
|
|
const statusIndex = ref(0)
|
|
|
|
const startDate = ref<string>('')
|
|
const endDate = ref<string>('')
|
|
|
|
const page = ref(1)
|
|
const pageSize = 20
|
|
const total = ref(0)
|
|
|
|
onMounted(() => {
|
|
// 默认最近 30 天(本地日期)
|
|
const end = new Date()
|
|
const start = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)
|
|
startDate.value = start.toISOString().substring(0, 10)
|
|
endDate.value = end.toISOString().substring(0, 10)
|
|
loadData()
|
|
})
|
|
|
|
async function loadData() {
|
|
isLoading.value = true
|
|
try {
|
|
const startTime = startDate.value ? (startDate.value + ' 00:00:00') : null
|
|
const endTime = endDate.value ? (endDate.value + ' 23:59:59') : null
|
|
|
|
const res = await fetchAdminProductReviews({
|
|
searchProduct: searchProduct.value,
|
|
searchUser: searchUser.value,
|
|
status: statusOptions.value[statusIndex.value].value,
|
|
startTime,
|
|
endTime,
|
|
page: page.value,
|
|
pageSize
|
|
})
|
|
replyList.value = res.items
|
|
total.value = res.total
|
|
} catch (e) {
|
|
uni.showToast({ title: '加载评价失败', icon: 'none' })
|
|
} finally {
|
|
isLoading.value = false
|
|
}
|
|
}
|
|
|
|
function onApplyRange(payload: any) {
|
|
startDate.value = payload?.start ?? ''
|
|
endDate.value = payload?.end ?? ''
|
|
page.value = 1
|
|
loadData()
|
|
}
|
|
|
|
function onClearRange() {
|
|
startDate.value = ''
|
|
endDate.value = ''
|
|
page.value = 1
|
|
loadData()
|
|
}
|
|
|
|
function onStatusChange(e: any) {
|
|
statusIndex.value = parseInt(String(e.detail.value))
|
|
page.value = 1
|
|
loadData()
|
|
}
|
|
|
|
function onSearch() {
|
|
page.value = 1
|
|
loadData()
|
|
}
|
|
|
|
function onReset() {
|
|
searchProduct.value = ''
|
|
searchUser.value = ''
|
|
statusIndex.value = 0
|
|
page.value = 1
|
|
loadData()
|
|
}
|
|
|
|
function onPrevPage() {
|
|
if (page.value <= 1) return
|
|
page.value--
|
|
loadData()
|
|
}
|
|
|
|
function onNextPage() {
|
|
if (replyList.value.length < pageSize) return
|
|
page.value++
|
|
loadData()
|
|
}
|
|
|
|
function onAddSelfReview() {
|
|
uni.showToast({ title: '添加自评开发中', icon: 'none' })
|
|
}
|
|
|
|
function formatDateTime(iso: string): string {
|
|
try {
|
|
return iso.replace('T', ' ').split('.')[0]
|
|
} catch (e) {
|
|
return iso
|
|
}
|
|
}
|
|
|
|
async function handleApprove(id: string) {
|
|
const ok = await approveProductReview(id)
|
|
if (ok) {
|
|
uni.showToast({ title: '已通过', icon: 'success' })
|
|
loadData()
|
|
}
|
|
}
|
|
|
|
async function handleReject(id: string) {
|
|
const ok = await rejectProductReview(id)
|
|
if (ok) {
|
|
uni.showToast({ title: '已驳回', icon: 'success' })
|
|
loadData()
|
|
}
|
|
}
|
|
|
|
async function handleDelete(id: string) {
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: '确定删除该评价吗?',
|
|
success: async (res) => {
|
|
if (!res.confirm) return
|
|
const ok = await deleteProductReview(id)
|
|
if (ok) {
|
|
uni.showToast({ title: '已删除', icon: 'success' })
|
|
loadData()
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
async function handleReply(item: ProductReviewItem) {
|
|
uni.showModal({
|
|
title: '回复评价',
|
|
editable: true,
|
|
content: item.merchant_reply ?? '',
|
|
placeholderText: '请输入回复内容',
|
|
success: async (res) => {
|
|
if (!res.confirm) return
|
|
const content = res.content ?? ''
|
|
const ok = await replyProductReview(item.id, content)
|
|
if (ok) {
|
|
uni.showToast({ title: '回复成功', icon: 'success' })
|
|
loadData()
|
|
}
|
|
}
|
|
})
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.product-reply-page {
|
|
padding: 20px;
|
|
background-color: #f5f7f9;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.search-card {
|
|
background: #fff;
|
|
padding: 24px;
|
|
border-radius: 4px;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.search-row {
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
gap: 24px;
|
|
}
|
|
.mt-16 { margin-top: 16px; }
|
|
|
|
.search-item {
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
.label { font-size: 14px; color: #606266; width: 80px; text-align: right; }
|
|
}
|
|
|
|
.mock-date-range {
|
|
width: 280px; height: 32px; border: 1px solid #dcdfe6; border-radius: 4px;
|
|
display: flex; flex-direction: row; align-items: center; padding: 0 12px; gap: 8px;
|
|
.emoji { font-size: 14px; }
|
|
.txt { font-size: 13px; color: #c0c4cc; }
|
|
}
|
|
|
|
.mock-select {
|
|
width: 160px; height: 32px; border: 1px solid #dcdfe6; border-radius: 4px;
|
|
display: flex; flex-direction: row; align-items: center; justify-content: space-between;
|
|
padding: 0 12px; font-size: 13px; color: #606266;
|
|
.arrow { font-size: 10px; color: #c0c4cc; }
|
|
}
|
|
|
|
.mock-input {
|
|
width: 200px; height: 32px; border: 1px solid #dcdfe6; border-radius: 4px; padding: 0 12px; font-size: 13px;
|
|
}
|
|
|
|
.btn-primary { background: #1890ff; color: #fff; height: 32px; padding: 0 16px; border-radius: 4px; font-size: 14px; border: none; }
|
|
.btn-white { background: #fff; color: #606266; height: 32px; padding: 0 16px; border-radius: 4px; font-size: 14px; border: 1px solid #dcdfe6; }
|
|
|
|
.action-bar {
|
|
margin-bottom: 16px;
|
|
display: flex;
|
|
flex-direction: row;
|
|
gap: 12px;
|
|
}
|
|
|
|
.list-card {
|
|
background: #fff;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.table-v5 { width: 100%; }
|
|
|
|
.th-row {
|
|
display: flex;
|
|
flex-direction: row;
|
|
background-color: #f8f9fa;
|
|
border-bottom: 1px solid #e8e8e8;
|
|
}
|
|
|
|
.th {
|
|
padding: 12px 8px; font-size: 13px; font-weight: 500; color: #333;
|
|
display: flex; align-items: center; justify-content: center;
|
|
}
|
|
|
|
.tr-row {
|
|
display: flex; flex-direction: row; border-bottom: 1px solid #f0f0f0;
|
|
&:hover { background-color: #fafafa; }
|
|
}
|
|
|
|
.td {
|
|
padding: 12px 8px; font-size: 13px; color: #606266;
|
|
display: flex; align-items: center; justify-content: center;
|
|
}
|
|
|
|
.col-check { width: 50px; }
|
|
.col-id { width: 80px; }
|
|
.col-product { flex: 1.5; justify-content: flex-start; gap: 12px; }
|
|
.col-spec { width: 100px; }
|
|
.col-user { width: 120px; }
|
|
.col-score { width: 80px; }
|
|
.col-content { flex: 1; }
|
|
.col-reply { flex: 1; }
|
|
.col-status { width: 100px; }
|
|
.col-time { width: 160px; }
|
|
.col-op { width: 180px; }
|
|
|
|
.p-img { width: 40px; height: 40px; border-radius: 4px; }
|
|
.p-name-txt { font-size: 13px; line-height: 1.4; color: #1890ff; }
|
|
|
|
.blue-link { color: #1890ff; }
|
|
|
|
.status-tag {
|
|
padding: 2px 8px; border-radius: 2px; font-size: 12px;
|
|
&.pass { background: rgba(82, 196, 26, 0.1); color: #52c41a; }
|
|
&.wait { background: rgba(250, 173, 20, 0.1); color: #faad14; }
|
|
}
|
|
|
|
.op-link { font-size: 13px; color: #1890ff; margin: 0 4px; cursor: pointer; &.red { color: #f5222d; } }
|
|
|
|
.pagination-row {
|
|
padding: 24px; display: flex; flex-direction: row; justify-content: flex-end; align-items: center; gap: 16px;
|
|
.total { font-size: 13px; color: #606266; }
|
|
}
|
|
|
|
.page-ctrl {
|
|
display: flex; flex-direction: row; gap: 8px;
|
|
.page-num, .page-btn {
|
|
width: 32px; height: 32px; border: 1px solid #dcdfe6; border-radius: 4px;
|
|
display: flex; align-items: center; justify-content: center; font-size: 13px;
|
|
&.active { background: #1890ff; color: #fff; }
|
|
&.disabled { background: #f5f5f5; color: #ccc; }
|
|
}
|
|
}
|
|
</style>
|