文件
yjyf/yjyf-app/pages/user/wallet.vue
MiAn 0370cb9bd6 feat: 新增师傅入驻审核与接单状态联动功能
- 新增师傅资质审核模块及权限
- 未审核通过的师傅默认禁用接单状态
- 新增售后退款申诉功能与相关界面
- 新增用户钱包管理及充值功能
- 更新服务定价矩阵相关数据库结构
- 修复微信支付证书验证问题
2026-11-17 10:28:01 +08:00

761 行
17 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="wallet-page">
<!-- 统一模式 A:沉浸式一体化导航栏(居中纯净标题,左侧安全返回) -->
<YjyfNavBar theme="orange" title="我的钱包" :fixed="true" :placeholder="true" />
<scroll-view class="wallet-scroll" scroll-y>
<!-- 1. 顶部沉浸式资产名片(优匠品牌标准渐变一体化延展) -->
<view class="wallet-hero" :style="{ backgroundPosition: '0 -' + navHeight + 'px' }">
<view class="hero-body">
<!-- 卡片顶栏:左侧余额标签,右侧醒目直达的【账单明细】胶囊 -->
<view class="hero-top">
<view class="hero-label-box">
<text class="hero-label">可用余额</text>
</view>
<!-- 账单明细入口:放置在资产卡片右上角,触手可及,动线自然顺畅 -->
<view class="hero-bill-pill clickable-hover" @tap="goToBills">
<text class="bill-pill-text">账单明细</text>
<image class="bill-pill-arrow" src="/static/icons/arrow-right-white.svg" mode="aspectFit" />
</view>
</view>
<view class="hero-balance">
<text class="currency">¥</text>
<text class="balance-num">{{ formatMoney(wallet.balance) }}</text>
</view>
<!-- 三大资产指标(真实接口数据,高透磨砂底衬,层次分明) -->
<view class="hero-metrics">
<view class="metric-item">
<text class="metric-lab">累计充值</text>
<text class="metric-val">¥{{ formatMoney(wallet.total_recharge) }}</text>
</view>
<view class="metric-divider"></view>
<view class="metric-item">
<text class="metric-lab">累计消费</text>
<text class="metric-val">¥{{ formatMoney(wallet.total_consume) }}</text>
</view>
<view class="metric-divider"></view>
<view class="metric-item">
<text class="metric-lab">累计退款</text>
<text class="metric-val">¥{{ formatMoney(wallet.total_refund) }}</text>
</view>
</view>
</view>
</view>
<!-- 2. 平铺充值主卡片(白底微浮,上叠 24rpx 形成纵深感,完全无需抽屉) -->
<view class="recharge-card">
<text class="section-title">充值金额</text>
<!-- 快捷面额网格(后台真实下发) -->
<view class="preset-grid" v-if="presetAmounts && presetAmounts.length > 0">
<view
class="preset-item clickable-hover"
:class="{ active: selectedAmount === amt && !isCustomAmount }"
v-for="amt in presetAmounts"
:key="amt"
@tap="choosePreset(amt)"
>
<text class="p-num">{{ amt }}元</text>
</view>
</view>
<!-- 自定义金额输入 -->
<view class="custom-input-box" :class="{ focused: isCustomAmount }">
<text class="input-sym">¥</text>
<input
class="input-elem"
type="digit"
v-model="customInput"
:placeholder="customPlaceholder"
placeholder-class="input-ph"
@focus="onCustomFocus"
@input="onCustomInput"
/>
<image
v-if="customInput"
class="input-clear clickable-hover"
src="/static/icons/input-clear.svg"
mode="aspectFit"
@tap="clearCustomInput"
/>
</view>
<!-- 支付方式单选行 -->
<view class="channel-row">
<view class="channel-left">
<image class="channel-ico" src="/static/icons/wxpay.svg" mode="aspectFit" />
<text class="channel-name">微信支付</text>
</view>
<image class="channel-check" src="/static/icons/check-orange.svg" mode="aspectFit" />
</view>
<!-- 立即充值主行动按钮 -->
<button
class="pay-cta-btn clickable-hover"
:class="{ disabled: rechargeDisabled || submitting }"
:disabled="rechargeDisabled || submitting"
@tap="handleDoRecharge"
>
{{ submitting ? '支付发起中...' : (actualRechargeAmount > 0 ? `立即充值 ¥${formatMoney(actualRechargeAmount)}` : '立即充值') }}
</button>
<!-- 协议点击说明 -->
<view class="rule-link-wrap" v-if="rechargeConfig && rechargeConfig.rule_text">
<text class="rule-link clickable-hover" @tap="openRuleDialog">充值即代表同意《充值服务协议》</text>
</view>
</view>
</scroll-view>
<!-- 3. 专业合规充值协议弹窗(支持多章节清晰排版,彻底替代粗糙的系统 Modal) -->
<view class="rule-dialog-mask" :class="{ show: showRuleDialog }" @tap="closeRuleDialog" @touchmove.stop.prevent>
<view class="rule-dialog-box" :class="{ show: showRuleDialog }" @tap.stop>
<view class="dialog-header">
<text class="dialog-title">充值服务协议</text>
<view class="dialog-close-btn clickable-hover" @tap="closeRuleDialog">
<image class="dialog-close-ico" src="/static/icons/close.svg" mode="aspectFit" />
</view>
</view>
<!-- 条例章节可滚动流 -->
<scroll-view class="dialog-scroll" scroll-y>
<view class="rule-section-list">
<view class="rule-section" v-for="(sec, idx) in parsedSections" :key="idx">
<view class="sec-badge-row">
<view class="sec-dot"></view>
<text class="sec-title">{{ sec.title }}</text>
</view>
<text class="sec-content">{{ sec.content }}</text>
</view>
</view>
</scroll-view>
<view class="dialog-footer">
<button class="dialog-confirm-btn clickable-hover" @tap="closeRuleDialog">
我已阅读并知晓
</button>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue';
import api from '@/utils/api.js';
import { executeUserRecharge } from '@/utils/pay.js';
import { getNavBarMetrics } from '@/utils/system.js';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
// 顶部导航高度计算
const navHeight = ref(getNavBarMetrics().totalNavHeight);
// 资产统计(真实接口返回,初始 0.00,无任何 mock/假数据)
const wallet = ref({
balance: 0.0,
total_recharge: 0.0,
total_consume: 0.0,
total_refund: 0.0
});
// 后台下发的真实充值配置
const rechargeConfig = ref(null);
const presetAmounts = ref([]);
const selectedAmount = ref(0);
const customInput = ref('');
const isCustomAmount = ref(false);
const submitting = ref(false);
// 协议弹窗显隐控制
const showRuleDialog = ref(false);
// 格式化金额
function formatMoney(val) {
const num = Number(val || 0);
return isNaN(num) ? '0.00' : num.toFixed(2);
}
// 动态自定义金额提示
const customPlaceholder = computed(() => {
if (rechargeConfig.value && rechargeConfig.value.min_amount !== undefined && rechargeConfig.value.max_amount !== undefined) {
return `自定义金额 (${Number(rechargeConfig.value.min_amount)} ~ ${Number(rechargeConfig.value.max_amount)}元)`;
}
return '自定义金额 (0.01 ~ 50000元)';
});
// 实际充值金额
const actualRechargeAmount = computed(() => {
if (isCustomAmount.value) {
const parsed = parseFloat(customInput.value);
return isNaN(parsed) || parsed < 0 ? 0 : parsed;
}
return selectedAmount.value;
});
// 充值按钮禁用状态
const rechargeDisabled = computed(() => {
const amt = actualRechargeAmount.value;
if (amt <= 0) return true;
if (rechargeConfig.value) {
const minA = Number(rechargeConfig.value.min_amount !== undefined ? rechargeConfig.value.min_amount : 0.01);
const maxA = Number(rechargeConfig.value.max_amount || 50000);
return amt < minA || amt > maxA;
}
return false;
});
// 解析结构化协议章节(将 【标题】内容 格式优雅拆解为小标题与正文段落)
const parsedSections = computed(() => {
const raw = (rechargeConfig.value && rechargeConfig.value.rule_text) || '';
if (!raw) return [];
// 匹配 【...】 格式或按段落解析
const blocks = raw.split(/\n\s*\n/).filter(b => b.trim().length > 0);
const results = [];
for (const block of blocks) {
const match = block.match(/^【(.*?)】\s*([\s\S]*)$/);
if (match) {
results.push({
title: match[1],
content: match[2].trim()
});
} else {
results.push({
title: '服务说明',
content: block.trim()
});
}
}
return results;
});
// 加载真实资产数据与充值配置
async function loadWalletData() {
try {
const res = await api.userWallet();
if (res) {
wallet.value = {
balance: Number(res.balance || 0),
total_recharge: Number(res.total_recharge || 0),
total_consume: Number(res.total_consume || 0),
total_refund: Number(res.total_refund || 0)
};
if (res.recharge_config) {
rechargeConfig.value = res.recharge_config;
if (Array.isArray(res.recharge_config.presets) && res.recharge_config.presets.length > 0) {
presetAmounts.value = res.recharge_config.presets;
}
if (res.recharge_config.default_preset) {
selectedAmount.value = Number(res.recharge_config.default_preset);
} else if (presetAmounts.value.length > 0) {
selectedAmount.value = presetAmounts.value[0];
}
}
}
} catch (e) {
console.error('加载钱包资产失败', e);
}
}
// 跳转到独立的收支账单明细页
function goToBills() {
uni.navigateTo({
url: '/pages/user/bills'
});
}
// 预设面额选择
function choosePreset(amt) {
isCustomAmount.value = false;
selectedAmount.value = amt;
customInput.value = '';
}
// 自定义输入交互
function onCustomFocus() {
isCustomAmount.value = true;
}
function onCustomInput() {
isCustomAmount.value = true;
}
function clearCustomInput() {
customInput.value = '';
}
// 打开/关闭专属协议弹窗
function openRuleDialog() {
showRuleDialog.value = true;
}
function closeRuleDialog() {
showRuleDialog.value = false;
}
// 发起真实在线充值
async function handleDoRecharge() {
if (rechargeConfig.value && rechargeConfig.value.enabled === false) {
uni.showToast({ title: rechargeConfig.value.close_tip || '充值通道已关闭', icon: 'none' });
return;
}
const amt = actualRechargeAmount.value;
if (rechargeConfig.value) {
const minA = Number(rechargeConfig.value.min_amount || 0.01);
const maxA = Number(rechargeConfig.value.max_amount || 50000);
if (amt < minA) {
uni.showToast({ title: `单笔充值不得低于 ¥${formatMoney(minA)}`, icon: 'none' });
return;
}
if (amt > maxA) {
uni.showToast({ title: `单笔充值不得超过 ¥${formatMoney(maxA)}`, icon: 'none' });
return;
}
}
submitting.value = true;
try {
uni.showLoading({ title: '正在创建支付...', mask: true });
await executeUserRecharge(amt);
try { uni.hideLoading(); } catch (e) {}
uni.showToast({ title: `成功充值 ¥${formatMoney(amt)}`, icon: 'success' });
customInput.value = '';
isCustomAmount.value = false;
// 充值成功,刷新真实可用余额
await loadWalletData();
} catch (e) {
try { uni.hideLoading(); } catch (err) {}
if (!e.cancelled) {
uni.showModal({
title: '充值未完成',
content: e.message || '微信支付未完成,请重试',
showCancel: false,
confirmText: '我知道了'
});
}
} finally {
submitting.value = false;
}
}
onMounted(() => {
navHeight.value = getNavBarMetrics().totalNavHeight;
loadWalletData();
});
</script>
<style lang="scss" scoped>
.wallet-page {
height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
background: $yjyf-bg-page;
}
.wallet-scroll {
flex: 1;
height: 0;
width: 100%;
}
/* 1. 顶部沉浸式资产名片(优匠品牌标准渐变背景延展) */
.wallet-hero {
padding-bottom: 56rpx;
background-color: $yjyf-primary;
background-image: $yjyf-gradient-primary;
background-size: 100% 640rpx;
background-repeat: no-repeat;
display: flex;
flex-direction: column;
}
.hero-body {
padding: 24rpx 36rpx 0;
box-sizing: border-box;
}
.hero-top {
display: flex;
align-items: center;
justify-content: space-between;
}
.hero-label-box {
display: flex;
align-items: center;
}
.hero-label {
font-size: 26rpx;
color: rgba(255, 255, 255, 0.92);
font-weight: 500;
}
/* 账单明细 Pill 入口(位于资产卡片右上角,触手可及,避开胶囊区) */
.hero-bill-pill {
display: flex;
align-items: center;
gap: 6rpx;
background: rgba(255, 255, 255, 0.22);
backdrop-filter: blur(8px);
border: 1rpx solid rgba(255, 255, 255, 0.35);
padding: 8rpx 18rpx;
border-radius: 24rpx;
transition: background-color 0.2s ease;
.bill-pill-text {
font-size: 24rpx;
color: #ffffff;
font-weight: 600;
}
.bill-pill-arrow {
width: 20rpx;
height: 20rpx;
opacity: 0.9;
}
}
.hero-balance {
display: flex;
align-items: baseline;
margin: 22rpx 0 28rpx;
.currency {
font-size: 40rpx;
font-weight: 700;
color: #ffffff;
margin-right: 8rpx;
}
.balance-num {
font-size: 76rpx;
font-weight: 800;
color: #ffffff;
line-height: 1;
letter-spacing: -1rpx;
}
}
.hero-metrics {
padding: 20rpx 24rpx;
border-radius: 18rpx;
background: rgba(255, 255, 255, 0.16);
backdrop-filter: blur(6px);
display: flex;
align-items: center;
justify-content: space-between;
.metric-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 6rpx;
.metric-lab {
font-size: 22rpx;
color: rgba(255, 255, 255, 0.85);
}
.metric-val {
font-size: 28rpx;
font-weight: 700;
color: #ffffff;
}
}
.metric-divider {
width: 1rpx;
height: 38rpx;
background: rgba(255, 255, 255, 0.25);
}
}
/* 2. 平铺充值主卡片(白底悬浮微叠,立体感强) */
.recharge-card {
margin: -24rpx 32rpx 48rpx;
background: $yjyf-bg-card;
border-radius: 28rpx;
padding: 36rpx 32rpx 32rpx;
box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.05);
position: relative;
z-index: 10;
box-sizing: border-box;
.section-title {
font-size: 30rpx;
font-weight: 700;
color: $yjyf-text-main;
margin-bottom: 24rpx;
display: block;
}
}
.preset-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 18rpx;
margin-bottom: 22rpx;
.preset-item {
height: 108rpx;
border: 2rpx solid #e5e7eb;
border-radius: 18rpx;
display: flex;
align-items: center;
justify-content: center;
background: #ffffff;
transition: all 0.2s ease;
.p-num {
font-size: 32rpx;
font-weight: 700;
color: $yjyf-text-main;
}
&.active {
border-color: $yjyf-primary;
background: $yjyf-primary-bg;
.p-num {
color: $yjyf-primary;
}
}
}
}
.custom-input-box {
display: flex;
align-items: center;
height: 94rpx;
background: #f9fafb;
border: 2rpx solid #e5e7eb;
border-radius: 18rpx;
padding: 0 24rpx;
transition: all 0.2s ease;
&.focused {
border-color: $yjyf-primary;
background: #ffffff;
}
.input-sym {
font-size: 32rpx;
font-weight: 700;
color: $yjyf-text-main;
margin-right: 12rpx;
}
.input-elem {
flex: 1;
height: 100%;
font-size: 28rpx;
color: $yjyf-text-main;
}
.input-ph {
font-size: 26rpx;
color: $yjyf-text-disabled;
}
.input-clear {
width: 32rpx;
height: 32rpx;
padding: 8rpx;
}
}
.channel-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 30rpx 4rpx 34rpx;
.channel-left {
display: flex;
align-items: center;
gap: 16rpx;
.channel-ico {
width: 42rpx;
height: 42rpx;
}
.channel-name {
font-size: 28rpx;
font-weight: 500;
color: $yjyf-text-main;
}
}
.channel-check {
width: 36rpx;
height: 36rpx;
}
}
.pay-cta-btn {
width: 100%;
height: 92rpx;
line-height: 92rpx;
background: $yjyf-gradient-primary;
color: #ffffff;
font-size: 32rpx;
font-weight: 700;
border-radius: 46rpx;
text-align: center;
box-shadow: 0 8rpx 24rpx rgba(240, 113, 13, 0.28);
&.disabled {
opacity: 0.5;
box-shadow: none;
}
}
.rule-link-wrap {
margin-top: 24rpx;
text-align: center;
.rule-link {
font-size: 22rpx;
color: $yjyf-text-muted;
}
}
/* 3. 专业合规充值协议弹窗 */
.rule-dialog-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(4px);
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
padding: 48rpx;
box-sizing: border-box;
visibility: hidden;
opacity: 0;
transition: all 0.25s ease;
&.show {
visibility: visible;
opacity: 1;
}
}
.rule-dialog-box {
width: 100%;
max-height: 80vh;
background: #ffffff;
border-radius: 32rpx;
padding: 36rpx 36rpx 32rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
transform: scale(0.92);
transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
&.show {
transform: scale(1);
}
}
.dialog-header {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 24rpx;
border-bottom: 1rpx solid $yjyf-border-color;
.dialog-title {
font-size: 32rpx;
font-weight: 700;
color: $yjyf-text-main;
}
.dialog-close-btn {
width: 56rpx;
height: 56rpx;
display: flex;
align-items: center;
justify-content: center;
.dialog-close-ico {
width: 32rpx;
height: 32rpx;
}
}
}
.dialog-scroll {
max-height: 52vh;
margin: 24rpx 0;
}
.rule-section-list {
display: flex;
flex-direction: column;
gap: 24rpx;
}
.rule-section {
display: flex;
flex-direction: column;
gap: 8rpx;
.sec-badge-row {
display: flex;
align-items: center;
gap: 10rpx;
.sec-dot {
width: 10rpx;
height: 10rpx;
border-radius: 50%;
background: $yjyf-primary;
}
.sec-title {
font-size: 26rpx;
font-weight: 700;
color: $yjyf-text-main;
}
}
.sec-content {
font-size: 24rpx;
color: $yjyf-text-regular;
line-height: 1.6;
padding-left: 20rpx;
}
}
.dialog-footer {
padding-top: 12rpx;
.dialog-confirm-btn {
width: 100%;
height: 84rpx;
line-height: 84rpx;
text-align: center;
background: $yjyf-gradient-primary;
color: #ffffff;
font-size: 28rpx;
font-weight: 700;
border-radius: 42rpx;
}
}
</style>