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