You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
322 lines
9.4 KiB
322 lines
9.4 KiB
<template>
|
|
<view>
|
|
<lf-nav title="秒杀专场" :showIcon="true" bgColor="#fff"></lf-nav>
|
|
<scroll-view :style="{height: autoHeight}" :scroll-y="true" :refresher-enabled="true"
|
|
:refresher-triggered="isRefresher" @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
|
|
<view class="content">
|
|
<view class="card" v-for="(item, index) in list" :key="index"
|
|
@click="$url('/pages/shop/goodsdetail?id='+ item.goods.id)">
|
|
<view class="goods-img">
|
|
<image class="img" :src="item.goods.img"></image>
|
|
<view class="tips lf-line-1">已有{{item.sell_num}}人购买</view>
|
|
</view>
|
|
<view class="goods-info">
|
|
<view>
|
|
<view class="lf-line-2 title lf-m-b-16">{{ item.goods.name }}</view>
|
|
<!-- <view class="desc" v-if="item.seckill.end_left_time.length==0">距离开始还剩余
|
|
{{item.seckill.start_left_time[0]}}天{{item.seckill.start_left_time[1]}}时{{item.seckill.start_left_time[2]}}分{{item.seckill.start_left_time[3]}}秒
|
|
</view>
|
|
<view class="desc" v-if="item.seckill.start_left_time.length==0">距离结束还剩余
|
|
{{item.seckill.end_left_time[0]}}天{{item.seckill.end_left_time[1]}}时{{item.seckill.end_left_time[2]}}分{{item.seckill.end_left_time[3]}}秒
|
|
</view> -->
|
|
<view class="desc" v-if="item.ifStart">距离结束还剩余
|
|
<countdown-timer :time="item.countTime" :autoStart="true" @finish="dateFinish">
|
|
<template v-slot="{day,hour,minute, second}">
|
|
<view class="lf-flex">
|
|
<view class="lf-font-24">{{ day >= 10 ? day : "0" + day }}</view>
|
|
<view class="lf-font-24">天</view>
|
|
<view class="lf-font-24">{{ hour >= 10 ? hour : "0" + hour }}</view>
|
|
<view class="lf-font-24">时</view>
|
|
<view class="lf-font-24">{{ minute >= 10 ? minute : "0" + minute }}</view>
|
|
<view class="lf-font-24">分</view>
|
|
<view class="lf-font-24">{{ second >= 10 ? second : "0" + second }}</view>
|
|
<view class="lf-font-24">秒</view>
|
|
</view>
|
|
</template>
|
|
</countdown-timer>
|
|
</view>
|
|
<view class="desc" v-else>距离开始还剩余
|
|
<countdown-timer :time="item.countTime" :autoStart="true" @finish="dateFinish">
|
|
<template v-slot="{day,hour,minute, second}">
|
|
<view class="lf-flex">
|
|
<view class="lf-font-24">{{ day >= 10 ? day : "0" + day }}</view>
|
|
<view class="lf-font-24">天</view>
|
|
<view class="lf-font-24">{{ hour >= 10 ? hour : "0" + hour }}</view>
|
|
<view class="lf-font-24">时</view>
|
|
<view class="lf-font-24">{{ minute >= 10 ? minute : "0" + minute }}</view>
|
|
<view class="lf-font-24">分</view>
|
|
<view class="lf-font-24">{{ second >= 10 ? second : "0" + second }}</view>
|
|
<view class="lf-font-24">秒</view>
|
|
</view>
|
|
</template>
|
|
</countdown-timer>
|
|
</view>
|
|
</view>
|
|
<view class="lf-row-between">
|
|
<view class="price">
|
|
<text>¥{{ item.seckill_price }}</text>
|
|
<text>¥{{ item.goods.market_price }}</text>
|
|
</view>
|
|
<view class="btn" hover-class="lf-opacity">立即秒杀</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<!-- 空数据的情况 -->
|
|
<view class="loading-more">
|
|
<text v-if="list.length != 0" :class="{'loading-more-text': loadingClass}">{{ loadingText }}</text>
|
|
<lf-nocontent src="/static/images/empty.png" v-else></lf-nocontent>
|
|
</view>
|
|
</view>
|
|
</scroll-view>
|
|
<u-back-top :scrollTop="pageScrollTop"></u-back-top>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import countdownTimer from '@/components/countdown-timer/countdown-timer';
|
|
export default {
|
|
data() {
|
|
return {
|
|
list: [],
|
|
page: 1,
|
|
isPage: true,
|
|
loadingClass: true,
|
|
loadingText: '正在加载中',
|
|
scrollH: 0,
|
|
nav_height: 0,
|
|
isRefresher: true,
|
|
pageSize: 10,
|
|
timer: '',
|
|
day: '',
|
|
hour: '',
|
|
min: '',
|
|
second: ''
|
|
}
|
|
},
|
|
components: {
|
|
countdownTimer
|
|
},
|
|
computed: {
|
|
autoHeight() {
|
|
return `calc(${this.scrollH}px - ${this.nav_height}px - 180rpx)`;
|
|
}
|
|
},
|
|
onLoad() {
|
|
let info = uni.getSystemInfoSync();
|
|
this.scrollH = info.screenHeight;
|
|
this.getSeckillList();
|
|
},
|
|
methods: {
|
|
// 页面触底,加载下一页
|
|
onScrolltolower() {
|
|
if (this.isPage) {
|
|
this.page = this.page + 1;
|
|
this.getSeckillList();
|
|
}
|
|
},
|
|
// 下拉刷新处理
|
|
refreshFn(options) {
|
|
this.page = 1;
|
|
this.isPage = true;
|
|
this.loadingClass = true;
|
|
this.list = []
|
|
this.loadingText = '正在加载中';
|
|
this.getSeckillList(options);
|
|
},
|
|
// scroll-view 下拉刷新
|
|
onRefresherrefresh() {
|
|
this.isRefresher = true;
|
|
this.refreshFn({
|
|
type: 'scrollRefresh'
|
|
});
|
|
},
|
|
getTime(){
|
|
var date = new Date(),
|
|
year = date.getFullYear(),
|
|
month = date.getMonth() + 1,
|
|
day = date.getDate(),
|
|
hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
|
|
minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
|
|
second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
|
|
month >= 1 && month <= 9 ? (month = "0" + month) : "";
|
|
day >= 0 && day <= 9 ? (day = "0" + day) : "";
|
|
var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
|
|
return timer;
|
|
},
|
|
getSeckillList(options = {}) {
|
|
this.$http.get({
|
|
api: 'api/seckill/all'
|
|
}).then(res => {
|
|
console.log("----", res);
|
|
let isPage = this.page < res.data.meta.pagination.total_pages ? true : false;
|
|
this.isPage = isPage;
|
|
if (!isPage) {
|
|
this.loadingClass = false;
|
|
this.loadingText = '没有更多数据啦~';
|
|
}
|
|
if (options.type == 'pageRefresh') {
|
|
uni.stopPullDownRefresh();
|
|
} else if (options.type == 'scrollRefresh') {
|
|
this.isRefresher = false;
|
|
}
|
|
if (this.page == 1) {
|
|
let list = res.data.data;
|
|
list.forEach((item,index) => {
|
|
let now_date = new Date(new Date().toLocaleDateString()).getTime();
|
|
let start_date = new Date(new Date(item.seckill.starts_at).toLocaleDateString()).getTime();
|
|
console.log(now_date)
|
|
console.log(start_date)
|
|
console.log(item)
|
|
if(now_date < start_date) {
|
|
this.$set(item,'ifStart',false)
|
|
var date = this.getTime()
|
|
let time = new Date(item.seckill.starts_at).getTime() - new Date(date).getTime()
|
|
this.$set(item,'countTime',time)
|
|
}else {
|
|
this.$set(item,'ifStart',true)
|
|
var date = this.getTime()
|
|
let time = new Date(item.seckill.ends_at).getTime() - new Date(date).getTime()
|
|
this.$set(item,'countTime',time)
|
|
}
|
|
|
|
})
|
|
this.list = list
|
|
console.log(this.list)
|
|
} else {
|
|
let list = res.data.data;
|
|
list.forEach((item,index) => {
|
|
let now_date = new Date(new Date().toLocaleDateString()).getTime();
|
|
let start_date = new Date(new Date(item.seckill.starts_at).toLocaleDateString()).getTime();
|
|
console.log(now_date)
|
|
console.log(start_date)
|
|
console.log(item)
|
|
if(now_date < start_date) {
|
|
this.$set(item,'ifStart',false)
|
|
var date = this.getTime()
|
|
let time = new Date(item.seckill.starts_at).getTime() - new Date(date).getTime()
|
|
this.$set(item,'countTime',time)
|
|
}else {
|
|
this.$set(item,'ifStart',true)
|
|
var date = this.getTime()
|
|
let time = new Date(item.seckill.ends_at).getTime() - new Date(date).getTime()
|
|
this.$set(item,'countTime',time)
|
|
}
|
|
|
|
})
|
|
this.list.push(...list);
|
|
}
|
|
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
page {
|
|
background-color: #F8F8F8;
|
|
}
|
|
</style>
|
|
<style lang="scss" scoped="scoped">
|
|
.content {
|
|
padding: 30rpx 32rpx;
|
|
width: 750rpx;
|
|
height: max-content;
|
|
box-sizing: border-box;
|
|
|
|
.card {
|
|
width: 686rpx;
|
|
height: 260rpx;
|
|
background: #FFFFFF;
|
|
border-radius: 20rpx;
|
|
box-sizing: border-box;
|
|
padding: 30rpx;
|
|
display: flex;
|
|
|
|
&:nth-child(n+2) {
|
|
margin-top: 30rpx;
|
|
}
|
|
|
|
.goods-img {
|
|
width: 200rpx;
|
|
height: 200rpx;
|
|
border-radius: 10rpx;
|
|
overflow: hidden;
|
|
position: relative;
|
|
margin-right: 15rpx;
|
|
|
|
.img {
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: #EEEEEE;
|
|
}
|
|
|
|
.tips {
|
|
position: absolute;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 37rpx;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
color: #FFFFFF;
|
|
font-size: 22rpx;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
}
|
|
|
|
.goods-info {
|
|
width: 410rpx;
|
|
height: 200rpx;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: space-between;
|
|
|
|
.title {
|
|
font-size: 28rpx;
|
|
color: #222222;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.desc {
|
|
// width: 281rpx;
|
|
height: max-content;
|
|
border-radius: 3rpx;
|
|
background-color: #E9F2F2;
|
|
font-size: 24rpx;
|
|
color: #15716E;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
.price>text:nth-child(1) {
|
|
font-size: 36rpx;
|
|
color: #F63434;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.price>text:nth-child(2) {
|
|
font-size: 24rpx;
|
|
color: #777777;
|
|
margin-left: 20rpx;
|
|
text-decoration: line-through;
|
|
}
|
|
|
|
.btn {
|
|
width: 142rpx;
|
|
height: 60rpx;
|
|
background: rgba(21, 113, 110, 0.05);
|
|
border-radius: 36rpx;
|
|
border: 2rpx solid #15716E;
|
|
font-size: 26rpx;
|
|
color: #15716E;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</style>
|