|
|
@ -66,7 +66,6 @@
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
import _ from "lodash";
|
|
|
|
import _ from "lodash";
|
|
|
|
import { FormatDate } from "@/plugins/utils";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const CAROUSEL_COUNT = 5; // 走马灯每页展示商品数
|
|
|
|
const CAROUSEL_COUNT = 5; // 走马灯每页展示商品数
|
|
|
|
|
|
|
|
|
|
|
@ -77,6 +76,10 @@ export default {
|
|
|
|
type: Object,
|
|
|
|
type: Object,
|
|
|
|
default: () => ({}),
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
current: {
|
|
|
|
|
|
|
|
type: Number,
|
|
|
|
|
|
|
|
default: 0,
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
@ -93,15 +96,13 @@ export default {
|
|
|
|
immediate: true,
|
|
|
|
immediate: true,
|
|
|
|
handler(val) {
|
|
|
|
handler(val) {
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
currentTime,
|
|
|
|
|
|
|
|
activityProductListVO: products,
|
|
|
|
activityProductListVO: products,
|
|
|
|
activityTimeVO: { activityEndTime, activityStartTime },
|
|
|
|
activityTimeVO: { activityStartTime, activityEndTime },
|
|
|
|
} = val;
|
|
|
|
} = val;
|
|
|
|
if (products && products.length > 0) {
|
|
|
|
if (products && products.length > 0) {
|
|
|
|
this.getFormatData(products);
|
|
|
|
this.setCarouselData(products);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.getSeckillData({
|
|
|
|
this.setTimerInterval({
|
|
|
|
currentTime,
|
|
|
|
|
|
|
|
startTime: activityStartTime,
|
|
|
|
startTime: activityStartTime,
|
|
|
|
endTime: activityEndTime,
|
|
|
|
endTime: activityEndTime,
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -111,12 +112,14 @@ export default {
|
|
|
|
computed: {
|
|
|
|
computed: {
|
|
|
|
// 秒杀活动倒计时
|
|
|
|
// 秒杀活动倒计时
|
|
|
|
countdown() {
|
|
|
|
countdown() {
|
|
|
|
const date = FormatDate(this.seckillTime, "hh:mm:ss");
|
|
|
|
const data = parseInt(this.seckillTime / 1e3);
|
|
|
|
const [hour, minute, second] = date.split(":");
|
|
|
|
const hour = Math.floor(data / 60 / 60);
|
|
|
|
|
|
|
|
const minute = Math.floor((data / 60) % 60);
|
|
|
|
|
|
|
|
const second = Math.floor(data % 60);
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
hour,
|
|
|
|
hour: hour < 10 ? `0${hour}` : `${hour}`,
|
|
|
|
minute,
|
|
|
|
minute: minute < 10 ? `0${minute}` : `${minute}`,
|
|
|
|
second,
|
|
|
|
second: second < 10 ? `0${second}` : `${second}`,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -125,7 +128,7 @@ export default {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
// 走马灯商品列表,五个商品为一组
|
|
|
|
// 走马灯商品列表,五个商品为一组
|
|
|
|
getFormatData(list) {
|
|
|
|
setCarouselData(list) {
|
|
|
|
const listCopy = _.cloneDeep(list);
|
|
|
|
const listCopy = _.cloneDeep(list);
|
|
|
|
const part = Math.ceil(listCopy.length / CAROUSEL_COUNT);
|
|
|
|
const part = Math.ceil(listCopy.length / CAROUSEL_COUNT);
|
|
|
|
if (part === 1) {
|
|
|
|
if (part === 1) {
|
|
|
@ -137,28 +140,26 @@ export default {
|
|
|
|
this.goodsList.push(goodsListItem);
|
|
|
|
this.goodsList.push(goodsListItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 获取秒杀时间数据
|
|
|
|
|
|
|
|
getSeckillData({ current, startTime, endTime }) {
|
|
|
|
// 获取秒杀倒计时时间
|
|
|
|
current = new Date(current);
|
|
|
|
setTimerInterval({ startTime, endTime }) {
|
|
|
|
startTime = new Date(startTime);
|
|
|
|
startTime = new Date(startTime).getTime();
|
|
|
|
endTime = new Date(endTime);
|
|
|
|
endTime = new Date(endTime).getTime();
|
|
|
|
if (current > startTime && current < endTime) {
|
|
|
|
if (this.current > startTime && this.current < endTime) {
|
|
|
|
// 活动进行中
|
|
|
|
// 活动进行中
|
|
|
|
this.seckillText = "距结束";
|
|
|
|
this.seckillText = "距结束";
|
|
|
|
this.seckillTime = endTime - current;
|
|
|
|
this.seckillTime = endTime - this.current;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 活动未开始
|
|
|
|
// 活动未开始
|
|
|
|
this.seckillText = "距开始";
|
|
|
|
this.seckillText = "距开始";
|
|
|
|
this.seckillTime = startTime - current;
|
|
|
|
this.seckillTime = startTime - this.current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setCountDownInterval();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 秒杀倒计时
|
|
|
|
|
|
|
|
setCountDownInterval() {
|
|
|
|
|
|
|
|
this.timeInterval = setInterval(() => {
|
|
|
|
this.timeInterval = setInterval(() => {
|
|
|
|
if (this.seckillTime <= 0) {
|
|
|
|
if (this.seckillTime <= 0) {
|
|
|
|
clearInterval(this.timeInterval);
|
|
|
|
clearInterval(this.timeInterval);
|
|
|
|
|
|
|
|
this.$emit("refresh");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.seckillTime -= 1000;
|
|
|
|
this.seckillTime -= 1000;
|
|
|
|
}, 1e3);
|
|
|
|
}, 1e3);
|
|
|
|