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

327 lines
9.3 KiB
Plaintext

<template>
<view class="finance-balance-record">
<!-- 筛选卡片 -->
<view class="filter-card border-shadow">
<view class="filter-row">
<view class="filter-item search-wrap">
<text class="filter-label">流水搜索:</text>
<input class="search-input" v-model="searchKeyword" placeholder="订单号/昵称/电话/用户ID" @confirm="handleQuery" />
</view>
<view class="filter-item">
<text class="filter-label">交易类型:</text>
<uni-data-select v-model="typeValue" :localdata="typeOptions" class="data-select" @change="handleQuery" />
</view>
<view class="btn-query" @click="handleQuery">
<text class="btn-txt">查询</text>
</view>
</view>
</view>
<!-- 列表表格 -->
<view class="table-container border-shadow">
<view class="table-header">
<view class="th col-id"><text class="th-txt">序号</text></view>
<view class="th col-order"><text class="th-txt">关联单据</text></view>
<view class="th col-time"><text class="th-txt">交易时间</text></view>
<view class="th col-amount"><text class="th-txt">交易金额</text></view>
<view class="th col-user"><text class="th-txt">用户</text></view>
<view class="th col-type"><text class="th-txt">业务类型</text></view>
<view class="th col-remark"><text class="th-txt">备注</text></view>
<view class="th col-op"><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 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-order text-left"><text class="td-txt">{{ item.link_id || '-' }}</text></view>
<view class="td col-time"><text class="td-txt">{{ item.created_at.substring(0, 16).replace('T', ' ') }}</text></view>
<view class="td col-amount">
<text :class="['td-txt', item.pm === 1 ? 'red-txt' : 'green-txt']">
{{ item.pm === 1 ? '+' : '-' }}{{ item.number.toFixed(2) }}
</text>
</view>
<view class="td col-user">
<view class="u-info-box">
<text class="u-name">{{ item.user_name || '未知' }}</text>
<text class="u-id">UID:{{ item.uid.substring(0, 8) }}</text>
</view>
</view>
<view class="td col-type"><text class="td-txt">{{ getBillTypeText(item.type) }}</text></view>
<view class="td col-remark text-left"><text class="td-txt">{{ item.mark || '-' }}</text></view>
<view class="td col-op">
<text class="btn-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 { fetchUserBillList } from '@/services/admin/financeService.uts'
import { UserBillRecord } from '@/types/admin/finance.uts'
const typeValue = 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 typeOptions = [
{ value: 'all', text: '全部类型' },
{ value: 'recharge', text: '充值' },
{ value: 'extract', text: '提现' },
{ value: 'pay', text: '支付' },
{ value: 'refund', text: '退款' },
{ value: 'system_add', text: '系统增加' },
{ value: 'system_sub', text: '系统减少' }
]
const tableData = ref<UserBillRecord[]>([])
const totalPages = computed(() : number => {
if (pageSize.value <= 0) return 1
return Math.ceil(total.value / pageSize.value)
})
async function loadList() {
loading.value = true
try {
const type = typeValue.value == 'all' ? null : typeValue.value
const res = await fetchUserBillList(
page.value,
pageSize.value,
'balance', // 余额明细
type,
null,
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(() => {
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 getBillTypeText(type : string) : string {
const found = typeOptions.find(opt => opt.value === type)
return found != null ? found.text : type
}
</script>
<style scoped lang="scss">
.finance-balance-record {
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: 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: 12px; white-space: nowrap; }
.search-wrap { flex: 1; }
.search-input { flex: 1; height: 32px; border: 1px solid #dcdfe6; border-radius: 4px; padding: 0 12px; font-size: 13px; }
.data-select { width: 160px; }
.btn-query {
background-color: #1890ff;
border-radius: 4px;
height: 32px;
padding: 0 24px;
display: flex;
align-items: center;
justify-content: center;
margin-left: 10px;
cursor: pointer;
}
.btn-txt { color: #fff; font-size: 14px; }
/* 表格样式 */
.table-container {
display: flex;
flex-direction: column;
}
.table-header {
background-color: #e6f0ff;
display: flex;
flex-direction: row;
border-bottom: 1px solid #f0f0f0;
}
.th {
padding: 12px 10px;
display: flex;
align-items: center;
justify-content: center;
}
.th-txt {
font-size: 13px;
font-weight: 600;
color: #303133;
}
.table-body {
display: flex;
flex-direction: column;
}
.table-row {
display: flex;
flex-direction: row;
border-bottom: 1px solid #f0f0f0;
min-height: 60px;
}
.table-row:hover {
background-color: #f9f9f9;
}
.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-id { font-size: 11px; color: #909399; }
}
/* 列宽分配 */
.col-id { width: 70px; }
.col-order { width: 200px; justify-content: flex-start; }
.col-time { width: 160px; }
.col-amount { width: 120px; }
.col-user { width: 160px; }
.col-type { width: 140px; }
.col-remark { flex: 1; min-width: 180px; justify-content: flex-start; }
.col-op { width: 80px; }
.text-left { justify-content: flex-start; text-align: left; }
/* 颜色 */
.red-txt { color: #f5222d; font-weight: bold; }
.green-txt { color: #52c41a; font-weight: bold; }
.btn-link { color: #1890ff; font-size: 13px; 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>