Files
lucky_shop/pages_tool/member/level.vue
ZF sun 2e535b9d93 refactor(member pages): unify onShow login redirect logic
1. extract common onShow login check to dedicated method redirectTologinOnShowLifecycle
2. add fallback callback for login failure to navigate back on wechat mini program
3. update all page login redirect calls to use the new unified method
4. add debug logs for redirect and auth flow tracing
2026-06-27 18:25:53 +08:00

368 lines
13 KiB
Vue

<template>
<view :style="themeColor" class="member-level">
<view class="level-top">
<image :src="$util.img('public/uniapp/level/level-top-bg.png')"></image>
</view>
<view class="banner-container">
<view class="memberInfo" v-if="memberInfo">
<image :src="$util.img(memberInfo.headimg)" v-if="memberInfo.headimg" @error="memberInfo.headimg = $util.getDefaultImage().head" mode="aspectFill" show-menu-by-longpress></image>
<image :src="$util.getDefaultImage().head" v-else mode="aspectFill" show-menu-by-longpress></image>
<view class="member-desc">
<view class="font-size-base">{{ memberInfo.nickname }}</view>
<view class="font-size-activity-tag">{{ $lang('currentLevelLabel') }}{{ memberInfo.member_level_name }}</view>
</view>
<view class="growth-rules font-size-tag" @click="growthRules">
<text class="iconfont icon-wenhao font-size-tag"></text>
{{ $lang('growthRules') }}
</view>
</view>
<swiper :style="{ width: '100vw', height: '390rpx' }" class="margin-bottom"
:indicator-dots="swiperConfig.indicatorDots" :indicator-color="swiperConfig.indicatorColor"
:indicator-active-color="swiperConfig.indicatorActiveColor" :autoplay="false"
:interval="swiperConfig.interval" :duration="swiperConfig.duration" :circular="swiperConfig.circular"
:previous-margin="swiperConfig.previousMargin" :next-margin="swiperConfig.nextMargin"
@change="swiperChange" @animationfinish="animationfinish" :current="curIndex">
<swiper-item :class="levelList.length == 1 ? 'image-container-box' : ''" v-for="(item, i) in levelList"
:key="i">
<view class="image-container" :class="[
curIndex === 0
? i === listLen - 1
? 'item-left'
: i === 1
? 'item-right'
: 'item-center'
: curIndex === listLen - 1
? i === 0
? 'item-right'
: i === listLen - 2
? 'item-left'
: 'item-center'
: i === curIndex - 1
? 'item-left'
: i === curIndex + 1
? 'item-right'
: 'item-center'
]">
<view class="slide-image" style="background-size: 100% 100%;background-repeat:no-repeat" :style="{
transform: curIndex === i ? 'scale(' + scaleX + ',' + scaleY + ')' : 'scale(1,1)',
transitionDuration: '.3s',
transitionTimingFunction: 'ease'
}">
<image v-if="levelList[curIndex]['level_picture']" :src="$util.img(levelList[curIndex]['level_picture'])" show-menu-by-longpress/>
<image v-else :style="{backgroundColor:levelList[curIndex]['bg_color']}"/>
<view class="info">
<view class="level-detail" :style="{color:levelList[curIndex]['level_text_color']}">
{{ levelList[curIndex].level_name }}
<text class="isnow " :style="{color:levelList[curIndex]['level_text_color']}" v-if="levelId == item.level_id">{{ $lang('currentLevelTag') }}</text>
</view>
<view class="growr-name" :style="{color:levelList[curIndex]['level_text_color']}">{{ $lang('currentGrowthValue') }}</view>
<view class="growr-value" :style="{color:levelList[curIndex]['level_text_color']}">{{ growth }}</view>
<block v-if="levelId == item.level_id">
<block v-if="levelList[curIndex + 1] != undefined">
<ns-progress :progress="levelList[curIndex + 1].rate"></ns-progress>
<view class="residue-growr-value"
:style="{color:levelList[curIndex]['level_text_color']}">
{{ $lang('growthToNextLevel', { needGrowth: levelList[curIndex + 1].needGrowth > 0 ? levelList[curIndex + 1].needGrowth : 0, levelName: levelList[curIndex + 1].level_name }) }}
</view>
</block>
<block v-else>
<view class="residue-growr-value" :style="{color:levelList[curIndex]['level_text_color']}">{{ $lang('maxLevelReached') }}</view>
</block>
</block>
<block v-else>
<ns-progress :progress="levelList[curIndex].rate" v-if="levelList[curIndex].needGrowth > 0"></ns-progress>
<view class="residue-growr-value" v-if="levelList[curIndex].needGrowth > 0" :style="{color:levelList[curIndex]['level_text_color']}">
{{ $lang('growthToNextLevel', { needGrowth: levelList[curIndex].needGrowth, levelName: levelList[curIndex].level_name }) }}
</view>
</block>
</view>
</view>
</view>
</swiper-item>
</swiper>
<view class="member-equity" v-if="levelList[curIndex].is_free_shipping > 0 || levelList[curIndex].consume_discount > 0 || levelList[curIndex].point_feedback > 0">
<view class="equity-title">{{ $lang('memberBenefits') }}</view>
<view class="equity-itme" v-if="levelList[curIndex].is_free_shipping > 0">
<image :src="$util.img('public/uniapp/level/exemption_postage.png')" mode="aspectFit" show-menu-by-longpress></image>
<view class="equity-content" :class="{ active: levelList[curIndex].consume_discount > 0 }">
<text>{{ $lang('freeShipping') }}</text>
<text class="equity-desc">{{ $lang('freeShippingDesc') }}</text>
</view>
</view>
<view class="equity-itme" v-if="levelList[curIndex].consume_discount > 0">
<image :src="$util.img('public/uniapp/level/consumption_discount.png')" mode="aspectFit" show-menu-by-longpress></image>
<view class="equity-content" :class="{ active: levelList[curIndex].point_feedback > 0 }">
<text>{{ $lang('consumptionDiscount') }}</text>
<text class="equity-desc" v-if="levelList[curIndex].is_default == 1">{{ $lang('noDiscountDesc') }}</text>
<text class="equity-desc" v-else>{{ $lang('discountDescWithValue', { discount: levelList[curIndex].consume_discount }) }}</text>
</view>
</view>
<view class="equity-itme" v-if="levelList[curIndex].point_feedback > 0">
<image :src="$util.img('public/uniapp/level/integral_feedback.png')" mode="aspectFit" show-menu-by-longpress></image>
<view class="equity-content">
<text>{{ $lang('pointsReward') }}</text>
<text class="equity-desc">{{ $lang('pointsRewardDesc', { multiplier: levelList[curIndex].point_feedback }) }}</text>
</view>
</view>
</view>
<view class="member-gift" v-if="levelList[curIndex].send_balance > 0 || levelList[curIndex].send_balance > 0 || levelList[curIndex].send_coupon">
<view class="gift-title">{{ $lang('memberGift') }}</view>
<view class="gift-itme" v-if="levelList[curIndex].send_point > 0">
<image :src="$util.img('public/uniapp/level/integral.png')" mode="aspectFit" show-menu-by-longpress></image>
<view class="gift-content" :class="{ active: levelList[curIndex].send_balance > 0 }">
<text>{{ $lang('pointsGift') }}</text>
<text class="gift-desc">{{ $lang('giftPoints', { points: levelList[curIndex].send_point }) }}</text>
</view>
</view>
<view class="gift-itme" v-if="levelList[curIndex].send_balance > 0">
<image :src="$util.img('public/uniapp/level/red_packet.png')" mode="aspectFit" show-menu-by-longpress></image>
<view class="gift-content" :class="{ active: levelList[curIndex].send_coupon }">
<text>{{ $lang('redPacketGift') }}</text>
<text class="gift-desc">{{ $lang('giftRedPacket', { amount: levelList[curIndex].send_balance }) }}</text>
</view>
</view>
<view class="gift-itme" v-if="levelList[curIndex].send_coupon" @click="openCoupon(levelList[curIndex].send_coupon)">
<image :src="$util.img('public/uniapp/level/coupon.png')" mode="aspectFit" show-menu-by-longpress></image>
<view class="gift-content">
<text>{{ $lang('couponGift') }}</text>
<text class="gift-desc">{{ $lang('giftCoupons', { count: levelList[curIndex].coupon_length }) }}</text>
</view>
</view>
</view>
</view>
<!-- 优惠券 -->
<uni-popup ref="couponPopup" type="bottom">
<view class="coupon-popup-box">
<view class="coupon-popup-title" @click="closeCoupon">
{{ $lang('coupons') }}
<text class="iconfont icon-close"></text>
</view>
<scroll-view class="coupon-popup-content" scroll-y>
<view class="coupon-item" v-for="(item, index) in couponPopList" :key="index">
<view class="coupon-name">
<text class="name">{{ item.coupon_name }}</text>
<text class="desc"></text>
</view>
<view class="coupon-price" v-if="item.type == 'reward'">
<text>{{ item.money }}</text>
{{ $lang('yuan') }}
</view>
<view class="coupon-price" v-if="item.type == 'discount'">
<text>{{ $util.numberFixed(item.discount, 1) }}</text>
{{ $lang('zhe') }}
</view>
</view>
</scroll-view>
</view>
</uni-popup>
<to-top v-if="showTop" @toTop="scrollToTopNative()"></to-top>
<loading-cover ref="loadingCover"></loading-cover>
<ns-login ref="login"></ns-login>
</view>
</template>
<script>
import scroll from '@/common/js/scroll-view.js';
export default {
mixins: [scroll],
data() {
return {
couponPopList: [],
curIndex: 0,
descIndex: 0,
isDescAnimating: false,
scaleX: (634 / 540).toFixed(4),
scaleY: (378 / 330).toFixed(4),
swiperConfig: {
indicatorDots: false,
indicatorColor: 'rgba(255, 255, 255, .4)',
indicatorActiveColor: 'rgba(255, 255, 255, 1)',
interval: 3000,
duration: 300,
circular: false,
previousMargin: '58rpx',
nextMargin: '58rpx'
},
levelList: [{
needGrowth: 0,
growth: 0
}],
levelId: 0,
growth: 0,
nowIndex: 0, //我当前所在等级的index
rule: [] //成长值规则
};
},
computed: {
listLen() {
return this.levelList.length;
},
remark() {
if (this.levelList[this.curIndex]) {
return this.levelList[this.curIndex].remark;
}
},
nextIndex() {
let num = 0;
if (this.curIndex == this.levelList.length - 1) {
return this.curIndex;
} else {
return this.curIndex + 1;
}
}
},
onShow() {
if (!this.storeToken) {
this.redirectTologinOnShowLifecycle('/pages_tool/member/level');
return;
}
this.getLevelRule();
this.getLevelList();
// #ifdef MP-ALIPAY
this.scaleX = 1
this.scaleY = 1
// #endif
},
filters: {
rate(index, list, growth) {
let nowGrowth = Number(growth);
let minGrouth = Number(list[index].growth);
if (index == list.length - 1) {
return nowGrowth > minGrouth ? 100 : 0;
} else {
let maxGrouth = Number(list[index + 1].growth);
let num2 = nowGrowth - minGrouth;
let num1 = maxGrouth - minGrouth;
let num = Math.floor((num2 / num1) * 100);
return num > 100 ? 100 : num;
}
}
},
methods: {
swiperChange(e) {
let that = this;
this.curIndex = e.detail.current;
this.isDescAnimating = true;
let timer = setTimeout(function() {
that.descIndex = e.detail.current;
clearTimeout(timer);
}, 150);
},
animationfinish(e) {
this.isDescAnimating = false;
},
getBannerDetail(index) {
uni.showLoading({
title: this.$lang('navigatingToDetail'),
duration: 2000,
mask: true
});
},
getLevelList() {
this.$api.sendRequest({
url: '/api/memberlevel/lists',
success: res => {
if (res.data && res.code == 0) {
this.levelList = res.data;
for (var i = 0; i < this.levelList.length; i++) {
if (this.levelList[i].send_coupon) {
this.levelList[i].coupon_length = this.levelList[i].send_coupon.split(',')
.length;
}
}
this.levelId = this.memberInfo.member_level;
this.growth = this.memberInfo.growth;
for (let i = 0; i < this.levelList.length; i++) {
if (this.levelList[i].level_id == this.levelId) {
this.curIndex = i;
this.descIndex = i;
this.nowIndex = i;
break;
}
}
this.levelList.forEach((v, i) => {
if (parseFloat(v.growth) < parseFloat(this.growth)) {
v.needGrowth = 0;
v.rate = 100;
} else {
v.needGrowth = (parseFloat(v.growth) - parseFloat(this.growth))
.toFixed(2);
v.rate = (this.growth / v.growth).toFixed(2) * 100;
}
});
this.levelList.forEach(v => {
if (v.consume_discount) {
v.consume_discount = (v.consume_discount / 10).toFixed(2);
}
});
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
} else {
this.$util.showToast({
title: res.message
});
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
}
}
});
},
getLevelRule() {
this.$api.sendRequest({
url: '/api/member/accountrule',
success: res => {
if (res.code == 0 && res.data && res.data.growth) {
this.rule = res.data.growth;
}
}
});
},
growthRules() {
this.$util.redirectTo('/pages_tool/member/level_growth_rules');
},
openCoupon(data) {
this.couponPopList = [];
this.$api.sendRequest({
url: '/coupon/api/coupon/couponbyid',
data: {
id: data
},
success: res => {
if (res.code >= 0) {
this.couponPopList = res.data;
}
}
});
this.$refs.couponPopup.open();
},
closeCoupon() {
this.$refs.couponPopup.close();
}
},
onBackPress(options) {
if (options.from === 'navigateBack') {
return false;
}
this.$util.redirectTo(this.$util.MEMBER_PAGE_URL);
return true;
},
watch: {
storeToken: function(nVal, oVal) {
if (nVal) {
this.getLevelList();
}
}
}
};
</script>
<style lang="scss">
@import './public/css/level.scss';
</style>