共富商城
This commit is contained in:
1 parent
22ebd0927d
commit
cf514a5b1c
2 files changed
+142
-76
No files matched your search
@@ -0,0 +1,91 @@
|
||||
import request from "/@/utils/request"
|
||||
|
||||
// 分页查询绑定关系
|
||||
export function fetchList(query?: Object) {
|
||||
return request({
|
||||
url: '/supermarket/mallMerchantUser/page',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 获取商户用户列表
|
||||
export function getMerchantUsers(merchantId: string, query?: Object) {
|
||||
return request({
|
||||
url: `/supermarket/mallMerchantUser/merchant/${merchantId}/users`,
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 获取用户商户信息
|
||||
export function getUserMerchant(userId: string) {
|
||||
return request({
|
||||
url: `/supermarket/mallMerchantUser/user/${userId}/merchant`,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 单个用户绑定
|
||||
export function bindUser(data: Object) {
|
||||
return request({
|
||||
url: '/supermarket/mallMerchantUser/bind',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 批量绑定用户
|
||||
export function batchBindUsers(data: Object) {
|
||||
return request({
|
||||
url: '/supermarket/mallMerchantUser/batchBind',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 解绑单个用户
|
||||
export function unbindUser(userId: string) {
|
||||
return request({
|
||||
url: `/supermarket/mallMerchantUser/unbind/${userId}`,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
// 批量解绑用户
|
||||
export function batchUnbindUsers(data: Object) {
|
||||
return request({
|
||||
url: '/supermarket/mallMerchantUser/batchUnbind',
|
||||
method: 'delete',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 更新用户角色
|
||||
export function updateUserRole(data: Object) {
|
||||
return request({
|
||||
url: '/supermarket/mallMerchantUser/updateRole',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 更新绑定状态
|
||||
export function updateBindStatus(data: Object) {
|
||||
return request({
|
||||
url: '/supermarket/mallMerchantUser/updateStatus',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 获取用户下拉列表
|
||||
export function getUserSelectList(query?: Object) {
|
||||
return request({
|
||||
url: '/supermarket/mallMerchantUser/merchant/users',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
@selection-change="handleUserSelectionChange"
|
||||
:row-key="row => row.userId">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="name" label="用户名称" show-overflow-tooltip />
|
||||
<el-table-column prop="name" label="姓名" show-overflow-tooltip />
|
||||
<el-table-column prop="phone" label="手机号" show-overflow-tooltip />
|
||||
</el-table>
|
||||
<div class="mt10">
|
||||
@@ -54,34 +54,11 @@
|
||||
:data="boundUsers"
|
||||
v-loading="boundLoading"
|
||||
height="400"
|
||||
@selection-change="handleBoundUserSelectionChange">
|
||||
@selection-change="handleBoundUserSelectionChange"
|
||||
:row-key="row => row.userId">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="name" label="用户名称" show-overflow-tooltip />
|
||||
<el-table-column prop="name" label="姓名" show-overflow-tooltip />
|
||||
<el-table-column prop="phone" label="手机号" show-overflow-tooltip />
|
||||
<el-table-column prop="roleType" label="角色" width="100">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.roleType === 1 ? 'success' : 'info'">
|
||||
{{ scope.row.roleType === 1 ? '管理员' : '普通用户' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="80">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
|
||||
{{ scope.row.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="120">
|
||||
<template #default="scope">
|
||||
<el-button size="small" @click="updateUserRole(scope.row)">
|
||||
改角色
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" @click="unbindUser(scope.row)">
|
||||
解绑
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="mt10">
|
||||
<el-button type="danger" @click="batchUnbindUsers" :disabled="selectedBoundUsers.length === 0">
|
||||
@@ -101,13 +78,12 @@
|
||||
|
||||
<script setup lang="ts" name="BindUserDialog">
|
||||
import { useMessage } from "/@/hooks/message";
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import {
|
||||
getUserSelectList,
|
||||
getMerchantUsers,
|
||||
batchBindUsers,
|
||||
unbindUser as unbindUserApi,
|
||||
batchUnbindUsers as batchUnbindUsersApi,
|
||||
updateUserRole as updateUserRoleApi
|
||||
batchUnbindUsers as batchUnbindUsersApi
|
||||
} from '/@/api/supermarket/mallMerchantUser';
|
||||
import { Search } from '@element-plus/icons-vue';
|
||||
|
||||
@@ -142,15 +118,16 @@ const openDialog = (merchant: any) => {
|
||||
selectedUsers.value = [];
|
||||
selectedBoundUsers.value = [];
|
||||
|
||||
// 加载数据
|
||||
getUserList();
|
||||
// 先获取已绑定用户,然后内部会调用getUserList过滤可选用户
|
||||
getBoundUsers();
|
||||
};
|
||||
|
||||
// 获取可选用户列表
|
||||
// 获取可选用户列表(从已获取的所有用户中过滤)
|
||||
const getUserList = async () => {
|
||||
try {
|
||||
userLoading.value = true;
|
||||
|
||||
// 重新获取用户列表(支持搜索)
|
||||
const res = await getUserSelectList({
|
||||
name: searchForm.name,
|
||||
phone: searchForm.phone,
|
||||
@@ -158,12 +135,18 @@ const getUserList = async () => {
|
||||
size: 100
|
||||
});
|
||||
|
||||
// 根据新的接口格式处理数据
|
||||
// 直接使用接口返回的数据格式
|
||||
const allUsers = res.data || [];
|
||||
console.log('可选用户接口返回的原始数据:', res);
|
||||
console.log('获取到的用户数据:', allUsers);
|
||||
console.log('用户数据长度:', allUsers.length);
|
||||
|
||||
// 过滤掉已绑定的用户
|
||||
const boundUserIds = boundUsers.value.map(user => user.userId);
|
||||
console.log('已绑定用户ID列表:', boundUserIds);
|
||||
availableUsers.value = allUsers.filter((user: any) => !boundUserIds.includes(user.userId));
|
||||
console.log('过滤后的可选用户:', availableUsers.value);
|
||||
console.log('可选用户数据长度:', availableUsers.value.length);
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg || '获取用户列表失败');
|
||||
} finally {
|
||||
@@ -176,7 +159,34 @@ const getBoundUsers = async () => {
|
||||
try {
|
||||
boundLoading.value = true;
|
||||
const res = await getMerchantUsers(merchantInfo.value.id);
|
||||
boundUsers.value = res.data || [];
|
||||
console.log('已绑定用户接口返回的原始数据:', res);
|
||||
|
||||
// 已绑定用户接口返回的name和phone是null,需要从可选用户中获取
|
||||
const boundUsersData = res.data || [];
|
||||
console.log('已绑定用户原始数据:', boundUsersData);
|
||||
|
||||
// 先获取所有用户信息,用于匹配已绑定用户的姓名和手机号
|
||||
const allUsersRes = await getUserSelectList({});
|
||||
const allUsers = allUsersRes.data || [];
|
||||
console.log('所有用户数据:', allUsers);
|
||||
|
||||
// 为已绑定用户补充姓名和手机号信息
|
||||
boundUsers.value = boundUsersData.map((boundUser: any) => {
|
||||
const userInfo = allUsers.find((user: any) => user.userId === boundUser.userId);
|
||||
return {
|
||||
...boundUser,
|
||||
name: userInfo?.name || boundUser.name || '未知',
|
||||
phone: userInfo?.phone || boundUser.phone || '未知'
|
||||
};
|
||||
});
|
||||
|
||||
console.log('处理后的已绑定用户数据:', boundUsers.value);
|
||||
|
||||
// 直接过滤可选用户,避免重复请求接口
|
||||
const boundUserIds = boundUsers.value.map(user => user.userId);
|
||||
console.log('已绑定用户ID列表:', boundUserIds);
|
||||
availableUsers.value = allUsers.filter((user: any) => !boundUserIds.includes(user.userId));
|
||||
console.log('过滤后的可选用户:', availableUsers.value);
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg || '获取绑定用户失败');
|
||||
} finally {
|
||||
@@ -226,24 +236,6 @@ const bindSelectedUsers = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 解绑用户
|
||||
const unbindUser = async (user: any) => {
|
||||
try {
|
||||
await useMessage().confirm(`确定要解绑用户 ${user.name} 吗?`);
|
||||
await unbindUserApi(user.userId);
|
||||
useMessage().success('解绑成功');
|
||||
|
||||
// 刷新数据
|
||||
getUserList();
|
||||
getBoundUsers();
|
||||
emit('refresh');
|
||||
} catch (err: any) {
|
||||
if (err !== 'cancel') {
|
||||
useMessage().error(err.msg || '解绑失败');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 批量解绑用户
|
||||
const batchUnbindUsers = async () => {
|
||||
if (selectedBoundUsers.value.length === 0) {
|
||||
@@ -252,9 +244,14 @@ const batchUnbindUsers = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
await useMessage().confirm(`确定要解绑选中的 ${selectedBoundUsers.value.length} 个用户吗?`);
|
||||
await ElMessageBox.confirm(`确定要解绑选中的 ${selectedBoundUsers.value.length} 个用户吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
});
|
||||
|
||||
const unbindData = {
|
||||
merchantId: merchantInfo.value.id,
|
||||
userIds: selectedBoundUsers.value.map(user => user.userId)
|
||||
};
|
||||
|
||||
@@ -272,28 +269,6 @@ const batchUnbindUsers = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 更新用户角色
|
||||
const updateUserRole = async (user: any) => {
|
||||
try {
|
||||
const newRoleType = user.roleType === 1 ? 2 : 1;
|
||||
const roleText = newRoleType === 1 ? '管理员' : '普通用户';
|
||||
|
||||
await useMessage().confirm(`确定要将用户 ${user.name} 的角色改为 ${roleText} 吗?`);
|
||||
|
||||
await updateUserRoleApi({
|
||||
userId: user.userId,
|
||||
roleType: newRoleType
|
||||
});
|
||||
|
||||
useMessage().success('角色更新成功');
|
||||
getBoundUsers();
|
||||
} catch (err: any) {
|
||||
if (err !== 'cancel') {
|
||||
useMessage().error(err.msg || '角色更新失败');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
openDialog
|
||||
|
||||
Reference in new issue
Block a user