|
|
|
@ -27,7 +27,11 @@
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="seckill-bar flex flex-middle flex-center">
|
|
|
|
|
<!-- 倒计时展示 -->
|
|
|
|
|
<div
|
|
|
|
|
v-if="tabList.length > 0"
|
|
|
|
|
class="seckill-bar flex flex-middle flex-center"
|
|
|
|
|
>
|
|
|
|
|
<p>{{ seckillTip }}</p>
|
|
|
|
|
<div class="seckill-bar-countdown flex flex-middle">
|
|
|
|
|
<div class="seckill-bar-countdown__time">{{ countdown.hour }}</div>
|
|
|
|
@ -84,8 +88,11 @@
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
import { ApiGetSeckillTimes, ApiGetSeckillGoods } from "@/plugins/api/seckill";
|
|
|
|
|
import { FormatDate } from "@/plugins/utils";
|
|
|
|
|
import {
|
|
|
|
|
ApiGetSeckillTimes,
|
|
|
|
|
ApiGetSeckillGoods,
|
|
|
|
|
ApiGetCurrentTime,
|
|
|
|
|
} from "@/plugins/api/seckill";
|
|
|
|
|
import TabBar from "./module/TabBar.vue";
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
@ -102,37 +109,47 @@ export default {
|
|
|
|
|
query: {
|
|
|
|
|
pageIndex: 1,
|
|
|
|
|
length: 16,
|
|
|
|
|
activityTimeId: 1,
|
|
|
|
|
activityTimeId: 0,
|
|
|
|
|
},
|
|
|
|
|
ticking: false,
|
|
|
|
|
isSticky: false,
|
|
|
|
|
currentTabItem: null, // 当前选中时间段
|
|
|
|
|
timeInterval: null, // 倒计时定时器
|
|
|
|
|
seckillTip: "", // 秒杀提示文案
|
|
|
|
|
seckillTime: 0, // 秒杀时间
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
countdown() {
|
|
|
|
|
const data = parseInt(this.seckillTime / 1e3);
|
|
|
|
|
const hour = Math.floor(data / 60 / 60);
|
|
|
|
|
const minute = Math.floor((data / 60) % 60);
|
|
|
|
|
const second = Math.floor(data % 60);
|
|
|
|
|
return {
|
|
|
|
|
hour: "01",
|
|
|
|
|
minute: "32",
|
|
|
|
|
second: "09",
|
|
|
|
|
hour: hour < 10 ? `0${hour}` : `${hour}`,
|
|
|
|
|
minute: minute < 10 ? `0${minute}` : `${minute}`,
|
|
|
|
|
second: second < 10 ? `0${second}` : `${second}`,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 当前选中时间段
|
|
|
|
|
currentTabItem() {
|
|
|
|
|
const tabItem = this.tabList.find(
|
|
|
|
|
(item) => item.id === this.query.activityTimeId
|
|
|
|
|
);
|
|
|
|
|
return tabItem || null;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 当前时间段秒杀文案
|
|
|
|
|
seckillTip() {
|
|
|
|
|
if (this.currentTabItem) {
|
|
|
|
|
return this.currentTabItem.isInProgress
|
|
|
|
|
? "本场正在秒杀中,好物转瞬即逝,不要错过哦~距结束仅剩"
|
|
|
|
|
: "本场秒杀即将开抢,距开始还剩";
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
watch: {
|
|
|
|
|
"query.activityTimeId": {
|
|
|
|
|
immediate: true,
|
|
|
|
|
handler(val) {
|
|
|
|
|
if (val === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
clearImmediate(this.timeInterval);
|
|
|
|
|
const tabItem = this.tabList.find((item) => item.id === val);
|
|
|
|
|
if (tabItem) {
|
|
|
|
|
this.currentTabItem = tabItem;
|
|
|
|
|
const { activityStartTime, activityEndTime } = tabItem;
|
|
|
|
|
this.setTimerInterval({
|
|
|
|
|
startTime: activityStartTime,
|
|
|
|
|
endTime: activityEndTime,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -145,6 +162,7 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
destroyed() {
|
|
|
|
|
window.removeEventListener("scroll", this.scrollEventMethod);
|
|
|
|
|
clearInterval(this.timeInterval);
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
scrollEventMethod() {
|
|
|
|
@ -177,6 +195,39 @@ export default {
|
|
|
|
|
this.goodsList = result.records;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 设置定时器
|
|
|
|
|
async setTimerInterval({ startTime, endTime }) {
|
|
|
|
|
// 获取服务器当前时间
|
|
|
|
|
const { result } = await ApiGetCurrentTime();
|
|
|
|
|
const current = result || Date.now();
|
|
|
|
|
|
|
|
|
|
startTime = new Date(startTime).getTime();
|
|
|
|
|
endTime = new Date(endTime).getTime();
|
|
|
|
|
if (current > endTime) {
|
|
|
|
|
// 秒杀结束
|
|
|
|
|
this.getSeckillTimes();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (startTime < current && endTime > current) {
|
|
|
|
|
// 秒杀进行中
|
|
|
|
|
this.seckillTime = endTime - current;
|
|
|
|
|
this.seckillTip = "本场正在秒杀中,好物转瞬即逝,不要错过哦~距结束仅剩";
|
|
|
|
|
} else {
|
|
|
|
|
// 秒杀未开始
|
|
|
|
|
this.seckillTime = startTime - current;
|
|
|
|
|
this.seckillTip = "本场秒杀即将开抢,距开始还剩";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.timeInterval = setInterval(() => {
|
|
|
|
|
if (this.seckillTime <= 0) {
|
|
|
|
|
clearInterval(this.timeInterval);
|
|
|
|
|
this.getSeckillTimes();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.seckillTime -= 1e3;
|
|
|
|
|
}, 1e3);
|
|
|
|
|
},
|
|
|
|
|
onJumpGoodsDetail(id) {
|
|
|
|
|
this.$router.push(`/goods/detail/${id}`);
|
|
|
|
|
},
|
|
|
|
@ -194,6 +245,7 @@ export default {
|
|
|
|
|
pageIndex: 1,
|
|
|
|
|
length: 16,
|
|
|
|
|
});
|
|
|
|
|
this.getGoodsList();
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|