Jacob
1 天以前 433c5ab2fd2a6fd48fb931b5070b742503a99a6b
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>
....@@ -85,9 +89,10 @@
8589 </view>
8690 </view>
8791 </view>
88
- <view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery">
89
- <image class="lottery_bannerImg"
90
- src="https://ossacmall.bluedeer.com.cn/app/static/images/zone_lotteryBanner.gif" mode="widthFix">
92
+ <view @click="goLottery" class="lottery_banner"
93
+ v-if="info && info.isLottery && info.lotteryBanner && lotteryBannerReady">
94
+ <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix"
95
+ :style="{ height: lotteryBannerHeight }">
9196 </image>
9297 </view>
9398 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -604,7 +609,7 @@
604609 showMenu: false,
605610 selectedMenuArr: [],
606611 expireTime: [],
607
- expireTimeUnit: [],
612
+ countdownToken: 0,
608613 isPageShow: false,
609614 loginBackFn: null,
610615 errText: '',
....@@ -639,6 +644,8 @@
639644 stockEmpty: true,
640645 urlOption: {},
641646 homeTop: '200',
647
+ lotteryBannerHeight: '', //抽奖banner预计算高度(rpx),空字符串表示未取到,按原逻辑自适应
648
+ lotteryBannerReady: false, //是否已拿到banner尺寸(或已确认拿不到),未就绪前不渲染,避免首帧撑高
642649 hasNewPop: false,
643650 leftCoupon: {},
644651 rightCoupon: {},
....@@ -1226,6 +1233,11 @@
12261233 // that.myCareBean = res2.data.totalCareBeans;
12271234 });
12281235 },
1236
+ goDetail() {
1237
+ uni.navigateTo({
1238
+ url: '/pages/consumption/index?zoneId=' + this.info.id
1239
+ })
1240
+ },
12291241 goLottery() {
12301242 let that = this;
12311243 var data = {
....@@ -1319,6 +1331,9 @@
13191331 })
13201332 },
13211333 validAlert(data) {
1334
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1335
+ this.countdownToken++
1336
+ const token = this.countdownToken
13221337 const {
13231338 startTime,
13241339 expireTime
....@@ -1337,17 +1352,17 @@
13371352 let minutes = startTimetamp.getMinutes()
13381353 minutes = minutes < 10 ? '0' + minutes : minutes;
13391354
1340
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1355
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13411356 this.startOrEnd = "后开启"
13421357 return
1343
- }
1344
- }
1345
- if (expireTime) {
1346
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1347
- if (expireTimetamp < nowTimestamp) {
1358
+ }
1359
+ }
1360
+ if (expireTime) {
1361
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1362
+ if (expireTimetamp < nowTimestamp) {
13481363 return
1349
- }
1350
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1364
+ }
1365
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13511366 this.startOrEnd = "后结束"
13521367 }
13531368 },
....@@ -1469,6 +1484,29 @@
14691484 this.$refs.popNewuserRef.show()
14701485 }
14711486 },
1487
+ // 预取抽奖banner真实宽高,计算出高度后再渲染,避免加载前被组件默认高度(225px)撑大
1488
+ setLotteryBannerSize(info) {
1489
+ let that = this
1490
+ that.lotteryBannerHeight = ''
1491
+ that.lotteryBannerReady = false
1492
+ if (!info || !info.isLottery || !info.lotteryBanner) {
1493
+ that.lotteryBannerReady = true
1494
+ return
1495
+ }
1496
+ uni.getImageInfo({
1497
+ src: info.lotteryBanner,
1498
+ success: (img) => {
1499
+ if (img.width > 0 && img.height > 0) {
1500
+ that.lotteryBannerHeight = (690 * img.height / img.width).toFixed(2) + 'rpx'
1501
+ }
1502
+ that.lotteryBannerReady = true
1503
+ },
1504
+ fail: (err) => {
1505
+ console.warn('抽奖banner尺寸预取失败,回退为自适应', err)
1506
+ that.lotteryBannerReady = true
1507
+ }
1508
+ })
1509
+ },
14721510 getZoneDetail: function () {
14731511 let that = this;
14741512 let belong = this.$store.getters.belong;
....@@ -1476,7 +1514,7 @@
14761514 console.log('专区详情入参::', params)
14771515 getZoneDetail(that.id, params).then(res => {
14781516 that.info = res.data;
1479
- //that.info.zoneType=8;
1517
+ that.setLotteryBannerSize(res.data);
14801518 that.updateZoneShareMenu();
14811519 if (res.data.zoneType == 6) {
14821520 that.setYueyangZone()
....@@ -1486,7 +1524,7 @@
14861524 that.homeTop = that.getHomeTop(0.4)
14871525 }
14881526 that.expireTime = [];
1489
- that.expireTimeUnit = [];
1527
+ that.countdownToken++;
14901528 that.where.page = 1;
14911529 that.getGoodList()
14921530 that.validAlert(res.data)
....@@ -1512,8 +1550,9 @@
15121550 }
15131551 });
15141552 },
1515
- countdownTimer(expireTime, type) {
1553
+ countdownTimer(expireTime, type, token) {
15161554 if (!expireTime) return
1555
+ if (token !== undefined && token !== this.countdownToken) return
15171556 let that = this;
15181557 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
15191558 const endTimestamp = new Date(expireTime).getTime();
....@@ -1525,56 +1564,56 @@
15251564 if (type == 'end') {
15261565 if (diff <= 0) {
15271566 this.expireTime = []
1528
- this.expireTimeUnit = []
15291567 return
15301568 } else { }
15311569 } else if (type == 'start') {
15321570 if (diff <= 0) {
15331571 this.expireTime = []
1534
- this.expireTimeUnit = []
15351572 const expireTime2 = that.info.expireTime
15361573 if (expireTime2) {
15371574 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15381575 if (expireTimetamp < nowTimestamp) {
15391576 return
15401577 }
1541
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1578
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15421579 this.startOrEnd = "后结束"
15431580 }
15441581 return
15451582 }
15461583 }
1584
+ const pad = num => (num < 10 ? '0' + num : String(num))
15471585 const res = []
1548
- const unit = []
15491586 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15501587 diff %= (1000 * 60 * 60 * 24)
1551
- if (days > 0) {
1552
- res.push(days);
1553
- unit.push('日')
1554
- }
15551588 // 转换为小时、分钟、秒
15561589 const hours = Math.floor(diff / (1000 * 60 * 60));
15571590 diff %= (1000 * 60 * 60); // 剩余毫秒数
1558
- if (hours > 0) {
1559
- res.push(hours < 10 ? '0' + hours : hours);
1560
- unit.push('时')
1561
- }
15621591 const minutes = Math.floor(diff / (1000 * 60));
1563
- if (minutes > 0) {
1564
- res.push(minutes < 10 ? '0' + minutes : minutes);
1565
- unit.push('分')
1566
- }
15671592 diff %= (1000 * 60); // 剩余毫秒数
15681593 const seconds = Math.floor(diff / 1000);
1569
- if (seconds > 0) {
1570
- res.push(seconds < 10 ? '0' + seconds : seconds);
1571
- unit.push('秒')
1594
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1595
+ if (days > 0) {
1596
+ res.push({
1597
+ digits: pad(days).split(''),
1598
+ unit: '日'
1599
+ })
15721600 }
1601
+ res.push({
1602
+ digits: pad(hours).split(''),
1603
+ unit: '时'
1604
+ })
1605
+ res.push({
1606
+ digits: pad(minutes).split(''),
1607
+ unit: '分'
1608
+ })
1609
+ res.push({
1610
+ digits: pad(seconds).split(''),
1611
+ unit: '秒'
1612
+ })
15731613 this.expireTime = res
1574
- this.expireTimeUnit = unit
15751614 if (this.isPageShow) {
15761615 setTimeout(() => {
1577
- that.countdownTimer(expireTime, type)
1616
+ that.countdownTimer(expireTime, type, token)
15781617 }, 1000)
15791618 }
15801619 },
....@@ -1661,13 +1700,11 @@
16611700 .lottery_banner {
16621701 margin: 15rpx auto;
16631702 width: 690rpx;
1664
- height: 120rpx;
16651703 text-align: center;
16661704 }
16671705
16681706 .lottery_bannerImg {
16691707 width: 690rpx;
1670
- height: 120rpx;
16711708 }
16721709
16731710 .tag-wrap-container {
....@@ -1866,6 +1903,21 @@
18661903 position: absolute;
18671904 top: 50%;
18681905 transform: translate(0, -50%);
1906
+}
1907
+
1908
+.detail-btn {
1909
+ border: 2rpx solid #fff;
1910
+ border-top-left-radius: 20rpx;
1911
+ border-bottom-left-radius: 20rpx;
1912
+ padding: 10rpx;
1913
+ background-color: #daf2b2;
1914
+ color: #1e984f;
1915
+ width: 50rpx;
1916
+ position: fixed;
1917
+ top: 200rpx;
1918
+ right: 0rpx;
1919
+ line-height: 1rem;
1920
+ z-index: 99;
18691921 }
18701922
18711923 .head_img {
....@@ -2136,11 +2188,22 @@
21362188 padding: 15rpx;
21372189 padding-left: 30rpx;
21382190 color: #979797;
2191
+ font-size: 26rpx;
21392192
21402193 .num {
2194
+ display: inline-block;
21412195 color: #000000;
21422196 background: #FFE20E;
2143
- padding: 0 10rpx;
2197
+ padding: 0 6rpx;
2198
+ margin: 0 4rpx;
2199
+ vertical-align: middle;
2200
+ }
2201
+
2202
+ /* 每个数字固定宽度,避免倒计时跳动时宽度忽长忽短 */
2203
+ .digit {
2204
+ display: inline-block;
2205
+ width: 19rpx;
2206
+ text-align: center;
21442207 }
21452208 }
21462209 </style>