This commit is contained in:
aaron 2025-03-10 09:36:33 +08:00
parent ef2dc67247
commit ac51b22378

View File

@ -70,7 +70,8 @@
<div v-else-if="searchResults.length > 0" class="search-results"> <div v-else-if="searchResults.length > 0" class="search-results">
<div class="search-title">搜索结果</div> <div class="search-title">搜索结果</div>
<a-radio-group v-model:value="selectedCommunityId"> <div class="search-subtitle">请选择一个小区进行关联</div>
<a-radio-group v-model:value="selectedCommunityId" class="community-radio-group">
<div v-for="community in searchResults" :key="community.id" class="search-item"> <div v-for="community in searchResults" :key="community.id" class="search-item">
<a-radio :value="community.id"> <a-radio :value="community.id">
<div class="community-info"> <div class="community-info">
@ -82,12 +83,20 @@
</a-radio-group> </a-radio-group>
<div class="search-actions"> <div class="search-actions">
<a-button type="primary" :disabled="!selectedCommunityId" :loading="submitting" @click="handleAddCommunity"> <div class="selection-status" v-if="selectedCommunityId">
确认添加 已选择: {{ getSelectedCommunityName() }}
</a-button> </div>
<a-button style="margin-left: 8px;" @click="handleCancelAdd"> <div class="selection-status selection-warning" v-else>
取消 <a-alert type="warning" message="请选择一个小区" banner />
</a-button> </div>
<div class="action-buttons">
<a-button type="primary" :disabled="!selectedCommunityId" :loading="submitting" @click="handleAddCommunity">
确认添加
</a-button>
<a-button style="margin-left: 8px;" @click="handleCancelAdd">
取消
</a-button>
</div>
</div> </div>
</div> </div>
@ -105,7 +114,7 @@
<script> <script>
import { defineComponent, ref, reactive, onMounted } from 'vue' import { defineComponent, ref, reactive, onMounted } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { message, Modal, Table, Tag, Spin, Empty, Divider } from 'ant-design-vue' import { message, Modal, Table, Tag, Spin, Empty, Divider, Radio, Alert } from 'ant-design-vue'
import request from '@/utils/request' import request from '@/utils/request'
import PageContainer from '@/components/PageContainer.vue' import PageContainer from '@/components/PageContainer.vue'
@ -116,7 +125,10 @@ export default defineComponent({
ATag: Tag, ATag: Tag,
ASpin: Spin, ASpin: Spin,
AEmpty: Empty, AEmpty: Empty,
ADivider: Divider ADivider: Divider,
ARadio: Radio,
ARadioGroup: Radio.Group,
AAlert: Alert
}, },
setup() { setup() {
const route = useRoute() const route = useRoute()
@ -264,9 +276,8 @@ export default defineComponent({
const res = await request.get(`/api/community/search_by_name/${searchValue.value}`) const res = await request.get(`/api/community/search_by_name/${searchValue.value}`)
if (res.code === 200) { if (res.code === 200) {
searchResults.value = res.data || [] searchResults.value = res.data || []
if (searchResults.value.length > 0) { //
selectedCommunityId.value = searchResults.value[0].id selectedCommunityId.value = null
}
} else { } else {
message.warning(res.message || '搜索小区失败') message.warning(res.message || '搜索小区失败')
searchResults.value = [] searchResults.value = []
@ -280,6 +291,13 @@ export default defineComponent({
} }
} }
//
const getSelectedCommunityName = () => {
if (!selectedCommunityId.value) return ''
const selected = searchResults.value.find(item => item.id === selectedCommunityId.value)
return selected ? selected.name : ''
}
// //
const handleAddCommunity = async () => { const handleAddCommunity = async () => {
if (!selectedCommunityId.value) { if (!selectedCommunityId.value) {
@ -361,7 +379,8 @@ export default defineComponent({
handleAddCommunity, handleAddCommunity,
handleCancelAdd, handleCancelAdd,
handleRemoveCommunity, handleRemoveCommunity,
handleTableChange handleTableChange,
getSelectedCommunityName
} }
} }
}) })
@ -453,8 +472,13 @@ export default defineComponent({
} }
.search-item { .search-item {
padding: 8px 0; padding: 12px;
border-bottom: 1px solid #f0f0f0; border-bottom: 1px solid #f0f0f0;
transition: background-color 0.3s;
}
.search-item:hover {
background-color: #f5f5f5;
} }
.search-item:last-child { .search-item:last-child {
@ -485,13 +509,37 @@ export default defineComponent({
margin-bottom: 12px; margin-bottom: 12px;
} }
.search-subtitle {
color: #666;
margin-bottom: 12px;
font-size: 13px;
}
.community-radio-group {
display: block;
width: 100%;
}
.search-actions { .search-actions {
margin-top: 16px; margin-top: 16px;
text-align: right;
padding-top: 16px; padding-top: 16px;
border-top: 1px solid #f0f0f0; border-top: 1px solid #f0f0f0;
} }
.selection-status {
margin-bottom: 12px;
color: #52c41a;
font-weight: 500;
}
.selection-warning {
color: #faad14;
}
.action-buttons {
text-align: right;
}
.search-tip { .search-tip {
text-align: center; text-align: center;
color: #999; color: #999;