CountDown.vue
7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<template>
<div class="count_down">
<div class="countDown" v-show="detailData.clusterTime">
<div class="countDownTop">
<div>
{{ day }}
{{
detailData.applyCount >= detailData.minPeopleCount ? '报名截止时间:' : showJietuanTime ? '报名截止倒计时' : '成团截止倒计时'
}}
</div>
<div v-if="detailData.applyCount >= detailData.minPeopleCount">{{ detailData.periodOfValidity }}</div>
<div class="countDownTime" v-else>
<div class="countDownFont">{{ showTime.day }}</div>
天
<div class="countDownFont">{{ showTime.hour }}</div>
时
<div class="countDownFont">{{ showTime.minute }}</div>
分
<div class="countDownFont">{{ showTime.second }}</div>
秒
</div>
</div>
<!-- <div class="countDownTop" v-else>
<div>{{day}}</div>
</div> -->
<div class="countDownBottom">
<div>
<div class="countDownBottomyellow" v-show="detailData.minPeopleCount">
{{ detailData.clusterName }}
</div>
<span v-if="detailData.applyCount >= detailData.minPeopleCount"
>已报名 {{ detailData.applyCount }}/{{ detailData.stockCount }}{{ detailData.unitName }}</span
>
<span v-else
>最低成团数{{ detailData.minPeopleCount }}{{ detailData.unitName }}/已报名{{ detailData.applyCount
}}{{ detailData.unitName }}</span
>
<!-- 已报名:<span>{{ detailData.applyCount }}</span><span>/{{ detailData.stockCount }}</span> -->
</div>
<div class="countDownAbout" @click="showPintuanAbout = true">关于拼团?</div>
</div>
</div>
<van-popup v-model="showPintuanAbout" round>
<div class="pintuan_about">
<img class="about_img" src="@/assets/service/tip.png" alt="" />
<p class="about_title">拼团规则说明</p>
<p class="about_content">1、拼团展示默认为最近活动档期,选择其它档期请时刻注意成团动态。</p>
<p class="about_content">2、在限时截止后,报名人数未达最低成团数,则结束本团活动,系统将在72小时内,全额退还!</p>
<p class="about_content">3、报名人数达到最低成团要求后,则拼团成功,凡在报名截止时间内未达最大限团人数,则可放心参与。</p>
<p class="about_content">4、已成团的活动,除特殊情况等不可抗拒因素外,活动如期举行。</p>
<p class="about_know" @click="showPintuanAbout = false">我知道了</p>
</div>
</van-popup>
</div>
</template>
<script>
export default {
props: ['day', 'productId', 'packageArr', 'bindId', 'comboId'],
data() {
return {
timeTamp: '',
showJietuanTime: false,
showTime: {
day: '',
hour: '',
minute: '',
second: '',
},
showPintuanAbout: false,
detailData: '',
}
},
watch: {
bindId(oldVal, newVal) {
this.getDateInfoById()
},
comboId(oldVal, newVal) {
this.getDateInfoById()
},
},
mounted() {
// console.log(this.detailData)
// console.log(this.packageArr)
this.getDateInfoById()
},
methods: {
// 根据选择的档期显示成团状态
getDateInfoById() {
const productId = this.productId
const bindId = this.bindId
const comboId = this.comboId
// console.log(productId, bindId, comboId)
this.yxAxios
.get(`${this.yanxueUrl}/api/Product/DateInfo/ById?productId=${productId}&bindId=${bindId}&comboId=${comboId}`)
.then((res) => {
// console.log(res.data)
if (res.data.status == 1) {
let data = res.data.data
// console.log(data.clusterTime)
data.clusterTime = this.Moment(new Date(data.clusterTime.replace(/\-/g, '/'))).format('YYYY/MM/DD HH:mm:ss')
data.periodOfValidity = this.Moment(new Date(data.periodOfValidity.replace(/\-/g, '/'))).format('YYYY/MM/DD HH:mm:ss')
console.log(data.clusterTime)
// 添加商品已报名数量,过期请删除start
if (this.$route.query.bindId == 3816) {
data.applyCount = data.applyCount + 521
}
// 添加商品已报名数量,过期请删除end
this.detailData = data
let timer = setInterval(() => {
this.timeDown() //倒计时
}, 1000)
this.$once('hook:beforeDestroy', () => {
clearInterval(timer) //清理定时器
console.log('清理定时器')
})
} else {
this.$toast('获取成团状态失败')
}
})
},
//倒计时计算
timeDown() {
var nowTime = Date.parse(new Date())
let timeTamp = ''
var clusterTime =Date.parse(new Date(this.detailData.clusterTime.replace(/\-/g, "/")));
var periodOfValidity =Date.parse(new Date(this.detailData.periodOfValidity.replace(/\-/g, "/")));
if(this.detailData.clusterName=='已成团'||clusterTime<nowTime){
timeTamp = periodOfValidity / 1000 - nowTime / 1000;
this.showJietuanTime = true
}else{
timeTamp = clusterTime / 1000 - nowTime / 1000;
this.showJietuanTime = false
}
// console.log(timeTamp)
this.timeTamp = timeTamp;
// console.log(timeTamp)
let k = this.calculateDiffTime(timeTamp);
// console.log(k)
},
calculateDiffTime(timeDiff) {
var day = parseInt(timeDiff / 86400)
var hour = parseInt((timeDiff % 86400) / 3600)
var minute = parseInt(((timeDiff % 86400) % 3600) / 60)
var second = parseInt((((timeDiff % 86400) % 3600) % 60) % 60)
this.showTime = {
day,
hour,
minute,
second,
}
day = day ? day + '天' : ''
hour = hour ? hour + '时' : ''
minute = minute ? minute + '分' : ''
second = second ? second + '秒' : ''
return day + hour + minute + second
},
},
}
</script>
<style lang="scss">
.countDown {
height: 130px;
width: 100%;
background-color: #201e2b;
.countDownTop {
height: 50%;
padding: 0 3vw;
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
color: #ffffff;
font-size: 32px;
.countDownTime {
font-size: 24px;
.countDownFont {
line-height: 34px;
color: #333333;
border-radius: 5px;
margin: 0 8px;
}
div {
width: 34px;
text-align: center;
display: inline-block;
background-color: #ffe9b1;
}
}
}
.countDownBottom {
height: 50%;
padding: 0 3vw;
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
color: #ffffff;
font-size: 24px;
.countDownBottomyellow {
display: inline-block;
height: 33px;
margin-right: 12px;
padding: 0 8px;
color: #333333;
font-size: 24px;
background-color: #ffe9b1;
border-radius: 4px;
}
.countDownBottomTime {
font-size: 2.8vw;
color: #ffffff;
opacity: 0.85;
}
.countDownAbout {
text-decoration: underline;
}
}
}
</style>