This commit is contained in:
wangxiaoxian 2026-03-04 15:14:11 +08:00
parent 80aea7044d
commit 70ef728405
1 changed files with 108 additions and 16 deletions

View File

@ -69,6 +69,17 @@
</template>
</el-table-column>
</el-table>
<div style="margin-top: 20px; display: flex; justify-content: flex-end;">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
</div>
</el-tab-pane>
<el-tab-pane label="水费记录" name="water">
<div class="section-header">
@ -96,6 +107,17 @@
</template>
</el-table-column>
</el-table>
<div style="margin-top: 20px; display: flex; justify-content: flex-end;">
<el-pagination
@size-change="handleWaterSizeChange"
@current-change="handleWaterCurrentChange"
:current-page="waterCurrentPage"
:page-sizes="[10, 20, 50, 100]"
:page-size="waterPageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="waterTotal">
</el-pagination>
</div>
</el-tab-pane>
</el-tabs>
@ -192,6 +214,14 @@ export default {
activeTab: 'rental',
//
returnQuery: {},
// -
currentPage: 1,
pageSize: 10,
total: 0,
// -
waterCurrentPage: 1,
waterPageSize: 10,
waterTotal: 0,
waterBillDialogVisible: false,
waterBillForm: {
id: '',
@ -239,6 +269,16 @@ export default {
this.returnQuery = this.$route.query
this.loadData()
},
watch: {
activeTab: function() {
// tab
if (this.activeTab === 'rental') {
this.loadRentalHistory()
} else if (this.activeTab === 'water') {
this.loadWaterBills()
}
}
},
methods: {
async loadData() {
this.isLoading = true
@ -259,34 +299,86 @@ export default {
this.room.apartmentName = apartment ? apartment.name : ''
}
//
const rentalsResponse = await rentalApi.getAll()
this.rentals = rentalsResponse.data || rentalsResponse
//
const waterBillsResponse = await waterBillApi.getAll({ roomId })
this.waterBills = (waterBillsResponse.data || waterBillsResponse)
.sort((a, b) => new Date(b.createTime) - new Date(a.createTime))
//
this.loadRentalHistory()
await this.loadRentalHistory()
// tab
if (this.activeTab === 'water') {
await this.loadWaterBills()
}
} catch (error) {
this.$message.error('加载数据失败')
} finally {
this.isLoading = false
}
},
loadRentalHistory() {
async loadWaterBills() {
this.isLoading = true
try {
const roomId = this.$route.params.id
this.rentalHistory = this.rentals
.filter(r => r.roomId == roomId)
.map(rental => {
// API
const response = await waterBillApi.getAll({
roomId,
page: this.waterCurrentPage,
pageSize: this.waterPageSize
})
//
this.waterBills = response.data || response
//
this.waterTotal = response.total || 0
} catch (error) {
this.$message.error('加载水费记录失败')
} finally {
this.isLoading = false
}
},
async loadRentalHistory() {
this.isLoading = true
try {
const roomId = this.$route.params.id
// API
const response = await rentalApi.getAll({
roomId,
page: this.currentPage,
pageSize: this.pageSize
})
//
const data = response.data || response
this.rentalHistory = data.map(rental => {
return {
...rental,
tenantName: rental.Tenant ? rental.Tenant.name : ''
}
})
.sort((a, b) => new Date(b.createTime) - new Date(a.createTime))
//
this.total = response.total || 0
} catch (error) {
this.$message.error('加载租赁历史失败')
} finally {
this.isLoading = false
}
},
handleSizeChange(size) {
this.pageSize = size
this.currentPage = 1
this.loadRentalHistory()
},
handleCurrentChange(current) {
this.currentPage = current
this.loadRentalHistory()
},
handleWaterSizeChange(size) {
this.waterPageSize = size
this.waterCurrentPage = 1
this.loadWaterBills()
},
handleWaterCurrentChange(current) {
this.waterCurrentPage = current
this.loadWaterBills()
},
getStatusType(status) {
switch (status) {