增加 用户所属小区
增加 按照手机号查询用户
This commit is contained in:
parent
a4f90c717b
commit
d3d72f843e
@ -8,6 +8,16 @@
|
||||
<!-- 添加筛选区域 -->
|
||||
<div class="table-filter">
|
||||
<a-form layout="inline">
|
||||
<a-form-item label="手机号">
|
||||
<a-input
|
||||
v-model:value="filterForm.phone"
|
||||
placeholder="请输入手机号"
|
||||
style="width: 200px"
|
||||
allowClear
|
||||
@change="handleFilterChange"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="用户角色">
|
||||
<a-select
|
||||
v-model:value="filterForm.role"
|
||||
@ -75,6 +85,14 @@
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
<template v-if="column.key === 'community_name'">
|
||||
<a-space>
|
||||
<span>{{ record.community_name || '-' }}</span>
|
||||
<a-button type="link" @click="handleEditCommunity(record)">
|
||||
修改
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
@ -125,6 +143,29 @@
|
||||
</a-space>
|
||||
</template>
|
||||
</a-modal>
|
||||
|
||||
<!-- 添加小区选择模态框 -->
|
||||
<a-modal
|
||||
v-model:visible="communityModalVisible"
|
||||
title="修改所属小区"
|
||||
@ok="handleCommunitySave"
|
||||
@cancel="handleCommunityCancel"
|
||||
:confirmLoading="communitySaving"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="所属小区">
|
||||
<a-select
|
||||
v-model:value="selectedCommunityId"
|
||||
style="width: 100%"
|
||||
placeholder="请选择小区"
|
||||
allowClear
|
||||
:options="communityOptions"
|
||||
:loading="communityLoading"
|
||||
:fieldNames="{ label: 'name', value: 'id' }"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</page-container>
|
||||
</template>
|
||||
|
||||
@ -199,10 +240,16 @@ export default defineComponent({
|
||||
key: 'create_time',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '所属小区',
|
||||
dataIndex: 'community_name',
|
||||
key: 'community_name',
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 120,
|
||||
width: 200,
|
||||
fixed: 'right'
|
||||
}
|
||||
]
|
||||
@ -215,7 +262,8 @@ export default defineComponent({
|
||||
|
||||
// 添加筛选表单
|
||||
const filterForm = ref({
|
||||
role: undefined
|
||||
role: undefined,
|
||||
phone: undefined
|
||||
})
|
||||
|
||||
// 获取用户列表数据
|
||||
@ -225,9 +273,17 @@ export default defineComponent({
|
||||
const params = {
|
||||
skip: (pagination.value.current - 1) * pagination.value.pageSize,
|
||||
limit: pagination.value.pageSize,
|
||||
role: filterForm.value.role // 添加角色筛选参数
|
||||
role: filterForm.value.role,
|
||||
phone: filterForm.value.phone // 添加手机号参数
|
||||
}
|
||||
|
||||
// 移除空值参数
|
||||
Object.keys(params).forEach(key => {
|
||||
if (params[key] === undefined || params[key] === '') {
|
||||
delete params[key]
|
||||
}
|
||||
})
|
||||
|
||||
const res = await getUserList(params)
|
||||
if (res.code === 200) {
|
||||
tableData.value = res.data.items
|
||||
@ -272,11 +328,25 @@ export default defineComponent({
|
||||
return colorMap[role] || 'default'
|
||||
}
|
||||
|
||||
// 共用的状态
|
||||
const currentUserId = ref(null)
|
||||
|
||||
// 角色编辑相关状态
|
||||
const roleModalVisible = ref(false)
|
||||
const rolesSaving = ref(false)
|
||||
const selectedRoles = ref([])
|
||||
const currentUserId = ref(null)
|
||||
|
||||
// 密码重置相关状态
|
||||
const passwordModalVisible = ref(false)
|
||||
const newPassword = ref('')
|
||||
const passwordInput = ref(null)
|
||||
|
||||
// 小区相关状态
|
||||
const communityModalVisible = ref(false)
|
||||
const communitySaving = ref(false)
|
||||
const communityLoading = ref(false)
|
||||
const selectedCommunityId = ref(undefined)
|
||||
const communityOptions = ref([])
|
||||
|
||||
// 可选角色列表
|
||||
const availableRoles = [
|
||||
@ -285,7 +355,7 @@ export default defineComponent({
|
||||
{ label: '配送员', value: 'deliveryman' }
|
||||
]
|
||||
|
||||
// 打开角色编辑模态框
|
||||
// 角色编辑处理函数
|
||||
const handleEditRoles = (record) => {
|
||||
currentUserId.value = record.userid
|
||||
selectedRoles.value = record.roles || ['user']
|
||||
@ -326,11 +396,10 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
// 取消角色修改
|
||||
// 修改取消处理函数
|
||||
const handleRolesCancel = () => {
|
||||
roleModalVisible.value = false
|
||||
selectedRoles.value = []
|
||||
currentUserId.value = null
|
||||
resetStates()
|
||||
}
|
||||
|
||||
// 处理筛选变化
|
||||
@ -346,16 +415,14 @@ export default defineComponent({
|
||||
|
||||
// 重置按钮点击
|
||||
const handleReset = () => {
|
||||
filterForm.value.role = undefined
|
||||
filterForm.value = {
|
||||
role: undefined,
|
||||
phone: undefined
|
||||
}
|
||||
pagination.value.current = 1
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 密码重置相关状态
|
||||
const passwordModalVisible = ref(false)
|
||||
const newPassword = ref('')
|
||||
const passwordInput = ref(null)
|
||||
|
||||
// 生成随机密码
|
||||
const generatePassword = () => {
|
||||
const chars = '0123456789abcdefghijklmnopqrstuvwxyz'
|
||||
@ -407,10 +474,72 @@ export default defineComponent({
|
||||
const handleClosePasswordModal = () => {
|
||||
passwordModalVisible.value = false
|
||||
newPassword.value = ''
|
||||
resetStates()
|
||||
}
|
||||
|
||||
// 获取小区列表
|
||||
const fetchCommunityList = async () => {
|
||||
try {
|
||||
communityLoading.value = true
|
||||
const res = await request.get('/api/community')
|
||||
if (res.code === 200 && res.data) {
|
||||
communityOptions.value = res.data.items || []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取小区列表失败:', error)
|
||||
message.error('获取小区列表失败')
|
||||
} finally {
|
||||
communityLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 小区编辑处理函数
|
||||
const handleEditCommunity = (record) => {
|
||||
currentUserId.value = record.userid
|
||||
selectedCommunityId.value = record.community_id
|
||||
communityModalVisible.value = true
|
||||
|
||||
if (communityOptions.value.length === 0) {
|
||||
fetchCommunityList()
|
||||
}
|
||||
}
|
||||
|
||||
// 保存小区修改
|
||||
const handleCommunitySave = async () => {
|
||||
try {
|
||||
communitySaving.value = true
|
||||
await request.put('/api/user/community', {
|
||||
user_id: currentUserId.value,
|
||||
community_id: selectedCommunityId.value
|
||||
})
|
||||
|
||||
message.success('修改成功')
|
||||
communityModalVisible.value = false
|
||||
fetchData() // 刷新列表
|
||||
} catch (error) {
|
||||
console.error('修改所属小区失败:', error)
|
||||
message.error('修改失败')
|
||||
} finally {
|
||||
communitySaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 修改取消处理函数
|
||||
const handleCommunityCancel = () => {
|
||||
communityModalVisible.value = false
|
||||
resetStates()
|
||||
}
|
||||
|
||||
// 重置状态的函数
|
||||
const resetStates = () => {
|
||||
currentUserId.value = null
|
||||
selectedRoles.value = []
|
||||
selectedCommunityId.value = undefined
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
fetchCommunityList() // 预加载小区列表
|
||||
})
|
||||
|
||||
return {
|
||||
@ -438,7 +567,16 @@ export default defineComponent({
|
||||
passwordInput,
|
||||
handleResetPassword,
|
||||
handleCopyPassword,
|
||||
handleClosePasswordModal
|
||||
handleClosePasswordModal,
|
||||
communityModalVisible,
|
||||
communitySaving,
|
||||
communityLoading,
|
||||
selectedCommunityId,
|
||||
communityOptions,
|
||||
handleEditCommunity,
|
||||
handleCommunitySave,
|
||||
handleCommunityCancel,
|
||||
currentUserId
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -519,4 +657,12 @@ export default defineComponent({
|
||||
font-size: 16px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
:deep(.ant-select) {
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
:deep(.ant-input) {
|
||||
width: 200px !important;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue
Block a user