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-03-26 13:38:34 +08:00
|
|
|
|
<a-button v-if="canCreateUser" 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-26 10:28:28 +08:00
|
|
|
|
{{ getShopDisplay(record) || '-' }}
|
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-03-26 17:39:58 +08:00
|
|
|
|
v-if="canShowUnbind(record)"
|
|
|
|
|
|
title="确定要解绑该用户与当前店铺的关系吗?"
|
|
|
|
|
|
@confirm="handleUnbind(record)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-button type="link" size="small">
|
|
|
|
|
|
解绑
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
</a-popconfirm>
|
|
|
|
|
|
<a-popconfirm
|
|
|
|
|
|
v-if="canShowDelete(record)"
|
|
|
|
|
|
title="确定要删除这个用户吗?删除后账号将被标记为已删除。"
|
2026-02-25 10:37:16 +08:00
|
|
|
|
@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"
|
|
|
|
|
|
>
|
2026-03-26 12:04:02 +08:00
|
|
|
|
<DraftActions
|
|
|
|
|
|
:saved-at="draftSavedAt"
|
|
|
|
|
|
@save="handleSaveDraft"
|
|
|
|
|
|
@clear="handleClearDraft"
|
|
|
|
|
|
/>
|
2026-02-25 10:37:16 +08:00
|
|
|
|
<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">
|
2026-03-26 10:53:19 +08:00
|
|
|
|
<a-input
|
|
|
|
|
|
v-model:value="formState.account"
|
|
|
|
|
|
placeholder="请输入账号"
|
|
|
|
|
|
@input="handleAccountInput"
|
|
|
|
|
|
/>
|
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-03-26 13:38:34 +08:00
|
|
|
|
@input="handlePhoneInput"
|
2026-03-21 15:18:09 +08:00
|
|
|
|
/>
|
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-26 10:28:28 +08:00
|
|
|
|
<a-form-item label="所属店铺" name="shopIds">
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<a-select
|
2026-03-26 10:28:28 +08:00
|
|
|
|
v-model:value="formState.shopIds"
|
|
|
|
|
|
mode="multiple"
|
2026-03-27 10:05:03 +08:00
|
|
|
|
:placeholder="currentUserType === 4 ? '请选择一个或多个店铺' : '请选择店铺'"
|
2026-02-25 16:58:58 +08:00
|
|
|
|
:loading="shopLoading"
|
2026-03-27 10:05:03 +08:00
|
|
|
|
:disabled="currentUserType !== 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-03-27 10:05:03 +08:00
|
|
|
|
<a-select-option
|
|
|
|
|
|
v-for="option in availableUserTypeOptions"
|
|
|
|
|
|
:key="option.value"
|
|
|
|
|
|
:value="option.value"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ option.label }}
|
|
|
|
|
|
</a-select-option>
|
2026-02-28 14:32:28 +08:00
|
|
|
|
</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>
|
2026-03-26 10:28:28 +08:00
|
|
|
|
<a-descriptions-item label="所属店铺">{{ getShopDisplay(viewRecord) || '-' }}</a-descriptions-item>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<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})`"
|
2026-03-26 10:28:28 +08:00
|
|
|
|
:description="getShopDisplay(assetTargetUser) ? `所属店铺:${getShopDisplay(assetTargetUser)}` : '未绑定店铺'"
|
2026-03-20 12:24:56 +08:00
|
|
|
|
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="余额变动">
|
2026-03-26 12:04:02 +08:00
|
|
|
|
<DraftActions
|
|
|
|
|
|
:saved-at="balanceDraftSavedAt"
|
|
|
|
|
|
@save="handleSaveBalanceDraft"
|
|
|
|
|
|
@clear="handleClearBalanceDraft"
|
|
|
|
|
|
/>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<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 管理">
|
2026-03-26 12:04:02 +08:00
|
|
|
|
<DraftActions
|
|
|
|
|
|
:saved-at="vipDraftSavedAt"
|
|
|
|
|
|
@save="handleSaveVipDraft"
|
|
|
|
|
|
@clear="handleClearVipDraft"
|
|
|
|
|
|
/>
|
2026-03-20 12:24:56 +08:00
|
|
|
|
<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'
|
2026-03-26 12:04:02 +08:00
|
|
|
|
import DraftActions from '@/components/DraftActions.vue'
|
2026-02-25 10:37:16 +08:00
|
|
|
|
import { DEFAULT_AVATAR } from '@/constants'
|
2026-03-26 10:53:19 +08:00
|
|
|
|
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
2026-03-26 12:04:02 +08:00
|
|
|
|
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
2026-03-26 13:38:34 +08:00
|
|
|
|
import { userApi, type AvailabilityCheckResponse } from '@/api/user'
|
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-03-27 10:05:03 +08:00
|
|
|
|
const normalizeUserType = (value: unknown) => {
|
|
|
|
|
|
const type = Number(value)
|
|
|
|
|
|
return Number.isFinite(type) ? type : -1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-03-26 12:04:02 +08:00
|
|
|
|
const draftSavedAt = ref<number | 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[]>([])
|
2026-03-26 12:04:02 +08:00
|
|
|
|
const balanceDraftSavedAt = ref<number | null>(null)
|
|
|
|
|
|
const vipDraftSavedAt = ref<number | null>(null)
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
|
|
|
|
|
const canOpenAssetPanel = computed(() =>
|
|
|
|
|
|
hasAnyPermission(['user:balance:view', 'user:balance:manage', 'user:vip:manage'])
|
|
|
|
|
|
)
|
2026-03-27 10:05:03 +08:00
|
|
|
|
const currentUserType = computed(() => normalizeUserType(currentUserInfo?.type))
|
|
|
|
|
|
const availableUserTypeOptions = computed(() => {
|
|
|
|
|
|
if (currentUserType.value === 4) {
|
|
|
|
|
|
return [
|
|
|
|
|
|
{ value: 0, label: '用户' },
|
|
|
|
|
|
{ value: 2, label: '店长' },
|
|
|
|
|
|
{ value: 3, label: '美甲师' },
|
|
|
|
|
|
{ value: 4, label: '管理员' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
if (currentUserType.value === 2) {
|
|
|
|
|
|
return [
|
|
|
|
|
|
{ value: 0, label: '用户' },
|
|
|
|
|
|
{ value: 3, label: '美甲师' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
if (currentUserType.value === 3) {
|
|
|
|
|
|
return [
|
|
|
|
|
|
{ value: 0, label: '用户' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
return []
|
|
|
|
|
|
})
|
2026-03-26 13:38:34 +08:00
|
|
|
|
const canCreateUser = computed(() =>
|
2026-03-27 10:05:03 +08:00
|
|
|
|
hasPermission('user:create') || currentUserType.value === 2 || currentUserType.value === 4
|
2026-03-26 13:38:34 +08:00
|
|
|
|
)
|
2026-03-26 17:39:58 +08:00
|
|
|
|
const canDeleteUser = computed(() =>
|
2026-03-27 10:05:03 +08:00
|
|
|
|
currentUserType.value === 4 && hasPermission('user:delete')
|
2026-03-26 17:39:58 +08:00
|
|
|
|
)
|
|
|
|
|
|
const canUnbindUser = computed(() =>
|
|
|
|
|
|
hasPermission('user:unbind')
|
|
|
|
|
|
)
|
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-26 10:28:28 +08:00
|
|
|
|
shopIds: [] as string[]
|
2026-02-25 16:58:58 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-03-26 10:53:19 +08:00
|
|
|
|
const handleAccountInput = () => {
|
|
|
|
|
|
const normalized = sanitizeAccountInput(formState.account)
|
|
|
|
|
|
if (normalized !== formState.account) {
|
|
|
|
|
|
formState.account = normalized
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-26 13:38:34 +08:00
|
|
|
|
const handlePhoneInput = () => {
|
|
|
|
|
|
const normalized = formState.phone.replace(/\D/g, '').slice(0, 11)
|
|
|
|
|
|
if (normalized !== formState.phone) {
|
|
|
|
|
|
formState.phone = normalized
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const validatePhoneUniqueness = async (value: string) => {
|
|
|
|
|
|
const normalized = value?.trim()
|
|
|
|
|
|
if (!normalized) {
|
|
|
|
|
|
throw new Error('请输入手机号')
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!PHONE_REGEX.test(normalized)) {
|
|
|
|
|
|
throw new Error('请输入正确的 11 位手机号')
|
|
|
|
|
|
}
|
|
|
|
|
|
if (isEdit.value && currentUser.value?.phone?.trim() === normalized) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await userApi.checkPhoneAvailability(normalized) as unknown as AvailabilityCheckResponse
|
|
|
|
|
|
if (!response.available) {
|
|
|
|
|
|
throw new Error(response.message || '该手机号已绑定其他用户')
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
if (error instanceof Error && error.message) {
|
|
|
|
|
|
throw error
|
|
|
|
|
|
}
|
|
|
|
|
|
throw new Error('手机号校验失败,请稍后重试')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-03-26 12:04:02 +08:00
|
|
|
|
const getBalanceDraftKey = () => buildDraftStorageKey('admin-user-assets', 'balance', assetTargetUser.value?.id ?? 'unknown')
|
|
|
|
|
|
const getVipDraftKey = () => buildDraftStorageKey('admin-user-assets', 'vip', assetTargetUser.value?.id ?? 'unknown')
|
|
|
|
|
|
|
|
|
|
|
|
const restoreBalanceDraft = () => {
|
|
|
|
|
|
const draft = loadDraftRecord<{
|
|
|
|
|
|
changeScene: string
|
|
|
|
|
|
amount?: number
|
|
|
|
|
|
relatedOrderId?: number
|
|
|
|
|
|
externalOrderNo: string
|
|
|
|
|
|
remark: string
|
|
|
|
|
|
}>(getBalanceDraftKey())
|
|
|
|
|
|
if (!draft) {
|
|
|
|
|
|
balanceDraftSavedAt.value = null
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
Object.assign(balanceForm, draft.payload)
|
|
|
|
|
|
balanceDraftSavedAt.value = draft.savedAt
|
|
|
|
|
|
message.success('已恢复余额变动暂存')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleSaveBalanceDraft = () => {
|
|
|
|
|
|
const draft = saveDraftRecord(getBalanceDraftKey(), {
|
|
|
|
|
|
changeScene: balanceForm.changeScene,
|
|
|
|
|
|
amount: balanceForm.amount,
|
|
|
|
|
|
relatedOrderId: balanceForm.relatedOrderId,
|
|
|
|
|
|
externalOrderNo: balanceForm.externalOrderNo,
|
|
|
|
|
|
remark: balanceForm.remark
|
|
|
|
|
|
})
|
|
|
|
|
|
balanceDraftSavedAt.value = draft.savedAt
|
|
|
|
|
|
message.success('余额变动已暂存到本地')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleClearBalanceDraft = (showMessage = true) => {
|
|
|
|
|
|
clearDraftRecord(getBalanceDraftKey())
|
|
|
|
|
|
balanceDraftSavedAt.value = null
|
|
|
|
|
|
if (showMessage) {
|
|
|
|
|
|
message.success('已清除余额变动暂存')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const restoreVipDraft = () => {
|
|
|
|
|
|
const draft = loadDraftRecord<{
|
|
|
|
|
|
vipLevel: string
|
|
|
|
|
|
remark: string
|
|
|
|
|
|
}>(getVipDraftKey())
|
|
|
|
|
|
if (!draft) {
|
|
|
|
|
|
vipDraftSavedAt.value = null
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
Object.assign(vipForm, draft.payload)
|
|
|
|
|
|
vipDraftSavedAt.value = draft.savedAt
|
|
|
|
|
|
message.success('已恢复 VIP 暂存')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleSaveVipDraft = () => {
|
|
|
|
|
|
const draft = saveDraftRecord(getVipDraftKey(), {
|
|
|
|
|
|
vipLevel: vipForm.vipLevel,
|
|
|
|
|
|
remark: vipForm.remark || ''
|
|
|
|
|
|
})
|
|
|
|
|
|
vipDraftSavedAt.value = draft.savedAt
|
|
|
|
|
|
message.success('VIP 设置已暂存到本地')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleClearVipDraft = (showMessage = true) => {
|
|
|
|
|
|
clearDraftRecord(getVipDraftKey())
|
|
|
|
|
|
vipDraftSavedAt.value = null
|
|
|
|
|
|
if (showMessage) {
|
|
|
|
|
|
message.success('已清除 VIP 暂存')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
|
const formRules = {
|
2026-03-26 10:53:19 +08:00
|
|
|
|
account: [
|
|
|
|
|
|
{ required: true, message: '请输入账号', trigger: 'blur' },
|
|
|
|
|
|
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_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) => {
|
2026-03-26 13:38:34 +08:00
|
|
|
|
await validatePhoneUniqueness(value)
|
2026-03-21 15:18:09 +08:00
|
|
|
|
return Promise.resolve()
|
|
|
|
|
|
},
|
2026-03-26 13:38:34 +08:00
|
|
|
|
trigger: 'blur'
|
2026-03-21 15:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
],
|
2026-02-25 10:37:16 +08:00
|
|
|
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
2026-03-26 10:28:28 +08:00
|
|
|
|
shopIds: [{
|
|
|
|
|
|
validator: async (_rule: unknown, value: string[]) => {
|
|
|
|
|
|
if (Array.isArray(value) && value.length > 0) {
|
|
|
|
|
|
return Promise.resolve()
|
|
|
|
|
|
}
|
|
|
|
|
|
return Promise.reject('请选择至少一个店铺')
|
|
|
|
|
|
},
|
|
|
|
|
|
trigger: 'change'
|
|
|
|
|
|
}],
|
2026-02-25 17:20:12 +08:00
|
|
|
|
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-26 17:39:58 +08:00
|
|
|
|
const canShowDelete = (record: Partial<UserVO> | Record<string, any>) => {
|
|
|
|
|
|
if (!canDeleteUser.value) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
if (record.type === 4) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
return String(record.id) !== String(currentUserInfo?.id ?? '')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const canShowUnbind = (record: Partial<UserVO> | Record<string, any>) => {
|
|
|
|
|
|
if (!canUnbindUser.value) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
return record.type !== 4
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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[]) => {
|
2026-03-27 10:05:03 +08:00
|
|
|
|
if (!currentUserInfo || currentUserType.value === 4) {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
return list
|
|
|
|
|
|
}
|
2026-03-27 10:05:03 +08:00
|
|
|
|
if (currentUserType.value === 2) {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
return list.filter(user => user.type === 0 || user.type === 3)
|
|
|
|
|
|
}
|
2026-03-27 10:05:03 +08:00
|
|
|
|
if (currentUserType.value === 3) {
|
2026-03-20 12:24:56 +08:00
|
|
|
|
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 || ''
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-26 10:28:28 +08:00
|
|
|
|
const getShopDisplay = (user?: Partial<UserVO> | Record<string, any> | null) => {
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
|
return ''
|
2026-03-21 15:18:09 +08:00
|
|
|
|
}
|
2026-03-26 10:28:28 +08:00
|
|
|
|
const names = (user.shopNames || []).filter(Boolean)
|
|
|
|
|
|
if (names.length) {
|
|
|
|
|
|
return names.join('、')
|
|
|
|
|
|
}
|
|
|
|
|
|
if (user.shopName) {
|
|
|
|
|
|
return user.shopName
|
|
|
|
|
|
}
|
|
|
|
|
|
if (user.shopIds?.length) {
|
|
|
|
|
|
return (user.shopIds as Array<string | number>)
|
|
|
|
|
|
.map((id: string | number) => getShopNameById(id) || `店铺 ${id}`)
|
|
|
|
|
|
.join('、')
|
|
|
|
|
|
}
|
|
|
|
|
|
return getShopNameById(user.shopId) || ''
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const resolveEditableShopIds = (user?: UserVO | null) => {
|
|
|
|
|
|
const sourceIds = user?.shopIds?.length
|
|
|
|
|
|
? user.shopIds
|
|
|
|
|
|
: (user?.shopId ? [user.shopId] : [])
|
|
|
|
|
|
const normalizedIds = sourceIds
|
|
|
|
|
|
.map(id => normalizeShopId(id))
|
|
|
|
|
|
.filter((id): id is string => Boolean(id))
|
|
|
|
|
|
.filter(id => shopList.value.some(shop => getShopOptionValue(shop) === id))
|
|
|
|
|
|
|
|
|
|
|
|
if (normalizedIds.length) {
|
|
|
|
|
|
return normalizedIds
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-27 10:05:03 +08:00
|
|
|
|
return currentUserType.value !== 4 && currentUserInfo?.shopId
|
2026-03-26 10:28:28 +08:00
|
|
|
|
? [normalizeShopId(currentUserInfo.shopId)!]
|
|
|
|
|
|
: []
|
2026-03-21 15:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
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 || []
|
2026-03-27 10:05:03 +08:00
|
|
|
|
if (currentUserType.value !== 4 && currentUserInfo?.shopId) {
|
2026-03-26 10:28:28 +08:00
|
|
|
|
formState.shopIds = [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
|
|
|
|
|
2026-03-26 10:28:28 +08:00
|
|
|
|
if (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-03-27 10:05:03 +08:00
|
|
|
|
type: availableUserTypeOptions.value[0]?.value ?? 0,
|
|
|
|
|
|
shopIds: currentUserType.value !== 4 && currentUserInfo?.shopId
|
2026-03-26 10:28:28 +08:00
|
|
|
|
? [normalizeShopId(currentUserInfo.shopId)!]
|
|
|
|
|
|
: []
|
2026-02-25 10:37:16 +08:00
|
|
|
|
})
|
2026-03-20 12:24:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-26 12:04:02 +08:00
|
|
|
|
const getDraftKey = () => buildDraftStorageKey('admin-users', isEdit.value ? 'edit' : 'create', currentUser.value?.id ?? 'new')
|
|
|
|
|
|
|
|
|
|
|
|
const buildDraftPayload = () => ({
|
|
|
|
|
|
account: formState.account,
|
|
|
|
|
|
nickname: formState.nickname,
|
|
|
|
|
|
phone: formState.phone,
|
|
|
|
|
|
password: formState.password,
|
|
|
|
|
|
type: formState.type,
|
|
|
|
|
|
shopIds: [...formState.shopIds]
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const restoreDraft = () => {
|
|
|
|
|
|
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey(), 'session')
|
|
|
|
|
|
if (!draft) {
|
|
|
|
|
|
draftSavedAt.value = null
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object.assign(formState, draft.payload)
|
|
|
|
|
|
draftSavedAt.value = draft.savedAt
|
|
|
|
|
|
message.success('已恢复暂存内容')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleSaveDraft = () => {
|
|
|
|
|
|
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload(), 'session')
|
|
|
|
|
|
draftSavedAt.value = draft.savedAt
|
|
|
|
|
|
message.success('已暂存到当前会话')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleClearDraft = (showMessage = true) => {
|
|
|
|
|
|
clearDraftRecord(getDraftKey(), 'session')
|
|
|
|
|
|
draftSavedAt.value = null
|
|
|
|
|
|
if (showMessage) {
|
|
|
|
|
|
message.success('已清除暂存')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-03-26 12:04:02 +08:00
|
|
|
|
restoreDraft()
|
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-26 10:28:28 +08:00
|
|
|
|
shopIds: resolveEditableShopIds(record)
|
2026-02-25 10:37:16 +08:00
|
|
|
|
})
|
2026-03-26 12:04:02 +08:00
|
|
|
|
restoreDraft()
|
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-03-26 12:04:02 +08:00
|
|
|
|
restoreBalanceDraft()
|
|
|
|
|
|
restoreVipDraft()
|
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-26 10:28:28 +08:00
|
|
|
|
const requestData: Record<string, unknown> = {
|
2026-03-21 15:18:09 +08:00
|
|
|
|
account: formState.account.trim(),
|
|
|
|
|
|
nickname: formState.nickname.trim(),
|
|
|
|
|
|
phone: formState.phone.trim(),
|
|
|
|
|
|
type: formState.type,
|
2026-03-26 10:28:28 +08:00
|
|
|
|
shopIds: formState.shopIds,
|
|
|
|
|
|
shopId: formState.shopIds.length ? formState.shopIds[0] : undefined,
|
2026-03-21 15:18:09 +08:00
|
|
|
|
...(formState.password.trim() ? { password: formState.password.trim() } : {})
|
|
|
|
|
|
}
|
2026-03-20 12:24:56 +08:00
|
|
|
|
|
2026-03-27 10:05:03 +08:00
|
|
|
|
if (isEdit.value && currentUserType.value !== 4) {
|
2026-03-26 10:28:28 +08:00
|
|
|
|
delete requestData.shopIds
|
|
|
|
|
|
delete requestData.shopId
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-03-26 12:04:02 +08:00
|
|
|
|
handleClearDraft(false)
|
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-26 16:16:38 +08:00
|
|
|
|
const success = await adminUserApi.updateUserStatus(record.id, checked ? 1 : 0)
|
|
|
|
|
|
if (!success) {
|
2026-03-26 17:39:58 +08:00
|
|
|
|
message.warning('未找到可更新状态的用户')
|
2026-03-26 16:16:38 +08:00
|
|
|
|
await fetchUserList()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-03-20 12:24:56 +08:00
|
|
|
|
record.status = checked ? 1 : 0
|
2026-03-26 17:39:58 +08:00
|
|
|
|
message.success(`已${checked ? '启用' : '停用'}该用户账号`)
|
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 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-26 16:16:38 +08:00
|
|
|
|
const success = await adminUserApi.deleteUser(record.id)
|
|
|
|
|
|
if (!success) {
|
2026-03-26 17:39:58 +08:00
|
|
|
|
message.warning('未找到可删除的用户')
|
2026-03-26 16:16:38 +08:00
|
|
|
|
await fetchUserList()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-03-26 16:55:30 +08:00
|
|
|
|
userList.value = userList.value.filter(user => user.id !== record.id)
|
|
|
|
|
|
pagination.total = Math.max(0, Number(pagination.total || 0) - 1)
|
2026-03-26 17:39:58 +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-26 17:39:58 +08:00
|
|
|
|
const handleUnbind = async (record: any) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (record.type === 4) {
|
|
|
|
|
|
message.warning('管理员账号无法解绑')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const success = await adminUserApi.unbindUser(record.id)
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
|
message.warning('未找到当前店铺下可解绑的用户绑定')
|
|
|
|
|
|
await fetchUserList()
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
userList.value = userList.value.filter(user => user.id !== record.id)
|
|
|
|
|
|
pagination.total = Math.max(0, Number(pagination.total || 0) - 1)
|
|
|
|
|
|
message.success('已解绑当前店铺下的用户')
|
|
|
|
|
|
await fetchUserList()
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('解绑用户失败:', error)
|
|
|
|
|
|
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('余额变动已保存')
|
2026-03-26 12:04:02 +08:00
|
|
|
|
handleClearBalanceDraft(false)
|
2026-03-20 12:24:56 +08:00
|
|
|
|
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 已更新')
|
2026-03-26 12:04:02 +08:00
|
|
|
|
handleClearVipDraft(false)
|
2026-03-20 12:24:56 +08:00
|
|
|
|
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('已恢复自动判级')
|
2026-03-26 12:04:02 +08:00
|
|
|
|
handleClearVipDraft(false)
|
2026-03-20 12:24:56 +08:00
|
|
|
|
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>
|