Showing
6 changed files
with
107 additions
and
7 deletions
1 | 1 | ||
2 | <wxs src="./helper.wxs" module="helper" /> | 2 | <wxs src="./helper.wxs" module="helper" /> |
3 | - | 3 | + <time-countdown class="product_countdown" wx:if="{{product.status === 2}}" endTime="{{product.end_time}}"></time-countdown> |
4 | <image class="product_image" src="{{product.cover_img}}"></image> | 4 | <image class="product_image" src="{{product.cover_img}}"></image> |
5 | <view class="product_name" >{{product.name}}</view> | 5 | <view class="product_name" >{{product.name}}</view> |
6 | <view class="product_price" >{{product.price}}</view> | 6 | <view class="product_price" >{{product.price}}</view> |
7 | - <view class="product_time">{{helper.formatTime(product.start_time, product.end_time)}}</view> | ||
7 | + <view wx:if="{{product.status !== 2}}" class="product_time">{{helper.formatTime(product.start_time, product.end_time)}}</view> | ||
8 | + <view class="product_margin"></view> |
@@ -26,7 +26,6 @@ | @@ -26,7 +26,6 @@ | ||
26 | color: #B0B0B0; | 26 | color: #B0B0B0; |
27 | font-size: 24rpx; | 27 | font-size: 24rpx; |
28 | margin-top: 16rpx; | 28 | margin-top: 16rpx; |
29 | - margin-bottom: 40rpx; | ||
30 | } | 29 | } |
31 | 30 | ||
32 | .product_time:before { | 31 | .product_time:before { |
@@ -47,4 +46,15 @@ | @@ -47,4 +46,15 @@ | ||
47 | background-color: #D8D8D8; | 46 | background-color: #D8D8D8; |
48 | margin-left: 20rpx; | 47 | margin-left: 20rpx; |
49 | vertical-align: 6rpx | 48 | vertical-align: 6rpx |
49 | +} | ||
50 | + | ||
51 | +.product_margin { | ||
52 | + margin-bottom: 40rpx; | ||
53 | +} | ||
54 | + | ||
55 | +.product_countdown { | ||
56 | + display: block; | ||
57 | + height: 92rpx; | ||
58 | + margin-top: 40rpx; | ||
59 | + margin-bottom: 40rpx; | ||
50 | } | 60 | } |
@@ -4,7 +4,12 @@ Component({ | @@ -4,7 +4,12 @@ Component({ | ||
4 | * 组件的属性列表 | 4 | * 组件的属性列表 |
5 | */ | 5 | */ |
6 | properties: { | 6 | properties: { |
7 | - | 7 | + endTime: {//结束时间 |
8 | + type: Number | ||
9 | + }, | ||
10 | + formatTime: { | ||
11 | + type: Array | ||
12 | + } | ||
8 | }, | 13 | }, |
9 | 14 | ||
10 | /** | 15 | /** |
@@ -14,10 +19,53 @@ Component({ | @@ -14,10 +19,53 @@ Component({ | ||
14 | 19 | ||
15 | }, | 20 | }, |
16 | 21 | ||
22 | + ready: function() { | ||
23 | + this.formatTime() | ||
24 | + }, | ||
17 | /** | 25 | /** |
18 | * 组件的方法列表 | 26 | * 组件的方法列表 |
19 | */ | 27 | */ |
20 | methods: { | 28 | methods: { |
29 | + formatTime:function() { | ||
30 | + let self = this | ||
31 | + setInterval(function() { | ||
32 | + self.setData({ | ||
33 | + formatTime: self.formatCountDown(self.properties.endTime) | ||
34 | + }) | ||
35 | + },1000) | ||
36 | + }, | ||
37 | + formatCountDown:function formatCountDown(end) { | ||
38 | + if (end === 0) { | ||
39 | + return '00000000' | ||
40 | + } | ||
41 | + var timeInSecond = (end * 1000 - Date.now()) / 1000 | ||
42 | + | ||
43 | + var day = 24 * 60 * 60 | ||
44 | + var numberOfDay = Math.floor(timeInSecond / day) | ||
45 | + timeInSecond = timeInSecond - numberOfDay * day | ||
46 | + numberOfDay = Math.min(numberOfDay, 99) | ||
47 | + | ||
48 | + var hour = 60 * 60 | ||
49 | + var numberOfHour = Math.floor(timeInSecond / hour) | ||
50 | + timeInSecond = timeInSecond - numberOfHour * hour | ||
51 | + | ||
52 | + var minute = 60 | ||
53 | + var numberOfMinute = Math.floor(timeInSecond / minute) | ||
54 | + timeInSecond = timeInSecond - numberOfMinute * minute | ||
55 | + | ||
56 | + var numberOfSecond = parseInt(timeInSecond) | ||
57 | + | ||
58 | + var list = [numberOfDay, numberOfHour, numberOfMinute, numberOfSecond] | ||
21 | 59 | ||
60 | + for (var i = 0; i < list.length; i++) { | ||
61 | + var item = list[i] | ||
62 | + if (item < 10) { | ||
63 | + list[i] = '0' + item | ||
64 | + } else { | ||
65 | + list[i] = '' + item | ||
66 | + } | ||
67 | + } | ||
68 | + return list | ||
69 | + } | ||
22 | } | 70 | } |
23 | }) | 71 | }) |
1 | <!--pages/zeroSell/components/timeCountDown/time-countdown.wxml--> | 1 | <!--pages/zeroSell/components/timeCountDown/time-countdown.wxml--> |
2 | -<text>pages/zeroSell/components/timeCountDown/time-countdown.wxml</text> | 2 | +<block wx:for="{{formatTime}}" wx:key=""> |
3 | + <view class="num-wrapper"> | ||
4 | + <text>{{item}}</text> | ||
5 | + <view class="mask"></view> | ||
6 | + </view> | ||
7 | + <view class="number-seprator" wx:if="{{index !== 3}}"> | ||
8 | + : | ||
9 | + </view> | ||
10 | + </block> |
1 | -/* pages/zeroSell/components/timeCountDown/time-countdown.wxss */ | ||
1 | +.num-wrapper { | ||
2 | + display: inline-block; | ||
3 | + position: relative; | ||
4 | + width: 72rpx; | ||
5 | + height: 72rpx; | ||
6 | + font-size: 56rpx; | ||
7 | + line-height: 72rpx; | ||
8 | + background: black; | ||
9 | + color: white; | ||
10 | + font-weight: bolder; | ||
11 | +} | ||
12 | + | ||
13 | +.num-wrapper + .num-wrapper { | ||
14 | + margin-left: 10rpx; | ||
15 | +} | ||
16 | + | ||
17 | +.mask { | ||
18 | + position: absolute; | ||
19 | + width: 100%; | ||
20 | + height: 50%; | ||
21 | + top: 0; | ||
22 | + left: 0; | ||
23 | + opacity: 0.4; | ||
24 | + background-color: black; | ||
25 | +} | ||
26 | + | ||
27 | +.number-seprator { | ||
28 | + font-size: 56rpx; | ||
29 | + line-height: 72rpx; | ||
30 | + color: black; | ||
31 | + display: inline; | ||
32 | +} |
-
Please register or login to post a comment