Files
medical-mall/pages/mall/admin/finance/recharge.uvue

478 lines
12 KiB
Plaintext

<template>
<view class="finance-recharge">
<!-- 头部筛选区 -->
<view class="filter-card border-shadow">
<view class="filter-row">
<view class="filter-item">
<text class="filter-label">支付状态:</text>
<uni-data-select v-model="paidValue" :localdata="paidOptions" class="data-select" @change="handleQuery" />
</view>
<view class="filter-item search-wrap">
<text class="filter-label">搜索:</text>
<input class="search-input" v-model="searchKeyword" placeholder="请输入用户昵称、订单号" @confirm="handleQuery" />
</view>
<view class="btn-query" @click="handleQuery">
<text class="btn-txt">查询</text>
</view>
</view>
</view>
<!-- 统计网格 -->
<view class="stats-grid">
<view class="stat-card border-shadow" v-for="(item, index) in statsItems" :key="index">
<view class="icon-circle" :class="item.colorClass">
<text class="stat-icon">{{ item.icon }}</text>
</view>
<view class="stat-info">
<text class="stat-value">{{ item.value }}</text>
<text class="stat-label">{{ item.label }}</text>
</view>
</view>
</view>
<!-- 操作区域 -->
<view class="action-section">
<view class="btn-export">
<text class="btn-export-txt">导出</text>
</view>
</view>
<!-- 数据表格 (Flex 模拟) -->
<view class="table-container border-shadow">
<view class="table-header">
<view class="th col-id"><text class="th-txt">ID</text></view>
<view class="th col-nickname"><text class="th-txt">用户信息</text></view>
<view class="th col-orderno"><text class="th-txt">订单号</text></view>
<view class="th col-amount"><text class="th-txt">支付金额</text></view>
<view class="th col-paid"><text class="th-txt">是否支付</text></view>
<view class="th col-type"><text class="th-txt">充值类型</text></view>
<view class="th col-time"><text class="th-txt">支付时间</text></view>
<view class="th col-ops"><text class="th-txt">操作</text></view>
</view>
<view class="table-body">
<view v-if="loading" class="table-loading" style="padding: 40px; text-align: center;">
<text>加载中...</text>
</view>
<view v-else-if="tableData.length === 0" class="table-empty" style="padding: 40px; text-align: center;">
<text>暂无充值记录</text>
</view>
<view v-else class="table-row" v-for="(item, index) in tableData" :key="item.id">
<view class="td col-id"><text class="td-txt">{{ (page - 1) * pageSize + index + 1 }}</text></view>
<view class="td col-nickname">
<view class="u-info-box">
<text class="u-name">{{ item.user_name || '未知' }}</text>
<text class="u-email">{{ item.user_email || '-' }}</text>
</view>
</view>
<view class="td col-orderno"><text class="td-txt">{{ item.order_no }}</text></view>
<view class="td col-amount">
<view class="amount-box">
<text class="price">¥{{ item.price.toFixed(2) }}</text>
<text class="give" v-if="item.give_price > 0">赠:¥{{ item.give_price.toFixed(2) }}</text>
</view>
</view>
<view class="td col-paid">
<text class="status-tag" :class="item.paid == 1 ? 'paid' : 'unpaid'">
{{ item.paid == 1 ? '已支付' : '未支付' }}
</text>
</view>
<view class="td col-type"><text class="td-txt">{{ getRechargeTypeText(item.recharge_type) }}</text></view>
<view class="td col-time"><text class="td-txt">{{ item.pay_time ? item.pay_time.substring(0, 16).replace('T', ' ') : '-' }}</text></view>
<view class="td col-ops">
<text class="op-link">详情</text>
</view>
</view>
</view>
</view>
<!-- 分页区域 -->
<view class="pagination-footer">
<view class="page-total">
<text class="total-txt">共 {{ total }} 条</text>
</view>
<view class="page-btns">
<view class="p-btn" :class="{ disabled: page <= 1 }" @click="prevPage">
<text><</text>
</view>
<view class="p-btn active">
<text>{{ page }}</text>
</view>
<view class="p-btn" :class="{ disabled: page >= totalPages }" @click="nextPage">
<text>></text>
</view>
</view>
<view class="page-jump">
<text class="jump-txt">前往</text>
<input class="jump-input" v-model="jumpPage" type="number" @confirm="goToJumpPage" />
<text class="jump-txt">页</text>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { ref, onMounted, computed } from 'vue'
import { fetchRechargeList, fetchFinanceOverview } from '@/services/admin/financeService.uts'
const paidValue = ref<string>('all')
const searchKeyword = ref('')
const page = ref(1)
const pageSize = ref(15)
const total = ref(0)
const loading = ref(false)
const jumpPage = ref('')
const paidOptions = [
{ value: 'all', text: '全部状态' },
{ value: '1', text: '已支付' },
{ value: '0', text: '未支付' }
]
const statsItems = ref([
{ label: '充值总金额', value: '0.00', icon: '¥', colorClass: 'blue' },
{ label: '充值退款金额', value: '0.00', icon: '¥', colorClass: 'orange' },
{ label: '本月充值金额', value: '0.00', icon: '月', colorClass: 'green' },
{ label: '今日充值金额', value: '0.00', icon: '今', colorClass: 'pink' }
])
const tableData = ref<any[]>([])
const totalPages = computed(() : number => {
if (pageSize.value <= 0) return 1
return Math.ceil(total.value / pageSize.value)
})
async function loadStats() {
const endTime = new Date().toISOString()
const startTime = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString()
const res = await fetchFinanceOverview(startTime, endTime)
if (res != null) {
statsItems.value[0].value = res.recharge_amount.toFixed(2)
}
}
async function loadList() {
loading.value = true
try {
const paid = paidValue.value == 'all' ? null : parseInt(paidValue.value)
const res = await fetchRechargeList(
page.value,
pageSize.value,
paid,
null,
null,
searchKeyword.value || null
)
tableData.value = res.items
total.value = res.total
} catch (e) {
uni.showToast({ title: '加载充值记录失败', icon: 'none' })
} finally {
loading.value = false
}
}
onMounted(() => {
loadStats()
loadList()
})
const handleQuery = () => {
page.value = 1
loadList()
}
const prevPage = () => {
if (page.value > 1) {
page.value--
loadList()
}
}
const nextPage = () => {
if (page.value < totalPages.value) {
page.value++
loadList()
}
}
const goToJumpPage = () => {
const targetPage = parseInt(jumpPage.value)
if (!isNaN(targetPage) && targetPage >= 1 && targetPage <= totalPages.value) {
page.value = targetPage
loadList()
jumpPage.value = ''
} else {
uni.showToast({ title: '页码无效', icon: 'none' })
}
}
function getRechargeTypeText(type : string | null) : string {
if (type == 'wechat') return '微信充值'
if (type == 'alipay') return '支付宝充值'
if (type == 'system') return '后台补单'
return type || '其他充值'
}
</script>
<style scoped lang="scss">
.finance-recharge {
padding: 20px;
background-color: #f5f7fa;
min-height: 100vh;
}
.border-shadow {
background-color: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}
/* 筛选卡片 */
.filter-card {
padding: 20px 24px;
margin-bottom: 20px;
}
.filter-row {
display: flex;
flex-direction: row;
align-items: center;
}
.filter-item {
display: flex;
flex-direction: row;
align-items: center;
margin-right: 28px;
}
.filter-label {
font-size: 14px;
color: #333;
margin-right: 10px;
white-space: nowrap;
}
.data-select {
width: 140px;
}
.search-wrap {
flex: 1;
}
.search-input {
flex: 1;
height: 32px;
border: 1px solid #dcdfe6;
border-radius: 4px;
padding: 0 12px;
font-size: 13px;
}
.btn-query {
background-color: #1890ff;
border-radius: 4px;
height: 32px;
padding: 0 20px;
display: flex;
align-items: center;
justify-content: center;
margin-left: 10px;
cursor: pointer;
}
.btn-txt {
color: #fff;
font-size: 14px;
}
/* 统计网格 */
.stats-grid {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-bottom: 20px;
}
.stat-card {
width: 24%;
padding: 24px 20px;
display: flex;
flex-direction: row;
align-items: center;
}
.icon-circle {
width: 52px;
height: 52px;
border-radius: 26px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16px;
}
.blue { background-color: #e6f7ff; color: #1890ff; }
.orange { background-color: #fff7e1; color: #fa8c16; }
.green { background-color: #f6ffed; color: #52c41a; }
.pink { background-color: #fff0f6; color: #eb2f96; }
.stat-icon { font-size: 22px; font-weight: bold; }
.stat-info {
display: flex;
flex-direction: column;
}
.stat-value {
font-size: 22px;
font-weight: 700;
color: #303133;
line-height: 1.1;
}
.stat-label {
font-size: 12px;
color: #909399;
margin-top: 6px;
}
/* 操作区 */
.action-section {
margin-bottom: 15px;
}
.btn-export {
width: 60px;
height: 30px;
border: 1px solid #dcdfe6;
border-radius: 4px;
background-color: #fff;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.btn-export-txt {
font-size: 13px;
color: #606266;
}
/* 表格 */
.table-container {
display: flex;
flex-direction: column;
}
.table-header {
background-color: #f8f9fb;
display: flex;
flex-direction: row;
border-bottom: 1px solid #ebeef5;
}
.th {
padding: 12px 10px;
display: flex;
align-items: center;
justify-content: center;
}
.th-txt {
font-size: 14px;
font-weight: 600;
color: #909399;
}
.table-row {
display: flex;
flex-direction: row;
border-bottom: 1px solid #ebeef5;
min-height: 60px;
}
.td {
padding: 12px 10px;
display: flex;
align-items: center;
justify-content: center;
}
.td-txt {
font-size: 13px;
color: #606266;
}
.u-info-box {
display: flex;
flex-direction: column;
align-items: flex-start;
.u-name { font-size: 13px; color: #303133; font-weight: 500; }
.u-email { font-size: 11px; color: #909399; }
}
.amount-box {
display: flex;
flex-direction: column;
align-items: center;
.price { font-size: 14px; color: #303133; font-weight: bold; }
.give { font-size: 11px; color: #f56c6c; }
}
.status-tag {
font-size: 12px;
padding: 2px 8px;
border-radius: 2px;
&.paid { background-color: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
&.unpaid { background-color: #fff1f0; color: #ff4d4f; border: 1px solid #ffa39e; }
}
.col-id { width: 60px; }
.col-nickname { width: 180px; justify-content: flex-start; }
.col-orderno { width: 220px; }
.col-amount { width: 120px; }
.col-paid { width: 100px; }
.col-type { width: 120px; }
.col-time { width: 160px; }
.col-ops { flex: 1; min-width: 100px; }
.op-link {
font-size: 13px;
color: #1890ff;
cursor: pointer;
}
/* 分页 */
.pagination-footer {
padding: 24px 0;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
gap: 12px;
}
.total-txt { font-size: 14px; color: #606266; }
.page-btns { display: flex; flex-direction: row; gap: 8px; }
.p-btn {
width: 32px;
height: 32px;
border: 1px solid #dcdfe6;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
cursor: pointer;
}
.p-btn.active { background-color: #2d8cf0; border-color: #2d8cf0; color: #fff; }
.p-btn.disabled { color: #c0c4cc; background-color: #f5f7fa; cursor: not-allowed; }
.page-jump { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.jump-txt { font-size: 14px; color: #606266; }
.jump-input { width: 40px; height: 32px; border: 1px solid #dcdfe6; text-align: center; border-radius: 4px; font-size: 14px; }
</style>