Files
wer-admin/src/views/biz/income/index.vue
2026-11-09 17:25:01 +08:00

176 lines
6.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="p-2 app-container income-index-page">
<div class="search-wrap">
<el-card shadow="hover" class="search-panel" :class="{ 'is-collapsed': !showSearch }">
<template #header>
<div class="panel-heading search-panel-toggle" @click.stop="showSearch = !showSearch">
<div><h3>筛选条件</h3></div>
</div>
</template>
<el-form ref="queryFormRef" :model="queryParams" :inline="true" class="query-form">
<el-form-item label="交易日期" style="width: 308px">
<el-date-picker
v-model="dateRangeOccurredAt"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
></el-date-picker>
</el-form-item>
<el-form-item label="设备类型" prop="deviceType">
<el-select v-model="queryParams.deviceType" placeholder="全部类型" clearable>
<el-option v-for="item in deviceTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
<el-card shadow="hover" class="table-panel">
<template #header>
<div class="toolbar-shell">
<div class="table-heading">
<h3>收入明细列表</h3>
</div>
<div class="toolbar-actions">
<right-toolbar v-model:show-search="showSearch" :search="false" @query-table="getList"></right-toolbar>
</div>
</div>
</template>
<!-- data-full-height-table="false":表格按内容自适应高度,不跟随全局「全高表格」设置铺满整屏 -->
<el-table v-loading="loading" border class="data-table" data-full-height-table="false" :data="incomeList">
<el-table-column label="交易日期" align="center" prop="occurredAt" min-width="180" show-overflow-tooltip />
<el-table-column label="商户" align="center" prop="merchantName" min-width="140" show-overflow-tooltip />
<el-table-column label="房间" align="center" prop="installLocation" min-width="120" show-overflow-tooltip />
<el-table-column label="设备编号" align="center" prop="deviceNo" min-width="140" show-overflow-tooltip />
<el-table-column label="设备类型" align="center" min-width="120">
<template #default="scope">{{ deviceTypeText(scope.row.deviceType) }}</template>
</el-table-column>
<el-table-column label="充值金额(元)" align="center" min-width="120">
<template #default="scope">
<span class="amount-text">{{ formatAmount(scope.row.amount) }}</span>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
:total="total"
@pagination="getList"
/>
</el-card>
</div>
</template>
<script setup name="Income" lang="ts">
import { listIncome } from '@/api/income';
import type { IncomeRecordQuery, IncomeRecordVO } from '@/api/income/types';
import { useLoading } from '@/hooks/async/useLoading';
import { useDateRangeQuery } from '@/hooks/form/useDateRangeQuery';
import { useSearchReset } from '@/hooks/form/useSearchReset';
import { useSearchToggle } from '@/hooks/form/useSearchToggle';
import { getDeviceTypeLabel, useDeviceTypeDict } from '../device/constants';
const deviceTypeDict = useDeviceTypeDict();
/** 设备类型选项:优先后端字典 ur_device_type,字典未加载时用本地兜底 */
const deviceTypeOptions = computed<DictDataOption[]>(() =>
deviceTypeDict.value?.length
? deviceTypeDict.value
: [
{ label: '电表', value: '0' },
{ label: '水表', value: '1' }
]
);
/** 金额展示:后端以字符串返回(如 "0.00"),单位已写在列名里,不带 ¥;无值时不展示 */
const formatAmount = (value?: string | number | null) => {
if (value == null || value === '') return '';
const amount = Number(value);
return Number.isNaN(amount)
? `${value}`
: amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
};
/** 设备类型文案:无值时不展示(留空,不用占位符) */
const deviceTypeText = (deviceType?: string | null) => {
if (deviceType == null || deviceType === '') return '';
return getDeviceTypeLabel(deviceTypeOptions.value, String(deviceType));
};
const incomeList = ref<IncomeRecordVO[]>([]);
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();
const { showSearch } = useSearchToggle();
const { loading, withLoading } = useLoading(true);
const queryParams = ref<IncomeRecordQuery>({
pageNum: 1,
pageSize: 10,
deviceType: undefined
});
/** 交易日期区间 → queryParams.params.beginOccurredAt / endOccurredAt */
const {
dateRange: dateRangeOccurredAt,
applyDateRange: applyOccurredAtDateRange,
resetDateRange: resetOccurredAtDateRange
} = useDateRangeQuery('OccurredAt');
/** 查询收入明细列表 */
const getList = async () => {
applyOccurredAtDateRange(queryParams.value);
await withLoading(async () => {
const res = await listIncome(queryParams.value);
incomeList.value = res.data?.rows ?? [];
total.value = res.data?.total ?? 0;
});
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
const { resetQuery } = useSearchReset({
queryFormRef,
queryParams,
pageNumKey: 'pageNum',
pageSizeKey: 'pageSize',
initialPageSize: 10,
resetExtras: () => {
resetOccurredAtDateRange();
},
afterReset: () => {
handleQuery();
}
});
onMounted(() => {
getList();
});
</script>
<style lang="scss" scoped>
@use '@/assets/styles/components/page-shell' as pageShell;
@include pageShell.table-crud-page;
.data-table {
.amount-text {
color: var(--el-color-primary);
font-variant-numeric: tabular-nums;
}
}
</style>