Files
RentWeAppFront/pages/bill/bill.vue

317 lines
6.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="bill-list-page">
<!-- 自定义导航栏 -->
<customNavbar title="我的账单"></customNavbar>
<!-- 筛选栏 -->
<view class="filter-bar">
<!-- 年份筛选点击区域 -->
<view class="year-filter" @click="toggleYearPicker">
<text class="year-text">{{ currentYear }}</text>
<u-icon name="arrow-down" size="24" color="#666"></u-icon>
</view>
<!-- 自定义年份选择器弹窗 -->
<u-popup v-model="showYearPicker" mode="bottom" border-radius="20rpx" :closeable="true">
<view class="year-picker-popup">
<!-- 弹窗标题 -->
<view class="popup-header">
<text class="popup-title">选择年份</text>
</view>
<!-- 年份列表 -->
<view class="year-list">
<view class="year-item" v-for="year in years" :key="year"
:class="{ active: currentYear === year }" @click="selectYear(year)">
{{ year }}
</view>
</view>
</view>
</u-popup>
<!-- 支出/收入切换 -->
<view class="tab-bar">
<view class="tab-item" :class="{ active: currentTab === 'out' }" @click="switchTab('out')">
支出
</view>
<view class="tab-item" :class="{ active: currentTab === 'in' }" @click="switchTab('in')">
收入
</view>
</view>
</view>
<!-- 账单列表 -->
<scroll-view scroll-y class="scroll-content" :scroll-top="0" :refresher-enabled="true"
:refresher-triggered="isRefreshing" @refresherrefresh="refresh" @scrolltolower="loadMore">
<view v-if="bills.length > 0">
<view class="bill-item" v-for="item in bills" :key="item.id" @click="goDetail(item)">
<!-- 左侧信息 -->
<view class="bill-left">
<text class="bill-name">{{ item.feeName }}</text>
<text class="bill-date" v-if="item.payTime">支付时间{{ item.payTime }}</text>
<text class="bill-status" v-if="currentTab === 'out'">{{ item.status }}</text>
</view>
<!-- 右侧金额 + 箭头 -->
<view class="bill-right">
<text class="amount">{{ formatMoney(item.amount) }}</text>
<u-icon name="arrow-right" size="28" color="#ccc" />
</view>
</view>
</view>
<view v-else class="empty">
<u-empty mode="list" text="暂无账单" />
</view>
<u-loadmore :status="loadStatus" />
</scroll-view>
</view>
</template>
<script>
export default {
data() {
return {
currentTab: 'out', // in 收 / out 支
bills: [],
isRefreshing: false,
loadStatus: 'more', // u-loadmore 状态
// 年份筛选相关
currentYear: 2025,
years: [2025, 2024, 2023, 2022, 2021],
showYearPicker: false
};
},
onLoad(options) {
// 可以从 options 获取用户ID或合同ID
this.loadBills();
},
methods: {
switchTab(tab) {
this.currentTab = tab;
this.loadBills();
},
// 切换年份选择器显示
toggleYearPicker() {
this.showYearPicker = !this.showYearPicker;
},
// 选择年份
selectYear(year) {
this.currentYear = year;
this.showYearPicker = false;
// 重新加载账单数据
this.loadBills();
},
loadBills() {
// 模拟数据加载
if (this.currentTab === 'in') {
this.bills = [{
id: 'b101',
feeName: '第一期2024.12.01-2024.12.31',
payTime: '2024-12-05',
amount: 3000,
status: '已收',
},
{
id: 'b102',
feeName: '第二期2025.01.01-2025.01.31',
payTime: '',
amount: 3000,
status: '未收',
},
];
} else {
this.bills = [{
id: 'b201',
feeName: '第一期租金2024.12.01-2024.12.31',
payTime: '2024-12-05',
amount: 3000,
status: '已支付',
},
{
id: 'b202',
feeName: '第二期租金2025.01.01-2025.01.31',
payTime: '',
amount: 3000,
status: '待支付',
},
];
}
},
refresh() {
this.isRefreshing = true;
setTimeout(() => {
this.loadBills();
this.isRefreshing = false;
}, 1000);
},
loadMore() {
// 可以调用接口分页加载更多数据
this.loadStatus = 'noMore';
},
formatMoney(val) {
if (!val && val !== 0) return '—';
return '¥' + Number(val).toFixed(2);
},
goDetail(item) {
uni.navigateTo({
url: `/pages/bill/billDetail?id=${item.id}`,
});
},
},
};
</script>
<style lang="scss" scoped>
.bill-list-page {
background: #f7f8fa;
min-height: 100vh;
padding-top: 120rpx;
/* 给导航栏留空间 */
}
.filter-bar {
display: flex;
justify-content: space-between;
align-items: center;
background: #fff;
padding: 24rpx 30rpx;
margin: 20rpx;
border-radius: 12rpx;
box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.05);
}
/* 年份筛选 */
.year-filter {
display: flex;
align-items: center;
gap: 8rpx;
font-size: 32rpx;
color: #333;
cursor: pointer;
}
/* 支出/收入切换 */
.tab-bar {
display: flex;
gap: 20rpx;
}
.tab-item {
padding: 12rpx 32rpx;
font-size: 28rpx;
border-radius: 24rpx;
color: #333;
background-color: #f5f5f5;
transition: all 0.2s ease;
&.active {
color: #fff;
background: #ff3b30;
}
}
/* 自定义年份选择器样式 */
.year-picker-popup {
background: #fff;
padding: 30rpx 0;
}
.popup-header {
text-align: center;
padding: 20rpx 0;
border-bottom: 1rpx solid #f0f0f0;
}
.popup-title {
font-size: 34rpx;
font-weight: 600;
color: #333;
}
.year-list {
padding: 20rpx;
}
.year-item {
font-size: 32rpx;
color: #666;
text-align: center;
padding: 24rpx;
border-radius: 12rpx;
margin-bottom: 16rpx;
background: #f5f5f5;
transition: all 0.2s ease;
&:last-child {
margin-bottom: 0;
}
&.active {
background: #ff3b30;
color: #fff;
}
&:hover {
background: #ff5252;
color: #fff;
}
}
.scroll-content {
margin-top: 20rpx;
padding-bottom: 20rpx;
}
.bill-item {
display: flex;
justify-content: space-between;
background: #fff;
margin: 0 20rpx 20rpx 20rpx;
border-radius: 12rpx;
padding: 20rpx;
box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.05);
}
.bill-left {
display: flex;
flex-direction: column;
.bill-name {
font-size: 28rpx;
color: #2D2B2C;
font-weight: 500;
}
.bill-date,
.bill-status {
font-size: 24rpx;
color: #ADADB1;
margin-top: 18rpx;
}
}
.bill-right {
display: flex;
align-items: center;
.amount {
font-size: 28rpx;
color: #F34038;
margin-right: 10rpx;
}
}
.empty {
margin-top: 200rpx;
text-align: center;
}
</style>