This commit is contained in:
parent
70ef728405
commit
0a839183bc
|
|
@ -4,6 +4,7 @@ import { get, post, put, del } from './request';
|
||||||
// 区域管理API
|
// 区域管理API
|
||||||
export const regionApi = {
|
export const regionApi = {
|
||||||
getAll: () => get('/regions'),
|
getAll: () => get('/regions'),
|
||||||
|
list: (params = {}) => get('/regions/list', params),
|
||||||
getById: (id) => get(`/regions/${id}`),
|
getById: (id) => get(`/regions/${id}`),
|
||||||
create: (data) => post('/regions', data),
|
create: (data) => post('/regions', data),
|
||||||
update: (id, data) => put(`/regions/${id}`, data),
|
update: (id, data) => put(`/regions/${id}`, data),
|
||||||
|
|
@ -13,6 +14,7 @@ export const regionApi = {
|
||||||
// 公寓管理API
|
// 公寓管理API
|
||||||
export const apartmentApi = {
|
export const apartmentApi = {
|
||||||
getAll: (params = {}) => get('/apartments', params),
|
getAll: (params = {}) => get('/apartments', params),
|
||||||
|
list: (params = {}) => get('/apartments/list', params),
|
||||||
getById: (id) => get(`/apartments/${id}`),
|
getById: (id) => get(`/apartments/${id}`),
|
||||||
create: (data) => post('/apartments', data),
|
create: (data) => post('/apartments', data),
|
||||||
update: (id, data) => put(`/apartments/${id}`, data),
|
update: (id, data) => put(`/apartments/${id}`, data),
|
||||||
|
|
@ -22,6 +24,7 @@ export const apartmentApi = {
|
||||||
// 房间管理API
|
// 房间管理API
|
||||||
export const roomApi = {
|
export const roomApi = {
|
||||||
getAll: (params = {}) => get('/rooms', params),
|
getAll: (params = {}) => get('/rooms', params),
|
||||||
|
list: (params = {}) => get('/rooms/list', params),
|
||||||
getById: (id) => get(`/rooms/${id}`),
|
getById: (id) => get(`/rooms/${id}`),
|
||||||
create: (data) => post('/rooms', data),
|
create: (data) => post('/rooms', data),
|
||||||
update: (id, data) => put(`/rooms/${id}`, data),
|
update: (id, data) => put(`/rooms/${id}`, data),
|
||||||
|
|
@ -31,6 +34,7 @@ export const roomApi = {
|
||||||
// 租客管理API
|
// 租客管理API
|
||||||
export const tenantApi = {
|
export const tenantApi = {
|
||||||
getAll: () => get('/tenants'),
|
getAll: () => get('/tenants'),
|
||||||
|
list: (params = {}) => get('/tenants/list', params),
|
||||||
getById: (id) => get(`/tenants/${id}`),
|
getById: (id) => get(`/tenants/${id}`),
|
||||||
create: (data) => post('/tenants', data),
|
create: (data) => post('/tenants', data),
|
||||||
update: (id, data) => put(`/tenants/${id}`, data),
|
update: (id, data) => put(`/tenants/${id}`, data),
|
||||||
|
|
@ -49,6 +53,7 @@ export const contractApi = {
|
||||||
// 租房管理API
|
// 租房管理API
|
||||||
export const rentalApi = {
|
export const rentalApi = {
|
||||||
getAll: (params = {}) => get('/rentals', params),
|
getAll: (params = {}) => get('/rentals', params),
|
||||||
|
list: (params = {}) => get('/rentals/list', params),
|
||||||
getById: (id) => get(`/rentals/${id}`),
|
getById: (id) => get(`/rentals/${id}`),
|
||||||
create: (data) => post('/rentals', data),
|
create: (data) => post('/rentals', data),
|
||||||
update: (id, data) => put(`/rentals/${id}`, data),
|
update: (id, data) => put(`/rentals/${id}`, data),
|
||||||
|
|
@ -67,6 +72,7 @@ export const statisticsApi = {
|
||||||
// 水费管理API
|
// 水费管理API
|
||||||
export const waterBillApi = {
|
export const waterBillApi = {
|
||||||
getAll: (params = {}) => get('/water-bills', params),
|
getAll: (params = {}) => get('/water-bills', params),
|
||||||
|
list: (params = {}) => get('/water-bills/list', params),
|
||||||
getById: (id) => get(`/water-bills/${id}`),
|
getById: (id) => get(`/water-bills/${id}`),
|
||||||
create: (data) => post('/water-bills', data),
|
create: (data) => post('/water-bills', data),
|
||||||
update: (id, data) => put(`/water-bills/${id}`, data),
|
update: (id, data) => put(`/water-bills/${id}`, data),
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadRegions() {
|
async loadRegions() {
|
||||||
try {
|
try {
|
||||||
const response = await regionApi.getAll()
|
const response = await regionApi.list()
|
||||||
this.regions = response
|
this.regions = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载区域数据失败')
|
this.$message.error('加载区域数据失败')
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadRegions() {
|
async loadRegions() {
|
||||||
try {
|
try {
|
||||||
const response = await regionApi.getAll()
|
const response = await regionApi.list()
|
||||||
this.regions = response
|
this.regions = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载区域数据失败')
|
this.$message.error('加载区域数据失败')
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadTenants() {
|
async loadTenants() {
|
||||||
try {
|
try {
|
||||||
const response = await tenantApi.getAll()
|
const response = await tenantApi.list()
|
||||||
this.tenants = response
|
this.tenants = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载租客数据失败')
|
this.$message.error('加载租客数据失败')
|
||||||
|
|
@ -95,7 +95,7 @@ export default {
|
||||||
},
|
},
|
||||||
async loadRooms() {
|
async loadRooms() {
|
||||||
try {
|
try {
|
||||||
const response = await roomApi.getAll()
|
const response = await roomApi.list()
|
||||||
this.rooms = response
|
this.rooms = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载房间数据失败')
|
this.$message.error('加载房间数据失败')
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadTenants() {
|
async loadTenants() {
|
||||||
try {
|
try {
|
||||||
const response = await tenantApi.getAll()
|
const response = await tenantApi.list()
|
||||||
this.tenants = response
|
this.tenants = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载租客数据失败')
|
this.$message.error('加载租客数据失败')
|
||||||
|
|
@ -97,7 +97,7 @@ export default {
|
||||||
},
|
},
|
||||||
async loadRooms() {
|
async loadRooms() {
|
||||||
try {
|
try {
|
||||||
const response = await roomApi.getAll()
|
const response = await roomApi.list()
|
||||||
this.rooms = response
|
this.rooms = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载房间数据失败')
|
this.$message.error('加载房间数据失败')
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadRegions() {
|
async loadRegions() {
|
||||||
try {
|
try {
|
||||||
const response = await regionApi.getAll()
|
const response = await regionApi.list()
|
||||||
this.regions = response
|
this.regions = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载区域数据失败')
|
this.$message.error('加载区域数据失败')
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadRegions() {
|
async loadRegions() {
|
||||||
try {
|
try {
|
||||||
const response = await regionApi.getAll()
|
const response = await regionApi.list()
|
||||||
this.regions = response
|
this.regions = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载区域数据失败')
|
this.$message.error('加载区域数据失败')
|
||||||
|
|
|
||||||
|
|
@ -140,14 +140,14 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadData() {
|
async loadData() {
|
||||||
try {
|
try {
|
||||||
// 并行加载房间和公寓数据
|
// 并行加载房间和公寓数据(使用list接口)
|
||||||
const [roomsResponse, apartmentsResponse] = await Promise.all([
|
const [roomsResponse, apartmentsResponse] = await Promise.all([
|
||||||
roomApi.getAll(),
|
roomApi.list(),
|
||||||
apartmentApi.getAll()
|
apartmentApi.list()
|
||||||
])
|
])
|
||||||
|
|
||||||
this.rooms = roomsResponse.data || roomsResponse
|
this.rooms = roomsResponse
|
||||||
this.apartments = apartmentsResponse.data || apartmentsResponse
|
this.apartments = apartmentsResponse
|
||||||
|
|
||||||
// 检查URL参数中是否有roomId
|
// 检查URL参数中是否有roomId
|
||||||
const roomId = this.$route.query.roomId ? Number(this.$route.query.roomId) : null
|
const roomId = this.$route.query.roomId ? Number(this.$route.query.roomId) : null
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div v-loading="isLoading" class="room-info-section">
|
<div v-loading="isLoading" class="room-info-section">
|
||||||
<h2>{{ room.apartmentName }} - {{ room.roomNumber }}</h2>
|
<h2>{{ room.Apartment.name }} - {{ room.roomNumber }}</h2>
|
||||||
<div class="room-basic-info">
|
<div class="room-basic-info">
|
||||||
<div class="info-item">
|
<div class="info-item">
|
||||||
<span class="label">面积:</span>
|
<span class="label">面积:</span>
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-tabs v-model="activeTab">
|
<el-tabs v-model="activeTab">
|
||||||
<el-tab-pane label="租赁档案" name="rental">
|
<el-tab-pane label="租赁档案" name="rental">
|
||||||
<el-table :data="rentalHistory" style="width: 100%">
|
<el-table :data="rentalHistory" style="width: 100%">
|
||||||
|
|
@ -121,7 +121,7 @@
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
|
||||||
</el-tabs>
|
</el-tabs>
|
||||||
|
|
||||||
<!-- 水费编辑对话框 -->
|
<!-- 水费编辑对话框 -->
|
||||||
<el-dialog title="编辑水费" :visible.sync="waterBillDialogVisible" width="500px">
|
<el-dialog title="编辑水费" :visible.sync="waterBillDialogVisible" width="500px">
|
||||||
<el-form :model="waterBillForm" :rules="waterBillRules" ref="waterBillForm">
|
<el-form :model="waterBillForm" :rules="waterBillRules" ref="waterBillForm">
|
||||||
|
|
@ -152,9 +152,9 @@
|
||||||
<el-button type="primary" @click="handleSaveWaterBill">保存</el-button>
|
<el-button type="primary" @click="handleSaveWaterBill">保存</el-button>
|
||||||
</span>
|
</span>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- 租赁编辑对话框 -->
|
<!-- 租赁编辑对话框 -->
|
||||||
<el-dialog :title="rentalForm.id ? '编辑租赁记录' : '新增租赁记录'" :visible.sync="rentalDialogVisible" width="500px">
|
<el-dialog :title="rentalForm.id ? '编辑租赁记录' : '新增租赁记录'" :visible.sync="rentalDialogVisible" width="500px">
|
||||||
<el-form :model="rentalForm" :rules="rentalRules" ref="rentalForm">
|
<el-form :model="rentalForm" :rules="rentalRules" ref="rentalForm">
|
||||||
|
|
@ -199,7 +199,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { roomApi, rentalApi, apartmentApi, waterBillApi } from '../../api/api'
|
import { roomApi, rentalApi, waterBillApi } from '../../api/api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'RentalDetail',
|
name: 'RentalDetail',
|
||||||
|
|
@ -207,7 +207,6 @@ export default {
|
||||||
return {
|
return {
|
||||||
room: {},
|
room: {},
|
||||||
rentals: [],
|
rentals: [],
|
||||||
apartments: [],
|
|
||||||
rentalHistory: [],
|
rentalHistory: [],
|
||||||
waterBills: [],
|
waterBills: [],
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
|
@ -284,24 +283,14 @@ export default {
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
try {
|
try {
|
||||||
const roomId = this.$route.params.id
|
const roomId = this.$route.params.id
|
||||||
|
|
||||||
// 加载房间数据
|
// 加载房间数据
|
||||||
const roomResponse = await roomApi.getById(roomId)
|
const roomResponse = await roomApi.getById(roomId)
|
||||||
this.room = roomResponse
|
this.room = roomResponse
|
||||||
|
|
||||||
// 加载公寓数据
|
|
||||||
const apartmentsResponse = await apartmentApi.getAll()
|
|
||||||
this.apartments = apartmentsResponse.data || apartmentsResponse
|
|
||||||
|
|
||||||
// 添加公寓名称
|
|
||||||
if (this.room.apartmentId) {
|
|
||||||
const apartment = this.apartments.find(a => a.id == this.room.apartmentId)
|
|
||||||
this.room.apartmentName = apartment ? apartment.name : ''
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载租赁历史
|
// 加载租赁历史
|
||||||
await this.loadRentalHistory()
|
await this.loadRentalHistory()
|
||||||
|
|
||||||
// 如果当前激活的是水费tab,加载水费数据
|
// 如果当前激活的是水费tab,加载水费数据
|
||||||
if (this.activeTab === 'water') {
|
if (this.activeTab === 'water') {
|
||||||
await this.loadWaterBills()
|
await this.loadWaterBills()
|
||||||
|
|
@ -322,10 +311,10 @@ export default {
|
||||||
page: this.waterCurrentPage,
|
page: this.waterCurrentPage,
|
||||||
pageSize: this.waterPageSize
|
pageSize: this.waterPageSize
|
||||||
})
|
})
|
||||||
|
|
||||||
// 处理返回数据
|
// 处理返回数据
|
||||||
this.waterBills = response.data || response
|
this.waterBills = response.data || response
|
||||||
|
|
||||||
// 设置总数
|
// 设置总数
|
||||||
this.waterTotal = response.total || 0
|
this.waterTotal = response.total || 0
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -344,7 +333,7 @@ export default {
|
||||||
page: this.currentPage,
|
page: this.currentPage,
|
||||||
pageSize: this.pageSize
|
pageSize: this.pageSize
|
||||||
})
|
})
|
||||||
|
|
||||||
// 处理返回数据
|
// 处理返回数据
|
||||||
const data = response.data || response
|
const data = response.data || response
|
||||||
this.rentalHistory = data.map(rental => {
|
this.rentalHistory = data.map(rental => {
|
||||||
|
|
@ -353,7 +342,7 @@ export default {
|
||||||
tenantName: rental.Tenant ? rental.Tenant.name : ''
|
tenantName: rental.Tenant ? rental.Tenant.name : ''
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 设置总数
|
// 设置总数
|
||||||
this.total = response.total || 0
|
this.total = response.total || 0
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -451,14 +440,14 @@ export default {
|
||||||
// 找到当前房间的租房记录
|
// 找到当前房间的租房记录
|
||||||
const roomId = this.$route.params.id
|
const roomId = this.$route.params.id
|
||||||
const rental = this.rentals.find(r => r.roomId == roomId && r.status === 'active')
|
const rental = this.rentals.find(r => r.roomId == roomId && r.status === 'active')
|
||||||
|
|
||||||
if (rental) {
|
if (rental) {
|
||||||
// 更新租房记录状态
|
// 更新租房记录状态
|
||||||
await rentalApi.update(rental.id, { status: 'expired' })
|
await rentalApi.update(rental.id, { status: 'expired' })
|
||||||
|
|
||||||
// 更新房间状态
|
// 更新房间状态
|
||||||
await roomApi.update(roomId, { status: 'empty' })
|
await roomApi.update(roomId, { status: 'empty' })
|
||||||
|
|
||||||
this.$message.success('退房成功')
|
this.$message.success('退房成功')
|
||||||
this.loadData()
|
this.loadData()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -597,15 +586,15 @@ export default {
|
||||||
// 计算新的开始日期和结束日期
|
// 计算新的开始日期和结束日期
|
||||||
const oldEndDate = new Date(rental.endDate)
|
const oldEndDate = new Date(rental.endDate)
|
||||||
const newStartDate = new Date(oldEndDate)
|
const newStartDate = new Date(oldEndDate)
|
||||||
|
|
||||||
// 计算租赁时长(月)
|
// 计算租赁时长(月)
|
||||||
const oldStartDate = new Date(rental.startDate)
|
const oldStartDate = new Date(rental.startDate)
|
||||||
const monthsDiff = (oldEndDate.getFullYear() - oldStartDate.getFullYear()) * 12 + (oldEndDate.getMonth() - oldStartDate.getMonth())
|
const monthsDiff = (oldEndDate.getFullYear() - oldStartDate.getFullYear()) * 12 + (oldEndDate.getMonth() - oldStartDate.getMonth())
|
||||||
|
|
||||||
// 计算新的结束日期
|
// 计算新的结束日期
|
||||||
const newEndDate = new Date(newStartDate)
|
const newEndDate = new Date(newStartDate)
|
||||||
newEndDate.setMonth(newEndDate.getMonth() + monthsDiff)
|
newEndDate.setMonth(newEndDate.getMonth() + monthsDiff)
|
||||||
|
|
||||||
// 预填表单,保持租客信息不变,清空ID
|
// 预填表单,保持租客信息不变,清空ID
|
||||||
this.rentalForm = {
|
this.rentalForm = {
|
||||||
id: '',
|
id: '',
|
||||||
|
|
@ -750,4 +739,4 @@ export default {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -108,10 +108,10 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadData() {
|
async loadData() {
|
||||||
try {
|
try {
|
||||||
// 并行加载房间和公寓数据
|
// 并行加载房间和公寓数据(使用list接口)
|
||||||
const [roomsResponse, apartmentsResponse] = await Promise.all([
|
const [roomsResponse, apartmentsResponse] = await Promise.all([
|
||||||
roomApi.getAll(),
|
roomApi.list(),
|
||||||
apartmentApi.getAll()
|
apartmentApi.list()
|
||||||
])
|
])
|
||||||
|
|
||||||
this.rooms = roomsResponse
|
this.rooms = roomsResponse
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,8 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadApartments() {
|
async loadApartments() {
|
||||||
try {
|
try {
|
||||||
const response = await apartmentApi.getAll()
|
const response = await apartmentApi.list()
|
||||||
this.apartments = response.data || response
|
this.apartments = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载公寓数据失败')
|
this.$message.error('加载公寓数据失败')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,8 +133,8 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async loadApartments() {
|
async loadApartments() {
|
||||||
try {
|
try {
|
||||||
const response = await apartmentApi.getAll()
|
const response = await apartmentApi.list()
|
||||||
this.apartments = response.data || response
|
this.apartments = response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('加载公寓数据失败')
|
this.$message.error('加载公寓数据失败')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue