2026-02-25 10:37:16 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="users">
|
|
|
|
|
|
<a-page-header title="用户管理" sub-title="管理系统用户" />
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
<a-card :bordered="false">
|
|
|
|
|
|
<template #extra>
|
|
|
|
|
|
<a-space>
|
|
|
|
|
|
<a-input-search
|
|
|
|
|
|
v-model:value="searchText"
|
2026-03-20 12:24:56 +08:00
|
|
|
|
placeholder="搜索账号、昵称或手机号"
|
|
|
|
|
|
style="width: 260px"
|
2026-02-25 10:37:16 +08:00
|
|
|
|
@search="handleSearch"
|
|
|
|
|
|
/>
|
2026-02-26 22:51:56 +08:00
|
|
|
|
<a-button v-if="hasPermission('user:create')" type="primary" @click="showAddModal">
|
2026-02-25 10:37:16 +08:00
|
|
|
|
<template #icon>
|
|
|
|
|
|
<PlusOutlined />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
新增用户
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
</a-space>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<a-table
|
|
|
|
|
|
:columns="columns"
|
|
|
|
|
|
:data-source="userList"
|
|
|
|
|
|
:loading="loading"
|
|
|
|
|
|
:pagination="pagination"
|
|
|
|
|
|
row-key="id"
|
2026-03-20 12:24:56 +08:00
|
|
|
|
@change="handleTableChange"
|
2026-02-25 10:37:16 +08:00
|
|
|
|
>
|
|
|
|
|
|
<template #bodyCell="{ column, record }">
|
|
|
|
|
|
<template v-if="column.key === 'avatar'">
|
|
|
|
|
|
<a-avatar :size="40" :src="record.avatar || DEFAULT_AVATAR" />
|
|
|
|
|
|
</template>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
2026-02-25 17:20:12 +08:00
|
|
|
|
<template v-else-if="column.key === 'shopName'">
|
2026-03-21 15:18:09 +08:00
|
|
|
|
{{ record.shopName || getShopNameById(record.shopId) || '-' }}
|
2026-02-25 17:20:12 +08:00
|
|
|
|
</template>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
2026-02-25 11:38:31 +08:00
|
|
|
|
<template v-else-if="column.key === 'type'">
|
|
|
|
|
|
<a-tag :color="getUserTypeColor(record.type)">
|
|
|
|
|
|
{{ getUserTypeText(record.type) }}
|
2026-02-25 10:37:16 +08:00
|
|
|
|
</a-tag>
|
|
|
|
|
|
</template>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
|
|
|
|
|
<template v-else-if="column.key === 'level'">
|
|
|
|
|
|
<a-tag :color="record.level && record.level !== '普通' ? 'gold' : 'default'">
|
|
|
|
|
|
{{ record.level || '普通' }}
|
|
|
|
|
|
</a-tag>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
<template v-else-if="column.key === 'status'">
|
|
|
|
|
|
<a-switch
|
|
|
|
|
|
:checked="record.status === 1"
|
2026-03-20 12:24:56 +08:00
|
|
|
|
:disabled="!hasPermission('user:disable') || record.type === 4"
|
2026-03-10 23:23:15 +08:00
|
|
|
|
@change="(checked: any) => handleStatusChange(record, checked === true)"
|
2026-02-25 10:37:16 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</template>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
<template v-else-if="column.key === 'actions'">
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<a-space wrap>
|
2026-02-28 14:32:28 +08:00
|
|
|
|
<a-button v-if="hasPermission('user:view')" type="link" size="small" @click="showViewModal(record)">
|
|
|
|
|
|
查看
|
|
|
|
|
|
</a-button>
|
2026-02-26 22:51:56 +08:00
|
|
|
|
<a-button v-if="hasPermission('user:edit')" type="link" size="small" @click="showEditModal(record)">
|
2026-02-25 10:37:16 +08:00
|
|
|
|
编辑
|
|
|
|
|
|
</a-button>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<a-button
|
|
|
|
|
|
v-if="canOpenAssetPanel"
|
|
|
|
|
|
type="link"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
@click="showAssetModal(record)"
|
|
|
|
|
|
>
|
|
|
|
|
|
余额/VIP
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-if="hasPermission('user:reset_password')"
|
|
|
|
|
|
type="link"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
@click="handleResetPassword(record)"
|
|
|
|
|
|
>
|
2026-02-25 10:37:16 +08:00
|
|
|
|
重置密码
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-popconfirm
|
2026-02-26 23:28:24 +08:00
|
|
|
|
v-if="hasPermission('user:delete') && record.type !== 4"
|
2026-02-25 10:37:16 +08:00
|
|
|
|
title="确定要删除这个用户吗?"
|
|
|
|
|
|
@confirm="handleDelete(record)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-button type="link" size="small" danger>
|
|
|
|
|
|
删除
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
</a-popconfirm>
|
|
|
|
|
|
</a-space>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-table>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
|
|
|
|
|
|
<a-modal
|
|
|
|
|
|
v-model:open="modalVisible"
|
|
|
|
|
|
:title="isEdit ? '编辑用户' : '新增用户'"
|
2026-03-20 12:24:56 +08:00
|
|
|
|
:confirm-loading="modalLoading"
|
2026-02-25 10:37:16 +08:00
|
|
|
|
@ok="handleModalOk"
|
|
|
|
|
|
@cancel="handleModalCancel"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-form
|
|
|
|
|
|
ref="formRef"
|
|
|
|
|
|
:model="formState"
|
|
|
|
|
|
:rules="formRules"
|
|
|
|
|
|
:label-col="{ span: 6 }"
|
|
|
|
|
|
:wrapper-col="{ span: 16 }"
|
|
|
|
|
|
>
|
2026-02-25 11:38:31 +08:00
|
|
|
|
<a-form-item label="账号" name="account">
|
|
|
|
|
|
<a-input v-model:value="formState.account" placeholder="请输入账号" />
|
2026-02-25 10:37:16 +08:00
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="昵称" name="nickname">
|
|
|
|
|
|
<a-input v-model:value="formState.nickname" placeholder="请输入昵称" />
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="手机号" name="phone">
|
2026-03-21 15:18:09 +08:00
|
|
|
|
<a-input
|
|
|
|
|
|
v-model:value="formState.phone"
|
|
|
|
|
|
placeholder="请输入手机号"
|
|
|
|
|
|
:maxlength="11"
|
|
|
|
|
|
inputmode="numeric"
|
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
|
/>
|
2026-02-25 10:37:16 +08:00
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item v-if="!isEdit" label="密码" name="password">
|
|
|
|
|
|
<a-input-password v-model:value="formState.password" placeholder="请输入密码" />
|
|
|
|
|
|
</a-form-item>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<a-form-item label="所属店铺" name="shopId">
|
|
|
|
|
|
<a-select
|
|
|
|
|
|
v-model:value="formState.shopId"
|
2026-02-25 16:58:58 +08:00
|
|
|
|
placeholder="请选择店铺"
|
|
|
|
|
|
:loading="shopLoading"
|
2026-03-20 12:24:56 +08:00
|
|
|
|
:disabled="currentUserInfo?.type !== 4 && !!currentUserInfo?.shopId"
|
2026-02-25 16:58:58 +08:00
|
|
|
|
>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<a-select-option
|
|
|
|
|
|
v-for="shop in shopList"
|
|
|
|
|
|
:key="shop.id"
|
2026-03-21 15:18:09 +08:00
|
|
|
|
:value="getShopOptionValue(shop)"
|
2026-02-25 16:58:58 +08:00
|
|
|
|
>
|
|
|
|
|
|
{{ shop.shopName }}
|
|
|
|
|
|
</a-select-option>
|
|
|
|
|
|
</a-select>
|
|
|
|
|
|
</a-form-item>
|
2026-02-25 17:20:12 +08:00
|
|
|
|
<a-form-item label="用户类型" name="type">
|
|
|
|
|
|
<a-select v-model:value="formState.type" placeholder="请选择用户类型">
|
2026-02-28 14:32:28 +08:00
|
|
|
|
<a-select-option v-if="currentUserInfo?.type === 4" :value="0">用户</a-select-option>
|
|
|
|
|
|
<a-select-option v-if="currentUserInfo?.type === 4" :value="2">店长</a-select-option>
|
|
|
|
|
|
<a-select-option v-if="currentUserInfo?.type === 4" :value="3">美甲师</a-select-option>
|
|
|
|
|
|
<a-select-option v-if="currentUserInfo?.type === 4" :value="4">管理员</a-select-option>
|
|
|
|
|
|
<a-select-option v-else-if="currentUserInfo?.type === 2" :value="0">用户</a-select-option>
|
|
|
|
|
|
<a-select-option v-else-if="currentUserInfo?.type === 2" :value="3">美甲师</a-select-option>
|
|
|
|
|
|
<a-select-option v-else-if="currentUserInfo?.type === 3" :value="0">用户</a-select-option>
|
|
|
|
|
|
</a-select>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
</a-form>
|
|
|
|
|
|
</a-modal>
|
|
|
|
|
|
|
|
|
|
|
|
<a-modal
|
|
|
|
|
|
v-model:open="viewModalVisible"
|
|
|
|
|
|
title="查看用户详情"
|
2026-03-20 12:24:56 +08:00
|
|
|
|
:footer="null"
|
|
|
|
|
|
width="640px"
|
|
|
|
|
|
@cancel="viewModalVisible = false"
|
2026-02-28 14:32:28 +08:00
|
|
|
|
>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<a-descriptions bordered :column="1" size="small">
|
|
|
|
|
|
<a-descriptions-item label="账号">{{ viewRecord?.account || '-' }}</a-descriptions-item>
|
|
|
|
|
|
<a-descriptions-item label="昵称">{{ viewRecord?.nickname || '-' }}</a-descriptions-item>
|
|
|
|
|
|
<a-descriptions-item label="手机号">{{ viewRecord?.phone || '-' }}</a-descriptions-item>
|
|
|
|
|
|
<a-descriptions-item label="所属店铺">{{ viewRecord?.shopName || '-' }}</a-descriptions-item>
|
|
|
|
|
|
<a-descriptions-item label="用户类型">{{ getUserTypeText(viewRecord?.type || 0) }}</a-descriptions-item>
|
|
|
|
|
|
<a-descriptions-item label="VIP 等级">{{ viewRecord?.level || '普通' }}</a-descriptions-item>
|
|
|
|
|
|
<a-descriptions-item label="状态">{{ viewRecord?.status === 1 ? '正常' : '禁用' }}</a-descriptions-item>
|
|
|
|
|
|
<a-descriptions-item label="创建时间">{{ viewRecord?.createTime || '-' }}</a-descriptions-item>
|
|
|
|
|
|
</a-descriptions>
|
|
|
|
|
|
</a-modal>
|
|
|
|
|
|
|
|
|
|
|
|
<a-modal
|
|
|
|
|
|
v-model:open="assetModalVisible"
|
|
|
|
|
|
title="余额 / VIP 管理"
|
|
|
|
|
|
width="960px"
|
|
|
|
|
|
:footer="null"
|
|
|
|
|
|
@cancel="handleAssetModalCancel"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-spin :spinning="assetLoading">
|
|
|
|
|
|
<div v-if="assetTargetUser" class="asset-modal">
|
|
|
|
|
|
<a-alert
|
|
|
|
|
|
:message="`${assetTargetUser.nickname}(${assetTargetUser.account})`"
|
|
|
|
|
|
:description="assetTargetUser.shopName ? `所属店铺:${assetTargetUser.shopName}` : '未绑定店铺'"
|
|
|
|
|
|
type="info"
|
|
|
|
|
|
show-icon
|
|
|
|
|
|
style="margin-bottom: 16px"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<a-row :gutter="16" class="asset-summary">
|
|
|
|
|
|
<a-col :span="8">
|
|
|
|
|
|
<a-card size="small" title="当前余额">
|
|
|
|
|
|
<div class="summary-value">¥{{ formatMoney(assetData?.balance) }}</div>
|
|
|
|
|
|
<div class="summary-sub">累计充值:¥{{ formatMoney(assetData?.totalRechargeAmount) }}</div>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
<a-col :span="8">
|
|
|
|
|
|
<a-card size="small" title="VIP 状态">
|
|
|
|
|
|
<div class="summary-value">{{ assetData?.vipLevel || '普通' }}</div>
|
|
|
|
|
|
<div class="summary-sub">
|
|
|
|
|
|
{{ assetData?.manualOverride ? '当前为手工指定' : '当前按累计充值自动判级' }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
<a-col :span="8">
|
|
|
|
|
|
<a-card size="small" title="最近充值">
|
|
|
|
|
|
<div class="summary-value">{{ formatDate(assetData?.lastRechargeTime) }}</div>
|
|
|
|
|
|
<div class="summary-sub">权益说明:{{ assetData?.benefitInfo || '-' }}</div>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
</a-row>
|
|
|
|
|
|
|
|
|
|
|
|
<a-row :gutter="16" class="asset-actions">
|
|
|
|
|
|
<a-col :span="12">
|
|
|
|
|
|
<a-card size="small" title="余额变动">
|
|
|
|
|
|
<a-form layout="vertical">
|
|
|
|
|
|
<a-form-item label="变动场景">
|
|
|
|
|
|
<a-select v-model:value="balanceForm.changeScene">
|
|
|
|
|
|
<a-select-option value="RECHARGE">充值</a-select-option>
|
|
|
|
|
|
<a-select-option value="MANUAL_ADD">手工增加余额</a-select-option>
|
|
|
|
|
|
<a-select-option value="MANUAL_DEDUCT">手工扣减余额</a-select-option>
|
|
|
|
|
|
</a-select>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="变动金额">
|
|
|
|
|
|
<a-input-number
|
|
|
|
|
|
v-model:value="balanceForm.amount"
|
|
|
|
|
|
:min="0.01"
|
|
|
|
|
|
:precision="2"
|
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
|
placeholder="请输入金额"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="关联系统订单 ID(可选)">
|
|
|
|
|
|
<a-input-number
|
|
|
|
|
|
v-model:value="balanceForm.relatedOrderId"
|
|
|
|
|
|
:min="1"
|
|
|
|
|
|
:precision="0"
|
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
|
placeholder="如有系统订单可填写"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="外部单号(扣减时二选一)">
|
|
|
|
|
|
<a-input
|
|
|
|
|
|
v-model:value="balanceForm.externalOrderNo"
|
|
|
|
|
|
placeholder="没有系统订单时请填写外部单号"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="备注">
|
|
|
|
|
|
<a-textarea
|
|
|
|
|
|
v-model:value="balanceForm.remark"
|
|
|
|
|
|
:rows="3"
|
|
|
|
|
|
placeholder="请输入备注"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-if="hasPermission('user:balance:manage')"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
:loading="assetSaving"
|
|
|
|
|
|
@click="handleBalanceChange"
|
|
|
|
|
|
>
|
|
|
|
|
|
提交余额变动
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-typography-text v-else type="secondary">
|
|
|
|
|
|
当前账号只有查看权限,不能调整余额。
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
</a-form>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
|
|
|
|
|
|
<a-col :span="12">
|
|
|
|
|
|
<a-card size="small" title="VIP 管理">
|
|
|
|
|
|
<a-form layout="vertical">
|
|
|
|
|
|
<a-form-item label="目标等级">
|
|
|
|
|
|
<a-select v-model:value="vipForm.vipLevel">
|
|
|
|
|
|
<a-select-option value="普通">普通</a-select-option>
|
|
|
|
|
|
<a-select-option value="青铜">青铜</a-select-option>
|
|
|
|
|
|
<a-select-option value="白银">白银</a-select-option>
|
|
|
|
|
|
<a-select-option value="黄金">黄金</a-select-option>
|
|
|
|
|
|
</a-select>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="备注">
|
|
|
|
|
|
<a-textarea
|
|
|
|
|
|
v-model:value="vipForm.remark"
|
|
|
|
|
|
:rows="3"
|
|
|
|
|
|
placeholder="可填写手工调整原因"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-space>
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-if="hasPermission('user:vip:manage')"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
:loading="assetSaving"
|
|
|
|
|
|
@click="handleVipOverride"
|
|
|
|
|
|
>
|
|
|
|
|
|
手工设置 VIP
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-if="hasPermission('user:vip:manage')"
|
|
|
|
|
|
:loading="assetSaving"
|
|
|
|
|
|
@click="handleVipRecalculate"
|
|
|
|
|
|
>
|
|
|
|
|
|
恢复自动判级
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
</a-space>
|
|
|
|
|
|
<div class="vip-note">
|
|
|
|
|
|
{{ assetData?.manualOverride ? '当前处于手工指定状态。' : '当前按累计充值自动判级。' }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a-form>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
</a-row>
|
|
|
|
|
|
|
|
|
|
|
|
<a-card size="small" title="余额流水" class="history-card">
|
|
|
|
|
|
<a-table
|
|
|
|
|
|
:columns="historyColumns"
|
|
|
|
|
|
:data-source="balanceHistory"
|
|
|
|
|
|
:pagination="false"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
row-key="id"
|
|
|
|
|
|
:scroll="{ y: 320 }"
|
2026-02-28 14:32:28 +08:00
|
|
|
|
>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<template #bodyCell="{ column, record }">
|
|
|
|
|
|
<template v-if="column.key === 'amount'">
|
|
|
|
|
|
<span :class="Number(record.amount) >= 0 ? 'amount-plus' : 'amount-minus'">
|
|
|
|
|
|
{{ Number(record.amount) >= 0 ? '+' : '' }}{{ formatMoney(record.amount) }}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="column.key === 'changeScene'">
|
|
|
|
|
|
{{ getSceneText(record.changeScene) }}
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="column.key === 'balanceRange'">
|
|
|
|
|
|
{{ formatMoney(record.beforeBalance) }} -> {{ formatMoney(record.afterBalance) }}
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="column.key === 'relatedOrder'">
|
|
|
|
|
|
{{ record.relatedOrderNo || record.externalOrderNo || '-' }}
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="column.key === 'changeTime'">
|
|
|
|
|
|
{{ formatDate(record.changeTime) }}
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-table>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a-spin>
|
2026-02-25 10:37:16 +08:00
|
|
|
|
</a-modal>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-03-20 12:24:56 +08:00
|
|
|
|
import { computed, onMounted, reactive, ref } from 'vue'
|
2026-02-25 10:37:16 +08:00
|
|
|
|
import { message, Modal } from 'ant-design-vue'
|
|
|
|
|
|
import type { FormInstance } from 'ant-design-vue'
|
|
|
|
|
|
import { PlusOutlined } from '@ant-design/icons-vue'
|
|
|
|
|
|
import { DEFAULT_AVATAR } from '@/constants'
|
2026-03-20 12:24:56 +08:00
|
|
|
|
import {
|
|
|
|
|
|
adminShopApi,
|
|
|
|
|
|
adminUserApi,
|
|
|
|
|
|
type AdminUserBalanceChangeRequest,
|
|
|
|
|
|
type AdminUserVipOverrideRequest,
|
|
|
|
|
|
type Shop,
|
|
|
|
|
|
type UserAssetVO,
|
|
|
|
|
|
type UserBalanceHistoryItem,
|
|
|
|
|
|
type UserVO
|
|
|
|
|
|
} from '@/api/admin'
|
2026-02-26 17:54:18 +08:00
|
|
|
|
import { usePermission } from '@/utils/permission'
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const { hasPermission, hasAnyPermission, loadUserPermissions } = usePermission()
|
2026-02-25 10:37:16 +08:00
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const currentUserInfo = (() => {
|
2026-02-25 17:20:12 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const userInfoStr = localStorage.getItem('adminUserInfo')
|
2026-03-20 12:24:56 +08:00
|
|
|
|
return userInfoStr ? JSON.parse(userInfoStr) : null
|
2026-02-25 17:20:12 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('获取当前用户信息失败', error)
|
2026-03-20 12:24:56 +08:00
|
|
|
|
return null
|
2026-02-25 17:20:12 +08:00
|
|
|
|
}
|
2026-03-20 12:24:56 +08:00
|
|
|
|
})()
|
2026-02-25 17:20:12 +08:00
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
const loading = ref(false)
|
2026-02-25 16:58:58 +08:00
|
|
|
|
const shopLoading = ref(false)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
const modalVisible = ref(false)
|
|
|
|
|
|
const modalLoading = ref(false)
|
2026-02-28 14:32:28 +08:00
|
|
|
|
const viewModalVisible = ref(false)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
const isEdit = ref(false)
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const searchText = ref('')
|
2026-02-25 10:37:16 +08:00
|
|
|
|
const formRef = ref<FormInstance>()
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const userList = ref<UserVO[]>([])
|
|
|
|
|
|
const shopList = ref<Shop[]>([])
|
|
|
|
|
|
const currentUser = ref<UserVO | null>(null)
|
|
|
|
|
|
const viewRecord = ref<UserVO | null>(null)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const assetModalVisible = ref(false)
|
|
|
|
|
|
const assetLoading = ref(false)
|
|
|
|
|
|
const assetSaving = ref(false)
|
|
|
|
|
|
const assetTargetUser = ref<UserVO | null>(null)
|
|
|
|
|
|
const assetData = ref<UserAssetVO | null>(null)
|
|
|
|
|
|
const balanceHistory = ref<UserBalanceHistoryItem[]>([])
|
|
|
|
|
|
|
|
|
|
|
|
const canOpenAssetPanel = computed(() =>
|
|
|
|
|
|
hasAnyPermission(['user:balance:view', 'user:balance:manage', 'user:vip:manage'])
|
|
|
|
|
|
)
|
2026-03-21 15:18:09 +08:00
|
|
|
|
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
2026-02-28 14:32:28 +08:00
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
const pagination = reactive({
|
|
|
|
|
|
current: 1,
|
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
|
total: 0,
|
|
|
|
|
|
showSizeChanger: true,
|
|
|
|
|
|
showQuickJumper: true,
|
|
|
|
|
|
showTotal: (total: number) => `共 ${total} 条`
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const formState = reactive({
|
2026-02-25 11:38:31 +08:00
|
|
|
|
account: '',
|
2026-02-25 10:37:16 +08:00
|
|
|
|
nickname: '',
|
|
|
|
|
|
phone: '',
|
|
|
|
|
|
password: '',
|
2026-02-25 16:58:58 +08:00
|
|
|
|
type: 0,
|
2026-03-21 15:18:09 +08:00
|
|
|
|
shopId: undefined as string | undefined
|
2026-02-25 16:58:58 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const balanceForm = reactive<AdminUserBalanceChangeRequest>({
|
|
|
|
|
|
changeScene: 'RECHARGE',
|
|
|
|
|
|
amount: undefined as unknown as number,
|
|
|
|
|
|
relatedOrderId: undefined,
|
|
|
|
|
|
externalOrderNo: '',
|
|
|
|
|
|
remark: ''
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const vipForm = reactive<AdminUserVipOverrideRequest>({
|
|
|
|
|
|
vipLevel: '普通',
|
|
|
|
|
|
remark: ''
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
const formRules = {
|
2026-02-25 11:38:31 +08:00
|
|
|
|
account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
|
2026-02-25 10:37:16 +08:00
|
|
|
|
nickname: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
2026-03-21 15:18:09 +08:00
|
|
|
|
phone: [
|
|
|
|
|
|
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: async (_rule: unknown, value: string) => {
|
|
|
|
|
|
const normalized = value?.trim()
|
|
|
|
|
|
if (!normalized) {
|
|
|
|
|
|
return Promise.reject('请输入手机号')
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!PHONE_REGEX.test(normalized)) {
|
|
|
|
|
|
return Promise.reject('请输入正确的 11 位手机号')
|
|
|
|
|
|
}
|
|
|
|
|
|
return Promise.resolve()
|
|
|
|
|
|
},
|
|
|
|
|
|
trigger: ['blur', 'change']
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
2026-02-25 10:37:16 +08:00
|
|
|
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
2026-02-25 17:20:12 +08:00
|
|
|
|
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
|
|
|
|
|
type: [{ required: true, message: '请选择用户类型', trigger: 'change' }]
|
2026-03-10 23:23:15 +08:00
|
|
|
|
} as any
|
2026-02-25 10:37:16 +08:00
|
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
|
{ title: '头像', key: 'avatar', width: 80 },
|
2026-02-25 11:38:31 +08:00
|
|
|
|
{ title: '账号', dataIndex: 'account', key: 'account' },
|
2026-02-25 10:37:16 +08:00
|
|
|
|
{ title: '昵称', dataIndex: 'nickname', key: 'nickname' },
|
|
|
|
|
|
{ title: '手机号', dataIndex: 'phone', key: 'phone' },
|
2026-03-20 12:24:56 +08:00
|
|
|
|
{ title: '所属店铺', key: 'shopName', width: 140 },
|
|
|
|
|
|
{ title: '用户类型', key: 'type', width: 110 },
|
|
|
|
|
|
{ title: 'VIP 等级', key: 'level', width: 110 },
|
2026-02-25 10:37:16 +08:00
|
|
|
|
{ title: '状态', key: 'status', width: 100 },
|
2026-03-20 12:24:56 +08:00
|
|
|
|
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
|
|
|
|
|
|
{ title: '操作', key: 'actions', width: 280, fixed: 'right' as const }
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
const historyColumns = [
|
|
|
|
|
|
{ title: '场景', key: 'changeScene', width: 120 },
|
|
|
|
|
|
{ title: '金额', key: 'amount', width: 110 },
|
|
|
|
|
|
{ title: '余额变化', key: 'balanceRange', width: 170 },
|
|
|
|
|
|
{ title: '关联单号', key: 'relatedOrder', width: 180 },
|
|
|
|
|
|
{ title: '备注', dataIndex: 'remark', key: 'remark' },
|
|
|
|
|
|
{ title: '时间', key: 'changeTime', width: 180 }
|
2026-02-25 10:37:16 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
const getUserTypeText = (type: number) => {
|
|
|
|
|
|
const map: Record<number, string> = {
|
|
|
|
|
|
0: '用户',
|
|
|
|
|
|
2: '店长',
|
|
|
|
|
|
3: '美甲师',
|
|
|
|
|
|
4: '管理员'
|
|
|
|
|
|
}
|
|
|
|
|
|
return map[type] || '未知'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const getUserTypeColor = (type: number) => {
|
|
|
|
|
|
const map: Record<number, string> = {
|
|
|
|
|
|
0: 'default',
|
|
|
|
|
|
2: 'blue',
|
|
|
|
|
|
3: 'green',
|
|
|
|
|
|
4: 'purple'
|
|
|
|
|
|
}
|
|
|
|
|
|
return map[type] || 'default'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const getSceneText = (scene?: string) => {
|
|
|
|
|
|
const map: Record<string, string> = {
|
|
|
|
|
|
RECHARGE: '充值',
|
|
|
|
|
|
MANUAL_ADD: '手工增加',
|
|
|
|
|
|
MANUAL_DEDUCT: '手工扣减',
|
|
|
|
|
|
ORDER_CONSUME: '订单消费',
|
|
|
|
|
|
ORDER_REFUND: '订单退款'
|
|
|
|
|
|
}
|
|
|
|
|
|
return scene ? map[scene] || scene : '-'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const formatMoney = (value?: number | string | null) => {
|
|
|
|
|
|
if (value === undefined || value === null || value === '') {
|
|
|
|
|
|
return '0.00'
|
|
|
|
|
|
}
|
|
|
|
|
|
return Number(value).toFixed(2)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const formatDate = (value?: string) => {
|
|
|
|
|
|
if (!value) {
|
|
|
|
|
|
return '-'
|
|
|
|
|
|
}
|
|
|
|
|
|
return value.replace('T', ' ').slice(0, 19)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const filterVisibleUsers = (list: UserVO[]) => {
|
|
|
|
|
|
if (!currentUserInfo || currentUserInfo.type === 4) {
|
|
|
|
|
|
return list
|
|
|
|
|
|
}
|
|
|
|
|
|
if (currentUserInfo.type === 2) {
|
|
|
|
|
|
return list.filter(user => user.type === 0 || user.type === 3)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (currentUserInfo.type === 3) {
|
|
|
|
|
|
return list.filter(user => user.type === 0)
|
|
|
|
|
|
}
|
|
|
|
|
|
return list
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-21 15:18:09 +08:00
|
|
|
|
const normalizeShopId = (value: unknown) => {
|
|
|
|
|
|
if (value === undefined || value === null || value === '') {
|
|
|
|
|
|
return undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
return String(value)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const getShopOptionValue = (shop: Shop) => normalizeShopId((shop as any).id) || ''
|
|
|
|
|
|
|
|
|
|
|
|
const getShopNameById = (shopId?: string | number | null) => {
|
|
|
|
|
|
const targetShopId = normalizeShopId(shopId)
|
|
|
|
|
|
if (!targetShopId) {
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
|
|
|
|
|
const matchedShop = shopList.value.find(shop => getShopOptionValue(shop) === targetShopId)
|
|
|
|
|
|
return matchedShop?.shopName || ''
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const resolveEditableShopId = (shopId?: string | number | null) => {
|
|
|
|
|
|
const targetShopId = normalizeShopId(shopId)
|
|
|
|
|
|
if (targetShopId && shopList.value.some(shop => getShopOptionValue(shop) === targetShopId)) {
|
|
|
|
|
|
return targetShopId
|
|
|
|
|
|
}
|
|
|
|
|
|
return shopList.value.length === 1 ? getShopOptionValue(shopList.value[0]!) : undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-25 16:58:58 +08:00
|
|
|
|
const fetchShopList = async () => {
|
|
|
|
|
|
shopLoading.value = true
|
|
|
|
|
|
try {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const shops = await adminShopApi.listAllShops() as unknown as Shop[]
|
|
|
|
|
|
shopList.value = shops || []
|
|
|
|
|
|
if (currentUserInfo?.type !== 4 && currentUserInfo?.shopId) {
|
2026-03-21 15:18:09 +08:00
|
|
|
|
formState.shopId = normalizeShopId(currentUserInfo.shopId)
|
2026-02-25 16:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
2026-02-26 23:28:24 +08:00
|
|
|
|
console.error('获取店铺列表失败:', error)
|
2026-02-25 16:58:58 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
shopLoading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
const fetchUserList = async () => {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const params: Record<string, unknown> = {
|
2026-02-25 10:37:16 +08:00
|
|
|
|
page: pagination.current,
|
|
|
|
|
|
size: pagination.pageSize,
|
2026-03-20 12:24:56 +08:00
|
|
|
|
keyword: searchText.value || undefined
|
2026-02-25 16:50:32 +08:00
|
|
|
|
}
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
|
|
|
|
|
if (currentUserInfo?.type !== 4 && currentUserInfo?.shopId) {
|
2026-02-25 17:20:12 +08:00
|
|
|
|
params.shopId = currentUserInfo.shopId
|
2026-02-25 16:50:32 +08:00
|
|
|
|
}
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
|
|
|
|
|
const res = await adminUserApi.listUsers(params as any)
|
|
|
|
|
|
const list = filterVisibleUsers(res.list || [])
|
|
|
|
|
|
userList.value = list
|
|
|
|
|
|
pagination.total = res.total || list.length
|
2026-02-25 10:37:16 +08:00
|
|
|
|
} catch (error) {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
console.error('获取用户列表失败:', error)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
message.error('获取用户列表失败')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const resetFormState = () => {
|
2026-02-25 10:37:16 +08:00
|
|
|
|
Object.assign(formState, {
|
2026-02-25 11:38:31 +08:00
|
|
|
|
account: '',
|
2026-02-25 10:37:16 +08:00
|
|
|
|
nickname: '',
|
|
|
|
|
|
phone: '',
|
|
|
|
|
|
password: '',
|
2026-02-25 16:58:58 +08:00
|
|
|
|
type: 0,
|
2026-03-21 15:18:09 +08:00
|
|
|
|
shopId: currentUserInfo?.type !== 4 && currentUserInfo?.shopId
|
|
|
|
|
|
? normalizeShopId(currentUserInfo.shopId)
|
|
|
|
|
|
: undefined
|
2026-02-25 10:37:16 +08:00
|
|
|
|
})
|
2026-03-20 12:24:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleSearch = () => {
|
|
|
|
|
|
pagination.current = 1
|
|
|
|
|
|
void fetchUserList()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleTableChange = (pag: any) => {
|
|
|
|
|
|
pagination.current = pag.current || 1
|
|
|
|
|
|
pagination.pageSize = pag.pageSize || pagination.pageSize
|
|
|
|
|
|
void fetchUserList()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const showAddModal = () => {
|
|
|
|
|
|
isEdit.value = false
|
|
|
|
|
|
currentUser.value = null
|
|
|
|
|
|
resetFormState()
|
2026-02-25 10:37:16 +08:00
|
|
|
|
modalVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const showEditModal = (record: any) => {
|
2026-02-25 10:37:16 +08:00
|
|
|
|
isEdit.value = true
|
|
|
|
|
|
currentUser.value = record
|
|
|
|
|
|
Object.assign(formState, {
|
2026-02-25 11:38:31 +08:00
|
|
|
|
account: record.account,
|
2026-02-25 10:37:16 +08:00
|
|
|
|
nickname: record.nickname,
|
2026-03-20 12:24:56 +08:00
|
|
|
|
phone: record.phone || '',
|
2026-02-25 10:37:16 +08:00
|
|
|
|
password: '',
|
2026-02-25 16:58:58 +08:00
|
|
|
|
type: record.type,
|
2026-03-21 15:18:09 +08:00
|
|
|
|
shopId: resolveEditableShopId(record.shopId)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
})
|
|
|
|
|
|
modalVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const showViewModal = (record: any) => {
|
|
|
|
|
|
viewRecord.value = record
|
2026-02-28 14:32:28 +08:00
|
|
|
|
viewModalVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const loadUserAssetData = async (userId: number) => {
|
|
|
|
|
|
const [asset, history] = await Promise.all([
|
|
|
|
|
|
adminUserApi.getUserAsset(userId),
|
|
|
|
|
|
adminUserApi.getUserBalanceHistory(userId)
|
|
|
|
|
|
])
|
|
|
|
|
|
assetData.value = asset
|
|
|
|
|
|
balanceHistory.value = history || []
|
|
|
|
|
|
vipForm.vipLevel = asset.vipLevel || '普通'
|
2026-02-28 14:32:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const resetAssetForms = () => {
|
|
|
|
|
|
Object.assign(balanceForm, {
|
|
|
|
|
|
changeScene: 'RECHARGE',
|
|
|
|
|
|
amount: undefined,
|
|
|
|
|
|
relatedOrderId: undefined,
|
|
|
|
|
|
externalOrderNo: '',
|
|
|
|
|
|
remark: ''
|
|
|
|
|
|
})
|
|
|
|
|
|
Object.assign(vipForm, {
|
|
|
|
|
|
vipLevel: assetData.value?.vipLevel || '普通',
|
|
|
|
|
|
remark: ''
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const showAssetModal = async (record: any) => {
|
|
|
|
|
|
assetTargetUser.value = record
|
|
|
|
|
|
assetModalVisible.value = true
|
|
|
|
|
|
assetLoading.value = true
|
|
|
|
|
|
assetData.value = null
|
|
|
|
|
|
balanceHistory.value = []
|
|
|
|
|
|
resetAssetForms()
|
2026-02-26 23:28:24 +08:00
|
|
|
|
try {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
await loadUserAssetData(record.id)
|
|
|
|
|
|
resetAssetForms()
|
2026-02-26 23:28:24 +08:00
|
|
|
|
} catch (error) {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
console.error('获取用户资产失败:', error)
|
|
|
|
|
|
message.error('获取用户资产失败')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
assetLoading.value = false
|
2026-02-26 23:28:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const handleAssetModalCancel = () => {
|
|
|
|
|
|
assetModalVisible.value = false
|
|
|
|
|
|
assetTargetUser.value = null
|
|
|
|
|
|
assetData.value = null
|
|
|
|
|
|
balanceHistory.value = []
|
|
|
|
|
|
resetAssetForms()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
const handleModalOk = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await formRef.value?.validate()
|
|
|
|
|
|
modalLoading.value = true
|
2026-03-21 15:18:09 +08:00
|
|
|
|
const requestData = {
|
|
|
|
|
|
account: formState.account.trim(),
|
|
|
|
|
|
nickname: formState.nickname.trim(),
|
|
|
|
|
|
phone: formState.phone.trim(),
|
|
|
|
|
|
type: formState.type,
|
|
|
|
|
|
shopId: formState.shopId || undefined,
|
|
|
|
|
|
...(formState.password.trim() ? { password: formState.password.trim() } : {})
|
|
|
|
|
|
}
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
if (isEdit.value && currentUser.value) {
|
2026-03-21 15:18:09 +08:00
|
|
|
|
await adminUserApi.updateUser(currentUser.value.id, requestData)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
message.success('更新成功')
|
|
|
|
|
|
} else {
|
2026-03-21 15:18:09 +08:00
|
|
|
|
await adminUserApi.createUser(requestData)
|
2026-03-20 12:24:56 +08:00
|
|
|
|
message.success('创建成功')
|
2026-02-25 10:37:16 +08:00
|
|
|
|
}
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
modalVisible.value = false
|
2026-03-20 12:24:56 +08:00
|
|
|
|
formRef.value?.resetFields()
|
|
|
|
|
|
await fetchUserList()
|
2026-02-26 23:28:24 +08:00
|
|
|
|
} catch (error: any) {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
console.error('用户保存失败:', error)
|
|
|
|
|
|
message.error(error.message || '操作失败')
|
2026-02-25 10:37:16 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
modalLoading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleModalCancel = () => {
|
|
|
|
|
|
modalVisible.value = false
|
|
|
|
|
|
formRef.value?.resetFields()
|
2026-03-20 12:24:56 +08:00
|
|
|
|
resetFormState()
|
2026-02-25 10:37:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const handleStatusChange = async (record: any, checked: boolean) => {
|
2026-02-25 10:37:16 +08:00
|
|
|
|
try {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
await adminUserApi.updateUserStatus(record.id, checked ? 1 : 0)
|
|
|
|
|
|
record.status = checked ? 1 : 0
|
2026-02-25 10:37:16 +08:00
|
|
|
|
message.success('状态更新成功')
|
|
|
|
|
|
} catch (error) {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
console.error('状态更新失败:', error)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
message.error('状态更新失败')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const handleResetPassword = (record: any) => {
|
2026-02-25 10:37:16 +08:00
|
|
|
|
Modal.confirm({
|
|
|
|
|
|
title: '确认重置密码',
|
2026-02-28 15:17:30 +08:00
|
|
|
|
content: `确定要将用户 ${record.nickname} 的密码重置为 888888 吗?`,
|
2026-03-20 12:24:56 +08:00
|
|
|
|
async onOk() {
|
2026-02-25 10:37:16 +08:00
|
|
|
|
try {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
await adminUserApi.resetPassword(record.id)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
message.success('密码重置成功')
|
|
|
|
|
|
} catch (error) {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
console.error('重置密码失败:', error)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
message.error('密码重置失败')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const handleDelete = async (record: any) => {
|
2026-02-25 10:37:16 +08:00
|
|
|
|
try {
|
2026-02-26 23:28:24 +08:00
|
|
|
|
if (record.type === 4) {
|
|
|
|
|
|
message.warning('管理员账号无法被删除')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
|
|
|
|
|
const timestamp = Date.now()
|
|
|
|
|
|
await adminUserApi.updateUser(record.id, {
|
|
|
|
|
|
account: `${record.account}_deleted_${timestamp}`,
|
|
|
|
|
|
phone: record.phone ? `${record.phone}_deleted_${timestamp}` : undefined
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
await adminUserApi.deleteUser(record.id)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
message.success('删除成功')
|
2026-03-20 12:24:56 +08:00
|
|
|
|
await fetchUserList()
|
2026-02-25 10:37:16 +08:00
|
|
|
|
} catch (error) {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
console.error('删除用户失败:', error)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
message.error('删除失败')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:24:56 +08:00
|
|
|
|
const refreshAssetPanel = async () => {
|
|
|
|
|
|
if (!assetTargetUser.value) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
assetLoading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
await loadUserAssetData(assetTargetUser.value.id)
|
|
|
|
|
|
const matchedUser = userList.value.find(user => user.id === assetTargetUser.value?.id)
|
|
|
|
|
|
if (matchedUser && assetData.value) {
|
|
|
|
|
|
matchedUser.level = assetData.value.vipLevel
|
|
|
|
|
|
matchedUser.vipId = assetData.value.vipInfoId
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
assetLoading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleBalanceChange = async () => {
|
|
|
|
|
|
if (!assetTargetUser.value) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!balanceForm.amount || Number(balanceForm.amount) <= 0) {
|
|
|
|
|
|
message.warning('请输入大于 0 的金额')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if (
|
|
|
|
|
|
balanceForm.changeScene === 'MANUAL_DEDUCT'
|
|
|
|
|
|
&& !balanceForm.relatedOrderId
|
|
|
|
|
|
&& !balanceForm.externalOrderNo?.trim()
|
|
|
|
|
|
) {
|
|
|
|
|
|
message.warning('手工扣减余额时必须填写系统订单 ID 或外部单号')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
assetSaving.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
await adminUserApi.changeUserBalance(assetTargetUser.value.id, {
|
|
|
|
|
|
amount: Number(balanceForm.amount),
|
|
|
|
|
|
changeScene: balanceForm.changeScene,
|
|
|
|
|
|
relatedOrderId: balanceForm.relatedOrderId,
|
|
|
|
|
|
externalOrderNo: balanceForm.externalOrderNo?.trim() || undefined,
|
|
|
|
|
|
remark: balanceForm.remark?.trim() || undefined
|
|
|
|
|
|
})
|
|
|
|
|
|
message.success('余额变动已保存')
|
|
|
|
|
|
Object.assign(balanceForm, {
|
|
|
|
|
|
amount: undefined,
|
|
|
|
|
|
relatedOrderId: undefined,
|
|
|
|
|
|
externalOrderNo: '',
|
|
|
|
|
|
remark: ''
|
|
|
|
|
|
})
|
|
|
|
|
|
await refreshAssetPanel()
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
console.error('余额变动失败:', error)
|
|
|
|
|
|
message.error(error.message || '余额变动失败')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
assetSaving.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleVipOverride = async () => {
|
|
|
|
|
|
if (!assetTargetUser.value) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
assetSaving.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
await adminUserApi.overrideUserVip(assetTargetUser.value.id, {
|
|
|
|
|
|
vipLevel: vipForm.vipLevel,
|
|
|
|
|
|
remark: vipForm.remark?.trim() || undefined
|
|
|
|
|
|
})
|
|
|
|
|
|
message.success('VIP 已更新')
|
|
|
|
|
|
vipForm.remark = ''
|
|
|
|
|
|
await refreshAssetPanel()
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
console.error('VIP 更新失败:', error)
|
|
|
|
|
|
message.error(error.message || 'VIP 更新失败')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
assetSaving.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleVipRecalculate = () => {
|
|
|
|
|
|
if (!assetTargetUser.value) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
|
title: '恢复自动判级',
|
|
|
|
|
|
content: '恢复后会清除手工指定状态,并按累计充值金额重新计算 VIP 等级,是否继续?',
|
|
|
|
|
|
async onOk() {
|
|
|
|
|
|
assetSaving.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
await adminUserApi.recalculateUserVip(assetTargetUser.value!.id)
|
|
|
|
|
|
message.success('已恢复自动判级')
|
|
|
|
|
|
vipForm.remark = ''
|
|
|
|
|
|
await refreshAssetPanel()
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
console.error('恢复自动判级失败:', error)
|
|
|
|
|
|
message.error(error.message || '恢复自动判级失败')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
assetSaving.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-26 18:44:47 +08:00
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
await loadUserPermissions()
|
2026-03-20 12:24:56 +08:00
|
|
|
|
await fetchShopList()
|
|
|
|
|
|
await fetchUserList()
|
2026-02-25 10:37:16 +08:00
|
|
|
|
})
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.users {
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
}
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
|
|
|
|
|
.asset-modal {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.asset-summary,
|
|
|
|
|
|
.asset-actions,
|
|
|
|
|
|
.history-card {
|
|
|
|
|
|
margin-top: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.summary-value {
|
|
|
|
|
|
font-size: 22px;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
line-height: 1.4;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.summary-sub {
|
|
|
|
|
|
margin-top: 8px;
|
|
|
|
|
|
color: #666;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
line-height: 1.6;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.vip-note {
|
|
|
|
|
|
margin-top: 12px;
|
|
|
|
|
|
color: #666;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.amount-plus {
|
|
|
|
|
|
color: #52c41a;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.amount-minus {
|
|
|
|
|
|
color: #ff4d4f;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
}
|
2026-02-25 10:37:16 +08:00
|
|
|
|
</style>
|