| .. | .. |
|---|
| 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" |
|---|
| 93 | + v-if="info && info.isLottery && info.lotteryBanner && lotteryBannerReady"> |
|---|
| 94 | + <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix" |
|---|
| 95 | + :style="{ height: lotteryBannerHeight }"> |
|---|
| 91 | 96 | </image> |
|---|
| 92 | 97 | </view> |
|---|
| 93 | 98 | <view class="tag-img-container" v-if="info.zoneType == 7"> |
|---|
| .. | .. |
|---|
| 604 | 609 | showMenu: false, |
|---|
| 605 | 610 | selectedMenuArr: [], |
|---|
| 606 | 611 | expireTime: [], |
|---|
| 607 | | - expireTimeUnit: [], |
|---|
| 612 | + countdownToken: 0, |
|---|
| 608 | 613 | isPageShow: false, |
|---|
| 609 | 614 | loginBackFn: null, |
|---|
| 610 | 615 | errText: '', |
|---|
| .. | .. |
|---|
| 639 | 644 | stockEmpty: true, |
|---|
| 640 | 645 | urlOption: {}, |
|---|
| 641 | 646 | homeTop: '200', |
|---|
| 647 | + lotteryBannerHeight: '', //抽奖banner预计算高度(rpx),空字符串表示未取到,按原逻辑自适应 |
|---|
| 648 | + lotteryBannerReady: false, //是否已拿到banner尺寸(或已确认拿不到),未就绪前不渲染,避免首帧撑高 |
|---|
| 642 | 649 | hasNewPop: false, |
|---|
| 643 | 650 | leftCoupon: {}, |
|---|
| 644 | 651 | rightCoupon: {}, |
|---|
| .. | .. |
|---|
| 1226 | 1233 | // that.myCareBean = res2.data.totalCareBeans; |
|---|
| 1227 | 1234 | }); |
|---|
| 1228 | 1235 | }, |
|---|
| 1236 | + goDetail() { |
|---|
| 1237 | + uni.navigateTo({ |
|---|
| 1238 | + url: '/pages/consumption/index?zoneId=' + this.info.id |
|---|
| 1239 | + }) |
|---|
| 1240 | + }, |
|---|
| 1229 | 1241 | goLottery() { |
|---|
| 1230 | 1242 | let that = this; |
|---|
| 1231 | 1243 | var data = { |
|---|
| .. | .. |
|---|
| 1319 | 1331 | }) |
|---|
| 1320 | 1332 | }, |
|---|
| 1321 | 1333 | validAlert(data) { |
|---|
| 1334 | + // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动 |
|---|
| 1335 | + this.countdownToken++ |
|---|
| 1336 | + const token = this.countdownToken |
|---|
| 1322 | 1337 | const { |
|---|
| 1323 | 1338 | startTime, |
|---|
| 1324 | 1339 | expireTime |
|---|
| .. | .. |
|---|
| 1337 | 1352 | let minutes = startTimetamp.getMinutes() |
|---|
| 1338 | 1353 | minutes = minutes < 10 ? '0' + minutes : minutes; |
|---|
| 1339 | 1354 | |
|---|
| 1340 | | - this.countdownTimer(startTime.split('-').join('/'), 'start') |
|---|
| 1355 | + this.countdownTimer(startTime.split('-').join('/'), 'start', token) |
|---|
| 1341 | 1356 | this.startOrEnd = "后开启" |
|---|
| 1342 | 1357 | return |
|---|
| 1343 | | - } |
|---|
| 1344 | | - } |
|---|
| 1345 | | - if (expireTime) { |
|---|
| 1346 | | - const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime(); |
|---|
| 1347 | | - if (expireTimetamp < nowTimestamp) { |
|---|
| 1358 | + } |
|---|
| 1359 | + } |
|---|
| 1360 | + if (expireTime) { |
|---|
| 1361 | + const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime(); |
|---|
| 1362 | + if (expireTimetamp < nowTimestamp) { |
|---|
| 1348 | 1363 | return |
|---|
| 1349 | | - } |
|---|
| 1350 | | - this.countdownTimer(expireTime.split('-').join('/'), 'end') |
|---|
| 1364 | + } |
|---|
| 1365 | + this.countdownTimer(expireTime.split('-').join('/'), 'end', token) |
|---|
| 1351 | 1366 | this.startOrEnd = "后结束" |
|---|
| 1352 | 1367 | } |
|---|
| 1353 | 1368 | }, |
|---|
| .. | .. |
|---|
| 1469 | 1484 | this.$refs.popNewuserRef.show() |
|---|
| 1470 | 1485 | } |
|---|
| 1471 | 1486 | }, |
|---|
| 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 | + }, |
|---|
| 1472 | 1510 | getZoneDetail: function () { |
|---|
| 1473 | 1511 | let that = this; |
|---|
| 1474 | 1512 | let belong = this.$store.getters.belong; |
|---|
| .. | .. |
|---|
| 1476 | 1514 | console.log('专区详情入参::', params) |
|---|
| 1477 | 1515 | getZoneDetail(that.id, params).then(res => { |
|---|
| 1478 | 1516 | that.info = res.data; |
|---|
| 1479 | | - //that.info.zoneType=8; |
|---|
| 1517 | + that.setLotteryBannerSize(res.data); |
|---|
| 1480 | 1518 | that.updateZoneShareMenu(); |
|---|
| 1481 | 1519 | if (res.data.zoneType == 6) { |
|---|
| 1482 | 1520 | that.setYueyangZone() |
|---|
| .. | .. |
|---|
| 1486 | 1524 | that.homeTop = that.getHomeTop(0.4) |
|---|
| 1487 | 1525 | } |
|---|
| 1488 | 1526 | that.expireTime = []; |
|---|
| 1489 | | - that.expireTimeUnit = []; |
|---|
| 1527 | + that.countdownToken++; |
|---|
| 1490 | 1528 | that.where.page = 1; |
|---|
| 1491 | 1529 | that.getGoodList() |
|---|
| 1492 | 1530 | that.validAlert(res.data) |
|---|
| .. | .. |
|---|
| 1512 | 1550 | } |
|---|
| 1513 | 1551 | }); |
|---|
| 1514 | 1552 | }, |
|---|
| 1515 | | - countdownTimer(expireTime, type) { |
|---|
| 1553 | + countdownTimer(expireTime, type, token) { |
|---|
| 1516 | 1554 | if (!expireTime) return |
|---|
| 1555 | + if (token !== undefined && token !== this.countdownToken) return |
|---|
| 1517 | 1556 | let that = this; |
|---|
| 1518 | 1557 | // 结束时间的时间戳(需传入一个有效的日期对象或时间戳) |
|---|
| 1519 | 1558 | const endTimestamp = new Date(expireTime).getTime(); |
|---|
| .. | .. |
|---|
| 1525 | 1564 | if (type == 'end') { |
|---|
| 1526 | 1565 | if (diff <= 0) { |
|---|
| 1527 | 1566 | this.expireTime = [] |
|---|
| 1528 | | - this.expireTimeUnit = [] |
|---|
| 1529 | 1567 | return |
|---|
| 1530 | 1568 | } else { } |
|---|
| 1531 | 1569 | } else if (type == 'start') { |
|---|
| 1532 | 1570 | if (diff <= 0) { |
|---|
| 1533 | 1571 | this.expireTime = [] |
|---|
| 1534 | | - this.expireTimeUnit = [] |
|---|
| 1535 | 1572 | const expireTime2 = that.info.expireTime |
|---|
| 1536 | 1573 | if (expireTime2) { |
|---|
| 1537 | 1574 | const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime(); |
|---|
| 1538 | 1575 | if (expireTimetamp < nowTimestamp) { |
|---|
| 1539 | 1576 | return |
|---|
| 1540 | 1577 | } |
|---|
| 1541 | | - this.countdownTimer(expireTime2.split('-').join('/'), 'end') |
|---|
| 1578 | + this.countdownTimer(expireTime2.split('-').join('/'), 'end', token) |
|---|
| 1542 | 1579 | this.startOrEnd = "后结束" |
|---|
| 1543 | 1580 | } |
|---|
| 1544 | 1581 | return |
|---|
| 1545 | 1582 | } |
|---|
| 1546 | 1583 | } |
|---|
| 1584 | + const pad = num => (num < 10 ? '0' + num : String(num)) |
|---|
| 1547 | 1585 | const res = [] |
|---|
| 1548 | | - const unit = [] |
|---|
| 1549 | 1586 | const days = Math.floor(diff / (1000 * 60 * 60 * 24)) |
|---|
| 1550 | 1587 | diff %= (1000 * 60 * 60 * 24) |
|---|
| 1551 | | - if (days > 0) { |
|---|
| 1552 | | - res.push(days); |
|---|
| 1553 | | - unit.push('日') |
|---|
| 1554 | | - } |
|---|
| 1555 | 1588 | // 转换为小时、分钟、秒 |
|---|
| 1556 | 1589 | const hours = Math.floor(diff / (1000 * 60 * 60)); |
|---|
| 1557 | 1590 | diff %= (1000 * 60 * 60); // 剩余毫秒数 |
|---|
| 1558 | | - if (hours > 0) { |
|---|
| 1559 | | - res.push(hours < 10 ? '0' + hours : hours); |
|---|
| 1560 | | - unit.push('时') |
|---|
| 1561 | | - } |
|---|
| 1562 | 1591 | const minutes = Math.floor(diff / (1000 * 60)); |
|---|
| 1563 | | - if (minutes > 0) { |
|---|
| 1564 | | - res.push(minutes < 10 ? '0' + minutes : minutes); |
|---|
| 1565 | | - unit.push('分') |
|---|
| 1566 | | - } |
|---|
| 1567 | 1592 | diff %= (1000 * 60); // 剩余毫秒数 |
|---|
| 1568 | 1593 | const seconds = Math.floor(diff / 1000); |
|---|
| 1569 | | - if (seconds > 0) { |
|---|
| 1570 | | - res.push(seconds < 10 ? '0' + seconds : seconds); |
|---|
| 1571 | | - unit.push('秒') |
|---|
| 1594 | + // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定 |
|---|
| 1595 | + if (days > 0) { |
|---|
| 1596 | + res.push({ |
|---|
| 1597 | + digits: pad(days).split(''), |
|---|
| 1598 | + unit: '日' |
|---|
| 1599 | + }) |
|---|
| 1572 | 1600 | } |
|---|
| 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 | + }) |
|---|
| 1573 | 1613 | this.expireTime = res |
|---|
| 1574 | | - this.expireTimeUnit = unit |
|---|
| 1575 | 1614 | if (this.isPageShow) { |
|---|
| 1576 | 1615 | setTimeout(() => { |
|---|
| 1577 | | - that.countdownTimer(expireTime, type) |
|---|
| 1616 | + that.countdownTimer(expireTime, type, token) |
|---|
| 1578 | 1617 | }, 1000) |
|---|
| 1579 | 1618 | } |
|---|
| 1580 | 1619 | }, |
|---|
| .. | .. |
|---|
| 1661 | 1700 | .lottery_banner { |
|---|
| 1662 | 1701 | margin: 15rpx auto; |
|---|
| 1663 | 1702 | width: 690rpx; |
|---|
| 1664 | | - height: 120rpx; |
|---|
| 1665 | 1703 | text-align: center; |
|---|
| 1666 | 1704 | } |
|---|
| 1667 | 1705 | |
|---|
| 1668 | 1706 | .lottery_bannerImg { |
|---|
| 1669 | 1707 | width: 690rpx; |
|---|
| 1670 | | - height: 120rpx; |
|---|
| 1671 | 1708 | } |
|---|
| 1672 | 1709 | |
|---|
| 1673 | 1710 | .tag-wrap-container { |
|---|
| .. | .. |
|---|
| 1866 | 1903 | position: absolute; |
|---|
| 1867 | 1904 | top: 50%; |
|---|
| 1868 | 1905 | 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; |
|---|
| 1869 | 1921 | } |
|---|
| 1870 | 1922 | |
|---|
| 1871 | 1923 | .head_img { |
|---|
| .. | .. |
|---|
| 2136 | 2188 | padding: 15rpx; |
|---|
| 2137 | 2189 | padding-left: 30rpx; |
|---|
| 2138 | 2190 | color: #979797; |
|---|
| 2191 | + font-size: 26rpx; |
|---|
| 2139 | 2192 | |
|---|
| 2140 | 2193 | .num { |
|---|
| 2194 | + display: inline-block; |
|---|
| 2141 | 2195 | color: #000000; |
|---|
| 2142 | 2196 | background: #FFE20E; |
|---|
| 2143 | | - 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; |
|---|
| 2144 | 2207 | } |
|---|
| 2145 | 2208 | } |
|---|
| 2146 | 2209 | </style> |
|---|