| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806 |
- <template>
- <view class="upgrade-page-wrapper">
- <scroll-view class="page" scroll-y>
- <!-- 当前会员状态条 -->
- <view class="status-card">
- <view class="status-top">
- <view class="status-badge" :class="isFree ? 'badge-free' : 'badge-family'">
- <text class="badge-icon">{{ isFree ? '○' : '●' }}</text>
- <text class="badge-text">{{ currentLevelName }}</text>
- </view>
- <text class="free-hint" v-if="isFree">开通会员解锁全部特权</text>
- <text class="expiry-value" v-else-if="membership && membership.memberLevel !== 'FREE'">
- {{ formatDate(membership.endDate) }} 到期
- </text>
- </view>
- <view class="status-body" v-if="membership && membership.memberLevel !== 'FREE'">
- <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>
- <!-- 等级切换 tabs -->
- <view class="level-tabs" v-if="buyableLevels.length > 0">
- <view class="level-tab" v-for="lv in buyableLevels" :key="lv.levelCode"
- :class="selectedLevel === lv.levelCode ? 'level-tab-active' : ''"
- @click="selectLevel(lv.levelCode)">
- <text class="level-tab-name">{{ lv.levelName }}</text>
- </view>
- </view>
- <!-- 开通/升级/续费卡片(标题统一为所选等级名) -->
- <view class="upgrade-card">
- <view class="upgrade-header">
- <text class="upgrade-title">{{ getSelectedLevelName() }}</text>
- </view>
- <!-- 档位选择 -->
- <view class="period-tabs">
- <view
- class="period-tab"
- v-for="p in visiblePeriods"
- :key="p.key"
- :class="selectedPeriod === p.key ? 'period-tab-active' : ''"
- @click="selectPeriod(p.key)"
- >
- <text class="period-tab-label">{{ p.label }}</text>
- <text class="period-tab-price">¥{{ getPriceForPeriod(p.key) }}</text>
- <text class="period-original" v-if="showOriginalPrice(p.key)">¥{{ getOriginalPriceForPeriod(p.key) / 100 }}</text>
- </view>
- </view>
- <button class="btn-upgrade" @click="goNext">下一步</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" :class="selectedLevel === 'FAMILY' ? 'active' : ''">家庭会员</text>
- <text class="compare-cell cell-premium" :class="selectedLevel === 'PREMIUM' ? '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" :class="selectedLevel === 'FAMILY' ? 'active' : ''">{{ item.family }}</text>
- <text class="compare-cell cell-premium" :class="selectedLevel === 'PREMIUM' ? 'active' : ''">{{ item.premium }}</text>
- </view>
- </view>
- </view>
- <!-- 开通赠券规则 -->
- <view class="join-rules-section" v-if="joinRules.length > 0">
- <text class="section-title">开通赠券</text>
- <view class="join-rule-item" v-for="(rule, idx) in joinRules" :key="getJoinRuleKey(rule, idx)">
- <text class="join-rule-text">加入{{ getLevelName(rule.grantLevelCode) }}会员,赠送{{ rule.grantQuantity || 1 }}张「{{ rule.name }}」</text>
- <text class="join-rule-desc">{{ getCouponDesc(rule) }}</text>
- </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>
- </view>
- </template>
- <script>
- import { getMyMembership, getMembershipPlans, getUpgradeRecords, getJoinCouponRules } from '../../utils/api.js'
- import { parseDate } from '../../utils/format.js'
- export default {
- data() {
- return {
- membership: null,
- levels: [],
- records: [],
- isFree: true,
- currentLevelName: '免费用户',
- compareData: [
- { name: '商品折扣', free: '普通价格', family: '会员折扣', premium: '会员折扣', lifetime: '会员折扣' },
- { name: '家庭管理', free: '基础功能', family: '全部功能', premium: '全部功能+优先响应', lifetime: '全部功能+专属管家' },
- { name: '管家服务', free: '—', family: '—', premium: '每周一次', lifetime: '专属管家7×24h' },
- { name: '推荐佣金', free: '不可参与', family: '可参与', premium: '可参与', lifetime: '可参与' },
- { name: '专属活动', free: '部分参与', family: '全部参与', premium: '优先参与', lifetime: 'VIP专属+定制活动' },
- { name: '成长报告', free: '月度', family: '每周+深度', premium: '每日+深度+专家解读', lifetime: '实时+专家深度解读' },
- { name: '任务配额', free: '每日5个', family: '不限量', premium: '不限量+优先审核', lifetime: '不限量+专属通道' }
- ],
- periods: [
- { key: 'monthly', label: '月度', unit: '/月' },
- { key: 'quarterly', label: '季度', unit: '/季' },
- { key: 'yearly', label: '年度', unit: '/年' }
- ],
- selectedPeriod: 'yearly',
- selectedLevel: 'FAMILY',
- joinRules: [],
- }
- },
- computed: {
- buyableLevels() {
- var self = this
- return this.levels.filter(function(lv) {
- return lv.levelCode !== 'FREE' && lv.levelCode !== 'LIFETIME' && lv.levelCode !== 'PROVIDER'
- })
- },
- visiblePeriods() {
- var self = this
- return this.periods.filter(function(p) {
- if (self.selectedLevel === 'FAMILY') {
- return p.key === 'yearly'
- }
- if (self.selectedLevel === 'BASIC') {
- return p.key === 'monthly'
- }
- if (self.selectedLevel === 'PREMIUM') {
- return p.key === 'monthly' || p.key === 'yearly'
- }
- return true
- })
- }
- },
- onLoad() {
- this.loadData()
- this.loadJoinRules()
- },
- methods: {
- loadJoinRules() {
- var that = this
- getJoinCouponRules().then(function(res) {
- if (res.code === 200) {
- that.joinRules = res.data || []
- }
- }).catch(function(e) {
- console.error('加载开通赠券规则失败', e)
- })
- },
- getLevelName(code) {
- var map = {
- FREE: '免费版',
- BASIC: '体验会员',
- FAMILY: '家庭会员',
- PREMIUM: '高级会员'
- }
- return map[code] || code || ''
- },
- getSelectedLevelName() {
- var name = ''
- for (var i = 0; i < this.levels.length; i++) {
- if (this.levels[i].levelCode === this.selectedLevel) {
- name = this.levels[i].levelName
- break
- }
- }
- return name || this.getLevelName(this.selectedLevel)
- },
- getJoinRuleKey(rule, idx) {
- return rule.id + '-' + idx
- },
- getCouponDesc(item) {
- if (!item) return ''
- if (item.type === 'DISCOUNT') {
- return '折扣券 ' + (item.discountRate / 100).toFixed(1) + '折'
- }
- return '立减 ' + (item.value / 100).toFixed(2) + '元'
- },
- async loadData() {
- try {
- const membershipRes = await getMyMembership()
- this.membership = membershipRes.data
- if (this.membership && this.membership.memberLevel && this.membership.memberLevel !== 'FREE') {
- this.isFree = false
- this.currentLevelName = this.membership.levelName || '家庭会员'
- this.selectedLevel = this.membership.memberLevel
- } else {
- this.isFree = true
- this.currentLevelName = '免费用户'
- this.selectedLevel = 'FAMILY'
- }
- } catch (e) {
- console.error('加载会员信息失败', e)
- }
- try {
- const levelsRes = await getMembershipPlans()
- 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)
- }
- },
- selectLevel: function(code) {
- this.selectedLevel = code
- this.selectedPeriod = 'yearly'
- },
- selectPeriod: function(key) {
- this.selectedPeriod = key
- },
- getPriceForPeriod: function(periodKey) {
- var plan = null
- for (var i = 0; i < this.levels.length; i++) {
- if (this.levels[i].levelCode === this.selectedLevel) {
- plan = this.levels[i]
- break
- }
- }
- if (!plan) return '0'
- if (periodKey === 'monthly') return plan.monthly ? (plan.monthly / 100).toFixed(0) : '0'
- if (periodKey === 'quarterly') return plan.quarterly ? (plan.quarterly / 100).toFixed(0) : '0'
- if (periodKey === 'yearly') return plan.yearly ? (plan.yearly / 100).toFixed(0) : '0'
- return '0'
- },
- goNext: function() {
- var levelCode = this.selectedLevel
- var period = this.selectedPeriod
- uni.navigateTo({ url: '/pages/membership/pay?levelCode=' + levelCode + '&period=' + period })
- },
- getOriginalPriceForPeriod: function(periodKey) {
- var plan = null
- for (var i = 0; i < this.levels.length; i++) {
- if (this.levels[i].levelCode === this.selectedLevel) {
- plan = this.levels[i]
- break
- }
- }
- if (!plan) return null
- if (periodKey === 'monthly') return plan.originalMonthly || null
- if (periodKey === 'quarterly') return plan.originalQuarterly || null
- if (periodKey === 'yearly') return plan.originalYearly || null
- return null
- },
- showOriginalPrice: function(periodKey) {
- var original = this.getOriginalPriceForPeriod(periodKey)
- var current = this.getPriceForPeriod(periodKey)
- if (!original || !current) return false
- return original > current * 100
- },
- formatDate(date) {
- if (!date) return ''
- var d = parseDate(date)
- if (!d) return ''
- 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: 26rpx 30rpx;
- margin-bottom: 24rpx;
- }
- .status-top {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
- .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-lifetime {
- background: linear-gradient(135deg, #8B5CF6 0%, #A855F7 100%);
- color: #fff;
- }
- .badge-icon {
- font-size: 20rpx;
- margin-right: 8rpx;
- }
- .badge-text {
- font-weight: 600;
- }
- .status-body {
- margin-top: 18rpx;
- }
- .expiry-value {
- font-size: 26rpx;
- color: #fff;
- font-weight: 500;
- flex-shrink: 0;
- }
- .days-remaining {
- display: flex;
- align-items: baseline;
- justify-content: center;
- margin-top: 14rpx;
- }
- .days-num {
- font-size: 44rpx;
- font-weight: bold;
- color: #FEF3C7;
- }
- .days-unit {
- font-size: 24rpx;
- color: rgba(255,255,255,0.7);
- margin-left: 8rpx;
- }
- .expired-msg {
- text-align: center;
- margin-top: 12rpx;
- }
- .expired-text {
- font-size: 24rpx;
- color: #FEF3C7;
- }
- .free-hint {
- font-size: 24rpx;
- color: rgba(255,255,255,0.85);
- flex-shrink: 0;
- }
- .lifetime-hint {
- font-size: 26rpx;
- color: #FEF3C7;
- text-align: center;
- display: block;
- font-weight: 500;
- }
- /* ===== 升级/续费卡片 ===== */
- .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;
- }
- .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;
- }
- /* ===== 权益对比 ===== */
- .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 {
- background: #FFEDD5;
- color: #F97316;
- font-weight: 600;
- }
- .cell-premium.active {
- background: #EDE9FE;
- color: #8B5CF6;
- font-weight: 600;
- }
- .cell-lifetime {
- background: #F5F5F5;
- color: #999;
- }
- .cell-lifetime.disabled {
- color: #999;
- }
- .header-row .cell-lifetime {
- background: #F5F5F5;
- color: #999;
- font-weight: 600;
- }
- .header-row .compare-cell {
- font-size: 24rpx;
- font-weight: 600;
- color: #64748B;
- }
- .header-row .cell-family.active {
- background: #FFEDD5;
- color: #F97316;
- }
- .header-row .cell-premium.active {
- background: #EDE9FE;
- color: #8B5CF6;
- }
- /* ===== 等级切换 Tabs ===== */
- .level-tabs {
- display: flex;
- margin-bottom: 30rpx;
- border-radius: 16rpx;
- overflow: hidden;
- border: 2rpx solid #FED7AA;
- }
- .level-tab {
- flex: 1;
- padding: 24rpx;
- text-align: center;
- background: #FFF7ED;
- cursor: pointer;
- }
- .level-tab-active {
- background: #fff;
- border-bottom: 4rpx solid #F97316;
- }
- .level-tab-name {
- font-size: 28rpx;
- font-weight: 600;
- color: #1E293B;
- display: block;
- }
- .level-tab-active .level-tab-name {
- color: #F97316;
- }
- /* ===== 开通赠券 ===== */
- .join-rules-section {
- background: #FFFFFF;
- border-radius: 20rpx;
- padding: 30rpx;
- margin-bottom: 30rpx;
- box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
- }
- .join-rule-item {
- display: flex;
- align-items: center;
- padding: 16rpx 0;
- border-bottom: 1rpx solid #FED7AA;
- }
- .join-rule-item:last-child {
- border-bottom: none;
- }
- .join-rule-text {
- flex: 1;
- font-size: 26rpx;
- color: #1E293B;
- }
- .join-rule-desc {
- font-size: 24rpx;
- color: #F97316;
- font-weight: 600;
- }
- /* ===== 升级记录 ===== */
- .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;
- }
- /* ===== 档位选择 ===== */
- .period-tabs {
- display: flex;
- justify-content: space-between;
- margin: 24rpx 0;
- gap: 16rpx;
- }
- .period-tab {
- flex: 1;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 20rpx 0;
- border: 2rpx solid #FED7AA;
- border-radius: 16rpx;
- background: #FFFBF5;
- }
- .period-tab-active {
- border-color: #F97316;
- background: #FFF7ED;
- }
- .period-tab-label {
- font-size: 26rpx;
- color: #64748B;
- font-weight: 500;
- }
- .period-tab-active .period-tab-label {
- color: #F97316;
- font-weight: 600;
- }
- .period-tab-price {
- font-size: 28rpx;
- font-weight: bold;
- color: #F97316;
- margin-top: 8rpx;
- }
- /* ===== 划线原价 ===== */
- .period-original {
- font-size: 20rpx;
- color: #94A3B8;
- text-decoration: line-through;
- margin-top: 2rpx;
- }
- </style>
|