小区,房屋导入
parent
25f79e9d61
commit
80481f1dcb
|
|
@ -18,6 +18,11 @@ export interface Community {
|
|||
committeeNum?: number
|
||||
}
|
||||
|
||||
export interface CommunitySimpleVO {
|
||||
id: number
|
||||
communityName: string
|
||||
}
|
||||
|
||||
export const CommunityApi = {
|
||||
getCommunityPage: async (params: any) => {
|
||||
return await request.get({ url: `/community/community/page`, params })
|
||||
|
|
@ -49,5 +54,9 @@ export const CommunityApi = {
|
|||
|
||||
importCommunityTemplate: async () => {
|
||||
return await request.download({ url: `/community/community/get-import-template` })
|
||||
},
|
||||
|
||||
getCommunitySimpleList: async () => {
|
||||
return await request.get({ url: `/community/community/simple-list` })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ export const useMessage = () => {
|
|||
},
|
||||
// 错误提示
|
||||
alertError(content: string) {
|
||||
ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'error' })
|
||||
ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'error', dangerouslyUseHTMLString: true })
|
||||
},
|
||||
// 成功提示
|
||||
alertSuccess(content: string) {
|
||||
ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'success' })
|
||||
ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'success', dangerouslyUseHTMLString: true })
|
||||
},
|
||||
// 警告提示
|
||||
alertWarning(content: string) {
|
||||
|
|
|
|||
|
|
@ -91,29 +91,37 @@ const submitFormSuccess = (response: any) => {
|
|||
return
|
||||
}
|
||||
const data = response.data
|
||||
const createCount = data.createCommunityNames?.length || 0
|
||||
const updateCount = data.updateCommunityNames?.length || 0
|
||||
const failureCount = Object.keys(data.failureCommunities || {}).length
|
||||
const createCount = data.createCount || 0
|
||||
const updateCount = data.updateCount || 0
|
||||
const failureCount = data.failureMessages?.length || 0
|
||||
|
||||
let text = `创建成功:${createCount} 条;`
|
||||
if (createCount > 0) {
|
||||
text += '\n创建的小区:' + data.createCommunityNames.join('、')
|
||||
}
|
||||
// 构建提示信息(使用 HTML 的 <br> 标签实现换行)
|
||||
const messages: string[] = []
|
||||
messages.push(`创建成功:${createCount} 条<br/>`)
|
||||
messages.push(`更新成功:${updateCount} 条<br/>`)
|
||||
|
||||
text += `\n更新成功:${updateCount} 条;`
|
||||
if (updateCount > 0) {
|
||||
text += '\n更新的小区:' + data.updateCommunityNames.join('、')
|
||||
}
|
||||
|
||||
text += `\n导入失败:${failureCount} 条;`
|
||||
if (failureCount > 0) {
|
||||
text += '\n失败详情:'
|
||||
for (const [name, reason] of Object.entries(data.failureCommunities)) {
|
||||
text += `\n - ${name}: ${reason}`
|
||||
messages.push(`导入失败:${failureCount} 条<br/><br/>`)
|
||||
|
||||
// 展示失败详情,每条记录单独换行
|
||||
if (data.failureMessages) {
|
||||
messages.push(`<div style="text-align: left; margin-top: 10px;">`)
|
||||
messages.push(`<strong>失败详情:</strong><br/>`)
|
||||
data.failureMessages.forEach((msg: string) => {
|
||||
messages.push(`${msg}<br/>`)
|
||||
})
|
||||
messages.push(`</div>`)
|
||||
}
|
||||
}
|
||||
|
||||
message.alert(text)
|
||||
const htmlContent = messages.join('')
|
||||
|
||||
if (failureCount > 0) {
|
||||
message.alertError(htmlContent)
|
||||
} else {
|
||||
message.alertSuccess('导入成功!<br/>' + htmlContent)
|
||||
}
|
||||
|
||||
formLoading.value = false
|
||||
dialogVisible.value = false
|
||||
emits('success')
|
||||
|
|
|
|||
|
|
@ -7,11 +7,22 @@
|
|||
label-width="100px"
|
||||
v-loading="formLoading"
|
||||
>
|
||||
<el-form-item label="小区ID" prop="communityId">
|
||||
<el-input v-model="formData.communityId" placeholder="请输入小区ID" />
|
||||
</el-form-item>
|
||||
<el-form-item label="小区名称" prop="communityName">
|
||||
<el-input v-model="formData.communityName" placeholder="请输入小区名称" />
|
||||
<el-form-item label="小区名称" prop="communityId">
|
||||
<el-select
|
||||
v-model="formData.communityId"
|
||||
placeholder="请选择小区"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@change="handleCommunityChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in communityOptions"
|
||||
:key="item.id"
|
||||
:label="item.communityName"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="楼号" prop="buildingNo">
|
||||
<el-input v-model="formData.buildingNo" placeholder="请输入楼号" />
|
||||
|
|
@ -43,6 +54,7 @@
|
|||
</template>
|
||||
<script setup lang="ts">
|
||||
import { HouseApi, House } from '@/api/community/house'
|
||||
import { CommunityApi, CommunitySimpleVO } from '@/api/community/community'
|
||||
|
||||
/** 房屋信息主 表单 */
|
||||
defineOptions({ name: 'HouseForm' })
|
||||
|
|
@ -67,13 +79,34 @@ const formData = ref({
|
|||
ownerPhone: undefined
|
||||
})
|
||||
const formRules = reactive({
|
||||
communityId: [{ required: true, message: '小区ID不能为空', trigger: 'blur' }],
|
||||
communityName: [{ required: true, message: '小区名称不能为空', trigger: 'blur' }],
|
||||
communityId: [{ required: true, message: '小区不能为空', trigger: 'change' }],
|
||||
buildingNo: [{ required: true, message: '楼号不能为空', trigger: 'blur' }],
|
||||
unitNo: [{ required: true, message: '单元号不能为空', trigger: 'blur' }],
|
||||
roomNo: [{ required: true, message: '门牌号不能为空', trigger: 'blur' }]
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
const communityOptions = ref<CommunitySimpleVO[]>([]) // 小区选项列表
|
||||
|
||||
/** 加载小区列表 */
|
||||
const loadCommunityList = async () => {
|
||||
try {
|
||||
communityOptions.value = await CommunityApi.getCommunitySimpleList()
|
||||
} catch (error) {
|
||||
console.error('加载小区列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/** 小区选择变化 */
|
||||
const handleCommunityChange = (communityId: number | undefined) => {
|
||||
if (communityId) {
|
||||
const community = communityOptions.value.find(item => item.id === communityId)
|
||||
if (community) {
|
||||
formData.value.communityName = community.communityName
|
||||
}
|
||||
} else {
|
||||
formData.value.communityName = undefined
|
||||
}
|
||||
}
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
|
|
@ -81,6 +114,8 @@ const open = async (type: string, id?: number) => {
|
|||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
// 加载小区列表
|
||||
await loadCommunityList()
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
|
|
@ -133,4 +168,4 @@ const resetForm = () => {
|
|||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -91,13 +91,37 @@ const submitFormSuccess = (response: any) => {
|
|||
return
|
||||
}
|
||||
const data = response.data
|
||||
let text = '上传成功数量:' + (data.createCount || 0) + ';'
|
||||
text += '更新成功数量:' + (data.updateCount || 0) + ';'
|
||||
text += '更新失败数量:' + (data.failureCount || 0) + ';'
|
||||
if (data.failureMessages && data.failureMessages.length > 0) {
|
||||
text += '失败信息:' + data.failureMessages.join('; ')
|
||||
const createCount = data.createCount || 0
|
||||
const updateCount = data.updateCount || 0
|
||||
const failureCount = data.failureMessages?.length || 0
|
||||
|
||||
// 构建提示信息(使用 HTML 的 <br> 标签实现换行)
|
||||
const messages: string[] = []
|
||||
messages.push(`创建成功:${createCount} 条<br/>`)
|
||||
messages.push(`更新成功:${updateCount} 条<br/>`)
|
||||
|
||||
if (failureCount > 0) {
|
||||
messages.push(`导入失败:${failureCount} 条<br/><br/>`)
|
||||
|
||||
// 展示失败详情,每条记录单独换行
|
||||
if (data.failureMessages) {
|
||||
messages.push(`<div style="text-align: left; margin-top: 10px;">`)
|
||||
messages.push(`<strong>失败详情:</strong><br/>`)
|
||||
data.failureMessages.forEach((msg: string) => {
|
||||
messages.push(`${msg}<br/>`)
|
||||
})
|
||||
messages.push(`</div>`)
|
||||
}
|
||||
}
|
||||
message.alert(text)
|
||||
|
||||
const htmlContent = messages.join('')
|
||||
|
||||
if (failureCount > 0) {
|
||||
message.alertError(htmlContent)
|
||||
} else {
|
||||
message.alertSuccess('导入成功!<br/>' + htmlContent)
|
||||
}
|
||||
|
||||
formLoading.value = false
|
||||
dialogVisible.value = false
|
||||
emits('success')
|
||||
|
|
|
|||
|
|
@ -8,14 +8,21 @@
|
|||
:inline="true"
|
||||
label-width="80px"
|
||||
>
|
||||
<el-form-item label="小区名称" prop="communityName">
|
||||
<el-input
|
||||
v-model="queryParams.communityName"
|
||||
placeholder="请输入小区名称"
|
||||
<el-form-item label="小区名称" prop="communityId">
|
||||
<el-select
|
||||
v-model="queryParams.communityId"
|
||||
placeholder="请选择小区"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
filterable
|
||||
class="!w-240px"
|
||||
/>
|
||||
>
|
||||
<el-option
|
||||
v-for="item in communityOptions"
|
||||
:key="item.id"
|
||||
:label="item.communityName"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="业主姓名" prop="ownerName">
|
||||
<el-input
|
||||
|
|
@ -144,6 +151,7 @@
|
|||
<script setup lang="ts">
|
||||
import download from '@/utils/download'
|
||||
import { HouseApi, House } from '@/api/community/house'
|
||||
import { CommunityApi, CommunitySimpleVO } from '@/api/community/community'
|
||||
import HouseForm from './HouseForm.vue'
|
||||
import ImportForm from './ImportForm.vue'
|
||||
|
||||
|
|
@ -159,11 +167,12 @@ const total = ref(0) // 列表的总页数
|
|||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
communityName: undefined,
|
||||
communityId: undefined,
|
||||
ownerName: undefined
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
const exportLoading = ref(false) // 导出的加载中
|
||||
const communityOptions = ref<CommunitySimpleVO[]>([]) // 小区选项列表
|
||||
|
||||
/** 格式化手机号(脱敏显示) */
|
||||
const formatPhone = (phone: string) => {
|
||||
|
|
@ -174,6 +183,15 @@ const formatPhone = (phone: string) => {
|
|||
return phone
|
||||
}
|
||||
|
||||
/** 加载小区列表 */
|
||||
const loadCommunityList = async () => {
|
||||
try {
|
||||
communityOptions.value = await CommunityApi.getCommunitySimpleList()
|
||||
} catch (error) {
|
||||
console.error('加载小区列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
|
|
@ -257,6 +275,7 @@ const handleExport = async () => {
|
|||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
loadCommunityList()
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue