Jacob
1 天以前 f7034f535b85264e0c5b18e82fc295dab2052304
pages/zone/index.vue
....@@ -14,11 +14,15 @@
1414 <view :style="{ height: marTop + 'px' }"></view>
1515 <yueyangZone ref=yueyangZoneRef v-if="isYueyangZone" :zoneInfo="info" :careBeanRate="careBeanRate"
1616 style="position: relative;z-index: 2;" @goLottery="goLottery" :relationKey="relationKey"></yueyangZone>
17
+ <view v-if="isYueyangZone" class="detail-btn" @click="goDetail">
18
+ <text>消耗明细</text>
19
+ </view>
1720 <view v-else>
1821 <view class="expireTime" v-if="expireTime && expireTime.length">
1922 <text>专区将在</text>
20
- <text v-for="(val, index) in expireTime" :key="index">
21
- <text class="num">{{ val }}</text>{{ expireTimeUnit[index] }}
23
+ <text v-for="(item, index) in expireTime" :key="index">
24
+ <text class="num"><text v-for="(char, ci) in item.digits" :key="ci"
25
+ class="digit">{{ char }}</text></text>{{ item.unit }}
2226 </text>
2327 <text>{{ startOrEnd }}</text>
2428 </view>
....@@ -67,9 +71,10 @@
6771 </view>
6872 </view>
6973 </view>
70
- <view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery">
71
- <image class="lottery_bannerImg"
72
- src="https://ossacmall.bluedeer.com.cn/app/static/images/zone_lotteryBanner.gif" mode="widthFix">
74
+ <view @click="goLottery" class="lottery_banner"
75
+ v-if="info && info.isLottery && info.lotteryBanner && lotteryBannerReady">
76
+ <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix"
77
+ :style="{ height: lotteryBannerHeight }">
7378 </image>
7479 </view>
7580 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -586,7 +591,7 @@
586591 showMenu: false,
587592 selectedMenuArr: [],
588593 expireTime: [],
589
- expireTimeUnit: [],
594
+ countdownToken: 0,
590595 isPageShow: false,
591596 loginBackFn: null,
592597 errText: '',
....@@ -619,6 +624,8 @@
619624 stockEmpty: true,
620625 urlOption: {},
621626 homeTop: '200',
627
+ lotteryBannerHeight: '', //抽奖banner预计算高度(rpx),空字符串表示未取到,按原逻辑自适应
628
+ lotteryBannerReady: false, //是否已拿到banner尺寸(或已确认拿不到),未就绪前不渲染,避免首帧撑高
622629 hasNewPop: false,
623630 leftCoupon: {},
624631 rightCoupon: {},
....@@ -1195,6 +1202,11 @@
11951202 // that.myCareBean = res2.data.totalCareBeans;
11961203 });
11971204 },
1205
+ goDetail() {
1206
+ uni.navigateTo({
1207
+ url: '/pages/consumption/index?zoneId=' + this.info.id
1208
+ })
1209
+ },
11981210 goLottery() {
11991211 let that = this;
12001212 var data = {
....@@ -1288,6 +1300,9 @@
12881300 })
12891301 },
12901302 validAlert(data) {
1303
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1304
+ this.countdownToken++
1305
+ const token = this.countdownToken
12911306 const {
12921307 startTime,
12931308 expireTime
....@@ -1306,17 +1321,17 @@
13061321 let minutes = startTimetamp.getMinutes()
13071322 minutes = minutes < 10 ? '0' + minutes : minutes;
13081323
1309
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1324
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13101325 this.startOrEnd = "后开启"
13111326 return
1312
- }
1313
- }
1314
- if (expireTime) {
1315
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1316
- if (expireTimetamp < nowTimestamp) {
1327
+ }
1328
+ }
1329
+ if (expireTime) {
1330
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1331
+ if (expireTimetamp < nowTimestamp) {
13171332 return
1318
- }
1319
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1333
+ }
1334
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13201335 this.startOrEnd = "后结束"
13211336 }
13221337 },
....@@ -1438,6 +1453,29 @@
14381453 this.$refs.popNewuserRef.show()
14391454 }
14401455 },
1456
+ // 预取抽奖banner真实宽高,计算出高度后再渲染,避免加载前被组件默认高度(225px)撑大
1457
+ setLotteryBannerSize(info) {
1458
+ let that = this
1459
+ that.lotteryBannerHeight = ''
1460
+ that.lotteryBannerReady = false
1461
+ if (!info || !info.isLottery || !info.lotteryBanner) {
1462
+ that.lotteryBannerReady = true
1463
+ return
1464
+ }
1465
+ uni.getImageInfo({
1466
+ src: info.lotteryBanner,
1467
+ success: (img) => {
1468
+ if (img.width > 0 && img.height > 0) {
1469
+ that.lotteryBannerHeight = (690 * img.height / img.width).toFixed(2) + 'rpx'
1470
+ }
1471
+ that.lotteryBannerReady = true
1472
+ },
1473
+ fail: (err) => {
1474
+ console.warn('抽奖banner尺寸预取失败,回退为自适应', err)
1475
+ that.lotteryBannerReady = true
1476
+ }
1477
+ })
1478
+ },
14411479 getZoneDetail: function () {
14421480 let that = this;
14431481 let belong = this.$store.getters.belong;
....@@ -1445,6 +1483,8 @@
14451483 console.log('专区详情入参::', params)
14461484 getZoneDetail(that.id, params).then(res => {
14471485 that.info = res.data;
1486
+ //that.info.zoneType=8;
1487
+ that.setLotteryBannerSize(res.data);
14481488 that.updateZoneShareMenu();
14491489 if (res.data.zoneType == 6) {
14501490 that.setYueyangZone()
....@@ -1454,7 +1494,7 @@
14541494 that.homeTop = that.getHomeTop(0.4)
14551495 }
14561496 that.expireTime = [];
1457
- that.expireTimeUnit = [];
1497
+ that.countdownToken++;
14581498 that.where.page = 1;
14591499 that.getGoodList()
14601500 that.validAlert(res.data)
....@@ -1480,8 +1520,9 @@
14801520 }
14811521 });
14821522 },
1483
- countdownTimer(expireTime, type) {
1523
+ countdownTimer(expireTime, type, token) {
14841524 if (!expireTime) return
1525
+ if (token !== undefined && token !== this.countdownToken) return
14851526 let that = this;
14861527 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
14871528 const endTimestamp = new Date(expireTime).getTime();
....@@ -1493,56 +1534,56 @@
14931534 if (type == 'end') {
14941535 if (diff <= 0) {
14951536 this.expireTime = []
1496
- this.expireTimeUnit = []
14971537 return
14981538 } else { }
14991539 } else if (type == 'start') {
15001540 if (diff <= 0) {
15011541 this.expireTime = []
1502
- this.expireTimeUnit = []
15031542 const expireTime2 = that.info.expireTime
15041543 if (expireTime2) {
15051544 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15061545 if (expireTimetamp < nowTimestamp) {
15071546 return
15081547 }
1509
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1548
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15101549 this.startOrEnd = "后结束"
15111550 }
15121551 return
15131552 }
15141553 }
1554
+ const pad = num => (num < 10 ? '0' + num : String(num))
15151555 const res = []
1516
- const unit = []
15171556 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15181557 diff %= (1000 * 60 * 60 * 24)
1519
- if (days > 0) {
1520
- res.push(days);
1521
- unit.push('日')
1522
- }
15231558 // 转换为小时、分钟、秒
15241559 const hours = Math.floor(diff / (1000 * 60 * 60));
15251560 diff %= (1000 * 60 * 60); // 剩余毫秒数
1526
- if (hours > 0) {
1527
- res.push(hours < 10 ? '0' + hours : hours);
1528
- unit.push('时')
1529
- }
15301561 const minutes = Math.floor(diff / (1000 * 60));
1531
- if (minutes > 0) {
1532
- res.push(minutes < 10 ? '0' + minutes : minutes);
1533
- unit.push('分')
1534
- }
15351562 diff %= (1000 * 60); // 剩余毫秒数
15361563 const seconds = Math.floor(diff / 1000);
1537
- if (seconds > 0) {
1538
- res.push(seconds < 10 ? '0' + seconds : seconds);
1539
- unit.push('秒')
1564
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1565
+ if (days > 0) {
1566
+ res.push({
1567
+ digits: pad(days).split(''),
1568
+ unit: '日'
1569
+ })
15401570 }
1571
+ res.push({
1572
+ digits: pad(hours).split(''),
1573
+ unit: '时'
1574
+ })
1575
+ res.push({
1576
+ digits: pad(minutes).split(''),
1577
+ unit: '分'
1578
+ })
1579
+ res.push({
1580
+ digits: pad(seconds).split(''),
1581
+ unit: '秒'
1582
+ })
15411583 this.expireTime = res
1542
- this.expireTimeUnit = unit
15431584 if (this.isPageShow) {
15441585 setTimeout(() => {
1545
- that.countdownTimer(expireTime, type)
1586
+ that.countdownTimer(expireTime, type, token)
15461587 }, 1000)
15471588 }
15481589 },
....@@ -1629,13 +1670,11 @@
16291670 .lottery_banner {
16301671 margin: 15rpx auto;
16311672 width: 690rpx;
1632
- height: 120rpx;
16331673 text-align: center;
16341674 }
16351675
16361676 .lottery_bannerImg {
16371677 width: 690rpx;
1638
- height: 120rpx;
16391678 }
16401679
16411680 .tag-wrap-container {
....@@ -1834,6 +1873,21 @@
18341873 position: absolute;
18351874 top: 50%;
18361875 transform: translate(0, -50%);
1876
+}
1877
+
1878
+.detail-btn {
1879
+ border: 2rpx solid #fff;
1880
+ border-top-left-radius: 20rpx;
1881
+ border-bottom-left-radius: 20rpx;
1882
+ padding: 10rpx;
1883
+ background-color: #daf2b2;
1884
+ color: #1e984f;
1885
+ width: 50rpx;
1886
+ position: fixed;
1887
+ top: 200rpx;
1888
+ right: 0rpx;
1889
+ line-height: 1rem;
1890
+ z-index: 99;
18371891 }
18381892
18391893 .head_img {
....@@ -2062,11 +2116,22 @@
20622116 padding: 15rpx;
20632117 padding-left: 30rpx;
20642118 color: #979797;
2119
+ font-size: 26rpx;
20652120
20662121 .num {
2122
+ display: inline-block;
20672123 color: #000000;
20682124 background: #FFE20E;
2069
- padding: 0 10rpx;
2125
+ padding: 0 6rpx;
2126
+ margin: 0 4rpx;
2127
+ vertical-align: middle;
2128
+ }
2129
+
2130
+ /* 每个数字固定宽度,避免倒计时跳动时宽度忽长忽短 */
2131
+ .digit {
2132
+ display: inline-block;
2133
+ width: 19rpx;
2134
+ text-align: center;
20702135 }
20712136 }
20722137 </style>