feat: 完善会员资金明细与退款转账逻辑,新增支付密码组件与资金流水界面

这个提交包含在:
2026-10-24 17:55:36 +08:00
父节点 6b86177b5f
当前提交 b6c53abb84
共有 30 个文件被更改,包括 1222 次插入 和 537 次删除

查看文件

@@ -388,6 +388,10 @@
</view>
</view>
<!-- 支付密码弹窗(余额支付验证) -->
<fc-pay-password :show="pwdPopup.show" :title="pwdPopup.title" :tip="pwdPopup.tip"
@close="pwdPopup.show = false" @confirm="onPwdConfirm" />
<!-- 评价弹层 -->
<view v-if="showComment" class="detail__mask" @click="showComment = false">
<view class="detail__sheet" @click.stop>
@@ -491,6 +495,7 @@
import postApi from '@/common/api/post.js'
import favoriteApi from '@/common/api/favorite.js'
import reportApi from '@/common/api/report.js'
import memberApi from '@/common/api/member.js'
import { REPORT_REASONS } from '@/common/constants/report.js'
import { iconUrl, categoryIconUrl, loadUiConfig, uiState } from '@/common/store/ui.js'
import { fromNow, assetUrl } from '@/common/utils/format.js'
@@ -498,10 +503,11 @@ import { pay } from '@/common/utils/pay.js'
import { useUserStore } from '@/common/store/index.js'
import config from '@/common/config/index.js'
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
import FcPayPassword from '@/components/fc-pay-password/fc-pay-password.vue'
import QRCode from '@/common/utils/qrcode-generator.js'
export default {
components: { FcNavbar },
components: { FcNavbar, FcPayPassword },
data() {
return {
id: 0,
@@ -524,6 +530,7 @@ export default {
replySubmitting: false,
showPoster: false,
showPayModal: false,
pwdPopup: { show: false, title: '', tip: '' },
score: 5,
commentText: '',
submitting: false,
@@ -917,9 +924,33 @@ export default {
*/
async confirmPay() {
if (this.submitting) return
// 后台开启支付密码:余额支付需先验证(未设置则引导去余额中心设置)
if (this.payType === 'balance' && uiState.payPasswordEnabled) {
const assets = await this.fetchAssetsSafe()
if (!assets.hasPayPassword) {
uni.showModal({
title: '需要支付密码',
content: '开启支付密码验证后才能使用余额支付,请先到「余额中心」设置。',
confirmText: '去设置',
success: (r) => {
if (r.confirm) uni.navigateTo({ url: '/pages/member/recharge' })
},
})
return
}
this.pwdPopup = { show: true, title: '请输入支付密码', tip: `解锁该信息 · ¥${Number(this.payViewPrice).toFixed(2)}` }
return
}
await this.doPay()
},
/**
* 实际支付(confirmPay 校验通过 / 支付密码验证后调用)
* @param {string} [payPassword] 余额支付密码(开关开启时必传)
*/
async doPay(payPassword) {
this.submitting = true
try {
const res = await postApi.payView(this.id, { payType: this.payType })
const res = await postApi.payView(this.id, { payType: this.payType, payPassword })
if (res.order) {
await pay({ ...res.order, payType: this.payType })
await this.waitUnlock()
@@ -935,6 +966,24 @@ export default {
this.submitting = false
}
},
/**
* 支付密码弹窗确认(余额支付验证)
* @param {string} password
*/
async onPwdConfirm(password) {
this.pwdPopup.show = false
await this.doPay(password)
},
/**
* 拉取资产(仅取支付密码状态,失败不阻断流程)
*/
async fetchAssetsSafe() {
try {
return await memberApi.assets()
} catch (e) {
return {}
}
},
/**
* 微信支付结果轮询
*/

查看文件

@@ -0,0 +1,225 @@
<template>
<view class="flows">
<!-- 渐变头部:导航 + 类型筛选融为一体,避免筛选行贴状态栏 -->
<view class="flows__hero">
<fc-navbar title="余额明细" theme="gradient" :show-back="true" />
<view class="flows__tabs">
<view v-for="t in tabs" :key="t.key" class="flows__tab"
:class="{ 'flows__tab--active': type === t.key }" @click="switchType(t.key)">
<text>{{ t.name }}</text>
</view>
</view>
</view>
<!-- 明细列表 -->
<view class="flows__list">
<fc-empty v-if="list.length === 0 && !loading" icon="receipt" :text="'暂无' + typeText + '记录'" />
<template v-else>
<view v-for="f in list" :key="f.flowNo" class="flows__item">
<view class="flows__item-main">
<text class="flows__item-scene">{{ f.scene }}</text>
<text class="flows__item-time">{{ formatTime(f.createdAt) }}</text>
</view>
<view class="flows__item-side">
<text class="flows__item-amount" :class="f.type === 'income' ? 'is-income' : 'is-expense'">
{{ f.type === 'income' ? '+' : '-' }}{{ Number(f.amount).toFixed(2) }}
</text>
<text class="flows__item-balance">余额 {{ Number(f.balance).toFixed(2) }}</text>
</view>
</view>
<text v-if="loading" class="flows__more">加载中…</text>
<text v-else-if="hasMore" class="flows__more">上拉加载更多</text>
<text v-else-if="list.length > 0" class="flows__more">没有更多了</text>
</template>
</view>
</view>
</template>
<script>
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
import FcEmpty from '@/components/fc-empty/fc-empty.vue'
import memberApi from '@/common/api/member.js'
export default {
components: { FcNavbar, FcEmpty },
data() {
return {
tabs: [
{ key: '', name: '全部' },
{ key: 'recharge', name: '充值' },
{ key: 'expense', name: '消费' },
{ key: 'refund', name: '退款' },
],
type: '',
list: [],
page: 1,
hasMore: false,
loading: false,
}
},
computed: {
typeText() {
const t = this.tabs.find((x) => x.key === this.type)
return t && t.name !== '全部' ? t.name : ''
},
},
onLoad() {
this.reload()
},
/** 上拉加载更多 */
onReachBottom() {
if (this.hasMore && !this.loading) {
this.loadMore()
}
},
methods: {
switchType(key) {
if (this.type === key) return
this.type = key
this.reload()
},
/** 切换类型 / 首次进入:重置并加载第一页 */
reload() {
this.page = 1
this.list = []
this.hasMore = false
return this.loadMore()
},
async loadMore() {
if (this.loading) return
this.loading = true
try {
const res = await memberApi.flows({ page: this.page, size: 15, type: this.type })
const rows = (res && res.list) || []
this.list = this.page === 1 ? rows : this.list.concat(rows)
this.hasMore = !!(res && res.hasMore)
if (this.hasMore) this.page++
} catch (e) {
uni.showToast({ title: e.message || '加载失败', icon: 'none' })
} finally {
this.loading = false
}
},
/** ISO 时间转本地短格式(今天显示时分,其余显示月-日) */
formatTime(iso) {
if (!iso) return ''
const d = new Date(iso)
if (isNaN(d.getTime())) return ''
const now = new Date()
const pad = (n) => String(n).padStart(2, '0')
if (d.toDateString() === now.toDateString()) {
return `今天 ${pad(d.getHours())}:${pad(d.getMinutes())}`
}
return `${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
},
},
}
</script>
<style lang="scss" scoped>
.flows {
min-height: 100vh;
background: $fc-bg;
padding-bottom: calc(60rpx + env(safe-area-inset-bottom));
}
/* 渐变头部:导航与筛选一体,底部圆角过渡到列表区 */
.flows__hero {
background: $fc-gradient-hero;
border-radius: 0 0 40rpx 40rpx;
padding-bottom: 24rpx;
}
/* 类型筛选(胶囊分段控件) */
.flows__tabs {
display: flex;
gap: 16rpx;
padding: 12rpx 28rpx 0;
}
.flows__tab {
flex: 1;
height: 68rpx;
border-radius: $fc-radius-pill;
background: rgba(255, 255, 255, 0.9);
border: 2rpx solid $fc-border;
display: flex;
align-items: center;
justify-content: center;
font-size: $fc-font-sm;
color: $fc-text-secondary;
transition: all 0.2s ease;
&--active {
background: $fc-gradient-primary;
border-color: transparent;
color: $fc-primary-ink;
font-weight: 700;
box-shadow: 0 6rpx 18rpx rgba(0, 210, 106, 0.22);
}
}
/* 明细列表 */
.flows__list {
margin: 24rpx 28rpx 0;
background: #ffffff;
border-radius: $fc-radius-lg;
padding: 8rpx 28rpx;
box-shadow: $fc-shadow-sm;
}
.flows__item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 28rpx 0;
border-bottom: 2rpx solid $fc-border;
&:last-of-type {
border-bottom: none;
}
}
.flows__item-main {
display: flex;
flex-direction: column;
min-width: 0;
}
.flows__item-scene {
font-size: $fc-font-base;
color: $fc-text;
font-weight: 500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.flows__item-time {
margin-top: 8rpx;
font-size: $fc-font-xs;
color: $fc-text-placeholder;
}
.flows__item-side {
display: flex;
flex-direction: column;
align-items: flex-end;
flex-shrink: 0;
margin-left: 20rpx;
}
.flows__item-amount {
font-size: $fc-font-base;
font-weight: 700;
&.is-income {
color: $fc-primary-text;
}
&.is-expense {
color: $fc-price;
}
}
.flows__item-balance {
margin-top: 8rpx;
font-size: $fc-font-xs;
color: $fc-text-placeholder;
}
.flows__more {
display: block;
padding: 24rpx 0 16rpx;
text-align: center;
font-size: $fc-font-xs;
color: $fc-text-placeholder;
}
</style>

查看文件

@@ -289,20 +289,25 @@
</view>
</view>
</view>
<!-- 支付密码弹窗(余额支付验证) -->
<fc-pay-password :show="pwdPopup.show" :title="pwdPopup.title" :tip="pwdPopup.tip"
@close="pwdPopup.show = false" @confirm="onPwdConfirm" />
</view>
</template>
<script>
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
import FcPayPassword from '@/components/fc-pay-password/fc-pay-password.vue'
import memberApi from '@/common/api/member.js'
import { useUserStore } from '@/common/store/index.js'
import { iconUrl, loadUiConfig } from '@/common/store/ui.js'
import { iconUrl, loadUiConfig, uiState } from '@/common/store/ui.js'
import { formatTime } from '@/common/utils/format.js'
import { pay } from '@/common/utils/pay.js'
import config from '@/common/config/index.js'
export default {
components: { FcNavbar },
components: { FcNavbar, FcPayPassword },
data() {
return {
plans: [],
@@ -315,6 +320,9 @@ export default {
// 优惠券弹层与选券状态
showCouponSheet: false,
selectedCouponId: null,
// 支付密码弹窗(余额支付验证)
pwdPopup: { show: false, title: '', tip: '' },
pwdPending: false,
}
},
computed: {
@@ -671,8 +679,33 @@ export default {
})
return
}
// 后台开启支付密码:未设置则引导去余额中心;已设置则弹窗验证
if (uiState.payPasswordEnabled) {
if (this.assets.hasPayPassword === false) {
uni.showModal({
title: '需要支付密码',
content: '开启支付密码验证后才能使用余额支付,请先到「余额中心」设置。',
confirmText: '去设置',
success: (r) => {
if (r.confirm) this.recharge()
},
})
return
}
this.pwdPending = true
this.pwdPopup = { show: true, title: '请输入支付密码', tip: `开通${this.selectedPlan ? this.selectedPlan.name : 'VIP会员'} · 实付 ¥${this.finalPriceText}` }
return
}
}
await this.doOpenVip()
},
/**
* 实际提交开通(openVip 校验通过 / 支付密码验证后调用)
* @param {string} [payPassword] 余额支付密码(开关开启时必传)
*/
async doOpenVip(payPassword) {
if (!this.planId) return
this.submitting = true
uni.showLoading({ title: '正在处理…' })
@@ -681,6 +714,7 @@ export default {
planId: this.planId,
payType: this.payType,
userCouponId: this.selectedCouponId || 0,
payPassword,
})
// 微信支付走拉起逻辑
@@ -705,6 +739,17 @@ export default {
uni.showToast({ title: e.message || '开通未完成', icon: 'none' })
}
},
/**
* 支付密码弹窗确认(余额支付验证)
* @param {string} password
*/
async onPwdConfirm(password) {
this.pwdPopup.show = false
if (this.pwdPending) {
this.pwdPending = false
await this.doOpenVip(password)
}
},
/**
* 前往充值
*/

查看文件

@@ -1,9 +1,13 @@
<template>
<view class="recharge fc-page">
<!-- 规范化顶部导航 -->
<fc-navbar title="余额充值" theme="gradient" :show-back="true" />
<!-- 余额卡 -->
<fc-navbar title="余额中心" theme="gradient" :show-back="true" />
<!-- 余额卡(右上角:余额明细入口) -->
<view class="recharge__hero">
<view class="recharge__hero-entry" @click="goFlows">
<text>余额明细</text>
<text class="recharge__hero-entry-arrow">›</text>
</view>
<text class="recharge__hero-label">账户余额(元)</text>
<text class="recharge__hero-num">{{ assets.balance != null ? assets.balance : '0.00' }}</text>
<text class="recharge__hero-tip">充值后可用于付费发布、会员开通与联系方式解锁</text>
@@ -24,35 +28,44 @@
<text class="recharge__custom-symbol">¥</text>
<input v-model="amount" class="recharge__custom-input" type="digit" placeholder="自定义充值金额(元)" />
</view>
</view>
<!-- 支付方式:充值只支持微信支付(余额「充值」= 用余额给余额加钱,服务端已禁止,防资损) -->
<view class="fc-card">
<text class="recharge__title">支付方式</text>
<view class="recharge__pay">
<view class="recharge__pay-type recharge__pay-type--active">
<image class="fc-icon fc-icon--sm" :src="iconUrl('paywechat')" mode="aspectFit" />
<text class="recharge__pay-text">微信支付</text>
</view>
</view>
<view class="recharge__btn" @click="submit">
<text>立即充值 ¥{{ payAmount }}</text>
</view>
<text class="recharge__note">充值仅支持微信支付,支付成功后余额由微信回调自动入账(通常几秒内到账)。</text>
<text class="recharge__note">微信支付安全付款,支付成功后余额自动到账(通常几秒内)。</text>
</view>
<!-- 支付密码(后台开启「余额支付密码」后显示) -->
<view v-if="payPasswordEnabled" class="fc-card">
<view class="recharge__row" @click="openPayPassword">
<view class="recharge__row-left">
<image class="fc-icon fc-icon--sm" :src="iconUrl('lock')" mode="aspectFit" />
<text class="recharge__row-title">支付密码</text>
</view>
<view class="recharge__row-right">
<text class="recharge__row-value">{{ hasPayPassword ? '已设置' : '未设置' }}</text>
<text class="recharge__row-arrow">›</text>
</view>
</view>
<text class="recharge__note">开启后,余额支付时需验证 6 位支付密码。</text>
</view>
<!-- 支付密码弹窗(设置/修改:旧密码 → 新密码 → 确认新密码) -->
<fc-pay-password :show="pwdPopup.show" :title="pwdPopup.title" :tip="pwdPopup.tip"
@close="pwdPopup.show = false" @confirm="onPwdConfirm" />
</view>
</template>
<script>
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
import FcPayPassword from '@/components/fc-pay-password/fc-pay-password.vue'
import memberApi from '@/common/api/member.js'
import orderApi from '@/common/api/order.js'
import { iconUrl, loadUiConfig } from '@/common/store/ui.js'
import { iconUrl, loadUiConfig, uiState } from '@/common/store/ui.js'
import { pay } from '@/common/utils/pay.js'
import config from '@/common/config/index.js'
export default {
components: { FcNavbar },
components: { FcNavbar, FcPayPassword },
data() {
return {
assets: {},
@@ -64,12 +77,19 @@ export default {
{ value: 1000, tag: '' },
],
amount: '',
// 充值只允许微信支付(服务端 /order/recharge 已禁止 payType=balance,防「用余额给余额加钱」资损)
payType: config.constants.PAY_TYPE.WXPAY,
submitting: false,
// 支付密码
hasPayPassword: false,
pwdPopup: { show: false, title: '', tip: '' },
pwdStep: '', // old / new / confirm
pwdOld: '', // 修改密码时暂存旧密码
pwdTmp: '', // 新密码暂存(两次输入一致性校验)
}
},
computed: {
payPasswordEnabled() {
return !!uiState.payPasswordEnabled
},
/** 待充值金额(展示用,保留两位小数) */
payAmount() {
const n = Number(this.amount)
@@ -89,6 +109,7 @@ export default {
async loadAssets() {
try {
this.assets = await memberApi.assets()
this.hasPayPassword = !!(this.assets && this.assets.hasPayPassword)
} catch (e) {
this.assets = { balance: 0 }
}
@@ -96,6 +117,10 @@ export default {
pickTier(v) {
this.amount = String(v)
},
/** 跳转余额明细页 */
goFlows() {
uni.navigateTo({ url: '/pages/member/flows' })
},
async submit() {
if (this.submitting) return
const num = Number(this.amount)
@@ -109,9 +134,9 @@ export default {
}
this.submitting = true
try {
const res = await orderApi.recharge({ amount: num, payType: this.payType })
const res = await orderApi.recharge({ amount: num, payType: 'wxpay' })
// 微信支付:下单只落 pending,付款后由 /pay/notify 回调入账(余额不会立刻变化)
await pay({ orderNo: res.orderNo, payType: this.payType })
await pay({ orderNo: res.orderNo, payType: 'wxpay' })
await this.loadAssets()
this.amount = ''
uni.showToast({ title: '支付成功,到账略有延迟', icon: 'none' })
@@ -121,6 +146,54 @@ export default {
this.submitting = false
}
},
/* ==================== 支付密码(设置/修改) ==================== */
openPayPassword() {
if (this.hasPayPassword) {
// 修改:先验证旧密码
this.pwdStep = 'old'
this.pwdOld = ''
this.pwdTmp = ''
this.pwdPopup = { show: true, title: '请输入原支付密码', tip: '验证通过后设置新密码' }
} else {
this.pwdStep = 'new'
this.pwdOld = ''
this.pwdTmp = ''
this.pwdPopup = { show: true, title: '设置支付密码', tip: '6 位数字,用于余额支付验证' }
}
},
async onPwdConfirm(password) {
this.pwdPopup.show = false
try {
if (this.pwdStep === 'old') {
// 旧密码验证通过 → 输入新密码
this.pwdOld = password
this.pwdStep = 'new'
this.pwdPopup = { show: true, title: '设置新支付密码', tip: '6 位数字,不能与原密码相同' }
return
}
if (this.pwdStep === 'new') {
this.pwdTmp = password
this.pwdStep = 'confirm'
this.pwdPopup = { show: true, title: '确认新支付密码', tip: '请再次输入相同密码' }
return
}
if (this.pwdStep === 'confirm') {
if (password !== this.pwdTmp) {
uni.showToast({ title: '两次输入不一致,请重试', icon: 'none' })
return
}
await memberApi.setPayPassword({
password,
oldPassword: this.hasPayPassword ? this.pwdOld : undefined,
})
this.hasPayPassword = true
uni.showToast({ title: '支付密码已保存', icon: 'success' })
}
} catch (e) {
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
}
},
},
}
</script>
@@ -130,6 +203,7 @@ export default {
padding-bottom: 60rpx;
}
.recharge__hero {
position: relative;
background: $fc-gradient-hero;
padding: 48rpx 40rpx 60rpx;
border-radius: 0 0 40rpx 40rpx;
@@ -137,6 +211,28 @@ export default {
flex-direction: column;
align-items: center;
}
/* 右上角:余额明细入口(半透明白胶囊,微信零钱同款位置) */
.recharge__hero-entry {
position: absolute;
top: 24rpx;
right: 28rpx;
display: flex;
align-items: center;
padding: 10rpx 22rpx;
border-radius: $fc-radius-pill;
background: rgba(255, 255, 255, 0.85);
font-size: $fc-font-xs;
color: $fc-text-secondary;
&:active {
opacity: 0.7;
}
}
.recharge__hero-entry-arrow {
margin-left: 4rpx;
font-size: 28rpx;
line-height: 1;
color: $fc-text-placeholder;
}
.recharge__hero-label {
color: $fc-text-secondary;
font-weight: 500;
@@ -217,34 +313,6 @@ export default {
font-size: $fc-font-lg;
color: $fc-text;
}
.recharge__pay {
display: flex;
margin-top: 24rpx;
}
.recharge__pay-type {
flex: 1;
height: 80rpx;
border-radius: $fc-radius;
border: 2rpx solid $fc-border;
background: $fc-bg;
display: flex;
align-items: center;
justify-content: center;
font-size: $fc-font-sm;
color: $fc-text-regular;
&:first-child {
margin-right: 16rpx;
}
&--active {
border-color: $fc-primary-text;
background: $fc-primary-lighter;
color: $fc-primary-text;
font-weight: 600;
}
}
.recharge__pay-text {
margin-left: 10rpx;
}
.recharge__btn {
margin-top: 28rpx;
height: 90rpx;
@@ -265,4 +333,37 @@ export default {
color: $fc-text-placeholder;
line-height: $fc-leading;
}
/* 支付密码行 */
.recharge__row {
display: flex;
align-items: center;
justify-content: space-between;
}
.recharge__row-left {
display: flex;
align-items: center;
}
.recharge__row-title {
margin-left: 10rpx;
font-size: $fc-font-base;
color: $fc-text;
font-weight: 500;
}
.recharge__row-right {
display: flex;
align-items: center;
}
.recharge__row-value {
font-size: $fc-font-sm;
color: $fc-text-secondary;
}
.recharge__row-arrow {
margin-left: 8rpx;
font-size: 36rpx;
color: $fc-text-placeholder;
line-height: 1;
}
/* 行标题(支付密码行) */
</style>

查看文件

@@ -176,7 +176,7 @@ export default {
{ iconKey: 'bar-fav-on', text: '我的收藏', url: '/pages/favorite/index' },
{ iconKey: 'mine-follow', text: '我的关注', url: '/pages/favorite/follows' },
{ iconKey: 'mine-order', text: '我的订单', url: '/pages/member/orders' },
{ iconKey: 'link-recharge', text: '余额充值', url: '/pages/member/recharge' },
{ iconKey: 'link-recharge', text: '我的余额', url: '/pages/member/recharge' },
{ iconKey: 'mine-dist', text: '分销中心', url: '/pages/distribution/index' },
{ iconKey: 'shield', text: bizText, action: 'merchant' },
]
@@ -527,7 +527,7 @@ export default {
*/
go(url) {
if (!url) return
const needAuth = ['/pages/post/mine', '/pages/favorite/index', '/pages/favorite/follows', '/pages/member/orders', '/pages/member/recharge', '/pages/distribution/index', '/pages/post/create', '/pages/post/drafts']
const needAuth = ['/pages/post/mine', '/pages/favorite/index', '/pages/favorite/follows', '/pages/member/orders', '/pages/member/recharge', '/pages/member/flows', '/pages/distribution/index', '/pages/post/create', '/pages/post/drafts']
if (needAuth.includes(url) && !this.isLogin) {
this.goLogin()
return

查看文件

@@ -376,6 +376,10 @@
</scroll-view>
</view>
</view>
<!-- 支付密码弹窗(余额支付验证) -->
<fc-pay-password :show="pwdPopup.show" :title="pwdPopup.title" :tip="pwdPopup.tip"
@close="pwdPopup.show = false" @confirm="onPwdConfirm" />
</view>
</template>
@@ -391,16 +395,18 @@
*/
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
import FcAreaPicker from '@/components/fc-area-picker/fc-area-picker.vue'
import FcPayPassword from '@/components/fc-pay-password/fc-pay-password.vue'
import homeApi from '@/common/api/home.js'
import postApi from '@/common/api/post.js'
import memberApi from '@/common/api/member.js'
import { useUserStore } from '@/common/store/index.js'
import { iconUrl, categoryIconUrl, loadUiConfig, requestSubscribe } from '@/common/store/ui.js'
import { iconUrl, categoryIconUrl, loadUiConfig, requestSubscribe, uiState } from '@/common/store/ui.js'
import { pay } from '@/common/utils/pay.js'
import { assetUrl } from '@/common/utils/format.js'
import config from '@/common/config/index.js'
export default {
components: { FcNavbar, FcAreaPicker },
components: { FcNavbar, FcAreaPicker, FcPayPassword },
data() {
return {
categories: [],
@@ -410,6 +416,7 @@ export default {
areaRows: [],
submitting: false,
uploading: false,
pwdPopup: { show: false, title: '', tip: '' },
draftTimer: null,
catDrawerVisible: false,
catDrawerAnim: false,
@@ -589,6 +596,13 @@ export default {
needPay() {
return this.publish.mode === 'paid' && this.form.plan !== 'quota'
},
/**
* 当前选中付费套餐的价格文本(仅用于支付密码弹窗提示)
*/
selectedPlanPrice() {
const plan = this.plans.find((p) => p.key === this.form.plan)
return plan ? String(plan.price).replace(/[¥元]/g, '') : ''
},
/**
* 当前分类对应的常用计价单位
*/
@@ -1116,6 +1130,24 @@ export default {
if (this.form.phone && !/^1\d{10}$/.test(this.form.phone)) return '请输入正确的11位手机号'
return ''
},
/**
* 拉取资产(仅取支付密码状态,失败不阻断流程)
*/
async fetchAssetsSafe() {
try {
return await memberApi.assets()
} catch (e) {
return {}
}
},
/**
* 支付密码弹窗确认(余额支付验证)
* @param {string} password
*/
async onPwdConfirm(password) {
this.pwdPopup.show = false
await this.doSubmit(password)
},
/**
* 提交发布信息
*/
@@ -1131,6 +1163,32 @@ export default {
return
}
// 后台开启支付密码:余额支付发布需先验证(未设置则引导去余额中心设置)
if (this.needPay && this.form.payType === 'balance' && uiState.payPasswordEnabled) {
const assets = await this.fetchAssetsSafe()
if (!assets.hasPayPassword) {
uni.showModal({
title: '需要支付密码',
content: '开启支付密码验证后才能使用余额支付,请先到「余额中心」设置。',
confirmText: '去设置',
success: (r) => {
if (r.confirm) uni.navigateTo({ url: '/pages/member/recharge' })
},
})
return
}
const priceText = this.selectedPlanPrice ? ` · ¥${this.selectedPlanPrice}` : ''
this.pwdPopup = { show: true, title: '请输入支付密码', tip: `发布付费信息${priceText}` }
return
}
await this.doSubmit()
},
/**
* 实际提交(submit 校验通过 / 支付密码验证后调用)
* @param {string} [payPassword] 余额支付密码(开关开启时必传)
*/
async doSubmit(payPassword) {
this.submitting = true
try {
// 订阅消息授权(审核结果);未配置模板时静默跳过
@@ -1141,6 +1199,7 @@ export default {
priceUnit: this.form.isNegotiable ? '面议' : (this.form.priceUnit || '元'),
tags: this.form.tags,
plan: this.form.plan === 'quota' ? 'free' : this.form.plan,
payPassword,
}
const res = await postApi.create(payload)