Files
RentWeAppFront/pages-biz/wae/wae.vue

414 lines
9.4 KiB
Vue
Raw Normal View History

2025-11-14 11:39:33 +08:00
<template>
<view class="pending-bill-page">
2026-01-15 17:18:24 +08:00
<custom-navbar title="水电费待付" />
2025-11-14 11:39:33 +08:00
2026-05-14 14:42:51 +08:00
<DateFilter :start="startDate" :end="endDate" @update:start="startDate = $event"
@update:end="endDate = $event" @change="onDateFilterChange" />
<scroll-view
scroll-y
class="scroll-content"
:refresher-enabled="true"
:refresher-triggered="isRefreshing"
@refresherrefresh="refresh"
@scrolltolower="loadMore"
>
<view v-if="bills.length > 0">
2026-01-15 17:18:24 +08:00
<view class="bill-item" v-for="item in bills" :key="item.billNo">
<view class="bill-left">
<u-checkbox v-model="item.checked" @change="toggleCheck(item)" size="32"
active-color="#EA414A" />
<view class="bill-info">
2026-01-15 17:18:24 +08:00
<text class="bill-name">{{ item.billName }}</text>
<text class="bill-date">缴费截止<text class="date">{{ item.billEndDate }}</text></text>
</view>
</view>
<view class="bill-right">
2026-01-15 17:18:24 +08:00
<text class="amount">{{ formatMoney(item.billAmount) }}</text>
2026-05-14 14:42:51 +08:00
<button class="pay-btn" @click="goPay([item])" :disabled="isPaying">
去支付
</button>
</view>
</view>
</view>
2025-11-17 17:30:29 +08:00
<view v-else class="empty">
<u-empty mode="list" text="暂无水电费账单" />
</view>
2025-11-14 11:39:33 +08:00
<u-loadmore :status="loadStatus" />
</scroll-view>
<view v-if="selectedBills.length > 0" class="batch-pay-bar">
<view class="batch-pay-bar-left"><text>已选 {{ selectedBills.length }} </text></view>
<view class="batch-pay-bar-center">
合计<text class="sumAmount">{{ formatMoney(sumAmount) }}</text>
2026-01-15 17:18:24 +08:00
</view>
<view class="batch-pay-bar-right">
2026-05-14 14:42:51 +08:00
<button class="bottomPayBtn" type="primary" size="small"
@click="goPay(selectedBills)"
:disabled="isPaying">
批量缴费
</button>
</view>
</view>
</view>
2025-11-14 11:39:33 +08:00
</template>
<script>
2026-05-14 14:42:51 +08:00
import DateFilter from '../../components/DatePicker/DateFilter.vue';
export default {
2026-05-14 14:42:51 +08:00
components: { DateFilter },
data() {
return {
2026-01-15 17:18:24 +08:00
pageNo: 1,
pageSize: 10,
bills: [],
isRefreshing: false,
2026-05-14 14:42:51 +08:00
loadStatus: 'more', // ✅ 修复为正确状态
sumAmount: 0,
2026-05-14 14:42:51 +08:00
selectedBills: [],
startDate: "",
endDate: "",
minDate: "2000-01-01",
maxDate: "2199-12-31",
isPaying: false
};
},
2026-01-15 17:18:24 +08:00
onLoad(options) {
2026-06-03 16:02:11 +08:00
// loadBills 移到 onShow 中,等 token 校验通过后再加载
},
2026-06-03 16:02:11 +08:00
async onShow() {
try {
await this.$checkToken(this.$getToken())
this.checkOaAuth()
this.loadBills()
} catch (e) {
return
}
2026-01-15 17:18:24 +08:00
},
2026-05-14 14:42:51 +08:00
// ❌ 已删除冲突的 onReachBottom
methods: {
2026-06-02 16:23:56 +08:00
checkOaAuth() {
const token = this.$getToken()
if (!token) return
2026-06-02 16:23:56 +08:00
const userInfo = uni.getStorageSync('userInfo')
if (!userInfo || !userInfo.oaAuth) {
uni.showModal({
title: '提示',
content: '您还未实名认证,请先完成实名认证',
showCancel: false,
confirmText: '去认证',
success: () => {
uni.redirectTo({ url: '/pages-biz/profile/profile' })
}
})
}
},
loadBills() {
2026-05-14 14:42:51 +08:00
// ✅ 正确判断状态
if (this.loadStatus !== 'more') return;
2026-01-15 17:18:24 +08:00
this.loadStatus = 'loading';
2026-05-14 14:42:51 +08:00
2026-01-15 17:18:24 +08:00
const token = this.$getToken();
let url = '/bill/pageQueryWaeBill'
this.$u.post(url, {
pageNo: this.pageNo,
2026-01-30 09:01:38 +08:00
pageSize: this.pageSize,
2026-05-14 14:42:51 +08:00
startDate: this.startDate,
endDate: this.endDate,
2026-01-30 09:01:38 +08:00
billStatus: '待缴费'
2026-01-15 17:18:24 +08:00
}, {
WT: token
2026-05-14 14:42:51 +08:00
}).then(res => {
const rows = res.data.result || [];
rows.forEach(item => {
item.checked = false;
});
if (this.pageNo === 1) this.bills = [];
this.bills = this.bills.concat(rows);
if (rows.length < this.pageSize) {
this.loadStatus = 'nomore';
} else {
this.pageNo++;
this.loadStatus = 'more'; // ✅ 恢复可加载
}
}).catch(err => {
console.log("获取水电费账单失败:", err);
this.loadStatus = 'more'; // ✅ 异常恢复
})
},
refresh() {
this.isRefreshing = true;
2026-05-14 14:42:51 +08:00
this.pageNo = 1;
this.selectedBills = [];
this.sumAmount = 0;
setTimeout(() => {
this.loadBills();
this.isRefreshing = false;
2026-05-14 14:42:51 +08:00
}, 500);
},
loadMore() {
2026-01-15 17:18:24 +08:00
this.loadBills()
},
2026-05-14 14:42:51 +08:00
onDateFilterChange({ start, end }) {
this.loadStatus = 'more'
this.refresh();
},
formatMoney(val) {
if (val === null || val === undefined || isNaN(val)) return '—';
val = Number(val);
if (val >= 10000) {
return '¥' + (val / 10000).toFixed(2) + '万';
}
return '¥' + val.toFixed(2);
},
toggleCheck(item) {
item.checked = !item.checked;
2026-05-14 14:42:51 +08:00
if (item.checked) {
if (!this.selectedBills.some(b => b.billNo === item.billNo)) {
this.selectedBills.push(item);
}
} else {
2026-05-14 14:42:51 +08:00
this.selectedBills = this.selectedBills.filter(b => b.billNo !== item.billNo);
}
2026-05-14 14:42:51 +08:00
this.calcTotalAmount();
},
calcTotalAmount() {
let sum = 0;
this.selectedBills.forEach(b => {
sum += Number(b.billAmount || 0);
});
this.sumAmount = sum;
},
updateSelected() {
if (!Array.isArray(this.bills)) return;
this.selectedBills = this.bills.filter(b => b.checked);
2026-05-14 14:42:51 +08:00
this.calcTotalAmount();
},
async goPay(billList) {
2026-05-14 14:42:51 +08:00
if (this.isPaying) return;
if (!billList || billList.length === 0) return;
2026-05-14 14:42:51 +08:00
this.isPaying = true;
const token = this.$getToken()
try {
2026-05-14 14:42:51 +08:00
let unpaidBillVos = []
let tempSumAmount = 0
billList.forEach(bill => {
let tempBill = {
billNo: bill.billNo,
bizType: 'wae',
amount: bill.billAmount
}
2026-05-14 14:42:51 +08:00
tempSumAmount += Number(bill.billAmount)
unpaidBillVos.push(tempBill)
})
const params = {
amount: tempSumAmount,
billVoList: unpaidBillVos
}
let url = '/bill/pay'
const res = await this.$u.post(url, params, { WT: token });
2026-05-14 14:42:51 +08:00
if (res.code !== 200) {
uni.showToast({ title: res.msg, icon: 'none' });
this.isPaying = false;
return;
}
2026-05-14 14:42:51 +08:00
const order = res.data;
let orderId = order.mainOrderId
uni.requestPayment({
2026-05-14 14:42:51 +08:00
timeStamp: order.miniPayRequest.timeStamp,
nonceStr: order.miniPayRequest.nonceStr,
package: order.miniPayRequest.packageStr,
signType: order.miniPayRequest.signType,
paySign: order.miniPayRequest.paySign,
success: () => {
billList.forEach(b => b.checked = false);
this.updateSelected();
2026-05-14 14:42:51 +08:00
this.refresh();
this.isPaying = false;
},
2026-05-14 14:42:51 +08:00
fail: (err) => {
this.payFailCallback(err, orderId);
this.isPaying = false;
}
});
} catch (error) {
2026-05-14 14:42:51 +08:00
console.error('支付请求异常', error);
uni.showToast({ title: '支付请求失败', icon: 'none' });
this.isPaying = false;
}
},
2026-05-14 14:42:51 +08:00
// ✅ 修复支付失败回调(参数+接口格式)
payFailCallback(err, orderId) {
let reason = "支付失败";
if (err.errMsg?.includes("cancel")) {
reason = "您已取消支付";
} else if (err.errMsg?.includes("fail")) {
reason = "支付失败,请重试";
}
this.$u.get(`/bill/paycallback`, {
orderId: orderId,
payResult: "FAIL"
}, {
WT: this.$getToken()
}).then(res => {
console.log("回调成功")
}).catch(err => {
console.log("回调失败", err)
})
uni.showToast({ title: reason, icon: 'none' });
}
}
};
2025-11-14 11:39:33 +08:00
</script>
<style lang="scss" scoped>
.pending-bill-page {
background: #f7f8fa;
min-height: 100vh;
2026-01-15 17:18:24 +08:00
padding-top: 175rpx;
2026-05-14 14:42:51 +08:00
box-sizing: border-box;
}
2026-05-14 14:42:51 +08:00
/* ✅ 核心修复:给滚动区域固定高度 */
.scroll-content {
2026-05-14 14:42:51 +08:00
height: calc(100vh - 175rpx - 110rpx);
padding: 20rpx;
box-sizing: border-box;
}
.bill-item {
display: flex;
justify-content: space-between;
background: #fff;
margin-bottom: 20rpx;
border-radius: 12rpx;
padding: 20rpx;
box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.05);
}
.bill-left {
display: flex;
align-items: center;
.bill-info {
display: flex;
flex-direction: column;
2026-05-14 14:42:51 +08:00
margin-left: 12rpx;
.bill-name {
font-size: 30rpx;
color: #2D2B2C;
font-weight: 500;
}
.bill-date {
font-size: 24rpx;
color: #86868C;
margin-top: 6rpx;
2026-01-15 17:18:24 +08:00
.date {
font-size: 24rpx;
color: #2D2B2C;
}
}
}
}
.bill-right {
flex-direction: column;
align-items: flex-end;
width: 30%;
.amount {
text-align: center;
height: 28rpx;
line-height: 28rpx;
font-size: 30rpx;
color: #EF8849;
}
.pay-btn {
margin-top: 12rpx;
padding: 0 40rpx;
height: 60rpx;
line-height: 60rpx;
2026-05-14 14:42:51 +08:00
border-radius: 6rpx;
font-size: 30rpx;
color: #fff;
background-color: #F34038;
text-align: center;
}
}
.batch-pay-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
2026-05-14 14:42:51 +08:00
height: 110rpx;
padding: 0 30rpx;
background-color: #fff;
display: flex;
align-items: center;
justify-content: space-between;
box-shadow: 0 -4rpx 10rpx rgba(0, 0, 0, 0.08);
z-index: 999;
.batch-pay-bar-left {
font-size: 28rpx;
color: #86868C;
}
2026-01-15 17:18:24 +08:00
.batch-pay-bar-center {
font-size: 28rpx;
color: #222222;
2025-11-17 17:30:29 +08:00
.sumAmount {
font-size: 28rpx;
color: #ff7f00;
}
2026-01-15 17:18:24 +08:00
}
.batch-pay-bar-right {
flex-direction: column;
align-items: flex-end;
.bottomPayBtn {
height: 60rpx;
line-height: 60rpx;
padding: 0 40rpx;
border-radius: 6rpx;
font-size: 30rpx;
font-weight: bold;
text-align: center;
background: #F34038;
}
}
2025-11-17 17:30:29 +08:00
}
2025-11-14 11:39:33 +08:00
2026-05-14 14:42:51 +08:00
button[disabled] {
opacity: 0.5 !important;
background-color: #ccc !important;
color: #fff !important;
}
2025-11-17 17:30:29 +08:00
.empty {
margin-top: 200rpx;
text-align: center;
}
</style>