rentease-web/src/views/contract/List.vue

171 lines
5.2 KiB
Vue
Raw Normal View History

2026-03-02 12:29:23 +00:00
<template>
<div class="contract-list">
<el-card>
<template slot="header">
<div class="card-header">
<span>合同档案</span>
</div>
</template>
<el-form :inline="true" :model="searchForm" class="search-form">
<el-form-item label="状态">
<el-select v-model="searchForm.status" placeholder="请选择状态">
<el-option label="全部" value=""></el-option>
<el-option label="有效" value="active"></el-option>
<el-option label="过期" value="expired"></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleSearch">搜索</el-button>
<el-button @click="resetSearch">重置</el-button>
</el-form-item>
</el-form>
2026-03-03 15:35:20 +00:00
<el-table :data="contracts" style="width: 100%" v-loading="isLoading">
2026-03-02 12:29:23 +00:00
<el-table-column prop="id" label="ID" width="80"></el-table-column>
<el-table-column prop="regionName" label="区域"></el-table-column>
<el-table-column prop="apartmentName" label="公寓"></el-table-column>
<el-table-column prop="roomNumber" label="房间号"></el-table-column>
<el-table-column prop="tenantName" label="租客姓名"></el-table-column>
<el-table-column prop="startDate" label="开始日期" width="150"></el-table-column>
<el-table-column prop="endDate" label="结束日期" width="150"></el-table-column>
<el-table-column prop="rent" label="租金(元/月)" width="120"></el-table-column>
<el-table-column prop="deposit" label="押金(元)" width="120"></el-table-column>
<el-table-column prop="status" label="状态" width="100">
<template slot-scope="scope">
<el-tag :type="scope.row.status === 'active' ? 'success' : 'danger'">{{ scope.row.status === 'active' ? '有效' : '过期' }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
</el-table>
<div class="pagination" style="margin-top: 20px;">
<el-pagination
2026-03-03 15:35:20 +00:00
layout="total, sizes, prev, pager, next, jumper"
:total="total"
:page-size="pageSize"
:page-sizes="[10, 20, 50, 100]"
2026-03-02 12:29:23 +00:00
:current-page="currentPage"
@current-change="handleCurrentChange"
2026-03-03 15:35:20 +00:00
@size-change="handleSizeChange"
2026-03-02 12:29:23 +00:00
></el-pagination>
</div>
</el-card>
</div>
</template>
<script>
import { contractApi } from '../../api/api'
export default {
name: 'ContractList',
data() {
return {
contracts: [],
2026-03-03 15:35:20 +00:00
total: 0,
2026-03-02 12:29:23 +00:00
searchForm: {
status: ''
},
2026-03-03 15:35:20 +00:00
currentPage: 1,
pageSize: 10,
isLoading: false
2026-03-02 12:29:23 +00:00
}
},
mounted() {
this.loadContracts()
},
methods: {
async loadContracts() {
2026-03-03 15:35:20 +00:00
this.isLoading = true
2026-03-02 12:29:23 +00:00
try {
// 加载合同数据
2026-03-03 15:35:20 +00:00
const params = {
status: this.searchForm.status,
page: this.currentPage,
pageSize: this.pageSize
}
const contractsResponse = await contractApi.getAll(params)
2026-03-02 12:29:23 +00:00
// 处理合同数据,使用后端返回的关联信息
2026-03-03 15:35:20 +00:00
const contracts = contractsResponse.data || contractsResponse
this.contracts = contracts.map(contract => {
2026-03-02 12:29:23 +00:00
return {
...contract,
roomNumber: contract.Room ? contract.Room.roomNumber : '',
tenantName: contract.Tenant ? contract.Tenant.name : '',
apartmentName: contract.Room && contract.Room.Apartment ? contract.Room.Apartment.name : '',
regionName: contract.Room && contract.Room.Apartment && contract.Room.Apartment.Region ? contract.Room.Apartment.Region.name : ''
}
})
2026-03-03 15:35:20 +00:00
this.total = contractsResponse.total || 0
2026-03-02 12:29:23 +00:00
} catch (error) {
this.$message.error('加载数据失败')
2026-03-03 15:35:20 +00:00
} finally {
this.isLoading = false
2026-03-02 12:29:23 +00:00
}
},
handleAdd() {
this.$router.push('/contract/add')
},
handleEdit(id) {
this.$router.push(`/contract/edit/${id}`)
},
async handleDelete(id) {
this.$confirm('确定要删除这个合同吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
try {
await contractApi.delete(id)
this.$message.success('删除成功')
this.loadContracts()
} catch (error) {
this.$message.error('删除失败')
}
}).catch(() => {
// 取消删除
})
},
handleSearch() {
2026-03-03 15:35:20 +00:00
this.currentPage = 1
this.loadContracts()
2026-03-02 12:29:23 +00:00
},
resetSearch() {
this.searchForm = {
status: ''
}
2026-03-03 15:35:20 +00:00
this.currentPage = 1
this.loadContracts()
2026-03-02 12:29:23 +00:00
},
handleCurrentChange(val) {
this.currentPage = val
2026-03-03 15:35:20 +00:00
this.loadContracts()
},
handleSizeChange(val) {
this.pageSize = val
this.currentPage = 1
this.loadContracts()
2026-03-02 12:29:23 +00:00
}
}
}
</script>
<style scoped>
.contract-list {
padding: 20px 0;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.search-form {
margin-bottom: 20px;
}
.pagination {
display: flex;
justify-content: flex-end;
}
</style>