Jacob
1 天以前 106fc09e267f67bb35a279ed1bf71068a61e73c4
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">
....@@ -513,7 +518,7 @@
513518
514519 <script>
515520 import {
516
- HTTP_REQUEST_URL
521
+ WEB_ACTIVITY_BASE
517522 } from '@/config/app';
518523 import {
519524 mapGetters
....@@ -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 = {
....@@ -1237,11 +1249,7 @@
12371249 this.addTrack('yy_marketPageClick', data);
12381250
12391251 function go() {
1240
- let webUrl = 'https://ossacmall.bluedeer.com.cn/acmall_lottery/index.html'
1241
- if (HTTP_REQUEST_URL.indexOf('tohours') > 0) {
1242
- webUrl = webUrl.replace('https://ossacmall.bluedeer.com.cn',
1243
- 'https://sit.tohours.com/crmeb_web')
1244
- }
1252
+ let webUrl = `${WEB_ACTIVITY_BASE}/acmall_lottery/index.html`
12451253 webUrl += '?token=' +
12461254 that.$store.getters.token + '&unionId=' + that.$store.getters.unionId + '&mdayId=' + that.info
12471255 .mdayId
....@@ -1323,6 +1331,9 @@
13231331 })
13241332 },
13251333 validAlert(data) {
1334
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1335
+ this.countdownToken++
1336
+ const token = this.countdownToken
13261337 const {
13271338 startTime,
13281339 expireTime
....@@ -1341,17 +1352,17 @@
13411352 let minutes = startTimetamp.getMinutes()
13421353 minutes = minutes < 10 ? '0' + minutes : minutes;
13431354
1344
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1355
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13451356 this.startOrEnd = "后开启"
13461357 return
1347
- }
1348
- }
1349
- if (expireTime) {
1350
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1351
- if (expireTimetamp < nowTimestamp) {
1358
+ }
1359
+ }
1360
+ if (expireTime) {
1361
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1362
+ if (expireTimetamp < nowTimestamp) {
13521363 return
1353
- }
1354
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1364
+ }
1365
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13551366 this.startOrEnd = "后结束"
13561367 }
13571368 },
....@@ -1473,6 +1484,29 @@
14731484 this.$refs.popNewuserRef.show()
14741485 }
14751486 },
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
+ },
14761510 getZoneDetail: function () {
14771511 let that = this;
14781512 let belong = this.$store.getters.belong;
....@@ -1480,7 +1514,7 @@
14801514 console.log('专区详情入参::', params)
14811515 getZoneDetail(that.id, params).then(res => {
14821516 that.info = res.data;
1483
- //that.info.zoneType=8;
1517
+ that.setLotteryBannerSize(res.data);
14841518 that.updateZoneShareMenu();
14851519 if (res.data.zoneType == 6) {
14861520 that.setYueyangZone()
....@@ -1490,7 +1524,7 @@
14901524 that.homeTop = that.getHomeTop(0.4)
14911525 }
14921526 that.expireTime = [];
1493
- that.expireTimeUnit = [];
1527
+ that.countdownToken++;
14941528 that.where.page = 1;
14951529 that.getGoodList()
14961530 that.validAlert(res.data)
....@@ -1516,8 +1550,9 @@
15161550 }
15171551 });
15181552 },
1519
- countdownTimer(expireTime, type) {
1553
+ countdownTimer(expireTime, type, token) {
15201554 if (!expireTime) return
1555
+ if (token !== undefined && token !== this.countdownToken) return
15211556 let that = this;
15221557 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
15231558 const endTimestamp = new Date(expireTime).getTime();
....@@ -1529,56 +1564,56 @@
15291564 if (type == 'end') {
15301565 if (diff <= 0) {
15311566 this.expireTime = []
1532
- this.expireTimeUnit = []
15331567 return
15341568 } else { }
15351569 } else if (type == 'start') {
15361570 if (diff <= 0) {
15371571 this.expireTime = []
1538
- this.expireTimeUnit = []
15391572 const expireTime2 = that.info.expireTime
15401573 if (expireTime2) {
15411574 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15421575 if (expireTimetamp < nowTimestamp) {
15431576 return
15441577 }
1545
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1578
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15461579 this.startOrEnd = "后结束"
15471580 }
15481581 return
15491582 }
15501583 }
1584
+ const pad = num => (num < 10 ? '0' + num : String(num))
15511585 const res = []
1552
- const unit = []
15531586 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15541587 diff %= (1000 * 60 * 60 * 24)
1555
- if (days > 0) {
1556
- res.push(days);
1557
- unit.push('日')
1558
- }
15591588 // 转换为小时、分钟、秒
15601589 const hours = Math.floor(diff / (1000 * 60 * 60));
15611590 diff %= (1000 * 60 * 60); // 剩余毫秒数
1562
- if (hours > 0) {
1563
- res.push(hours < 10 ? '0' + hours : hours);
1564
- unit.push('时')
1565
- }
15661591 const minutes = Math.floor(diff / (1000 * 60));
1567
- if (minutes > 0) {
1568
- res.push(minutes < 10 ? '0' + minutes : minutes);
1569
- unit.push('分')
1570
- }
15711592 diff %= (1000 * 60); // 剩余毫秒数
15721593 const seconds = Math.floor(diff / 1000);
1573
- if (seconds > 0) {
1574
- res.push(seconds < 10 ? '0' + seconds : seconds);
1575
- unit.push('秒')
1594
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1595
+ if (days > 0) {
1596
+ res.push({
1597
+ digits: pad(days).split(''),
1598
+ unit: '日'
1599
+ })
15761600 }
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
+ })
15771613 this.expireTime = res
1578
- this.expireTimeUnit = unit
15791614 if (this.isPageShow) {
15801615 setTimeout(() => {
1581
- that.countdownTimer(expireTime, type)
1616
+ that.countdownTimer(expireTime, type, token)
15821617 }, 1000)
15831618 }
15841619 },
....@@ -1665,13 +1700,11 @@
16651700 .lottery_banner {
16661701 margin: 15rpx auto;
16671702 width: 690rpx;
1668
- height: 120rpx;
16691703 text-align: center;
16701704 }
16711705
16721706 .lottery_bannerImg {
16731707 width: 690rpx;
1674
- height: 120rpx;
16751708 }
16761709
16771710 .tag-wrap-container {
....@@ -1870,6 +1903,21 @@
18701903 position: absolute;
18711904 top: 50%;
18721905 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;
18731921 }
18741922
18751923 .head_img {
....@@ -2140,11 +2188,22 @@
21402188 padding: 15rpx;
21412189 padding-left: 30rpx;
21422190 color: #979797;
2191
+ font-size: 26rpx;
21432192
21442193 .num {
2194
+ display: inline-block;
21452195 color: #000000;
21462196 background: #FFE20E;
2147
- 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;
21482207 }
21492208 }
21502209 </style>