增加 用户所属小区

增加 按照手机号查询用户
This commit is contained in:
aaron 2025-01-16 23:09:43 +08:00
parent a4f90c717b
commit d3d72f843e

View File

@ -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>