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,8 @@
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" v-if="info && info.isLottery && info.lotteryBanner">
75
+ <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix">
7376 </image>
7477 </view>
7578 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -586,7 +589,7 @@
586589 showMenu: false,
587590 selectedMenuArr: [],
588591 expireTime: [],
589
- expireTimeUnit: [],
592
+ countdownToken: 0,
590593 isPageShow: false,
591594 loginBackFn: null,
592595 errText: '',
....@@ -1195,6 +1198,11 @@
11951198 // that.myCareBean = res2.data.totalCareBeans;
11961199 });
11971200 },
1201
+ goDetail() {
1202
+ uni.navigateTo({
1203
+ url: '/pages/consumption/index?zoneId=' + this.info.id
1204
+ })
1205
+ },
11981206 goLottery() {
11991207 let that = this;
12001208 var data = {
....@@ -1288,6 +1296,9 @@
12881296 })
12891297 },
12901298 validAlert(data) {
1299
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1300
+ this.countdownToken++
1301
+ const token = this.countdownToken
12911302 const {
12921303 startTime,
12931304 expireTime
....@@ -1306,17 +1317,17 @@
13061317 let minutes = startTimetamp.getMinutes()
13071318 minutes = minutes < 10 ? '0' + minutes : minutes;
13081319
1309
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1320
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13101321 this.startOrEnd = "后开启"
13111322 return
1312
- }
1313
- }
1314
- if (expireTime) {
1315
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1316
- if (expireTimetamp < nowTimestamp) {
1323
+ }
1324
+ }
1325
+ if (expireTime) {
1326
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1327
+ if (expireTimetamp < nowTimestamp) {
13171328 return
1318
- }
1319
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1329
+ }
1330
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13201331 this.startOrEnd = "后结束"
13211332 }
13221333 },
....@@ -1454,7 +1465,7 @@
14541465 that.homeTop = that.getHomeTop(0.4)
14551466 }
14561467 that.expireTime = [];
1457
- that.expireTimeUnit = [];
1468
+ that.countdownToken++;
14581469 that.where.page = 1;
14591470 that.getGoodList()
14601471 that.validAlert(res.data)
....@@ -1480,8 +1491,9 @@
14801491 }
14811492 });
14821493 },
1483
- countdownTimer(expireTime, type) {
1494
+ countdownTimer(expireTime, type, token) {
14841495 if (!expireTime) return
1496
+ if (token !== undefined && token !== this.countdownToken) return
14851497 let that = this;
14861498 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
14871499 const endTimestamp = new Date(expireTime).getTime();
....@@ -1493,56 +1505,56 @@
14931505 if (type == 'end') {
14941506 if (diff <= 0) {
14951507 this.expireTime = []
1496
- this.expireTimeUnit = []
14971508 return
14981509 } else { }
14991510 } else if (type == 'start') {
15001511 if (diff <= 0) {
15011512 this.expireTime = []
1502
- this.expireTimeUnit = []
15031513 const expireTime2 = that.info.expireTime
15041514 if (expireTime2) {
15051515 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15061516 if (expireTimetamp < nowTimestamp) {
15071517 return
15081518 }
1509
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1519
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15101520 this.startOrEnd = "后结束"
15111521 }
15121522 return
15131523 }
15141524 }
1525
+ const pad = num => (num < 10 ? '0' + num : String(num))
15151526 const res = []
1516
- const unit = []
15171527 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15181528 diff %= (1000 * 60 * 60 * 24)
1519
- if (days > 0) {
1520
- res.push(days);
1521
- unit.push('日')
1522
- }
15231529 // 转换为小时、分钟、秒
15241530 const hours = Math.floor(diff / (1000 * 60 * 60));
15251531 diff %= (1000 * 60 * 60); // 剩余毫秒数
1526
- if (hours > 0) {
1527
- res.push(hours < 10 ? '0' + hours : hours);
1528
- unit.push('时')
1529
- }
15301532 const minutes = Math.floor(diff / (1000 * 60));
1531
- if (minutes > 0) {
1532
- res.push(minutes < 10 ? '0' + minutes : minutes);
1533
- unit.push('分')
1534
- }
15351533 diff %= (1000 * 60); // 剩余毫秒数
15361534 const seconds = Math.floor(diff / 1000);
1537
- if (seconds > 0) {
1538
- res.push(seconds < 10 ? '0' + seconds : seconds);
1539
- unit.push('秒')
1535
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1536
+ if (days > 0) {
1537
+ res.push({
1538
+ digits: pad(days).split(''),
1539
+ unit: '日'
1540
+ })
15401541 }
1542
+ res.push({
1543
+ digits: pad(hours).split(''),
1544
+ unit: '时'
1545
+ })
1546
+ res.push({
1547
+ digits: pad(minutes).split(''),
1548
+ unit: '分'
1549
+ })
1550
+ res.push({
1551
+ digits: pad(seconds).split(''),
1552
+ unit: '秒'
1553
+ })
15411554 this.expireTime = res
1542
- this.expireTimeUnit = unit
15431555 if (this.isPageShow) {
15441556 setTimeout(() => {
1545
- that.countdownTimer(expireTime, type)
1557
+ that.countdownTimer(expireTime, type, token)
15461558 }, 1000)
15471559 }
15481560 },
....@@ -1629,13 +1641,11 @@
16291641 .lottery_banner {
16301642 margin: 15rpx auto;
16311643 width: 690rpx;
1632
- height: 120rpx;
16331644 text-align: center;
16341645 }
16351646
16361647 .lottery_bannerImg {
16371648 width: 690rpx;
1638
- height: 120rpx;
16391649 }
16401650
16411651 .tag-wrap-container {
....@@ -1834,6 +1844,21 @@
18341844 position: absolute;
18351845 top: 50%;
18361846 transform: translate(0, -50%);
1847
+}
1848
+
1849
+.detail-btn {
1850
+ border: 2rpx solid #fff;
1851
+ border-top-left-radius: 20rpx;
1852
+ border-bottom-left-radius: 20rpx;
1853
+ padding: 10rpx;
1854
+ background-color: #daf2b2;
1855
+ color: #1e984f;
1856
+ width: 50rpx;
1857
+ position: fixed;
1858
+ top: 200rpx;
1859
+ right: 0rpx;
1860
+ line-height: 1rem;
1861
+ z-index: 99;
18371862 }
18381863
18391864 .head_img {
....@@ -2062,11 +2087,22 @@
20622087 padding: 15rpx;
20632088 padding-left: 30rpx;
20642089 color: #979797;
2090
+ font-size: 26rpx;
20652091
20662092 .num {
2093
+ display: inline-block;
20672094 color: #000000;
20682095 background: #FFE20E;
2069
- padding: 0 10rpx;
2096
+ padding: 0 6rpx;
2097
+ margin: 0 4rpx;
2098
+ vertical-align: middle;
2099
+ }
2100
+
2101
+ /* 每个数字固定宽度,避免倒计时跳动时宽度忽长忽短 */
2102
+ .digit {
2103
+ display: inline-block;
2104
+ width: 19rpx;
2105
+ text-align: center;
20702106 }
20712107 }
20722108 </style>