|
|
@@ -0,0 +1,519 @@
|
|
|
+<script setup lang="ts">
|
|
|
+import { onMounted, reactive, ref } from 'vue'
|
|
|
+import { clientDownloadExcel, clientGet, clientPost } from '@/utils/request.ts'
|
|
|
+import type { FormInstance, UploadProps } from 'element-plus'
|
|
|
+import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
|
|
|
+import { Delete, Download, Edit, Plus, Refresh, Search, Upload } from '@element-plus/icons-vue'
|
|
|
+
|
|
|
+interface ARentalProperty {
|
|
|
+ id: string // 主键
|
|
|
+ buildingNumber?: string // 栋数
|
|
|
+ roomNumber?: string // 房间号
|
|
|
+ electricMeterNumber?: string // 电表号
|
|
|
+ roomItems?: string // 房间物品
|
|
|
+ tenantCompany?: string // 租赁单位
|
|
|
+ tenantName?: string // 租赁人姓名
|
|
|
+ contactPhone?: string // 联系电话
|
|
|
+ rentPaymentDate?: string // 交租金时间
|
|
|
+ depositAmount?: number // 押金(元)
|
|
|
+ propertyManagementFee?: number // 物业费(元)
|
|
|
+ remarks?: string // 备注
|
|
|
+ createTime?: Date // 创建时间
|
|
|
+ createBy?: string // 创建人
|
|
|
+ updateTime?: Date // 修改时间
|
|
|
+ updateBy?: string // 修改人
|
|
|
+}
|
|
|
+
|
|
|
+interface ARentalPropertyOneResponse extends BaseResponse {
|
|
|
+ data: ARentalProperty
|
|
|
+}
|
|
|
+
|
|
|
+interface ARentalPropertyListResponse extends BaseResponse {
|
|
|
+ data: PageType<ARentalProperty>
|
|
|
+}
|
|
|
+
|
|
|
+interface AddARentalProperty {
|
|
|
+ buildingNumber?: string // 栋数
|
|
|
+ roomNumber?: string // 房间号
|
|
|
+ electricMeterNumber?: string // 电表号
|
|
|
+ roomItems?: string // 房间物品
|
|
|
+ tenantCompany?: string // 租赁单位
|
|
|
+ tenantName?: string // 租赁人姓名
|
|
|
+ contactPhone?: string // 联系电话
|
|
|
+ rentPaymentDate?: string // 交租金时间
|
|
|
+ depositAmount?: number // 押金(元)
|
|
|
+ propertyManagementFee?: number // 物业费(元)
|
|
|
+ remarks?: string // 备注
|
|
|
+}
|
|
|
+
|
|
|
+interface UpdateARentalProperty {
|
|
|
+ id?: string
|
|
|
+ buildingNumber?: string // 栋数
|
|
|
+ roomNumber?: string // 房间号
|
|
|
+ electricMeterNumber?: string // 电表号
|
|
|
+ roomItems?: string // 房间物品
|
|
|
+ tenantCompany?: string // 租赁单位
|
|
|
+ tenantName?: string // 租赁人姓名
|
|
|
+ contactPhone?: string // 联系电话
|
|
|
+ rentPaymentDate?: string // 交租金时间
|
|
|
+ depositAmount?: number // 押金(元)
|
|
|
+ propertyManagementFee?: number // 物业费(元)
|
|
|
+ remarks?: string // 备注
|
|
|
+}
|
|
|
+
|
|
|
+// Reactive state variables
|
|
|
+const tableData = ref<ARentalProperty[]>([])
|
|
|
+const total = ref(0)
|
|
|
+const pageSize = ref(10)
|
|
|
+const pageNum = ref(1)
|
|
|
+
|
|
|
+const searchForm = reactive({
|
|
|
+ electricMeterNumber: '',
|
|
|
+ tenantCompany: '',
|
|
|
+ roomNumber: '',
|
|
|
+})
|
|
|
+
|
|
|
+const dialogVisible = ref(false)
|
|
|
+const dialogTitle = ref('')
|
|
|
+const isEdit = ref(false)
|
|
|
+const formData = reactive<ARentalProperty>({})
|
|
|
+const formRef = ref<FormInstance>()
|
|
|
+const selectedIds = ref<string[]>([])
|
|
|
+
|
|
|
+//新增
|
|
|
+const add = async (data: AddARentalProperty) => {
|
|
|
+ const res = await clientPost<AddARentalProperty, BaseResponse>('/arentalProperty/save', {
|
|
|
+ ...data,
|
|
|
+ })
|
|
|
+
|
|
|
+ if (res.code !== 200) {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ ElMessage.success(res.msg)
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+//根据id获取数据
|
|
|
+const getById = async (id: string) => {
|
|
|
+ const res = await clientGet<null, ARentalPropertyOneResponse>('/arentalProperty/getById/' + id)
|
|
|
+ if (res.code !== 200) {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ return res.data
|
|
|
+}
|
|
|
+
|
|
|
+//分页获取数据
|
|
|
+const getList = async () => {
|
|
|
+ const res = await clientGet<
|
|
|
+ {
|
|
|
+ pageNum: number
|
|
|
+ pageSize: number
|
|
|
+ electricMeterNumber?: string
|
|
|
+ tenantCompany?: string
|
|
|
+ roomNumber?: string
|
|
|
+ },
|
|
|
+ ARentalPropertyListResponse
|
|
|
+ >('/arentalProperty/findByPage', {
|
|
|
+ params: {
|
|
|
+ pageNum: pageNum.value,
|
|
|
+ pageSize: pageSize.value,
|
|
|
+ electricMeterNumber: searchForm.electricMeterNumber || undefined,
|
|
|
+ tenantCompany: searchForm.tenantCompany || undefined,
|
|
|
+ roomNumber: searchForm.roomNumber || undefined,
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ if (res.code !== 200) {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tableData.value = res.data.records
|
|
|
+ total.value = res.data.total
|
|
|
+}
|
|
|
+
|
|
|
+//批量删除
|
|
|
+const delBatch = async (ids: string[]) => {
|
|
|
+ const res = await clientPost<string[], BaseResponse>('/arentalProperty/deleteBatch', ids)
|
|
|
+ if (res.code !== 200) {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ ElMessage.success(res.msg)
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+//修改
|
|
|
+const update = async (data: UpdateARentalProperty) => {
|
|
|
+ const res = await clientPost<UpdateARentalProperty, BaseResponse>('/arentalProperty/update', {
|
|
|
+ ...data,
|
|
|
+ })
|
|
|
+ if (res.code !== 200) {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ ElMessage.success(res.msg)
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+//导出为excel
|
|
|
+const exportExcel = async () => {
|
|
|
+ const loading = ElLoading.service({
|
|
|
+ lock: true,
|
|
|
+ text: '导出中,请稍候...',
|
|
|
+ background: 'rgba(0, 0, 0, 0.1)',
|
|
|
+ fullscreen: true,
|
|
|
+ })
|
|
|
+
|
|
|
+ try {
|
|
|
+ await clientDownloadExcel('/arentalProperty/exportData', {
|
|
|
+ params: {
|
|
|
+ electricMeterNumber: searchForm.electricMeterNumber || undefined,
|
|
|
+ tenantCompany: searchForm.tenantCompany || undefined,
|
|
|
+ roomNumber: searchForm.roomNumber || undefined,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ ElMessage.success('导出成功')
|
|
|
+ } catch (error) {
|
|
|
+ console.error('导出失败:', error)
|
|
|
+ ElMessage.error('导出失败')
|
|
|
+ } finally {
|
|
|
+ loading.close()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//excel导入
|
|
|
+const importExcel = async (file: File) => {
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('file', file)
|
|
|
+ const res = await clientPost<FormData, BaseResponse>('/arentalProperty/importData', formData, {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'multipart/form-data',
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if (res.code !== 200) {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ ElMessage.success(res.msg)
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+// --- CRUD Operations and Handlers ---
|
|
|
+
|
|
|
+const handleAdd = () => {
|
|
|
+ isEdit.value = false
|
|
|
+ dialogTitle.value = '新增公租房租赁信息'
|
|
|
+ // Reset form data
|
|
|
+ Object.keys(formData).forEach((key) => delete formData[key as keyof ARentalProperty])
|
|
|
+ dialogVisible.value = true
|
|
|
+}
|
|
|
+
|
|
|
+const handleEdit = async (row: ARentalProperty) => {
|
|
|
+ isEdit.value = true
|
|
|
+ dialogTitle.value = '编辑公租房租赁信息'
|
|
|
+ const data = await getById(row.id)
|
|
|
+ if (data) {
|
|
|
+ Object.assign(formData, data)
|
|
|
+ dialogVisible.value = true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const handleDelete = async (id: string) => {
|
|
|
+ ElMessageBox.confirm('确定删除此条记录吗?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
+ .then(async () => {
|
|
|
+ const success = await delBatch([id])
|
|
|
+ if (success) {
|
|
|
+ getList()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ ElMessage.info('已取消删除')
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const handleBatchDelete = () => {
|
|
|
+ if (selectedIds.value.length === 0) {
|
|
|
+ ElMessage.warning('请选择要删除的记录')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ElMessageBox.confirm(`确定删除选中的 ${selectedIds.value.length} 条记录吗?`, '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
+ .then(async () => {
|
|
|
+ const success = await delBatch(selectedIds.value)
|
|
|
+ if (success) {
|
|
|
+ getList()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ ElMessage.info('已取消批量删除')
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const handleSearch = () => {
|
|
|
+ pageNum.value = 1 // Reset to first page on search
|
|
|
+ getList()
|
|
|
+}
|
|
|
+
|
|
|
+const handleResetSearch = () => {
|
|
|
+ searchForm.electricMeterNumber = ''
|
|
|
+ searchForm.tenantCompany = ''
|
|
|
+ searchForm.roomNumber = ''
|
|
|
+ pageNum.value = 1
|
|
|
+ getList()
|
|
|
+}
|
|
|
+
|
|
|
+const handleConfirm = async () => {
|
|
|
+ if (!formRef.value) return
|
|
|
+ await formRef.value.validate(async (valid) => {
|
|
|
+ if (valid) {
|
|
|
+ let success = false
|
|
|
+ if (isEdit.value) {
|
|
|
+ success = await update(formData)
|
|
|
+ } else {
|
|
|
+ success = await add(formData)
|
|
|
+ }
|
|
|
+ if (success) {
|
|
|
+ dialogVisible.value = false
|
|
|
+ getList()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ElMessage.error('请检查表单填写')
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const handleCurrentChange = (val: number) => {
|
|
|
+ pageNum.value = val
|
|
|
+ getList()
|
|
|
+}
|
|
|
+
|
|
|
+const handleSizeChange = (val: number) => {
|
|
|
+ pageSize.value = val
|
|
|
+ pageNum.value = 1 // Reset to first page when page size changes
|
|
|
+ getList()
|
|
|
+}
|
|
|
+
|
|
|
+const handleSelectionChange = (selection: ARentalProperty[]) => {
|
|
|
+ selectedIds.value = selection.map((item) => item.id)
|
|
|
+}
|
|
|
+
|
|
|
+const handleUploadSuccess: UploadProps['onSuccess'] = async (response, uploadFile) => {
|
|
|
+ if (response) {
|
|
|
+ ElMessage.success('文件导入成功')
|
|
|
+ getList()
|
|
|
+ } else {
|
|
|
+ ElMessage.error(`文件导入失败: ${response.msg}`)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const handleUploadError: UploadProps['onError'] = (error) => {
|
|
|
+ ElMessage.error(`文件导入失败: ${error.message}`)
|
|
|
+}
|
|
|
+
|
|
|
+const handleBeforeUpload: UploadProps['beforeUpload'] = (rawFile) => {
|
|
|
+ const isExcel =
|
|
|
+ rawFile.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
|
|
|
+ rawFile.type === 'application/vnd.ms-excel'
|
|
|
+ if (!isExcel) {
|
|
|
+ ElMessage.error('导入文件只能是 Excel 格式!')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+const init = () => {
|
|
|
+ getList()
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ init()
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+ <div class="p-4">
|
|
|
+ <h1 class="text-2xl font-bold mb-6">公租房租赁情况信息管理</h1>
|
|
|
+ <!-- Search and Action Bar -->
|
|
|
+ <div class="mb-6 p-4 bg-white rounded-lg shadow-sm flex flex-wrap items-center gap-4">
|
|
|
+ <el-form :inline="true" :model="searchForm" class="flex-grow flex flex-wrap gap-x-4">
|
|
|
+ <el-form-item label="电表号">
|
|
|
+ <el-input v-model="searchForm.electricMeterNumber" placeholder="请输入电表号" clearable />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="租赁单位">
|
|
|
+ <el-input v-model="searchForm.tenantCompany" placeholder="请输入租赁单位" clearable />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="房间号">
|
|
|
+ <el-input v-model="searchForm.roomNumber" placeholder="请输入房间号" clearable />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" :icon="Search" @click="handleSearch">查询</el-button>
|
|
|
+ <el-button :icon="Refresh" @click="handleResetSearch">重置</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <div class="flex gap-2">
|
|
|
+ <el-button type="primary" :icon="Plus" @click="handleAdd">新增</el-button>
|
|
|
+ <el-button
|
|
|
+ type="danger"
|
|
|
+ :icon="Delete"
|
|
|
+ @click="handleBatchDelete"
|
|
|
+ :disabled="selectedIds.length === 0"
|
|
|
+ >批量删除</el-button
|
|
|
+ >
|
|
|
+ <el-button type="success" :icon="Download" @click="exportExcel">导出</el-button>
|
|
|
+ <el-upload
|
|
|
+ class="inline-block ml-2"
|
|
|
+ action="/api/arentalProperty/importData"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-success="handleUploadSuccess"
|
|
|
+ :on-error="handleUploadError"
|
|
|
+ :before-upload="handleBeforeUpload"
|
|
|
+ :http-request="(options) => importExcel(options.file)"
|
|
|
+ >
|
|
|
+ <el-button type="info" :icon="Upload">导入</el-button>
|
|
|
+ </el-upload>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- Table -->
|
|
|
+ <div class="bg-white rounded-lg shadow-sm p-4">
|
|
|
+ <el-table
|
|
|
+ :data="tableData"
|
|
|
+ style="width: 100%"
|
|
|
+ max-height="65vh"
|
|
|
+ border
|
|
|
+ @selection-change="handleSelectionChange"
|
|
|
+ >
|
|
|
+ <el-table-column type="selection" width="55" />
|
|
|
+ <el-table-column prop="buildingNumber" label="栋数" width="80" />
|
|
|
+ <el-table-column prop="roomNumber" label="房间号" width="100" />
|
|
|
+ <el-table-column prop="electricMeterNumber" label="电表号" width="120" />
|
|
|
+ <el-table-column prop="roomItems" label="房间物品" />
|
|
|
+ <el-table-column prop="tenantCompany" label="租赁单位" />
|
|
|
+ <el-table-column prop="tenantName" label="租赁人姓名" width="120" />
|
|
|
+ <el-table-column prop="contactPhone" label="联系电话" width="120" />
|
|
|
+ <el-table-column prop="rentPaymentDate" label="交租金时间" width="120" />
|
|
|
+ <el-table-column prop="depositAmount" label="押金(元)" width="100" />
|
|
|
+ <el-table-column prop="propertyManagementFee" label="物业费(元)" width="120" />
|
|
|
+ <el-table-column prop="remarks" label="备注" />
|
|
|
+ <el-table-column prop="createTime" label="创建时间" width="180">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.createTime ? new Date(row.createTime).toLocaleString() : '-' }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" width="150" fixed="right">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-button :icon="Edit" size="small" @click="handleEdit(row)">编辑</el-button>
|
|
|
+ <el-button type="danger" :icon="Delete" size="small" @click="handleDelete(row.id)"
|
|
|
+ >删除</el-button
|
|
|
+ >
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+
|
|
|
+ <!-- Pagination -->
|
|
|
+ <div class="mt-4 flex justify-end">
|
|
|
+ <el-pagination
|
|
|
+ @size-change="handleSizeChange"
|
|
|
+ @current-change="handleCurrentChange"
|
|
|
+ :current-page="pageNum"
|
|
|
+ :page-sizes="[10, 20, 50, 100]"
|
|
|
+ :page-size="pageSize"
|
|
|
+ layout="total, sizes, prev, pager, next, jumper"
|
|
|
+ :total="total"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- Add/Edit Dialog -->
|
|
|
+ <el-dialog
|
|
|
+ v-model="dialogVisible"
|
|
|
+ :title="dialogTitle"
|
|
|
+ width="600px"
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ :close-on-press-escape="false"
|
|
|
+ >
|
|
|
+ <el-form :model="formData" ref="formRef" label-width="120px">
|
|
|
+ <el-form-item
|
|
|
+ label="栋数"
|
|
|
+ prop="buildingNumber"
|
|
|
+ :rules="[{ required: true, message: '请输入栋数', trigger: 'blur' }]"
|
|
|
+ >
|
|
|
+ <el-input v-model="formData.buildingNumber" placeholder="请输入栋数" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ label="房间号"
|
|
|
+ prop="roomNumber"
|
|
|
+ :rules="[{ required: true, message: '请输入房间号', trigger: 'blur' }]"
|
|
|
+ >
|
|
|
+ <el-input v-model="formData.roomNumber" placeholder="请输入房间号" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="电表号" prop="electricMeterNumber">
|
|
|
+ <el-input v-model="formData.electricMeterNumber" placeholder="请输入电表号" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="房间物品" prop="roomItems">
|
|
|
+ <el-input v-model="formData.roomItems" type="textarea" placeholder="请输入房间物品" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="租赁单位" prop="tenantCompany">
|
|
|
+ <el-input v-model="formData.tenantCompany" placeholder="请输入租赁单位" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="租赁人姓名" prop="tenantName">
|
|
|
+ <el-input v-model="formData.tenantName" placeholder="请输入租赁人姓名" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="联系电话" prop="contactPhone">
|
|
|
+ <el-input v-model="formData.contactPhone" placeholder="请输入联系电话" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="交租金时间" prop="rentPaymentDate">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="formData.rentPaymentDate"
|
|
|
+ type="date"
|
|
|
+ placeholder="选择日期"
|
|
|
+ value-format="YYYY-MM-DD"
|
|
|
+ style="width: 100%"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="押金(元)" prop="depositAmount">
|
|
|
+ <el-input-number
|
|
|
+ v-model="formData.depositAmount"
|
|
|
+ :min="0"
|
|
|
+ :precision="2"
|
|
|
+ :step="100"
|
|
|
+ style="width: 100%"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="物业费(元)" prop="propertyManagementFee">
|
|
|
+ <el-input-number
|
|
|
+ v-model="formData.propertyManagementFee"
|
|
|
+ :min="0"
|
|
|
+ :precision="2"
|
|
|
+ :step="10"
|
|
|
+ style="width: 100%"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="备注" prop="remarks">
|
|
|
+ <el-input v-model="formData.remarks" type="textarea" placeholder="请输入备注" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <span class="dialog-footer">
|
|
|
+ <el-button @click="dialogVisible = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="handleConfirm">确定</el-button>
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+/* Add any specific styles here if needed, otherwise UnoCSS handles most */
|
|
|
+</style>
|