优化,完善代码

This commit is contained in:
2026-05-14 14:42:51 +08:00
parent 79a21ff0a5
commit 16c91facac
26 changed files with 1792 additions and 1322 deletions

View File

@@ -1,8 +1,7 @@
<template>
<view class="contract-page">
<!-- 顶部导航栏 -->
<customNavbar title="我的合同" :showHome = "true"/>
<customNavbar title="我的合同" :showHome="true"/>
<!-- Tabs -->
<view class="tab-wrapper">
@@ -22,10 +21,9 @@
<view class="contract-info">
<view class="top-row">
<text class="asset-name">{{ $ellipsis(item.assetName,12) }}</text>
<text class="asset-name">{{ $ellipsis(item.contractName,12) }}</text>
<u-icon name="arrow-right" size="28" color="#ccc" />
</view>
<!-- <view class="asset-room">{{ item.assetRoom || "—" }}</view> -->
<view class="date-range">{{ item.startDate }} ~ {{ item.endDate }}</view>
<view :class="['status-tag', item.signStatus]">
@@ -41,65 +39,47 @@
<u-empty mode="list" text="暂无合同记录" />
</view>
</scroll-view>
</view>
</template>
<script>
import DateFilter from '../../components/DatePicker/DateFilter.vue';
export default {
components: { DateFilter },
data() {
return {
tabList: [{
name: "全部",
value: "all"
},
{
name: "待签署",
value: "pending"
},
{
name: "已签署",
value: "signed"
},
{
name: "已过期",
value: "expired"
},
tabList: [
{ name: "全部", value: "all" },
{ name: "待签署", value: "pending" },
{ name: "已签署", value: "signed" },
{ name: "已过期", value: "expired" },
],
currentTab: 0,
statusFilter: "all",
// --- 时间筛选 ---
startDate: "",
endDate: "",
// 可选:限制日期范围
minDate: "2000-01-01",
maxDate: "2099-12-31",
maxDate: "2199-12-31",
contracts: [],
pageNo: 1,
pageSize: 10,
total: 0,
loadStatus: "loadmore",
loadStatus: "more", // ✅ 修复为官方正确值
isRefreshing: false,
defaultCover: "/public/static/assets.jpg",
defaultCover: "/public/static/index/assets.jpg",
};
},
onLoad(options) {
this.loadContracts();
},
onShow() {
this.$checkToken(this.$getToken())
},
onShow() {
this.$checkToken(this.$getToken())
},
// ✅ 删除和 scroll-view 冲突的 onReachBottom
computed: {
staticHost() {
return this.$config.staticUrl
}
staticHost() {
return this.$config.staticUrl
}
},
methods: {
onTabChange(index) {
@@ -110,89 +90,74 @@ export default {
onDateFilterChange({ start, end }) {
this.resetAndLoad();
},
formatDate(time) {
const d = new Date(time);
const m = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
return `${d.getFullYear()}-${m}-${day}`;
},
resetAndLoad() {
this.pageNo = 1;
this.contracts = [];
this.loadStatus = "loadmore";
this.loadStatus = "more"; // ✅ 修复
this.loadContracts();
},
/** 你的 loadContracts() 保持不变,只需加:按时间筛选 */
loadContracts() {
if (this.loadStatus !== 'loadmore') return;
this.loadStatus = 'loading';
this.$u.post('/contract/queryPage', {
pageNo: this.pageNo,
pageSize: this.pageSize,
startDate: this.startDate,
endDate: this.endDate,
signStatus: this.statusFilter
}, {
WT: this.$getToken()
}).then(result => {
const rows = result.data.result || [];
// 第一页 & 无数据
if (this.pageNo === 1 && rows.length === 0) {
this.contracts = [];
this.loadStatus = 'nomore';
return;
}
// 追加数据
this.contracts = this.contracts.concat(rows);
// 是否还有下一页(核心判断)
if (rows.length < this.pageSize) {
this.loadStatus = 'nomore';
} else {
this.pageNo++; // ✅ 只有这里才能 +1
this.loadStatus = 'loadmore';
}
}).catch(err => {
console.log("获取合同信息失败:", err);
this.loadStatus = 'loadmore';
}).finally(() => {
this.isRefreshing = false;
});
},
// ✅ 正确判断加载状态
if (this.loadStatus !== 'more') return;
this.loadStatus = 'loading';
this.$u.post('/contract/queryPage', {
pageNo: this.pageNo,
pageSize: this.pageSize,
startDate: this.startDate,
endDate: this.endDate,
signStatus: this.statusFilter
}, {
WT: this.$getToken()
}).then(result => {
const rows = result.data.result || [];
if (this.pageNo === 1 && rows.length === 0) {
this.contracts = [];
this.loadStatus = 'nomore';
return;
}
this.contracts = this.contracts.concat(rows);
if (rows.length < this.pageSize) {
this.loadStatus = 'nomore';
} else {
this.pageNo++;
this.loadStatus = 'more'; // ✅ 修复
}
}).catch(err => {
console.log("获取合同信息失败:", err);
this.loadStatus = 'more'; // ✅ 异常恢复
}).finally(() => {
this.isRefreshing = false;
});
},
refresh() {
this.isRefreshing = true;
this.resetAndLoad();
},
loadMore() {
if (this.loadStatus !== "loadmore") return;
this.loadContracts();
if (this.loadStatus !== "more") return; // ✅ 修复
this.loadContracts();
},
goDetail(item) {
uni.navigateTo({
url: `/pages-biz/contract/contractDetail?contractNo=${item.contractNo}`,
});
},
getStatusText(status) {
switch (status) {
case "pending":
return "签署";
case "signed":
return "已签署";
case "expired":
return "已过期";
case "pending": return "待签署";
case "signed": return "签署";
case "expired": return "已过期";
default: return "未知";
}
},
},
@@ -203,12 +168,14 @@ export default {
.contract-page {
background-color: #f8f8f8;
padding-top: 170rpx;
/* 给导航栏留空间 */
min-height: 100vh;
box-sizing: border-box;
}
/* ✅ 核心修复:正确的滚动高度 */
.scroll-content {
height: calc(100vh - 100rpx);
height: calc(100vh - 170rpx - 100rpx);
box-sizing: border-box;
}
.contract-list {