用户列表详情联调
This commit is contained in:
@@ -1,4 +1,14 @@
|
||||
import type { AppUserBindingVO, AppUserForm, AppUserQuery, AppUserVO } from '@/api/appUser/types';
|
||||
import type {
|
||||
AppUserBindingVO,
|
||||
AppUserForm,
|
||||
AppUserQuery,
|
||||
AppUserReadingQuery,
|
||||
AppUserReadingVO,
|
||||
AppUserRechargeQuery,
|
||||
AppUserRechargeVO,
|
||||
AppUserResetVO,
|
||||
AppUserVO
|
||||
} from '@/api/appUser/types';
|
||||
import type { PageResult } from '@/api/types';
|
||||
import type { AxiosPromise } from '@/utils/api-types';
|
||||
import request from '@/utils/request';
|
||||
@@ -39,12 +49,57 @@ export const getAppUserDetail = (userId: string | number): AxiosPromise<AppUserV
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询用户已绑定的设备列表
|
||||
* 查询用户绑定记录(当前设备 / 历史设备共用一个接口)
|
||||
* @param userId
|
||||
* @param history true:查历史设备,false:查当前绑定设备
|
||||
*/
|
||||
export const getAppUserBindings = (userId: string | number): AxiosPromise<PageResult<AppUserBindingVO>> => {
|
||||
export const getAppUserBindings = (userId: string | number, history = false): AxiosPromise<PageResult<AppUserBindingVO>> => {
|
||||
return request({
|
||||
url: '/userManage/appUser/bindings/' + userId,
|
||||
method: 'get',
|
||||
params: { history }
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询用户支付记录
|
||||
* @param userId
|
||||
* @param query 分页参数
|
||||
*/
|
||||
export const listAppUserRecharges = (
|
||||
userId: string | number,
|
||||
query?: AppUserRechargeQuery
|
||||
): AxiosPromise<PageResult<AppUserRechargeVO>> => {
|
||||
return request({
|
||||
url: '/userManage/appUser/recharges/' + userId,
|
||||
method: 'get',
|
||||
params: query
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询用户抄表记录
|
||||
* @param userId
|
||||
* @param query 抄表时间区间(beginTime / endTime)
|
||||
*/
|
||||
export const listAppUserReadings = (
|
||||
userId: string | number,
|
||||
query?: AppUserReadingQuery
|
||||
): AxiosPromise<PageResult<AppUserReadingVO> | AppUserReadingVO[]> => {
|
||||
return request({
|
||||
url: '/userManage/appUser/readings/' + userId,
|
||||
method: 'get',
|
||||
params: query
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询用户清零记录
|
||||
* @param userId
|
||||
*/
|
||||
export const listAppUserResets = (userId: string | number): AxiosPromise<PageResult<AppUserResetVO> | AppUserResetVO[]> => {
|
||||
return request({
|
||||
url: '/userManage/appUser/resets/' + userId,
|
||||
method: 'get'
|
||||
});
|
||||
};
|
||||
@@ -73,6 +128,18 @@ export const bindAppUserDevices = (userId: string | number, deviceIds: Array<str
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 解绑用户设备
|
||||
* @param userId
|
||||
* @param deviceId
|
||||
*/
|
||||
export const unbindAppUserDevice = (userId: string | number, deviceId: string | number) => {
|
||||
return request({
|
||||
url: '/userManage/appUser/bindingsHistory/' + userId + '/' + deviceId,
|
||||
method: 'delete'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增小程序用户
|
||||
* @param data
|
||||
@@ -99,6 +166,18 @@ export const updateAppUser = (data: AppUserForm) => {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改小程序用户状态(启用 / 停用)
|
||||
* @param userId
|
||||
* @param status 状态(0正常 1停用)
|
||||
*/
|
||||
export const changeAppUserStatus = (userId: string | number, status: string) => {
|
||||
return request({
|
||||
url: '/userManage/appUser/status/' + userId + '/' + status,
|
||||
method: 'put'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除小程序用户
|
||||
* @param userId
|
||||
|
||||
@@ -149,6 +149,10 @@ export interface AppUserBindingVO {
|
||||
* 支付时间
|
||||
*/
|
||||
paidAt?: string;
|
||||
/**
|
||||
* 订单完成时间
|
||||
*/
|
||||
completedAt?: string;
|
||||
/**
|
||||
* 上次读数
|
||||
*/
|
||||
@@ -187,6 +191,61 @@ export interface AppUserBindingVO {
|
||||
roomNo?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户支付记录(后端 /userManage/appUser/recharges/{userId} 返回的行结构,字段与绑定记录一致)
|
||||
*/
|
||||
export type AppUserRechargeVO = AppUserBindingVO;
|
||||
|
||||
/**
|
||||
* 用户支付记录查询参数
|
||||
*/
|
||||
export interface AppUserRechargeQuery extends PageQuery {
|
||||
/**
|
||||
* 设备类型(0:电表,1:水表)
|
||||
*/
|
||||
deviceType?: string;
|
||||
/**
|
||||
* 支付方式
|
||||
*/
|
||||
paymentMethod?: string;
|
||||
/**
|
||||
* 订单状态(0成功 1失败)
|
||||
*/
|
||||
orderStatus?: string;
|
||||
/**
|
||||
* 支付开始时间
|
||||
*/
|
||||
beginTime?: string;
|
||||
/**
|
||||
* 支付结束时间
|
||||
*/
|
||||
endTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户抄表记录(后端 /userManage/appUser/readings/{userId} 返回的行结构)
|
||||
*/
|
||||
export type AppUserReadingVO = AppUserBindingVO;
|
||||
|
||||
/**
|
||||
* 用户抄表记录查询参数
|
||||
*/
|
||||
export interface AppUserReadingQuery {
|
||||
/**
|
||||
* 抄表开始时间
|
||||
*/
|
||||
beginTime?: string;
|
||||
/**
|
||||
* 抄表结束时间
|
||||
*/
|
||||
endTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户清零记录(后端 /userManage/appUser/resets/{userId} 返回的行结构)
|
||||
*/
|
||||
export type AppUserResetVO = AppUserBindingVO;
|
||||
|
||||
export interface AppUserForm extends BaseEntity {
|
||||
/**
|
||||
* 小程序用户ID
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<template>
|
||||
<div v-loading="loading" class="history-panel">
|
||||
<div v-if="historyDevices.length" class="record-list">
|
||||
<div v-for="item in historyDevices" :key="item.id" class="record-row">
|
||||
<div class="record-main">
|
||||
@@ -11,10 +12,18 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else description="暂无历史设备" />
|
||||
<el-empty v-else-if="!loading" description="暂无历史设备" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="HistoryTab" lang="ts">
|
||||
import { getAppUserBindings } from '@/api/appUser';
|
||||
import type { AppUserBindingVO } from '@/api/appUser/types';
|
||||
import { useLoading } from '@/hooks/async/useLoading';
|
||||
import { deviceLabel, normalizeRecordList, valueOrDash } from './helpers';
|
||||
|
||||
const props = defineProps<{ userId?: string | number }>();
|
||||
|
||||
/** 历史设备行 */
|
||||
interface HistoryDeviceItem {
|
||||
id: string | number;
|
||||
@@ -23,20 +32,48 @@ interface HistoryDeviceItem {
|
||||
unboundAt: string;
|
||||
}
|
||||
|
||||
/** TODO: 历史设备接口待接入,先用演示数据占位 */
|
||||
const historyDevices = ref<HistoryDeviceItem[]>([
|
||||
{
|
||||
id: 1,
|
||||
roomNo: '101室',
|
||||
deviceText: '蓝牙水表 · NO20260101',
|
||||
unboundAt: '2026年9月18日 09:03:12'
|
||||
const { loading, withLoading } = useLoading(false);
|
||||
const records = ref<AppUserBindingVO[]>([]);
|
||||
|
||||
/** 后端记录 → 列表展示项 */
|
||||
const historyDevices = computed<HistoryDeviceItem[]>(() =>
|
||||
records.value.map(record => ({
|
||||
id: record.id,
|
||||
roomNo: String(valueOrDash(record.roomNo)),
|
||||
deviceText: deviceLabel(record),
|
||||
unboundAt: record.unboundAt || '—'
|
||||
}))
|
||||
);
|
||||
|
||||
/** 查询历史设备:GET /userManage/appUser/bindings/{userId}?history=true */
|
||||
const getList = async () => {
|
||||
const currentUserId = props.userId;
|
||||
if (currentUserId === undefined || currentUserId === null || currentUserId === '') {
|
||||
records.value = [];
|
||||
return;
|
||||
}
|
||||
]);
|
||||
try {
|
||||
await withLoading(async () => {
|
||||
const res = await getAppUserBindings(currentUserId, true);
|
||||
records.value = normalizeRecordList<AppUserBindingVO>(res.data, record => record.deviceId != null);
|
||||
});
|
||||
} catch {
|
||||
// 请求异常已由 request 统一提示,这里保持上次渲染结果
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use '@/assets/styles/components/detail-panels' as panels;
|
||||
|
||||
.history-panel {
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
@include panels.record-list;
|
||||
@include panels.unbound-tag;
|
||||
</style>
|
||||
|
||||
@@ -1,86 +1,191 @@
|
||||
<template>
|
||||
<div v-if="paymentGroups.length" class="record-list">
|
||||
<div v-for="group in paymentGroups" :key="group.date" class="record-group">
|
||||
<div class="record-date">{{ group.date }}</div>
|
||||
<div v-for="record in group.records" :key="record.id" class="record-row">
|
||||
<div class="record-main">
|
||||
<div class="record-title">{{ record.deviceText }}</div>
|
||||
<div class="record-sub">{{ record.typeText }}</div>
|
||||
<div class="payment-panel">
|
||||
<!-- 支付记录筛选 -->
|
||||
<el-form :model="queryParams" :inline="true" class="query-form payment-filter">
|
||||
<el-form-item prop="deviceType">
|
||||
<el-select v-model="queryParams.deviceType" placeholder="请选择设备类型" clearable>
|
||||
<el-option label="电表" value="0" />
|
||||
<el-option label="水表" value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-date-picker
|
||||
v-model="dateRange"
|
||||
type="daterange"
|
||||
value-format="YYYY-MM-DD"
|
||||
range-separator="—"
|
||||
start-placeholder="开始时间"
|
||||
end-placeholder="结束时间"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item prop="orderStatus">
|
||||
<el-select v-model="queryParams.orderStatus" placeholder="请选择支付状态" clearable>
|
||||
<el-option label="支付成功" value="0" />
|
||||
<el-option label="支付失败" value="1" />
|
||||
</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-table v-loading="loading" border :data="records" class="data-table payment-table" empty-text="暂无支付记录">
|
||||
<el-table-column label="设备编号" align="center" min-width="140">
|
||||
<template #default="scope">{{ scope.row.deviceNo || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="设备类型" align="center" width="120">
|
||||
<template #default="scope">{{ deviceTypeText(scope.row.deviceType) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="支付金额(¥)" align="center" width="140">
|
||||
<template #default="scope">{{ formatAmount(scope.row.actualPaymentAmount) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="当前金额(¥)" align="center" width="140">
|
||||
<template #default="scope">{{ formatAmount(scope.row. balanceAfter) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="支付时间" align="center" min-width="170">
|
||||
<template #default="scope">{{ scope.row.paidAt || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="支付状态" align="center" width="120">
|
||||
<template #default="scope">
|
||||
<span class="payment-status" :class="`is-${orderStatusMeta(scope.row.orderStatus).variant}`">
|
||||
{{ orderStatusMeta(scope.row.orderStatus).text }}
|
||||
</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"
|
||||
/>
|
||||
</div>
|
||||
<div class="record-side">
|
||||
<div class="record-status" :class="record.success ? 'is-success' : 'is-failed'">{{ record.statusText }}</div>
|
||||
<div class="record-amount">¥{{ record.amount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else description="暂无支付记录" />
|
||||
</template>
|
||||
|
||||
<script setup name="PaymentTab" lang="ts">
|
||||
import { formatDate } from './helpers';
|
||||
import { listAppUserRecharges } from '@/api/appUser';
|
||||
import type { AppUserRechargeQuery, AppUserRechargeVO } from '@/api/appUser/types';
|
||||
import { useLoading } from '@/hooks/async/useLoading';
|
||||
import { normalizeRecordList } from './helpers';
|
||||
|
||||
/** 支付记录行 */
|
||||
interface PaymentRecordItem {
|
||||
id: string | number;
|
||||
deviceText: string;
|
||||
typeText: string;
|
||||
statusText: string;
|
||||
success: boolean;
|
||||
amount: number;
|
||||
paidAt: string;
|
||||
}
|
||||
const props = defineProps<{ userId?: string | number }>();
|
||||
|
||||
/** TODO: 支付记录接口待接入,先用演示数据占位 */
|
||||
const paymentRecords = ref<PaymentRecordItem[]>([
|
||||
{
|
||||
id: 1,
|
||||
deviceText: '蓝牙电表 · NO20260101',
|
||||
typeText: '电费充值',
|
||||
statusText: '支付成功',
|
||||
success: true,
|
||||
amount: 200,
|
||||
paidAt: '2026-09-21 11:02:52'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
deviceText: '蓝牙水表 · NO20260101',
|
||||
typeText: '水费充值',
|
||||
statusText: '支付失败',
|
||||
success: false,
|
||||
amount: 200,
|
||||
paidAt: '2026-09-21 10:31:08'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
deviceText: '蓝牙电表 · NO20260101',
|
||||
typeText: '电费充值',
|
||||
statusText: '支付成功',
|
||||
success: true,
|
||||
amount: 200,
|
||||
paidAt: '2026-09-21 09:12:40'
|
||||
}
|
||||
]);
|
||||
/** 订单状态映射:0成功 1失败 */
|
||||
const orderStatusMap: Record<string, { text: string; variant: 'success' | 'failed' }> = {
|
||||
'0': { text: '支付成功', variant: 'success' },
|
||||
'1': { text: '支付失败', variant: 'failed' }
|
||||
};
|
||||
|
||||
/** 支付记录按日期分组 */
|
||||
const paymentGroups = computed(() => {
|
||||
const groups: Array<{ date: string; records: PaymentRecordItem[] }> = [];
|
||||
paymentRecords.value.forEach(record => {
|
||||
const date = formatDate(record.paidAt);
|
||||
const group = groups.find(item => item.date === date);
|
||||
if (group) {
|
||||
group.records.push(record);
|
||||
} else {
|
||||
groups.push({ date, records: [record] });
|
||||
}
|
||||
const { loading, withLoading } = useLoading(false);
|
||||
const records = ref<AppUserRechargeVO[]>([]);
|
||||
const total = ref(0);
|
||||
const queryParams = reactive<AppUserRechargeQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
deviceType: undefined,
|
||||
orderStatus: undefined
|
||||
});
|
||||
return groups;
|
||||
/** 支付时间筛选区间(YYYY-MM-DD),为空表示不筛选 */
|
||||
const dateRange = ref<[string, string] | null>(null);
|
||||
|
||||
const orderStatusMeta = (status?: string): { text: string; variant: 'success' | 'failed' | 'default' } => {
|
||||
const key = String(status ?? '').trim();
|
||||
return orderStatusMap[key] || { text: '—', variant: 'default' };
|
||||
};
|
||||
|
||||
/** 设备类型:0电表 1水表 */
|
||||
const deviceTypeText = (deviceType?: string) => {
|
||||
if (String(deviceType) === '0') return '电表';
|
||||
if (String(deviceType) === '1') return '水表';
|
||||
return '—';
|
||||
};
|
||||
|
||||
/** 金额展示:保留两位小数 */
|
||||
const formatAmount = (value?: number | null) => (value === undefined || value === null ? '—' : Number(value).toFixed(2));
|
||||
|
||||
/** 查询支付记录:GET /userManage/appUser/recharges/{userId} */
|
||||
const getList = async () => {
|
||||
const currentUserId = props.userId;
|
||||
if (currentUserId === undefined || currentUserId === null || currentUserId === '') {
|
||||
records.value = [];
|
||||
total.value = 0;
|
||||
return;
|
||||
}
|
||||
const [beginTime, endTime] = dateRange.value || [];
|
||||
const params: AppUserRechargeQuery = {
|
||||
pageNum: queryParams.pageNum,
|
||||
pageSize: queryParams.pageSize,
|
||||
deviceType: queryParams.deviceType || undefined,
|
||||
orderStatus: queryParams.orderStatus || undefined,
|
||||
beginTime: beginTime || undefined,
|
||||
endTime: endTime || undefined
|
||||
};
|
||||
try {
|
||||
await withLoading(async () => {
|
||||
const res = await listAppUserRecharges(currentUserId, params);
|
||||
records.value = normalizeRecordList<AppUserRechargeVO>(res.data, record => record.id != null);
|
||||
total.value = Number(res.data?.total ?? 0);
|
||||
});
|
||||
} catch {
|
||||
// 请求异常已由 request 统一提示,这里保持上次渲染结果
|
||||
}
|
||||
};
|
||||
|
||||
/** 条件查询:回到第 1 页 */
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNum = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 重置筛选条件后重新查询 */
|
||||
const resetQuery = () => {
|
||||
queryParams.deviceType = undefined;
|
||||
queryParams.orderStatus = undefined;
|
||||
dateRange.value = null;
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use '@/assets/styles/components/detail-panels' as panels;
|
||||
.payment-panel {
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
@include panels.record-list;
|
||||
@include panels.record-status;
|
||||
.payment-filter {
|
||||
margin-bottom: 16px;
|
||||
|
||||
:deep(.el-select) {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
:deep(.el-date-editor) {
|
||||
width: 260px;
|
||||
}
|
||||
}
|
||||
|
||||
.payment-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* 支付状态:成功绿色,失败红色,未匹配到状态用中性色 */
|
||||
.payment-status {
|
||||
font-size: 14px;
|
||||
color: var(--el-text-color-regular);
|
||||
|
||||
&.is-success {
|
||||
color: var(--el-color-success);
|
||||
}
|
||||
|
||||
&.is-failed {
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="reading-panel">
|
||||
<!-- 抄表记录按日期区间筛选 -->
|
||||
<div v-loading="loading" class="reading-panel">
|
||||
<!-- 抄表记录按日期区间筛选,区间变化后重新请求后端 -->
|
||||
<div class="reading-toolbar">
|
||||
<span class="reading-toolbar__label">抄表时间</span>
|
||||
<el-date-picker
|
||||
@@ -15,8 +15,8 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="filteredReadingRecords.length" class="card-list">
|
||||
<div v-for="record in filteredReadingRecords" :key="record.id" class="record-card">
|
||||
<div v-if="readingRecords.length" class="card-list">
|
||||
<div v-for="record in readingRecords" :key="record.id" class="record-card">
|
||||
<div class="card-head">
|
||||
<div class="card-room">{{ record.roomNo }}</div>
|
||||
<div class="card-meta">{{ record.deviceText }}</div>
|
||||
@@ -24,77 +24,100 @@
|
||||
<div class="card-metrics card-metrics--three">
|
||||
<div class="metric-block">
|
||||
<span class="metric-label">起始读数</span>
|
||||
<span class="metric-value">{{ record.previousReading }}{{ record.unit }}</span>
|
||||
<span class="metric-value">{{ record.previousReading }}</span>
|
||||
</div>
|
||||
<div class="metric-block">
|
||||
<span class="metric-label">截止读数</span>
|
||||
<span class="metric-value is-highlight">{{ record.reading }}{{ record.unit }}</span>
|
||||
<span class="metric-value is-highlight">{{ record.reading }}</span>
|
||||
</div>
|
||||
<div class="metric-block">
|
||||
<span class="metric-label">区间用量</span>
|
||||
<span class="metric-value">{{ record.usage }}{{ record.unit }}</span>
|
||||
<span class="metric-value">{{ record.usage }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="card-time">抄表时间:{{ record.readingTime }}</div> -->
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else :description="readingDateRange?.length ? '该时间段内暂无抄表记录' : '暂无抄表记录'" />
|
||||
<el-empty v-else-if="!loading" :description="readingDateRange?.length ? '该时间段内暂无抄表记录' : '暂无抄表记录'" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="ReadingTab" lang="ts">
|
||||
import { listAppUserReadings } from '@/api/appUser';
|
||||
import type { AppUserReadingQuery, AppUserReadingVO } from '@/api/appUser/types';
|
||||
import { useLoading } from '@/hooks/async/useLoading';
|
||||
import { deviceLabel, formatReading, normalizeRecordList, quantityUnit, valueOrDash } from './helpers';
|
||||
|
||||
const props = defineProps<{ userId?: string | number }>();
|
||||
|
||||
/** 抄表记录行 */
|
||||
interface ReadingRecordItem {
|
||||
id: string | number;
|
||||
roomNo: string;
|
||||
deviceText: string;
|
||||
previousReading: number;
|
||||
reading: number;
|
||||
usage: number;
|
||||
unit: string;
|
||||
readingTime: string;
|
||||
previousReading: string;
|
||||
reading: string;
|
||||
usage: string;
|
||||
}
|
||||
|
||||
/** TODO: 抄表记录接口待接入,先用演示数据占位 */
|
||||
const readingRecords = ref<ReadingRecordItem[]>([
|
||||
{
|
||||
id: 1,
|
||||
roomNo: '101室',
|
||||
deviceText: '蓝牙电表 · NO20260101',
|
||||
previousReading: 1234,
|
||||
reading: 1250,
|
||||
usage: 16,
|
||||
unit: '度',
|
||||
readingTime: '2026-09-21 11:02:52'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
roomNo: '101室',
|
||||
deviceText: '蓝牙水表 · NO20260101',
|
||||
previousReading: 156,
|
||||
reading: 168.6,
|
||||
usage: 12.6,
|
||||
unit: '吨',
|
||||
readingTime: '2026-09-18 09:03:12'
|
||||
}
|
||||
]);
|
||||
|
||||
/** 抄表记录时间筛选区间(YYYY-MM-DD),为空表示不筛选 */
|
||||
const { loading, withLoading } = useLoading(false);
|
||||
const records = ref<AppUserReadingVO[]>([]);
|
||||
/** 抄表时间筛选区间(YYYY-MM-DD),为空表示不筛选 */
|
||||
const readingDateRange = ref<[string, string] | null>(null);
|
||||
|
||||
/** 抄表记录按所选时间区间过滤,接口接入后改为传 startTime / endTime 到后端 */
|
||||
const filteredReadingRecords = computed(() => {
|
||||
const [start, end] = readingDateRange.value || [];
|
||||
if (!start || !end) return readingRecords.value;
|
||||
return readingRecords.value.filter(record => {
|
||||
const day = String(record.readingTime || '').slice(0, 10);
|
||||
return !!day && day >= start && day <= end;
|
||||
/** 后端记录 → 列表展示项:只展示上次读数 / 本次读数 / 本次用量 */
|
||||
const readingRecords = computed<ReadingRecordItem[]>(() =>
|
||||
records.value.map(record => {
|
||||
const unit = quantityUnit(record);
|
||||
return {
|
||||
id: record.id,
|
||||
roomNo: String(valueOrDash(record.roomNo)),
|
||||
deviceText: deviceLabel(record),
|
||||
previousReading: formatReading(record.previousReadingValue, unit),
|
||||
reading: formatReading(record.readingValue, unit),
|
||||
usage: formatReading(record.usageQuantity, unit)
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
/** 查询抄表记录:GET /userManage/appUser/readings/{userId} */
|
||||
const getList = async () => {
|
||||
const currentUserId = props.userId;
|
||||
if (currentUserId === undefined || currentUserId === null || currentUserId === '') {
|
||||
records.value = [];
|
||||
return;
|
||||
}
|
||||
const params: AppUserReadingQuery = {};
|
||||
const [beginTime, endTime] = readingDateRange.value || [];
|
||||
if (beginTime) params.beginTime = beginTime;
|
||||
if (endTime) params.endTime = endTime;
|
||||
try {
|
||||
await withLoading(async () => {
|
||||
const res = await listAppUserReadings(currentUserId, params);
|
||||
records.value = normalizeRecordList<AppUserReadingVO>(res.data, record => record.id != null);
|
||||
});
|
||||
} catch {
|
||||
// 请求异常已由 request 统一提示,这里保持上次渲染结果
|
||||
}
|
||||
};
|
||||
|
||||
/** 时间区间变化后重新查询 */
|
||||
watch(readingDateRange, () => {
|
||||
getList();
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use '@/assets/styles/components/detail-panels' as panels;
|
||||
|
||||
.reading-panel {
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
@include panels.record-card-list;
|
||||
|
||||
.reading-toolbar {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<template>
|
||||
<div v-loading="loading" class="reset-panel">
|
||||
<div v-if="resetRecords.length" class="card-list">
|
||||
<div v-for="record in resetRecords" :key="record.id" class="record-card">
|
||||
<div class="card-head">
|
||||
@@ -8,47 +9,84 @@
|
||||
<div class="card-metrics">
|
||||
<div class="metric-block">
|
||||
<span class="metric-label">清零前读数</span>
|
||||
<span class="metric-value">{{ record.beforeReading }}{{ record.unit }}</span>
|
||||
<span class="metric-value">{{ record.beforeReading || '-'}}</span>
|
||||
</div>
|
||||
<div class="metric-block">
|
||||
<span class="metric-label">清零后读数</span>
|
||||
<span class="metric-value is-highlight">{{ record.afterReading }}{{ record.unit }}</span>
|
||||
<span class="metric-value is-highlight">{{ record.afterReading || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-time">清零时间:{{ record.resetTime }}</div>
|
||||
<div class="card-time">清零时间:{{ record.resetTime || '-'}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else description="暂无清零记录" />
|
||||
<el-empty v-else-if="!loading" description="暂无清零记录" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="ResetTab" lang="ts">
|
||||
import { listAppUserResets } from '@/api/appUser';
|
||||
import type { AppUserResetVO } from '@/api/appUser/types';
|
||||
import { useLoading } from '@/hooks/async/useLoading';
|
||||
import { deviceLabel, formatReading, normalizeRecordList, quantityUnit, valueOrDash } from './helpers';
|
||||
|
||||
const props = defineProps<{ userId?: string | number }>();
|
||||
|
||||
/** 清零记录行 */
|
||||
interface ResetRecordItem {
|
||||
id: string | number;
|
||||
roomNo: string;
|
||||
deviceText: string;
|
||||
beforeReading: number;
|
||||
afterReading: number;
|
||||
unit: string;
|
||||
beforeReading: string;
|
||||
afterReading: string;
|
||||
resetTime: string;
|
||||
}
|
||||
|
||||
/** TODO: 清零记录接口待接入,先用演示数据占位 */
|
||||
const resetRecords = ref<ResetRecordItem[]>([
|
||||
{
|
||||
id: 1,
|
||||
roomNo: '101室',
|
||||
deviceText: '蓝牙电表 · NO20260101',
|
||||
beforeReading: 1234,
|
||||
afterReading: 0,
|
||||
unit: '度',
|
||||
resetTime: '2026年9月21日 11:20:45'
|
||||
const { loading, withLoading } = useLoading(false);
|
||||
const records = ref<AppUserResetVO[]>([]);
|
||||
|
||||
/** 后端记录 → 列表展示项:只展示清零前后读数 / 清零时间 */
|
||||
const resetRecords = computed<ResetRecordItem[]>(() =>
|
||||
records.value.map(record => {
|
||||
const unit = quantityUnit(record);
|
||||
return {
|
||||
id: record.id,
|
||||
roomNo: String(valueOrDash(record.roomNo)),
|
||||
deviceText: deviceLabel(record),
|
||||
beforeReading: formatReading(record.beforeReadingValue, unit),
|
||||
afterReading: formatReading(record.afterReadingValue, unit),
|
||||
resetTime: record.resetTime || '—'
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
/** 查询清零记录:GET /userManage/appUser/resets/{userId} */
|
||||
const getList = async () => {
|
||||
const currentUserId = props.userId;
|
||||
if (currentUserId === undefined || currentUserId === null || currentUserId === '') {
|
||||
records.value = [];
|
||||
return;
|
||||
}
|
||||
]);
|
||||
try {
|
||||
await withLoading(async () => {
|
||||
const res = await listAppUserResets(currentUserId);
|
||||
records.value = normalizeRecordList<AppUserResetVO>(res.data, record => record.id != null);
|
||||
});
|
||||
} catch {
|
||||
// 请求异常已由 request 统一提示,这里保持上次渲染结果
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use '@/assets/styles/components/detail-panels' as panels;
|
||||
|
||||
.reset-panel {
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
@include panels.record-card-list;
|
||||
</style>
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
import type { AppUserBindingVO } from '@/api/appUser/types';
|
||||
|
||||
/**
|
||||
* 兼容后端返回:数组 / 分页对象 / 单个对象,统一取出记录列表
|
||||
* @param data 后端返回的数据
|
||||
* @param isSingle 判断分页对象本身是否为一条记录
|
||||
*/
|
||||
export const normalizeRecordList = <T>(data: unknown, isSingle: (record: Record<string, any>) => boolean = () => false): T[] => {
|
||||
if (Array.isArray(data)) return data as T[];
|
||||
if (data && typeof data === 'object') {
|
||||
const record = data as Record<string, any>;
|
||||
if (Array.isArray(record.rows)) return record.rows as T[];
|
||||
if (Array.isArray(record.list)) return record.list as T[];
|
||||
if (Array.isArray(record.records)) return record.records as T[];
|
||||
if (isSingle(record)) return [record as T];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
/** 空值统一显示占位符 */
|
||||
export const valueOrDash = (value?: string | number | null) => (value === undefined || value === null || value === '' ? '—' : value);
|
||||
|
||||
@@ -10,6 +27,16 @@ export const formatDate = (value?: string) => {
|
||||
return matched ? `${matched[1]}年${Number(matched[2])}月${Number(matched[3])}日` : String(value);
|
||||
};
|
||||
|
||||
/** 设备展示:名称 + 编号,缺名称时按设备类型兜底 */
|
||||
export const deviceLabel = (device: AppUserBindingVO) => {
|
||||
const name = device.deviceName || (String(device.deviceType) === '1' ? '水表' : '电表');
|
||||
return device.deviceNo ? `${name} · ${device.deviceNo}` : name;
|
||||
};
|
||||
|
||||
/** 数值 + 单位展示,缺值时显示占位符 */
|
||||
export const formatReading = (value: number | undefined | null, unit: string) =>
|
||||
value === undefined || value === null ? '—' : `${value}${unit}`;
|
||||
|
||||
/** 计量单位:电表按度、水表按吨,优先后端 unitName */
|
||||
export const quantityUnit = (device: AppUserBindingVO) => {
|
||||
if (String(device.unitName) === '0') return '度';
|
||||
|
||||
@@ -37,10 +37,10 @@
|
||||
|
||||
<div class="tab-content">
|
||||
<DeviceTab v-if="activeTab === 'device'" :devices="devices" @unbind="handleUnbindDevice" />
|
||||
<PaymentTab v-else-if="activeTab === 'payment'" />
|
||||
<ReadingTab v-else-if="activeTab === 'reading'" />
|
||||
<ResetTab v-else-if="activeTab === 'reset'" />
|
||||
<HistoryTab v-else-if="activeTab === 'history'" />
|
||||
<PaymentTab v-else-if="activeTab === 'payment'" :user-id="userId" />
|
||||
<ReadingTab v-else-if="activeTab === 'reading'" :user-id="userId" />
|
||||
<ResetTab v-else-if="activeTab === 'reset'" :user-id="userId" />
|
||||
<HistoryTab v-else-if="activeTab === 'history'" :user-id="userId" />
|
||||
<el-empty v-else :description="`暂无${currentTabLabel}`" />
|
||||
</div>
|
||||
</el-card>
|
||||
@@ -59,7 +59,7 @@
|
||||
|
||||
<script setup name="AppUserDetail" lang="ts">
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { getAppUserBindings, getAppUserDetail } from '@/api/appUser';
|
||||
import { getAppUserBindings, getAppUserDetail, unbindAppUserDevice } from '@/api/appUser';
|
||||
import { AppUserBindingVO, AppUserVO } from '@/api/appUser/types';
|
||||
import { useLoading } from '@/hooks/async/useLoading';
|
||||
import modal from '@/plugins/modal';
|
||||
@@ -69,11 +69,14 @@ import HistoryTab from './components/detail/HistoryTab.vue';
|
||||
import PaymentTab from './components/detail/PaymentTab.vue';
|
||||
import ReadingTab from './components/detail/ReadingTab.vue';
|
||||
import ResetTab from './components/detail/ResetTab.vue';
|
||||
import { normalizeRecordList } from './components/detail/helpers';
|
||||
import UserSummaryCard from './components/detail/UserSummaryCard.vue';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { loading, withLoading } = useLoading(true);
|
||||
/** 当前用户ID(由用户列表跳转携带) */
|
||||
const userId = computed(() => route.query.userId as string | undefined);
|
||||
const user = ref<Partial<AppUserVO>>({});
|
||||
/** 已绑定设备:GET /userManage/appUser/bindings/{userId} */
|
||||
const devices = ref<AppUserBindingVO[]>([]);
|
||||
@@ -102,43 +105,45 @@ const goBack = () => {
|
||||
|
||||
/** 打开绑定设备弹窗 */
|
||||
const handleBindDevice = () => {
|
||||
const userId = route.query.userId as string | undefined;
|
||||
if (!userId) {
|
||||
if (!userId.value) {
|
||||
modal.msgError('缺少用户ID,请从用户列表进入');
|
||||
return;
|
||||
}
|
||||
bindDeviceRef.value?.openDialog(userId);
|
||||
bindDeviceRef.value?.openDialog(userId.value);
|
||||
};
|
||||
|
||||
/** TODO: 解绑设备接口待后端提供,先占位提示 */
|
||||
const handleUnbindDevice = (device: AppUserBindingVO) => {
|
||||
modal.msgWarning(`解绑设备「${device.deviceNo || device.deviceId}」的接口待接入`);
|
||||
/** 解绑设备:DELETE /userManage/appUser/bindingsHistory/{userId}/{deviceId} */
|
||||
const handleUnbindDevice = async (device: AppUserBindingVO) => {
|
||||
if (!userId.value) {
|
||||
modal.msgError('缺少用户ID,请从用户列表进入');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await modal.confirm(`是否确认解绑设备"${device.deviceNo || device.deviceId}"?解绑后可在历史设备中查看`);
|
||||
} catch {
|
||||
// 用户取消确认
|
||||
return;
|
||||
}
|
||||
await unbindAppUserDevice(userId.value, device.deviceId);
|
||||
modal.msgSuccess('解绑成功');
|
||||
await getDetail();
|
||||
};
|
||||
|
||||
/** 绑定列表兼容后端返回:数组 / 分页对象 / 单个对象 */
|
||||
const normalizeDevices = (data: unknown): AppUserBindingVO[] => {
|
||||
if (Array.isArray(data)) return data as AppUserBindingVO[];
|
||||
if (data && typeof data === 'object') {
|
||||
const record = data as Record<string, any>;
|
||||
if (Array.isArray(record.rows)) return record.rows;
|
||||
if (Array.isArray(record.list)) return record.list;
|
||||
if (Array.isArray(record.records)) return record.records;
|
||||
if (record.deviceId != null) return [record as AppUserBindingVO];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
const normalizeDevices = (data: unknown): AppUserBindingVO[] =>
|
||||
normalizeRecordList<AppUserBindingVO>(data, record => record.deviceId != null);
|
||||
|
||||
/** 查询用户详情 */
|
||||
const getDetail = async () => {
|
||||
const userId = route.query.userId as string | undefined;
|
||||
if (!userId) {
|
||||
const currentUserId = userId.value;
|
||||
if (!currentUserId) {
|
||||
modal.msgError('缺少用户ID,请从用户列表进入');
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
await withLoading(async () => {
|
||||
// 头部概要信息 + 已绑定设备:GET /userManage/appUser/detail/{userId}、/bindings/{userId}
|
||||
const [detailRes, bindingRes] = await Promise.allSettled([getAppUserDetail(userId), getAppUserBindings(userId)]);
|
||||
const [detailRes, bindingRes] = await Promise.allSettled([getAppUserDetail(currentUserId), getAppUserBindings(currentUserId)]);
|
||||
if (detailRes.status === 'fulfilled') {
|
||||
user.value = detailRes.value.data || {};
|
||||
}
|
||||
|
||||
@@ -91,8 +91,8 @@
|
||||
</template>
|
||||
|
||||
<script setup name="AppUser" lang="ts">
|
||||
import { delAppUser, listAppUser, updateAppUser } from '@/api/appUser';
|
||||
import { AppUserForm, AppUserQuery, AppUserVO } from '@/api/appUser/types';
|
||||
import { changeAppUserStatus, delAppUser, listAppUser } from '@/api/appUser';
|
||||
import { AppUserQuery, AppUserVO } from '@/api/appUser/types';
|
||||
import { useLoading } from '@/hooks/async/useLoading';
|
||||
import { useSearchReset } from '@/hooks/form/useSearchReset';
|
||||
import { useSearchToggle } from '@/hooks/form/useSearchToggle';
|
||||
@@ -122,7 +122,7 @@ const queryParams = ref<AppUserQuery>({
|
||||
status: undefined
|
||||
});
|
||||
|
||||
const { ids, multiple, handleSelectionChange } = useTableSelection<AppUserVO>(item => item.userId);
|
||||
const { ids, multiple, handleSelectionChange, clearSelection } = useTableSelection<AppUserVO>(item => item.userId);
|
||||
|
||||
/** 查询小程序用户列表 */
|
||||
const getList = async () => {
|
||||
@@ -155,22 +155,35 @@ const handleView = (row: Partial<AppUserVO>) => {
|
||||
router.push({ path: '/appUser/detail', query: { userId: String(row.userId) } });
|
||||
};
|
||||
|
||||
/** 启用 / 停用:正常(0) → 停用(1),停用(1) → 正常(0) */
|
||||
/** 启用 / 停用:PUT /userManage/appUser/status/{userId}/{status},正常(0) → 停用(1),停用(1) → 正常(0) */
|
||||
const handleToggleStatus = async (row: Partial<AppUserVO>) => {
|
||||
if (row.userId == null) return;
|
||||
const nextStatus = row.status === '0' ? '1' : '0';
|
||||
const actionText = nextStatus === '0' ? '启用' : '停用';
|
||||
try {
|
||||
await modal.confirm(`是否确认${actionText}用户"${row.nickName || row.phoneNumber || row.userId}"?`);
|
||||
await updateAppUser({ userId: row.userId, status: nextStatus } as AppUserForm);
|
||||
} catch {
|
||||
// 用户取消确认
|
||||
return;
|
||||
}
|
||||
await changeAppUserStatus(row.userId, nextStatus);
|
||||
modal.msgSuccess(`${actionText}成功`);
|
||||
await getList();
|
||||
};
|
||||
|
||||
/** 删除按钮操作 */
|
||||
/** 删除按钮操作:DELETE /userManage/appUser/{userIds},批量时多个 ID 以逗号拼接 */
|
||||
const handleDelete = async (row?: Partial<AppUserVO>) => {
|
||||
const _userIds = row?.userId || ids.value;
|
||||
await modal.confirm('是否确认删除小程序用户编号为"' + _userIds + '"的数据项?');
|
||||
await delAppUser(_userIds);
|
||||
const userIds = row?.userId ?? ids.value;
|
||||
try {
|
||||
await modal.confirm('是否确认删除小程序用户编号为"' + userIds + '"的数据项?');
|
||||
} catch {
|
||||
// 用户取消确认
|
||||
return;
|
||||
}
|
||||
await delAppUser(userIds);
|
||||
modal.msgSuccess('删除成功');
|
||||
// 清掉勾选,避免列表刷新后批量删除按钮仍拿着已删除的 ID
|
||||
clearSelection();
|
||||
await getList();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user