| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719 |
- <template>
- <view class="upgrade-page-wrapper">
- <scroll-view class="page" scroll-y>
- <!-- 当前会员状态卡片 -->
- <view class="status-card">
- <view class="status-badge" :class="isFree ? 'badge-free' : 'badge-family'">
- <text class="badge-icon">{{ isFree ? '○' : '●' }}</text>
- <text class="badge-text">{{ currentLevelName }}</text>
- </view>
- <view class="status-body" v-if="membership && membership.levelCode !== 'FREE'">
- <view class="expiry-row">
- <text class="expiry-label">到期时间</text>
- <text class="expiry-value">{{ formatDate(membership.endDate) }}</text>
- </view>
- <view class="days-remaining" v-if="membership.isActive">
- <text class="days-num">{{ membership.daysRemaining || 0 }}</text>
- <text class="days-unit">天剩余</text>
- </view>
- <view class="expired-msg" v-else>
- <text class="expired-text">会员已过期,续费恢复权益</text>
- </view>
- </view>
- <view class="status-body" v-else>
- <text class="free-hint">当前为免费版,开通家庭会员解锁全部特权</text>
- </view>
- </view>
- <!-- 家庭会员开通卡片 -->
- <view class="upgrade-card" v-if="isFree">
- <view class="upgrade-header">
- <text class="upgrade-title">家庭会员</text>
- <text class="upgrade-subtitle">FAMILY</text>
- </view>
- <view class="upgrade-price">
- <text class="price-symbol">¥</text>
- <text class="price-amount">365</text>
- <text class="price-unit">/年</text>
- </view>
- <view class="feature-list">
- <view class="feature-item" v-for="(feature, idx) in features" :key="idx">
- <text class="feature-check">✓</text>
- <text class="feature-text">{{ feature }}</text>
- </view>
- </view>
- <!-- Coupon section -->
- <view class="coupon-row" @click="openCouponPicker">
- <text class="coupon-row-label">优惠券</text>
- <text v-if="selectedCoupon" class="coupon-row-discount">-{{ formatPriceWithSymbol(selectedCoupon.value) }} {{ selectedCoupon.name }}</text>
- <text v-else class="coupon-row-placeholder">选择优惠券</text>
- <text class="coupon-row-arrow">›</text>
- </view>
- <button class="btn-upgrade" @click="handleUpgrade">立即开通</button>
- </view>
- <!-- 续费卡片 -->
- <view class="upgrade-card" v-else>
- <view class="upgrade-header">
- <text class="upgrade-title">续费会员</text>
- <text class="upgrade-subtitle">保持权益不中断</text>
- </view>
- <view class="upgrade-price">
- <text class="price-symbol">¥</text>
- <text class="price-amount">365</text>
- <text class="price-unit">/年</text>
- </view>
- <!-- Coupon section -->
- <view class="coupon-row" @click="openCouponPicker">
- <text class="coupon-row-label">优惠券</text>
- <text v-if="selectedCoupon" class="coupon-row-discount">-{{ formatPriceWithSymbol(selectedCoupon.value) }} {{ selectedCoupon.name }}</text>
- <text v-else class="coupon-row-placeholder">选择优惠券</text>
- <text class="coupon-row-arrow">›</text>
- </view>
- <button class="btn-upgrade btn-renew" @click="handleRenew">立即续费</button>
- </view>
- <!-- 权益对比表 -->
- <view class="compare-section">
- <text class="section-title">权益对比</text>
- <view class="compare-table">
- <view class="compare-row header-row">
- <text class="compare-cell cell-feature">权益项</text>
- <text class="compare-cell cell-free">免费</text>
- <text class="compare-cell cell-family active">家庭会员</text>
- </view>
- <view class="compare-row" v-for="(item, idx) in compareData" :key="idx">
- <text class="compare-cell cell-feature">{{ item.name }}</text>
- <text class="compare-cell cell-free">{{ item.free }}</text>
- <text class="compare-cell cell-family active">{{ item.family }}</text>
- </view>
- </view>
- </view>
- <!-- 升级记录 -->
- <view class="records-section" v-if="records.length > 0">
- <text class="section-title">升级记录</text>
- <view class="record-item" v-for="record in records" :key="record.id">
- <view class="record-left">
- <text class="record-level">{{ record.levelName }}</text>
- <text class="record-time">{{ formatDate(record.createdAt) }}</text>
- </view>
- <text class="record-amount">{{ formatPriceWithSymbol(record.amount) }}</text>
- </view>
- </view>
- </scroll-view>
- <!-- Coupon Picker Bottom Sheet -->
- <view class="modal-mask" v-if="showCouponPicker" @click="showCouponPicker = false">
- <view class="coupon-picker" @click.stop>
- <view class="picker-header">
- <text class="picker-title">选择优惠券</text>
- <text class="picker-close" @click="showCouponPicker = false">关闭</text>
- </view>
- <scroll-view scroll-y class="picker-list">
- <view
- v-for="coupon in availableCoupons"
- :key="coupon.id"
- class="picker-item"
- :class="selectedCoupon && selectedCoupon.id === coupon.id ? 'picker-item-active' : ''"
- @click="selectCoupon(coupon)"
- >
- <view class="picker-item-left">
- <text class="picker-item-value">{{ formatPriceWithSymbol(coupon.value) }}</text>
- </view>
- <view class="picker-item-right">
- <text class="picker-item-name">{{ coupon.name }}</text>
- <text class="picker-item-condition">{{ getCouponCondition(coupon.minSpend) }}</text>
- </view>
- <view class="picker-item-check" v-if="selectedCoupon && selectedCoupon.id === coupon.id">
- <text>✓</text>
- </view>
- </view>
- <view class="picker-empty" v-if="availableCoupons.length === 0">
- <text>暂无可用优惠券</text>
- </view>
- </scroll-view>
- <view class="picker-footer" v-if="selectedCoupon">
- <button class="picker-btn-remove" @click="removeCoupon">不使用优惠券</button>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { getMyMembership, getMembershipLevels, getUpgradeRecords, upgradeMember, createOrder, getCouponList } from '../../utils/api.js'
- export default {
- data() {
- return {
- membership: null,
- levels: [],
- records: [],
- features: ['折扣购物', '家庭管理', '推荐佣金', '专属活动', '任务特权', '成长报告'],
- isFree: true,
- currentLevelName: '免费用户',
- compareData: [
- { name: '商品折扣', free: '普通价格', family: '会员专享价' },
- { name: '家庭管理', free: '基础功能', family: '全部功能' },
- { name: '推荐佣金', free: '不可参与', family: '最高15%' },
- { name: '专属活动', free: '部分参与', family: '全部参与' },
- { name: '成长报告', free: '月度', family: '每周+深度' },
- { name: '任务配额', free: '每日5个', family: '不限量' }
- ],
- coupons: [],
- selectedCoupon: null,
- showCouponPicker: false
- }
- },
- computed: {
- availableCoupons() {
- var self = this
- return this.coupons.filter(function(c) {
- if (c.status && c.status !== 'AVAILABLE') return false
- if (c.applicableTo && c.applicableTo !== 'ALL' && c.applicableTo !== 'MEMBERSHIP') return false
- return true
- })
- }
- },
- onLoad() {
- this.loadData()
- },
- methods: {
- async loadData() {
- try {
- const membershipRes = await getMyMembership()
- this.membership = membershipRes.data
- if (this.membership && this.membership.levelCode && this.membership.levelCode !== 'FREE') {
- this.isFree = false
- this.currentLevelName = this.membership.levelName || '家庭会员'
- } else {
- this.isFree = true
- this.currentLevelName = '免费用户'
- }
- } catch (e) {
- console.error('加载会员信息失败', e)
- }
- try {
- const levelsRes = await getMembershipLevels()
- this.levels = levelsRes.data || []
- } catch (e) {
- console.error('加载会员等级失败', e)
- }
- try {
- const recordsRes = await getUpgradeRecords()
- if (recordsRes.data && recordsRes.data.records) {
- this.records = recordsRes.data.records
- }
- } catch (e) {
- console.error('加载升级记录失败', e)
- }
- try {
- const couponsRes = await getCouponList()
- this.coupons = couponsRes.data || []
- } catch (e) {
- console.error('加载优惠券失败', e)
- }
- },
- openCouponPicker() {
- if (this.availableCoupons.length === 0 && !this.selectedCoupon) {
- uni.showToast({ title: '暂无可用优惠券', icon: 'none' })
- return
- }
- this.showCouponPicker = true
- },
- selectCoupon(coupon) {
- this.selectedCoupon = coupon
- this.showCouponPicker = false
- },
- removeCoupon() {
- this.selectedCoupon = null
- this.showCouponPicker = false
- },
- getCouponCondition(minSpend) {
- if (!minSpend || minSpend <= 0) return '无门槛'
- return '满' + (minSpend / 100).toFixed(2) + '元可用'
- },
- handleUpgrade() {
- uni.showModal({
- title: '确认开通',
- content: '确认开通家庭会员(¥365.00/年)?',
- success: async (res) => {
- if (!res.confirm) return
- try {
- await upgradeMember('FAMILY')
- uni.showToast({ title: '开通成功', icon: 'success' })
- this.loadData()
- } catch (e) {
- uni.showToast({ title: e.message || '开通失败', icon: 'none' })
- }
- }
- })
- },
- handleRenew() {
- uni.showModal({
- title: '确认续费',
- content: '确认续费家庭会员(¥365.00/年)?',
- success: async (res) => {
- if (!res.confirm) return
- try {
- await upgradeMember('FAMILY')
- uni.showToast({ title: '续费成功', icon: 'success' })
- this.loadData()
- } catch (e) {
- uni.showToast({ title: e.message || '续费失败', icon: 'none' })
- }
- }
- })
- },
- formatDate(date) {
- if (!date) return ''
- var d = new Date(date)
- return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
- }
- }
- }
- </script>
- <style scoped>
- .page {
- min-height: 100vh;
- background: #FFF7ED;
- padding: 30rpx;
- box-sizing: border-box;
- }
- /* ===== 状态卡片 ===== */
- .status-card {
- background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
- border-radius: 20rpx;
- padding: 40rpx;
- margin-bottom: 30rpx;
- }
- .status-badge {
- display: inline-flex;
- align-items: center;
- padding: 10rpx 24rpx;
- border-radius: 9999rpx;
- font-size: 24rpx;
- }
- .badge-free {
- background: rgba(255,255,255,0.2);
- color: #fff;
- }
- .badge-family {
- background: rgba(255,255,255,0.3);
- color: #fff;
- }
- .badge-icon {
- font-size: 20rpx;
- margin-right: 8rpx;
- }
- .badge-text {
- font-weight: 600;
- }
- .status-body {
- margin-top: 24rpx;
- }
- .expiry-row {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .expiry-label {
- font-size: 26rpx;
- color: rgba(255,255,255,0.8);
- }
- .expiry-value {
- font-size: 28rpx;
- color: #fff;
- font-weight: 500;
- }
- .days-remaining {
- display: flex;
- align-items: baseline;
- justify-content: center;
- margin-top: 20rpx;
- }
- .days-num {
- font-size: 56rpx;
- font-weight: bold;
- color: #FEF3C7;
- }
- .days-unit {
- font-size: 26rpx;
- color: rgba(255,255,255,0.7);
- margin-left: 8rpx;
- }
- .expired-msg {
- text-align: center;
- margin-top: 16rpx;
- }
- .expired-text {
- font-size: 26rpx;
- color: #FEF3C7;
- }
- .free-hint {
- font-size: 26rpx;
- color: rgba(255,255,255,0.85);
- text-align: center;
- display: block;
- }
- /* ===== 升级/续费卡片 ===== */
- .upgrade-card {
- background: #FFFFFF;
- border-radius: 20rpx;
- padding: 40rpx;
- margin-bottom: 30rpx;
- box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
- }
- .upgrade-header {
- text-align: center;
- margin-bottom: 20rpx;
- }
- .upgrade-title {
- font-size: 36rpx;
- font-weight: bold;
- color: #1E293B;
- display: block;
- }
- .upgrade-subtitle {
- font-size: 24rpx;
- color: #94A3B8;
- margin-top: 6rpx;
- display: block;
- }
- .upgrade-price {
- text-align: center;
- margin: 24rpx 0;
- }
- .price-symbol {
- font-size: 28rpx;
- color: #F97316;
- vertical-align: top;
- }
- .price-amount {
- font-size: 64rpx;
- font-weight: bold;
- color: #F97316;
- line-height: 1;
- }
- .price-unit {
- font-size: 26rpx;
- color: #94A3B8;
- margin-left: 6rpx;
- }
- .feature-list {
- margin: 24rpx 0;
- }
- .feature-item {
- display: flex;
- align-items: center;
- padding: 12rpx 0;
- }
- .feature-check {
- width: 40rpx;
- height: 40rpx;
- line-height: 40rpx;
- text-align: center;
- background: #F97316;
- color: #fff;
- border-radius: 50%;
- font-size: 22rpx;
- margin-right: 16rpx;
- flex-shrink: 0;
- }
- .feature-text {
- font-size: 28rpx;
- color: #1E293B;
- }
- .btn-upgrade {
- width: 100%;
- height: 88rpx;
- line-height: 88rpx;
- background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
- color: #fff;
- font-size: 32rpx;
- font-weight: 600;
- border-radius: 44rpx;
- margin-top: 20rpx;
- border: none;
- }
- .btn-upgrade::after {
- border: none;
- }
- .btn-upgrade:active {
- opacity: 0.9;
- }
- .btn-renew {
- background: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%);
- }
- /* ===== 权益对比 ===== */
- .compare-section {
- background: #FFFFFF;
- border-radius: 20rpx;
- padding: 30rpx;
- margin-bottom: 30rpx;
- box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
- }
- .section-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #1E293B;
- display: block;
- margin-bottom: 24rpx;
- }
- .compare-table {
- border-radius: 16rpx;
- overflow: hidden;
- border: 1rpx solid #FED7AA;
- }
- .compare-row {
- display: flex;
- border-bottom: 1rpx solid #FED7AA;
- }
- .compare-row:last-child {
- border-bottom: none;
- }
- .header-row {
- background: #FFF7ED;
- }
- .compare-cell {
- flex: 1;
- padding: 20rpx 16rpx;
- font-size: 26rpx;
- text-align: center;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .cell-feature {
- flex: 1.5;
- color: #1E293B;
- font-weight: 500;
- justify-content: flex-start;
- }
- .cell-free {
- color: #94A3B8;
- }
- .cell-family.active {
- color: #F97316;
- font-weight: 600;
- }
- .header-row .compare-cell {
- font-size: 24rpx;
- font-weight: 600;
- color: #64748B;
- }
- .header-row .cell-family.active {
- color: #F97316;
- }
- /* ===== 升级记录 ===== */
- .records-section {
- background: #FFFFFF;
- border-radius: 20rpx;
- padding: 30rpx;
- margin-bottom: 30rpx;
- box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
- }
- .record-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 20rpx 0;
- border-bottom: 1rpx solid #FED7AA;
- }
- .record-item:last-child {
- border-bottom: none;
- }
- .record-left {
- flex: 1;
- }
- .record-level {
- font-size: 28rpx;
- color: #1E293B;
- display: block;
- }
- .record-time {
- font-size: 22rpx;
- color: #94A3B8;
- margin-top: 4rpx;
- display: block;
- }
- .record-amount {
- font-size: 30rpx;
- font-weight: bold;
- color: #F97316;
- }
- /* ===== Coupon Row ===== */
- .coupon-row {
- display: flex;
- align-items: center;
- padding: 24rpx 0;
- border-top: 1rpx solid #f5f5f5;
- margin-top: 16rpx;
- }
- .coupon-row:active {
- opacity: 0.7;
- }
- .coupon-row-label {
- font-size: 26rpx;
- color: #666;
- margin-right: 16rpx;
- }
- .coupon-row-discount {
- flex: 1;
- font-size: 26rpx;
- color: #F97316;
- font-weight: 600;
- text-align: right;
- }
- .coupon-row-placeholder {
- flex: 1;
- font-size: 26rpx;
- color: #ccc;
- text-align: right;
- }
- .coupon-row-arrow {
- font-size: 32rpx;
- color: #ccc;
- margin-left: 8rpx;
- }
- /* ===== Coupon Picker Modal ===== */
- .modal-mask {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: rgba(0,0,0,0.5);
- z-index: 999;
- display: flex;
- align-items: flex-end;
- }
- .coupon-picker {
- background: #fff;
- border-radius: 24rpx 24rpx 0 0;
- width: 100%;
- max-height: 70vh;
- display: flex;
- flex-direction: column;
- }
- .picker-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx;
- border-bottom: 1rpx solid #eee;
- }
- .picker-title {
- font-size: 30rpx;
- font-weight: 600;
- color: #333;
- }
- .picker-close {
- font-size: 26rpx;
- color: #999;
- }
- .picker-list {
- max-height: 50vh;
- padding: 0 20rpx;
- }
- .picker-item {
- display: flex;
- align-items: center;
- padding: 24rpx 16rpx;
- border-bottom: 1rpx solid #f5f5f5;
- }
- .picker-item:active {
- background: #fafafa;
- }
- .picker-item-active {
- background: #FFF7ED;
- }
- .picker-item-left {
- width: 120rpx;
- text-align: center;
- flex-shrink: 0;
- }
- .picker-item-value {
- font-size: 32rpx;
- font-weight: bold;
- color: #F97316;
- }
- .picker-item-right {
- flex: 1;
- margin: 0 16rpx;
- }
- .picker-item-name {
- font-size: 26rpx;
- color: #333;
- display: block;
- margin-bottom: 4rpx;
- }
- .picker-item-condition {
- font-size: 22rpx;
- color: #999;
- }
- .picker-item-check {
- width: 40rpx;
- height: 40rpx;
- background: #F97316;
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- flex-shrink: 0;
- color: #fff;
- font-size: 24rpx;
- font-weight: bold;
- }
- .picker-empty {
- text-align: center;
- padding: 60rpx 0;
- font-size: 26rpx;
- color: #999;
- }
- .picker-footer {
- padding: 20rpx;
- border-top: 1rpx solid #eee;
- }
- .picker-btn-remove {
- background: #f5f5f5;
- color: #666;
- font-size: 26rpx;
- border-radius: 12rpx;
- border: none;
- }
- .picker-btn-remove::after {
- border: none;
- }
- </style>
|