Jacob
1 天以前 e6fea61c05d96ed2e6aa1aff9e7026e48b046332
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">
....@@ -495,7 +500,7 @@
495500
496501 <script>
497502 import {
498
- HTTP_REQUEST_URL
503
+ WEB_ACTIVITY_BASE
499504 } from '@/config/app';
500505 import {
501506 mapGetters
....@@ -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 = {
....@@ -1206,11 +1218,7 @@
12061218 this.addTrack('yy_marketPageClick', data);
12071219
12081220 function go() {
1209
- let webUrl = 'https://ossacmall.bluedeer.com.cn/acmall_lottery/index.html'
1210
- if (HTTP_REQUEST_URL.indexOf('tohours') > 0) {
1211
- webUrl = webUrl.replace('https://ossacmall.bluedeer.com.cn',
1212
- 'https://sit.tohours.com/crmeb_web')
1213
- }
1221
+ let webUrl = `${WEB_ACTIVITY_BASE}/acmall_lottery/index.html`
12141222 webUrl += '?token=' +
12151223 that.$store.getters.token + '&unionId=' + that.$store.getters.unionId + '&mdayId=' + that.info
12161224 .mdayId
....@@ -1292,6 +1300,9 @@
12921300 })
12931301 },
12941302 validAlert(data) {
1303
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1304
+ this.countdownToken++
1305
+ const token = this.countdownToken
12951306 const {
12961307 startTime,
12971308 expireTime
....@@ -1310,17 +1321,17 @@
13101321 let minutes = startTimetamp.getMinutes()
13111322 minutes = minutes < 10 ? '0' + minutes : minutes;
13121323
1313
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1324
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13141325 this.startOrEnd = "后开启"
13151326 return
1316
- }
1317
- }
1318
- if (expireTime) {
1319
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1320
- if (expireTimetamp < nowTimestamp) {
1327
+ }
1328
+ }
1329
+ if (expireTime) {
1330
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1331
+ if (expireTimetamp < nowTimestamp) {
13211332 return
1322
- }
1323
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1333
+ }
1334
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13241335 this.startOrEnd = "后结束"
13251336 }
13261337 },
....@@ -1442,6 +1453,29 @@
14421453 this.$refs.popNewuserRef.show()
14431454 }
14441455 },
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
+ },
14451479 getZoneDetail: function () {
14461480 let that = this;
14471481 let belong = this.$store.getters.belong;
....@@ -1449,6 +1483,8 @@
14491483 console.log('专区详情入参::', params)
14501484 getZoneDetail(that.id, params).then(res => {
14511485 that.info = res.data;
1486
+ //that.info.zoneType=8;
1487
+ that.setLotteryBannerSize(res.data);
14521488 that.updateZoneShareMenu();
14531489 if (res.data.zoneType == 6) {
14541490 that.setYueyangZone()
....@@ -1458,7 +1494,7 @@
14581494 that.homeTop = that.getHomeTop(0.4)
14591495 }
14601496 that.expireTime = [];
1461
- that.expireTimeUnit = [];
1497
+ that.countdownToken++;
14621498 that.where.page = 1;
14631499 that.getGoodList()
14641500 that.validAlert(res.data)
....@@ -1484,8 +1520,9 @@
14841520 }
14851521 });
14861522 },
1487
- countdownTimer(expireTime, type) {
1523
+ countdownTimer(expireTime, type, token) {
14881524 if (!expireTime) return
1525
+ if (token !== undefined && token !== this.countdownToken) return
14891526 let that = this;
14901527 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
14911528 const endTimestamp = new Date(expireTime).getTime();
....@@ -1497,56 +1534,56 @@
14971534 if (type == 'end') {
14981535 if (diff <= 0) {
14991536 this.expireTime = []
1500
- this.expireTimeUnit = []
15011537 return
15021538 } else { }
15031539 } else if (type == 'start') {
15041540 if (diff <= 0) {
15051541 this.expireTime = []
1506
- this.expireTimeUnit = []
15071542 const expireTime2 = that.info.expireTime
15081543 if (expireTime2) {
15091544 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15101545 if (expireTimetamp < nowTimestamp) {
15111546 return
15121547 }
1513
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1548
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15141549 this.startOrEnd = "后结束"
15151550 }
15161551 return
15171552 }
15181553 }
1554
+ const pad = num => (num < 10 ? '0' + num : String(num))
15191555 const res = []
1520
- const unit = []
15211556 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15221557 diff %= (1000 * 60 * 60 * 24)
1523
- if (days > 0) {
1524
- res.push(days);
1525
- unit.push('日')
1526
- }
15271558 // 转换为小时、分钟、秒
15281559 const hours = Math.floor(diff / (1000 * 60 * 60));
15291560 diff %= (1000 * 60 * 60); // 剩余毫秒数
1530
- if (hours > 0) {
1531
- res.push(hours < 10 ? '0' + hours : hours);
1532
- unit.push('时')
1533
- }
15341561 const minutes = Math.floor(diff / (1000 * 60));
1535
- if (minutes > 0) {
1536
- res.push(minutes < 10 ? '0' + minutes : minutes);
1537
- unit.push('分')
1538
- }
15391562 diff %= (1000 * 60); // 剩余毫秒数
15401563 const seconds = Math.floor(diff / 1000);
1541
- if (seconds > 0) {
1542
- res.push(seconds < 10 ? '0' + seconds : seconds);
1543
- unit.push('秒')
1564
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1565
+ if (days > 0) {
1566
+ res.push({
1567
+ digits: pad(days).split(''),
1568
+ unit: '日'
1569
+ })
15441570 }
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
+ })
15451583 this.expireTime = res
1546
- this.expireTimeUnit = unit
15471584 if (this.isPageShow) {
15481585 setTimeout(() => {
1549
- that.countdownTimer(expireTime, type)
1586
+ that.countdownTimer(expireTime, type, token)
15501587 }, 1000)
15511588 }
15521589 },
....@@ -1633,13 +1670,11 @@
16331670 .lottery_banner {
16341671 margin: 15rpx auto;
16351672 width: 690rpx;
1636
- height: 120rpx;
16371673 text-align: center;
16381674 }
16391675
16401676 .lottery_bannerImg {
16411677 width: 690rpx;
1642
- height: 120rpx;
16431678 }
16441679
16451680 .tag-wrap-container {
....@@ -1838,6 +1873,21 @@
18381873 position: absolute;
18391874 top: 50%;
18401875 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;
18411891 }
18421892
18431893 .head_img {
....@@ -2066,11 +2116,22 @@
20662116 padding: 15rpx;
20672117 padding-left: 30rpx;
20682118 color: #979797;
2119
+ font-size: 26rpx;
20692120
20702121 .num {
2122
+ display: inline-block;
20712123 color: #000000;
20722124 background: #FFE20E;
2073
- 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;
20742135 }
20752136 }
20762137 </style>