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.

101 lines
2.5 KiB

//index.js
//获取应用实例
const app = getApp()
// var total_micro_second = 30*60*1000;
// var total_micro_second = 10 * 1000;
function countdown(that) {
// 渲染倒计时时钟
let clock = that.data.clock*1000;
that.setData({
clockTime: dateformat(clock)
});
if (clock <= 1) {
that.setData({
reminder: "支付时间已结束"
});
// timeout则跳出递归
clearTimeout(c);
return;
}
var c=setTimeout(function () {
clock -= 1000;
that.setData({
clock: clock / 1000
});
console.log(clock);
countdown(that)
}, 1000);
}
// 时间格式化输出,如3:25:19 86。每10ms都会调用一次
function dateformat(micro_second) {
// 秒数
var second = Math.floor(micro_second / 1000);
// 小时位
var hr = Math.floor(second / 3600);
// 分钟位
var min = Math.floor((second - hr * 3600) / 60);
// 秒位
var sec = (second - hr * 3600 - min * 60);// equal to => var sec = second % 60;
// 毫秒位,保留2位
// var micro_sec = Math.floor((micro_second % 1000) / 10);
return min + ":" + sec;
}
Page({
data: {
reminder:'确认支付'
},
//事件处理函数
pay: function (e) {
let str = JSON.stringify(e.currentTarget.dataset.item);
wx.navigateTo({
url: '../pay/pay?jsonStr=' + str
})
console.log(str);
},
onLoad: function (options) {
let item = JSON.parse(options.jsonStr);
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true,
price: item.price,
title: item.name,
product: item,
clock: options.clock,
clockTime: dateformat(options.clock * 1000)
})
countdown(this);
} else if (this.data.canIUse) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
},
getUserInfo: function (e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})