Jacob
4 天以前 bf50dc43351d1a9781a84faf775913e813ea6ecb
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,8 @@
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" v-if="info && info.isLottery && info.lotteryBanner">
93
+ <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix">
9194 </image>
9295 </view>
9396 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -604,7 +607,7 @@
604607 showMenu: false,
605608 selectedMenuArr: [],
606609 expireTime: [],
607
- expireTimeUnit: [],
610
+ countdownToken: 0,
608611 isPageShow: false,
609612 loginBackFn: null,
610613 errText: '',
....@@ -1226,6 +1229,11 @@
12261229 // that.myCareBean = res2.data.totalCareBeans;
12271230 });
12281231 },
1232
+ goDetail() {
1233
+ uni.navigateTo({
1234
+ url: '/pages/consumption/index?zoneId=' + this.info.id
1235
+ })
1236
+ },
12291237 goLottery() {
12301238 let that = this;
12311239 var data = {
....@@ -1319,6 +1327,9 @@
13191327 })
13201328 },
13211329 validAlert(data) {
1330
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1331
+ this.countdownToken++
1332
+ const token = this.countdownToken
13221333 const {
13231334 startTime,
13241335 expireTime
....@@ -1337,17 +1348,17 @@
13371348 let minutes = startTimetamp.getMinutes()
13381349 minutes = minutes < 10 ? '0' + minutes : minutes;
13391350
1340
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1351
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13411352 this.startOrEnd = "后开启"
13421353 return
1343
- }
1344
- }
1345
- if (expireTime) {
1346
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1347
- if (expireTimetamp < nowTimestamp) {
1354
+ }
1355
+ }
1356
+ if (expireTime) {
1357
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1358
+ if (expireTimetamp < nowTimestamp) {
13481359 return
1349
- }
1350
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1360
+ }
1361
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13511362 this.startOrEnd = "后结束"
13521363 }
13531364 },
....@@ -1486,7 +1497,7 @@
14861497 that.homeTop = that.getHomeTop(0.4)
14871498 }
14881499 that.expireTime = [];
1489
- that.expireTimeUnit = [];
1500
+ that.countdownToken++;
14901501 that.where.page = 1;
14911502 that.getGoodList()
14921503 that.validAlert(res.data)
....@@ -1512,8 +1523,9 @@
15121523 }
15131524 });
15141525 },
1515
- countdownTimer(expireTime, type) {
1526
+ countdownTimer(expireTime, type, token) {
15161527 if (!expireTime) return
1528
+ if (token !== undefined && token !== this.countdownToken) return
15171529 let that = this;
15181530 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
15191531 const endTimestamp = new Date(expireTime).getTime();
....@@ -1525,56 +1537,56 @@
15251537 if (type == 'end') {
15261538 if (diff <= 0) {
15271539 this.expireTime = []
1528
- this.expireTimeUnit = []
15291540 return
15301541 } else { }
15311542 } else if (type == 'start') {
15321543 if (diff <= 0) {
15331544 this.expireTime = []
1534
- this.expireTimeUnit = []
15351545 const expireTime2 = that.info.expireTime
15361546 if (expireTime2) {
15371547 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15381548 if (expireTimetamp < nowTimestamp) {
15391549 return
15401550 }
1541
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1551
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15421552 this.startOrEnd = "后结束"
15431553 }
15441554 return
15451555 }
15461556 }
1557
+ const pad = num => (num < 10 ? '0' + num : String(num))
15471558 const res = []
1548
- const unit = []
15491559 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15501560 diff %= (1000 * 60 * 60 * 24)
1551
- if (days > 0) {
1552
- res.push(days);
1553
- unit.push('日')
1554
- }
15551561 // 转换为小时、分钟、秒
15561562 const hours = Math.floor(diff / (1000 * 60 * 60));
15571563 diff %= (1000 * 60 * 60); // 剩余毫秒数
1558
- if (hours > 0) {
1559
- res.push(hours < 10 ? '0' + hours : hours);
1560
- unit.push('时')
1561
- }
15621564 const minutes = Math.floor(diff / (1000 * 60));
1563
- if (minutes > 0) {
1564
- res.push(minutes < 10 ? '0' + minutes : minutes);
1565
- unit.push('分')
1566
- }
15671565 diff %= (1000 * 60); // 剩余毫秒数
15681566 const seconds = Math.floor(diff / 1000);
1569
- if (seconds > 0) {
1570
- res.push(seconds < 10 ? '0' + seconds : seconds);
1571
- unit.push('秒')
1567
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1568
+ if (days > 0) {
1569
+ res.push({
1570
+ digits: pad(days).split(''),
1571
+ unit: '日'
1572
+ })
15721573 }
1574
+ res.push({
1575
+ digits: pad(hours).split(''),
1576
+ unit: '时'
1577
+ })
1578
+ res.push({
1579
+ digits: pad(minutes).split(''),
1580
+ unit: '分'
1581
+ })
1582
+ res.push({
1583
+ digits: pad(seconds).split(''),
1584
+ unit: '秒'
1585
+ })
15731586 this.expireTime = res
1574
- this.expireTimeUnit = unit
15751587 if (this.isPageShow) {
15761588 setTimeout(() => {
1577
- that.countdownTimer(expireTime, type)
1589
+ that.countdownTimer(expireTime, type, token)
15781590 }, 1000)
15791591 }
15801592 },
....@@ -1661,13 +1673,11 @@
16611673 .lottery_banner {
16621674 margin: 15rpx auto;
16631675 width: 690rpx;
1664
- height: 120rpx;
16651676 text-align: center;
16661677 }
16671678
16681679 .lottery_bannerImg {
16691680 width: 690rpx;
1670
- height: 120rpx;
16711681 }
16721682
16731683 .tag-wrap-container {
....@@ -1866,6 +1876,21 @@
18661876 position: absolute;
18671877 top: 50%;
18681878 transform: translate(0, -50%);
1879
+}
1880
+
1881
+.detail-btn {
1882
+ border: 2rpx solid #fff;
1883
+ border-top-left-radius: 20rpx;
1884
+ border-bottom-left-radius: 20rpx;
1885
+ padding: 10rpx;
1886
+ background-color: #daf2b2;
1887
+ color: #1e984f;
1888
+ width: 50rpx;
1889
+ position: fixed;
1890
+ top: 200rpx;
1891
+ right: 0rpx;
1892
+ line-height: 1rem;
1893
+ z-index: 99;
18691894 }
18701895
18711896 .head_img {
....@@ -2136,11 +2161,22 @@
21362161 padding: 15rpx;
21372162 padding-left: 30rpx;
21382163 color: #979797;
2164
+ font-size: 26rpx;
21392165
21402166 .num {
2167
+ display: inline-block;
21412168 color: #000000;
21422169 background: #FFE20E;
2143
- padding: 0 10rpx;
2170
+ padding: 0 6rpx;
2171
+ margin: 0 4rpx;
2172
+ vertical-align: middle;
2173
+ }
2174
+
2175
+ /* 每个数字固定宽度,避免倒计时跳动时宽度忽长忽短 */
2176
+ .digit {
2177
+ display: inline-block;
2178
+ width: 19rpx;
2179
+ text-align: center;
21442180 }
21452181 }
21462182 </style>