| .. | .. |
|---|
| 14 | 14 | <view :style="{ height: marTop + 'px' }"></view> |
|---|
| 15 | 15 | <yueyangZone ref=yueyangZoneRef v-if="isYueyangZone" :zoneInfo="info" :careBeanRate="careBeanRate" |
|---|
| 16 | 16 | 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> |
|---|
| 17 | 20 | <view v-else> |
|---|
| 18 | 21 | <view class="expireTime" v-if="expireTime && expireTime.length"> |
|---|
| 19 | 22 | <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 }} |
|---|
| 22 | 26 | </text> |
|---|
| 23 | 27 | <text>{{ startOrEnd }}</text> |
|---|
| 24 | 28 | </view> |
|---|
| .. | .. |
|---|
| 85 | 89 | </view> |
|---|
| 86 | 90 | </view> |
|---|
| 87 | 91 | </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"> |
|---|
| 91 | 94 | </image> |
|---|
| 92 | 95 | </view> |
|---|
| 93 | 96 | <view class="tag-img-container" v-if="info.zoneType == 7"> |
|---|
| .. | .. |
|---|
| 604 | 607 | showMenu: false, |
|---|
| 605 | 608 | selectedMenuArr: [], |
|---|
| 606 | 609 | expireTime: [], |
|---|
| 607 | | - expireTimeUnit: [], |
|---|
| 610 | + countdownToken: 0, |
|---|
| 608 | 611 | isPageShow: false, |
|---|
| 609 | 612 | loginBackFn: null, |
|---|
| 610 | 613 | errText: '', |
|---|
| .. | .. |
|---|
| 1226 | 1229 | // that.myCareBean = res2.data.totalCareBeans; |
|---|
| 1227 | 1230 | }); |
|---|
| 1228 | 1231 | }, |
|---|
| 1232 | + goDetail() { |
|---|
| 1233 | + uni.navigateTo({ |
|---|
| 1234 | + url: '/pages/consumption/index?zoneId=' + this.info.id |
|---|
| 1235 | + }) |
|---|
| 1236 | + }, |
|---|
| 1229 | 1237 | goLottery() { |
|---|
| 1230 | 1238 | let that = this; |
|---|
| 1231 | 1239 | var data = { |
|---|
| .. | .. |
|---|
| 1319 | 1327 | }) |
|---|
| 1320 | 1328 | }, |
|---|
| 1321 | 1329 | validAlert(data) { |
|---|
| 1330 | + // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动 |
|---|
| 1331 | + this.countdownToken++ |
|---|
| 1332 | + const token = this.countdownToken |
|---|
| 1322 | 1333 | const { |
|---|
| 1323 | 1334 | startTime, |
|---|
| 1324 | 1335 | expireTime |
|---|
| .. | .. |
|---|
| 1337 | 1348 | let minutes = startTimetamp.getMinutes() |
|---|
| 1338 | 1349 | minutes = minutes < 10 ? '0' + minutes : minutes; |
|---|
| 1339 | 1350 | |
|---|
| 1340 | | - this.countdownTimer(startTime.split('-').join('/'), 'start') |
|---|
| 1351 | + this.countdownTimer(startTime.split('-').join('/'), 'start', token) |
|---|
| 1341 | 1352 | this.startOrEnd = "后开启" |
|---|
| 1342 | 1353 | 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) { |
|---|
| 1348 | 1359 | return |
|---|
| 1349 | | - } |
|---|
| 1350 | | - this.countdownTimer(expireTime.split('-').join('/'), 'end') |
|---|
| 1360 | + } |
|---|
| 1361 | + this.countdownTimer(expireTime.split('-').join('/'), 'end', token) |
|---|
| 1351 | 1362 | this.startOrEnd = "后结束" |
|---|
| 1352 | 1363 | } |
|---|
| 1353 | 1364 | }, |
|---|
| .. | .. |
|---|
| 1486 | 1497 | that.homeTop = that.getHomeTop(0.4) |
|---|
| 1487 | 1498 | } |
|---|
| 1488 | 1499 | that.expireTime = []; |
|---|
| 1489 | | - that.expireTimeUnit = []; |
|---|
| 1500 | + that.countdownToken++; |
|---|
| 1490 | 1501 | that.where.page = 1; |
|---|
| 1491 | 1502 | that.getGoodList() |
|---|
| 1492 | 1503 | that.validAlert(res.data) |
|---|
| .. | .. |
|---|
| 1512 | 1523 | } |
|---|
| 1513 | 1524 | }); |
|---|
| 1514 | 1525 | }, |
|---|
| 1515 | | - countdownTimer(expireTime, type) { |
|---|
| 1526 | + countdownTimer(expireTime, type, token) { |
|---|
| 1516 | 1527 | if (!expireTime) return |
|---|
| 1528 | + if (token !== undefined && token !== this.countdownToken) return |
|---|
| 1517 | 1529 | let that = this; |
|---|
| 1518 | 1530 | // 结束时间的时间戳(需传入一个有效的日期对象或时间戳) |
|---|
| 1519 | 1531 | const endTimestamp = new Date(expireTime).getTime(); |
|---|
| .. | .. |
|---|
| 1525 | 1537 | if (type == 'end') { |
|---|
| 1526 | 1538 | if (diff <= 0) { |
|---|
| 1527 | 1539 | this.expireTime = [] |
|---|
| 1528 | | - this.expireTimeUnit = [] |
|---|
| 1529 | 1540 | return |
|---|
| 1530 | 1541 | } else { } |
|---|
| 1531 | 1542 | } else if (type == 'start') { |
|---|
| 1532 | 1543 | if (diff <= 0) { |
|---|
| 1533 | 1544 | this.expireTime = [] |
|---|
| 1534 | | - this.expireTimeUnit = [] |
|---|
| 1535 | 1545 | const expireTime2 = that.info.expireTime |
|---|
| 1536 | 1546 | if (expireTime2) { |
|---|
| 1537 | 1547 | const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime(); |
|---|
| 1538 | 1548 | if (expireTimetamp < nowTimestamp) { |
|---|
| 1539 | 1549 | return |
|---|
| 1540 | 1550 | } |
|---|
| 1541 | | - this.countdownTimer(expireTime2.split('-').join('/'), 'end') |
|---|
| 1551 | + this.countdownTimer(expireTime2.split('-').join('/'), 'end', token) |
|---|
| 1542 | 1552 | this.startOrEnd = "后结束" |
|---|
| 1543 | 1553 | } |
|---|
| 1544 | 1554 | return |
|---|
| 1545 | 1555 | } |
|---|
| 1546 | 1556 | } |
|---|
| 1557 | + const pad = num => (num < 10 ? '0' + num : String(num)) |
|---|
| 1547 | 1558 | const res = [] |
|---|
| 1548 | | - const unit = [] |
|---|
| 1549 | 1559 | const days = Math.floor(diff / (1000 * 60 * 60 * 24)) |
|---|
| 1550 | 1560 | diff %= (1000 * 60 * 60 * 24) |
|---|
| 1551 | | - if (days > 0) { |
|---|
| 1552 | | - res.push(days); |
|---|
| 1553 | | - unit.push('日') |
|---|
| 1554 | | - } |
|---|
| 1555 | 1561 | // 转换为小时、分钟、秒 |
|---|
| 1556 | 1562 | const hours = Math.floor(diff / (1000 * 60 * 60)); |
|---|
| 1557 | 1563 | diff %= (1000 * 60 * 60); // 剩余毫秒数 |
|---|
| 1558 | | - if (hours > 0) { |
|---|
| 1559 | | - res.push(hours < 10 ? '0' + hours : hours); |
|---|
| 1560 | | - unit.push('时') |
|---|
| 1561 | | - } |
|---|
| 1562 | 1564 | const minutes = Math.floor(diff / (1000 * 60)); |
|---|
| 1563 | | - if (minutes > 0) { |
|---|
| 1564 | | - res.push(minutes < 10 ? '0' + minutes : minutes); |
|---|
| 1565 | | - unit.push('分') |
|---|
| 1566 | | - } |
|---|
| 1567 | 1565 | diff %= (1000 * 60); // 剩余毫秒数 |
|---|
| 1568 | 1566 | 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 | + }) |
|---|
| 1572 | 1573 | } |
|---|
| 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 | + }) |
|---|
| 1573 | 1586 | this.expireTime = res |
|---|
| 1574 | | - this.expireTimeUnit = unit |
|---|
| 1575 | 1587 | if (this.isPageShow) { |
|---|
| 1576 | 1588 | setTimeout(() => { |
|---|
| 1577 | | - that.countdownTimer(expireTime, type) |
|---|
| 1589 | + that.countdownTimer(expireTime, type, token) |
|---|
| 1578 | 1590 | }, 1000) |
|---|
| 1579 | 1591 | } |
|---|
| 1580 | 1592 | }, |
|---|
| .. | .. |
|---|
| 1661 | 1673 | .lottery_banner { |
|---|
| 1662 | 1674 | margin: 15rpx auto; |
|---|
| 1663 | 1675 | width: 690rpx; |
|---|
| 1664 | | - height: 120rpx; |
|---|
| 1665 | 1676 | text-align: center; |
|---|
| 1666 | 1677 | } |
|---|
| 1667 | 1678 | |
|---|
| 1668 | 1679 | .lottery_bannerImg { |
|---|
| 1669 | 1680 | width: 690rpx; |
|---|
| 1670 | | - height: 120rpx; |
|---|
| 1671 | 1681 | } |
|---|
| 1672 | 1682 | |
|---|
| 1673 | 1683 | .tag-wrap-container { |
|---|
| .. | .. |
|---|
| 1866 | 1876 | position: absolute; |
|---|
| 1867 | 1877 | top: 50%; |
|---|
| 1868 | 1878 | 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; |
|---|
| 1869 | 1894 | } |
|---|
| 1870 | 1895 | |
|---|
| 1871 | 1896 | .head_img { |
|---|
| .. | .. |
|---|
| 2136 | 2161 | padding: 15rpx; |
|---|
| 2137 | 2162 | padding-left: 30rpx; |
|---|
| 2138 | 2163 | color: #979797; |
|---|
| 2164 | + font-size: 26rpx; |
|---|
| 2139 | 2165 | |
|---|
| 2140 | 2166 | .num { |
|---|
| 2167 | + display: inline-block; |
|---|
| 2141 | 2168 | color: #000000; |
|---|
| 2142 | 2169 | 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; |
|---|
| 2144 | 2180 | } |
|---|
| 2145 | 2181 | } |
|---|
| 2146 | 2182 | </style> |
|---|