Browse Source

倒计时

master
Enzo 4 years ago
parent
commit
648c691199
  1. 20
      components/uni-countdown/uni-countdown.vue
  2. 117
      pages/shop/goodsdetail.vue
  3. 51
      pages/shop/seckillList.vue

20
components/uni-countdown/uni-countdown.vue

@ -1,15 +1,15 @@
<template> <template>
<view class="uni-countdown"> <view class="uni-countdown">
<text v-if="showDay" :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }"
<text v-if="showDay" :style="{ borderColor: borderColor, color: color }"
class="uni-countdown__number">{{ d }}</text> class="uni-countdown__number">{{ d }}</text>
<text v-if="showDay" :style="{ color: splitorColor }" class="uni-countdown__splitor">{{dayText}}</text> <text v-if="showDay" :style="{ color: splitorColor }" class="uni-countdown__splitor">{{dayText}}</text>
<text :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }"
<text :style="{ borderColor: borderColor, color: color }"
class="uni-countdown__number">{{ h }}</text> class="uni-countdown__number">{{ h }}</text>
<text :style="{ color: splitorColor }" class="uni-countdown__splitor">{{ showColon ? ':' : hourText }}</text>
<text :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }"
<text :style="{ color: splitorColor }" class="uni-countdown__splitor">{{ showColon ? '' : hourText }}</text>
<text :style="{ borderColor: borderColor, color: color }"
class="uni-countdown__number">{{ i }}</text> class="uni-countdown__number">{{ i }}</text>
<text :style="{ color: splitorColor }" class="uni-countdown__splitor">{{ showColon ? ':' : minuteText }}</text>
<text :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }"
<text :style="{ color: splitorColor }" class="uni-countdown__splitor">{{ showColon ? '' : minuteText }}</text>
<text :style="{ borderColor: borderColor, color: color }"
class="uni-countdown__number">{{ s }}</text> class="uni-countdown__number">{{ s }}</text>
<text v-if="!showColon" :style="{ color: splitorColor }" class="uni-countdown__splitor">{{secondText}}</text> <text v-if="!showColon" :style="{ color: splitorColor }" class="uni-countdown__splitor">{{secondText}}</text>
</view> </view>
@ -59,15 +59,15 @@
}, },
borderColor: { borderColor: {
type: String, type: String,
default: '#000000'
default: '#15716E'
}, },
color: { color: {
type: String, type: String,
default: '#000000'
default: '#15716E'
}, },
splitorColor: { splitorColor: {
type: String, type: String,
default: '#000000'
default: '#15716E'
}, },
day: { day: {
type: Number, type: Number,
@ -250,8 +250,6 @@
/* #endif */ /* #endif */
justify-content: center; justify-content: center;
align-items: center; align-items: center;
width: $countdown-width;
height: $countdown-height;
line-height: $countdown-height; line-height: $countdown-height;
margin: 5rpx; margin: 5rpx;
text-align: center; text-align: center;

117
pages/shop/goodsdetail.vue

@ -9,7 +9,7 @@
<image mode="aspectFill" :src="item" style="width: 100%; height: 100%;" @click="lookImg(index)"></image> <image mode="aspectFill" :src="item" style="width: 100%; height: 100%;" @click="lookImg(index)"></image>
<view class="seckill-box" v-if="type == 'seckill'"> <view class="seckill-box" v-if="type == 'seckill'">
<view>距离结束还剩余</view> <view>距离结束还剩余</view>
<view v-if="$isRight(time)">
<view>
<countdown-timer :time="time" :autoStart="true" @finish="dateFinish"> <countdown-timer :time="time" :autoStart="true" @finish="dateFinish">
<template v-slot="{day, hour, minute, second}"> <template v-slot="{day, hour, minute, second}">
<view class="lf-flex"> <view class="lf-flex">
@ -177,7 +177,7 @@
<button class="btn" style="width: 349rpx;">立即秒杀</button> <button class="btn" style="width: 349rpx;">立即秒杀</button>
</view> </view>
<view v-else-if="type == 'point'"> <view v-else-if="type == 'point'">
<button class="btn" style="width: 349rpx;" @click="goExchange()">立即兑换</button>
<button class="btn" style="width: 349rpx;">立即兑换</button>
</view> </view>
<view class="lf-flex" v-else> <view class="lf-flex" v-else>
<button class="btn1" @click="shoot(1)">加入购物车</button> <button class="btn1" @click="shoot(1)">加入购物车</button>
@ -268,9 +268,7 @@
token: '', token: '',
coupons: [], // coupons: [], //
goods_num: 1, goods_num: 1,
is_date_finish: false,
show_share: false,
shareImg: ''
is_date_finish: false
} }
}, },
computed: { computed: {
@ -319,11 +317,6 @@
this.getGoodsStock(); // this.getGoodsStock(); //
}, },
methods: { methods: {
goExchange() {
if(this.showSpec == '请选择规格') {
this.shoot(3)
}
},
// //
switchCollect(){ switchCollect(){
if(!this.token){ if(!this.token){
@ -396,7 +389,7 @@
} }
} }
}, },
//
// TODO
confirm(){ confirm(){
if(this.is_date_finish){ if(this.is_date_finish){
return this.$msg('活动已结束'); return this.$msg('活动已结束');
@ -484,7 +477,7 @@
// //
this.$cookieStorage.set('order_confirm', par); this.$cookieStorage.set('order_confirm', par);
uni.hideLoading(); uni.hideLoading();
this.$url('/pages/order/confirm/confirm?goods_type=1');
this.$url('/pages/order/confirm/confirm');
// this.$http.post({ // this.$http.post({
// api: 'api/shopping/order/checkout', // api: 'api/shopping/order/checkout',
// data: par, // data: par,
@ -499,73 +492,50 @@
// } // }
// uni.hideLoading() // uni.hideLoading()
// }).catch(err => uni.hideLoading()) // }).catch(err => uni.hideLoading())
}else if(this.click_type == 3) {
//
this.$cookieStorage.set('order_confirm', par);
uni.hideLoading();
this.$url('/pages/order/confirm/confirm?goods_type=0');
} }
}, },
// //
shareGraphic(){ shareGraphic(){
this.getShearImg();
this.getCreateShareImg();
}, },
//
getShearImg() {
wx.showLoading({
title: "生成中",
mask: true
});
var token = this.token;
this.$http.get({
api: 'api/distribution/createMiniShareImg',
header: {
Authorization: token
},
data: {
goods_id: this.goods_id
}
}).then(res => {
if (res.statusCode == 200) {
res = res.data;
if (res.status) {
this.setData({
shareImg: res.data.image
});
setTimeout(() => {
this.changeImg();
}, 100)
} else {
wx.showModal({
content: res.message || '请求失败',
showCancel: false
});
}
} else {
wx.showModal({
content: '请求失败',
showCancel: false
});
}
//h5
getCreateShareImg(){
wx.showLoading({
title:"生成中",
mask:true
})
let origin = window.location.origin;
let share_url = origin+'/pages/store/detail/detail';
this.$http.get({
api:'api/distribution/createH5ShareImg',
data:{
goods_id:this.id,
share_url:share_url
}
}).then(res=>{
res = res.data;
if(res.status){
this.qr_code_image = res.data.image;
wx.hideLoading();
this.changeShare();
}).catch(rej => {
wx.showModal({
content: '内部错误',
showCancel: false
});
wx.hideLoading();
this.changeShare();
});
},
//
changeShare() {
this.setData({
show_share: !this.show_share
});
if(this.qr_code_image){
this.share_gaphic =!this.share_gaphic;
this.is_toggle_share = false;
}
} else{
wx.showModal({
content: res.message || '请求失败,请重试',
showCancel: false
});
}
wx.hideLoading()
}).catch(rej=>{
wx.hideLoading()
wx.showModal({
content: rej.message || '内部错误,请重试',
showCancel: false
});
})
}, },
// //
getNewdetail(){ getNewdetail(){
@ -590,7 +560,6 @@
this.seckill = meta.seckill; this.seckill = meta.seckill;
let currentDate = this.$shared.recordTime(); let currentDate = this.$shared.recordTime();
this.time = new Date(meta.seckill.ends_at).getTime() - new Date(currentDate).getTime() this.time = new Date(meta.seckill.ends_at).getTime() - new Date(currentDate).getTime()
console.log("time", this.time, meta.seckill.ends_at, currentDate)
} }
if(type != 'point'){ if(type != 'point'){
this.getBrandDetail(goods_detail.brand_id); this.getBrandDetail(goods_detail.brand_id);

51
pages/shop/seckillList.vue

@ -54,7 +54,7 @@
</view> --> </view> -->
<view class="desc" v-if="item.seckill.end_left_time.length==0"> <view class="desc" v-if="item.seckill.end_left_time.length==0">
距离开始还剩余 距离开始还剩余
<countdown-time :day="item.seckill.end_left_time[0]" :hour="item.seckill.end_left_time[1]" :minute="item.seckill.end_left_time[2]" :second="item.seckill.end_left_time[3]">
<countdown-time :day="item.seckill.start_left_time[0]" :hour="item.seckill.start_left_time[1]" :minute="item.seckill.start_left_time[2]" :second="item.seckill.start_left_time[3]">
</countdown-time> </countdown-time>
</view> </view>
@ -85,7 +85,6 @@
</template> </template>
<script> <script>
import countdownTimer from '@/components/countdown-timer/countdown-timer';
import countdownTime from '@/components/uni-countdown/uni-countdown.vue'; import countdownTime from '@/components/uni-countdown/uni-countdown.vue';
export default { export default {
data() { data() {
@ -107,7 +106,6 @@
} }
}, },
components: { components: {
countdownTimer,
countdownTime countdownTime
}, },
computed: { computed: {
@ -174,52 +172,9 @@
this.isRefresher = false; this.isRefresher = false;
} }
if (this.page == 1) { 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)
console.log("time", 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)
console.log("time", time);
}
})
this.list = list
console.log(this.list)
this.list = res.data.data;
} else { } 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);
this.list.push(...res.data.data);
} }
}) })

Loading…
Cancel
Save