function goTimer(orderTimeoutSeconds) {
let intDiff = orderTimeoutSeconds;
let myTimer = window.setInterval(function () {
let day = 0,
hour = 0,
minute = 0,
second = 0;//时间默认值
if (intDiff > 0) {
day = Math.floor(intDiff / (60 * 60 * 24));
hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
}
if (minute <= 9) minute = '0' + minute;
if (second <= 9) second = '0' + second;
$('#hour_show').html('' + hour + ':');
$('#minute_show').html('' + minute + ':');
$('#second_show').html('' + second + '');
if (hour <= 0 && minute <= 0 && second <= 0) {
qrcode_timeout(true);
clearInterval(myTimer);
}
intDiff = intDiff - 2;
}, 2000);
}
function qrcode_timeout(needReload) {
const qrCodeImg = document.getElementById('show_qrcode');
if (qrCodeImg != null) {
qrCodeImg.setAttribute("src", "/static/images/qrcode_timeout.png");
}
else{
const orderInfo = document.getElementById("orderInfo");
if (orderInfo != null) {
orderInfo.remove();
const showInfo=document.getElementById("showInfo");
if(showInfo!=null){
showInfo.innerText="已超时";
}
}
}
hiddenDiv();
if (needReload) {
location.reload();
}
}
function hiddenDiv() {
const orderTime = document.getElementById("order_time");
if (orderTime != null) {
orderTime.style.visibility = "hidden";
}
const openLink = document.getElementById("open_link");
if (openLink != null) {
openLink.style.visibility = "hidden";
}
const qrcodeByLink = document.getElementById("qrcodeByLink");
if (qrcodeByLink != null) {
qrcodeByLink.style.visibility = "hidden";
}
const qrcode = document.getElementById("qrcode");
if (qrcode != null) {
qrcode.style.visibility = "visible";
}
}
function orderSuccess(needReload) {
const qrCodeImg = document.getElementById('show_qrcode');
if(qrCodeImg!=null) {
qrCodeImg.setAttribute("src", "/static/images/pay_ok.png");
}
else{
const orderInfo = document.getElementById("orderInfo");
if (orderInfo != null) {
orderInfo.remove();
const showInfo=document.getElementById("showInfo");
if(showInfo!=null){
showInfo.innerText="已完成";
}
}
}
hiddenDiv();
if (needReload) {
location.reload();
}
}
function start(orderStatus, orderTimeoutSeconds) {
//默认6分钟过期
if (orderStatus === "unfinished") {
goTimer(orderTimeoutSeconds);
} else if (orderStatus === "timeout") {
qrcode_timeout(false);
} else if (orderStatus === "success") {
orderSuccess(false);
}
}