作者 刘晓艳

倒计时

... ... @@ -27,12 +27,14 @@
},
//获取banner
getBanner() {
let url = '/portal/Group/banner'
app.post(url, {}, {}).then((res) => {
// console.log('获取banner',res)
this.setData({banner: res.info});
})
},
let url = '/portal/Group/banner'
app.post(url, {}, {}).then((res) => {
// console.log('获取banner',res)
this.setData({
banner: res.info
});
})
},
//tab切换
tabCharge(e) {
var index = e.currentTarget.dataset.current
... ... @@ -98,8 +100,10 @@
//成交记录
record() {
if(!this.data.record_has_more) return;
this.setData({record_has_more: false});
if (!this.data.record_has_more) return;
this.setData({
record_has_more: false
});
let url = '/portal/Group/group_complete'
let params = {
page: this.data.record_page_number
... ... @@ -109,17 +113,21 @@
}
app.post(url, params, header).then((res) => {
console.log(res)
if(res.this_page < res.total_page) {
this.setData({record_has_more: true});
if (res.this_page < res.total_page) {
this.setData({
record_has_more: true
});
}
var recordList= res.list
for(var i=0;i<recordList.length;i++){
var chargeTime = recordList[i].create_time
chargeTime = time.formatTimeTwo(chargeTime, 'Y-M-D')
console.log(chargeTime)
recordList[i].create_time = chargeTime
}
this.setData({recordList: this.data.recordList.concat(recordList)});
var recordList = res.list
for (var i = 0; i < recordList.length; i++) {
var chargeTime = recordList[i].create_time
chargeTime = time.formatTimeTwo(chargeTime, 'Y-M-D')
console.log(chargeTime)
recordList[i].create_time = chargeTime
}
this.setData({
recordList: this.data.recordList.concat(recordList)
});
})
},
... ... @@ -211,8 +219,10 @@
//参与的组团
takeGroup() {
if(!this.data.group_has_more) return;
this.setData({group_has_more: false});
if (!this.data.group_has_more) return;
this.setData({
group_has_more: false
});
let url = '/portal/Group/group_list'
let params = {
page: this.data.group_page_number
... ... @@ -223,15 +233,28 @@
app.post(url, params, header).then((res) => {
var groupList = res.list
var goodsList = this.data.goodsList
console.log(groupList.length)
console.log(groupList)
for (var i = 0; i < groupList.length; i++) {
goodsList.push({
actEndTime: ''
})
// goodsList[i].actEndTime = '2018-12-27 13:59:44'
goodsList[i].actEndTime = groupList[i].over_time
// goodsList[i].actEndTime = '2019-05-01 10:00:43'
goodsList[i].actEndTime = groupList[i].over_time.replace(/-/g, "/")
// goodsList = [
// { actEndTime: '2019-05-01 10:00:43' },
// { actEndTime: '2019-04-01 11:00:00' },
// { actEndTime: '2019-06-01 12:45:56' },
// { actEndTime: '2019-07-01 15:00:23' },
// { actEndTime: '2019-05-23 17:00:22' },
// { actEndTime: '2019-05-14 19:00:44' },
// { actEndTime: '2019-05-21 21:00:34' },
// { actEndTime: '2019-06-17 09:00:37' },
// { actEndTime: '2019-03-21 05:00:59' },
// { actEndTime: '2019-04-19 07:00:48' },
// { actEndTime: '2019-04-28 03:00:11' }
// ]
}
goodsList.pop()
// goodsList.pop()
let endTimeList = [];
goodsList.forEach(o => {
endTimeList.push(o.actEndTime)
... ... @@ -241,13 +264,15 @@
});
// console.log(endTimeList)
this.countDown();
if(res.this_page < res.total_page) {
this.setData({group_has_more: true});
if (res.this_page < res.total_page) {
this.setData({
group_has_more: true
});
}
// console.log('list', list);
this.setData({
groupList: this.data.groupList.concat(res.list),
goodsList: goodsList
groupList: this.data.groupList.concat(res.list),
goodsList: goodsList
});
})
},
... ... @@ -281,6 +306,7 @@
min: this.timeFormat(min),
sec: this.timeFormat(sec)
}
// console.log(obj)
} else { //活动已结束,全部设置为'00'
obj = {
day: '00',
... ... @@ -320,36 +346,36 @@
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
const self = this;
if(+self.data.current === 0) {
if(self.data.group_has_more) {
self.data.group_page_number ++;
self.takeGroup();
}else {
wx.showToast({
title: '没有更多数据了~',
icon: 'none'
});
}
console.log('上拉加载');
}else if(+self.data.current === 1) {
if(self.data.record_has_more) {
self.data.record_page_number ++;
self.record();
}else {
wx.showToast({
title: '没有更多数据了~',
icon: 'none'
});
}
console.log('上拉加载');
}
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
const self = this;
if (+self.data.current === 0) {
if (self.data.group_has_more) {
self.data.group_page_number++;
self.takeGroup();
} else {
wx.showToast({
title: '没有更多数据了~',
icon: 'none'
});
}
console.log('上拉加载');
} else if (+self.data.current === 1) {
if (self.data.record_has_more) {
self.data.record_page_number++;
self.record();
} else {
wx.showToast({
title: '没有更多数据了~',
icon: 'none'
});
}
console.log('上拉加载');
}
},
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
... ...
... ... @@ -10,9 +10,24 @@ Page({
imgUrls: ['../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png'],
id: '',
list_info: {},
rule:[]
rule: [],
countdown: '',
endDate2: '',
banner:''
},
//获取banner
getBanner() {
let url = '/portal/Group/banner'
app.post(url, {}, {}).then((res) => {
// console.log('获取banner',res)
this.setData({
banner: res.info
});
})
},
//查看全部
listMore(e) {
this.setData({
... ... @@ -31,10 +46,45 @@ Page({
app.post(url, params, header).then((res) => {
console.log(res)
this.setData({
list_info: res.info
list_info: res.info,
endDate2: res.info.over_time.replace(/-/g, "/")
})
this.countTime()
})
},
countTime() {
var that = this;
var date = new Date();
var now = date.getTime();
var endDate = new Date(that.data.endDate2); //设置截止时间
var end = endDate.getTime();
var leftTime = end - now; //时间差
var d, h, m, s, ms;
if (leftTime >= 0) {
d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
m = Math.floor(leftTime / 1000 / 60 % 60);
s = Math.floor(leftTime / 1000 % 60);
ms = Math.floor(leftTime % 1000);
ms = ms < 100 ? "0" + ms : ms
s = s < 10 ? "0" + s : s
m = m < 10 ? "0" + m : m
h = h < 10 ? "0" + h : h
that.setData({
countdown: h + ":" + m + ":" + s,
})
//递归每秒调用countTime方法,显示动态时间效果
setTimeout(that.countTime, 100);
} else {
console.log('已截止')
that.setData({
countdown: '00:00:00'
})
}
},
//团购规则
getRule() {
let url = '/wxapp/public/arc_group'
... ... @@ -58,6 +108,7 @@ Page({
})
this.listDetail()
this.getRule()
this.getBanner()
},
/**
... ... @@ -112,7 +163,7 @@ Page({
// 设置菜单中的转发按钮触发转发事件时的转发内容
var shareObj = {
title: '科学队长', // 默认是小程序的名称(可以写slogan等)
path: '/pages/my/takeGroupBuy/takeGroupBuy?group_id=' + group_id,// 默认是当前页面,必须是以‘/’开头的完整路径
path: '/pages/my/takeGroupBuy/takeGroupBuy?group_id=' + group_id, // 默认是当前页面,必须是以‘/’开头的完整路径
imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
success: function(res) {
if (res.errMsg == 'shareAppMessage:ok') {}
... ...
<!--pages/groupBuyDetail/groupBuyDetail.wxml-->
<view class='banner_img'>
<image src='../../../images/banner.jpg'></image>
<image src='{{banner}}'></image>
</view>
<view class='content_box'>
<view class="item_list">
... ... @@ -26,7 +26,7 @@
<text>{{list_info.count}}</text> 人,快呼唤伙伴参与吧!</view>
<view class='list_info'>
<view class='list_info_item'>剩余
<text>{{list_info.surplus_time}} </text> 结束</view>
<text>{{countdown}} </text> 结束</view>
</view>
<view>
<view class='user_info_box'>
... ...
// pages/my/takeGroupBuy/takeGroupBuy.js
const app = getApp()
const time = require('../../../utils/util.js');
Page({
/**
... ... @@ -10,10 +11,17 @@ Page({
take_info: '',
is_agree: false,
rule: '',
group_id: ''
group_id: '',
countDownList: [],
actEndTimeList: [],
goodsList: [{
actEndTime: ''
}],
countdown: '',
endDate2: ''
},
//查看详情
listDetail(e) {
var id = e.currentTarget.dataset.id
... ... @@ -34,13 +42,16 @@ Page({
"XX-Token": wx.getStorageSync('token')
}
app.post(url, params, header).then((res) => {
console.log(res)
console.log(res.info.over_time)
that.setData({
group_info: res.info
group_info: res.info,
endDate2: res.info.over_time.replace(/-/g, "/")
})
this.countTime()
})
},
//团购规则
getRule() {
let url = '/wxapp/public/arc_group'
... ... @@ -142,6 +153,37 @@ Page({
})
},
countTime() {
var that = this;
var date = new Date();
var now = date.getTime();
var endDate = new Date(that.data.endDate2);//设置截止时间
var end = endDate.getTime();
var leftTime = end - now; //时间差
var d, h, m, s, ms;
if (leftTime >= 0) {
d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
m = Math.floor(leftTime / 1000 / 60 % 60);
s = Math.floor(leftTime / 1000 % 60);
ms = Math.floor(leftTime % 1000);
ms = ms < 100 ? "0" + ms : ms
s = s < 10 ? "0" + s : s
m = m < 10 ? "0" + m : m
h = h < 10 ? "0" + h : h
that.setData({
countdown: h + ":" + m + ":" + s,
})
//递归每秒调用countTime方法,显示动态时间效果
setTimeout(that.countTime, 100);
} else {
console.log('已截止')
that.setData({
countdown: '00:00:00'
})
}
},
/**
* 生命周期函数--监听页面加载
... ... @@ -169,9 +211,12 @@ Page({
})
}
})
// this.checkMobile()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
... ...
... ... @@ -53,7 +53,7 @@
<text>{{group_info.count}}</text> 人,快呼唤伙伴参与吧!</view>
<view class='list_info'>
<view class='list_info_item'>剩余
<text>{{group_info.surplus_time}}</text> 结束</view>
<text>{{countdown}}</text> 结束</view>
</view>
<view>
<view class='user_info_box'>
... ...
... ... @@ -13,7 +13,7 @@
"compileType": "miniprogram",
"libVersion": "2.4.0",
"appid": "wx267cf208ca289769",
"projectname": "science",
"projectname": "kexueduiz",
"debugOptions": {
"hidedInDevtools": []
},
... ... @@ -36,7 +36,7 @@
"list": []
},
"miniprogram": {
"current": 3,
"current": 4,
"list": [
{
"id": -1,
... ... @@ -61,6 +61,12 @@
"name": "group",
"pathName": "pages/my/groupBuy/groupBuy",
"query": "group_id=60"
},
{
"id": 4,
"name": "参与团购",
"pathName": "pages/my/takeGroupBuy/takeGroupBuy",
"query": "group_id=90"
}
]
}
... ...