feat: 页面优化1
This commit is contained in:
parent
6c0b41639b
commit
b0fd568271
|
@ -1,378 +1,390 @@
|
||||||
{{define "payPage.html"}}
|
{{define "payPage.html"}}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>收银台页面</title>
|
||||||
|
|
||||||
<head>
|
<style>
|
||||||
<meta charset="UTF-8">
|
/* 基础样式 */
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
body {
|
||||||
<title>收银台页面</title>
|
font-family: Arial, sans-serif;
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
<style>
|
/* 段落样式 */
|
||||||
/* 基础样式 */
|
p {
|
||||||
body {
|
color: #666666;
|
||||||
font-family: Arial, sans-serif;
|
margin-bottom: 10px;
|
||||||
max-width: 800px;
|
}
|
||||||
margin: 0 auto;
|
|
||||||
padding: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 段落样式 */
|
/* 无序列表样式 */
|
||||||
p {
|
ul {
|
||||||
color: #666666;
|
list-style: none;
|
||||||
margin-bottom: 10px;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 无序列表样式 */
|
/* 列表项样式 */
|
||||||
ul {
|
li {
|
||||||
list-style: none;
|
margin: 10px 0;
|
||||||
padding: 0;
|
display: flex;
|
||||||
}
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
/* 列表项样式 */
|
/* 按钮样式 */
|
||||||
li {
|
button {
|
||||||
margin: 10px 0;
|
background-color: #007bff;
|
||||||
display: flex;
|
color: #fff;
|
||||||
align-items: center;
|
border: none;
|
||||||
}
|
padding: 10px 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
/* 按钮样式 */
|
/* 按钮悬停样式 */
|
||||||
button {
|
button:hover {
|
||||||
background-color: #007BFF;
|
background-color: #0056b3;
|
||||||
color: #fff;
|
}
|
||||||
border: none;
|
|
||||||
padding: 10px 20px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background-color 0.3s ease;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 16px;
|
|
||||||
margin-top: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 按钮悬停样式 */
|
/* loading样式 */
|
||||||
button:hover {
|
.loading-container {
|
||||||
background-color: #0056b3;
|
display: flex;
|
||||||
}
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
/* loading样式 */
|
.loading-spinner {
|
||||||
.loading-container {
|
border: 5px solid #f3f3f3;
|
||||||
display: flex;
|
border-top: 5px solid #007bff;
|
||||||
flex-direction: column;
|
border-radius: 50%;
|
||||||
align-items: center;
|
width: 50px;
|
||||||
justify-content: center;
|
height: 50px;
|
||||||
height: 100%;
|
animation: spin 1s linear infinite;
|
||||||
}
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.loading-spinner {
|
@keyframes spin {
|
||||||
border: 5px solid #f3f3f3;
|
0% {
|
||||||
border-top: 5px solid #007BFF;
|
transform: rotate(0deg);
|
||||||
border-radius: 50%;
|
}
|
||||||
width: 50px;
|
100% {
|
||||||
height: 50px;
|
transform: rotate(360deg);
|
||||||
animation: spin 1s linear infinite;
|
}
|
||||||
margin-bottom: 20px;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes spin {
|
.loading-text {
|
||||||
0% { transform: rotate(0deg); }
|
color: #666;
|
||||||
100% { transform: rotate(360deg); }
|
font-size: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading-text {
|
/* 支付信息卡片 */
|
||||||
color: #666;
|
.payment-info {
|
||||||
font-size: 18px;
|
background: #f9f9f9;
|
||||||
}
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
/* 支付信息卡片 */
|
.payment-info h2 {
|
||||||
.payment-info {
|
margin-top: 0;
|
||||||
background: #f9f9f9;
|
color: #333;
|
||||||
padding: 20px;
|
}
|
||||||
border-radius: 8px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.payment-info h2 {
|
/* 支付方式选项 */
|
||||||
margin-top: 0;
|
.payment-option {
|
||||||
color: #333;
|
padding: 15px;
|
||||||
}
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
/* 支付方式选项 */
|
.payment-option:hover {
|
||||||
.payment-option {
|
border-color: #007bff;
|
||||||
padding: 15px;
|
background-color: #f0f7ff;
|
||||||
border: 1px solid #ddd;
|
}
|
||||||
border-radius: 8px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.payment-option:hover {
|
.payment-option input[type="radio"] {
|
||||||
border-color: #007BFF;
|
margin-right: 15px;
|
||||||
background-color: #f0f7ff;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.payment-option input[type="radio"] {
|
.payment-option.selected {
|
||||||
margin-right: 15px;
|
border-color: #007bff;
|
||||||
}
|
background-color: #f0f7ff;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
.payment-option.selected {
|
{{if eq .code 200 }}
|
||||||
border-color: #007BFF;
|
<body>
|
||||||
background-color: #f0f7ff;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
{{if eq .code 200 }}
|
|
||||||
<body>
|
|
||||||
<!-- 页面内容 -->
|
<!-- 页面内容 -->
|
||||||
<div class="payment-info" id="payment-info" style="display: none;">
|
<div class="payment-info" id="payment-info" style="display: none">
|
||||||
<h2>订单支付</h2>
|
<h2>订单支付</h2>
|
||||||
<p>{{.desc}}</p>
|
<p>{{.desc}}</p>
|
||||||
<p>交易号:{{ .id }}</p>
|
<p>交易号:{{ .id }}</p>
|
||||||
<p>交易金额:<strong style="color: #ff5500; font-size: 24px;">{{ .amount }}</strong> 元</p>
|
<p>
|
||||||
|
交易金额:<strong style="color: #ff5500; font-size: 24px"
|
||||||
|
>{{ .amount }}</strong
|
||||||
|
>
|
||||||
|
元
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 支付方式选择区域 -->
|
<!-- 支付方式选择区域 -->
|
||||||
<div id="pay-container" style="display: none;">
|
<div id="pay-container" style="display: none">
|
||||||
<div id="pay"></div>
|
<div id="pay"></div>
|
||||||
<!-- 支付方式列表 -->
|
<!-- 支付方式列表 -->
|
||||||
<ul id="payment-list"></ul>
|
<ul id="payment-list"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Loading状态 -->
|
<!-- Loading状态 -->
|
||||||
<div id="loading" class="loading-container" style="display: flex;">
|
<div id="loading" class="loading-container" style="display: flex">
|
||||||
<div class="loading-spinner"></div>
|
<div class="loading-spinner"></div>
|
||||||
<p class="loading-text">支付处理中,请稍等...</p>
|
<p class="loading-text">支付处理中,请稍等...</p>
|
||||||
</div>
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
</body>
|
<script>
|
||||||
|
// 从URL中提取参数
|
||||||
<script>
|
function getQueryParam(param) {
|
||||||
// 从URL中提取参数
|
const queryString = window.location.search.substring(1);
|
||||||
function getQueryParam(param) {
|
const params = queryString.split("&");
|
||||||
const queryString = window.location.search.substring(1);
|
for (let i = 0; i < params.length; i++) {
|
||||||
const params = queryString.split('&');
|
const [key, value] = params[i].split("=");
|
||||||
for (let i = 0; i < params.length; i++) {
|
if (key === param) {
|
||||||
const [key, value] = params[i].split('=');
|
return decodeURIComponent(value);
|
||||||
if (key === param) {
|
|
||||||
return decodeURIComponent(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// 显示Loading效果
|
// 显示Loading效果
|
||||||
function showLoading() {
|
function showLoading() {
|
||||||
document.getElementById('payment-info').style.display = 'none';
|
document.getElementById("payment-info").style.display = "none";
|
||||||
document.getElementById('pay-container').style.display = 'none';
|
document.getElementById("pay-container").style.display = "none";
|
||||||
document.getElementById('loading').style.display = 'block';
|
document.getElementById("loading").style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关闭Loading效果
|
// 关闭Loading效果
|
||||||
function closeLoading() {
|
function closeLoading() {
|
||||||
document.getElementById('loading').style.display = 'none';
|
document.getElementById("loading").style.display = "none";
|
||||||
document.getElementById('payment-info').style.display = 'block';
|
document.getElementById("payment-info").style.display = "block";
|
||||||
document.getElementById('pay-container').style.display = 'block';
|
document.getElementById("pay-container").style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理支付回调
|
// 处理支付回调
|
||||||
function handlePaymentCallback() {
|
function handlePaymentCallback() {
|
||||||
const id = getQueryParam('no');
|
const id = getQueryParam("no");
|
||||||
if (!id) {
|
if (!id) {
|
||||||
closeLoading();
|
closeLoading();
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
// 查询订单状态
|
// 查询订单状态
|
||||||
fetch(`/pay/front/api/v1/payPage/query?no=${id}`, {
|
fetch(`/pay/front/api/v1/payPage/query?no=${id}`, {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
})
|
})
|
||||||
.then(async response => {
|
.then(async (response) => {
|
||||||
if (!response.ok) throw new Error('请求失败');
|
if (!response.ok) throw new Error("请求失败");
|
||||||
return await response.json();
|
return await response.json();
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then((data) => {
|
||||||
closeLoading();
|
closeLoading();
|
||||||
switch(data.status) {
|
switch (data.status) {
|
||||||
case 2: // 处理中
|
case 2: // 处理中
|
||||||
handlePaymentCallback(); // 重查状态
|
handlePaymentCallback(); // 重查状态
|
||||||
break;
|
break;
|
||||||
case 3: // 支付成功
|
case 3: // 支付成功
|
||||||
if (data.return_url) {
|
if (data.return_url) {
|
||||||
window.location.href = data.return_url; // 自动跳转
|
window.location.href = data.return_url; // 自动跳转
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: // 其他状态(待支付/失败/关闭)
|
default: // 其他状态(待支付/失败/关闭)
|
||||||
fetchPaymentMethods();
|
fetchPaymentMethods();
|
||||||
// window.location.reload();
|
// window.location.reload();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
// closeLoading();
|
// closeLoading();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取支付方式列表
|
|
||||||
function fetchPaymentMethods() {
|
|
||||||
|
|
||||||
const id = getQueryParam('no');
|
|
||||||
if (id) {
|
|
||||||
fetch(`/pay/front/api/v1/payPage/list?id=${id}`, {
|
|
||||||
method: 'POST',
|
|
||||||
})
|
|
||||||
.then(async response => {
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json()
|
|
||||||
console.log(data)
|
|
||||||
if (data.code !== 200) {
|
|
||||||
throw new Error('无效');
|
|
||||||
} else {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Error('无效');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
// 处理返回的数据,例如渲染支付方式列表
|
|
||||||
if (data === null || data.data.length === 0) {
|
|
||||||
const pay = document.getElementById('pay');
|
|
||||||
pay.innerHTML = '<h3>支付环境异常,请检查</h3>';
|
|
||||||
} else if (data.data.length === 1) {
|
|
||||||
if(localStorage.getItem('auto-redirect') != 2){
|
|
||||||
// 否则设置自动跳转标记,并跳转
|
|
||||||
localStorage.setItem('auto-redirect', 2);
|
|
||||||
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${data.data[0].pay_channel_id}&no=${id}`;
|
|
||||||
} else {
|
|
||||||
closeLoading();
|
|
||||||
renderPaymentMethods(data.data);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
closeLoading();
|
|
||||||
// 多种支付方式,展示支付界面
|
|
||||||
renderPaymentMethods(data.data);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
closeLoading();
|
|
||||||
console.error('获取支付方式失败:', error);
|
|
||||||
const pay = document.getElementById('pay');
|
|
||||||
pay.innerHTML = '<h3 style="color: red;">获取支付方式失败,请刷新重试</h3>';
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
closeLoading();
|
|
||||||
console.error('Order no not found in URL');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 渲染支付方式列表
|
|
||||||
function renderPaymentMethods(paymentMethods) {
|
|
||||||
const pay = document.getElementById('pay');
|
|
||||||
pay.innerHTML = '<h3>请选择支付方式</h3>';
|
|
||||||
|
|
||||||
const paymentList = document.getElementById('payment-list');
|
|
||||||
paymentList.innerHTML = '';
|
|
||||||
|
|
||||||
// 标记是否是第一个支付方式
|
|
||||||
let isFirstMethod = true;
|
|
||||||
|
|
||||||
paymentMethods.forEach(method => {
|
|
||||||
const listItem = document.createElement('li');
|
|
||||||
listItem.className = 'payment-option';
|
|
||||||
|
|
||||||
const radioInput = document.createElement('input');
|
|
||||||
radioInput.type = 'radio';
|
|
||||||
radioInput.name = 'paymentMethod';
|
|
||||||
radioInput.value = method.pay_channel_id;
|
|
||||||
radioInput.id = `method-${method.pay_channel_id}`;
|
|
||||||
|
|
||||||
// 如果是第一个支付方式,默认选中
|
|
||||||
if(isFirstMethod) {
|
|
||||||
radioInput.checked = true;
|
|
||||||
listItem.classList.add('selected');
|
|
||||||
isFirstMethod = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const label = document.createElement('label');
|
|
||||||
label.htmlFor = `method-${method.pay_channel_id}`;
|
|
||||||
label.textContent = method.pay_name;
|
|
||||||
|
|
||||||
if (method.icon_url) {
|
|
||||||
const icon = document.createElement('img');
|
|
||||||
icon.src = method.icon_url;
|
|
||||||
icon.style.height = '24px';
|
|
||||||
icon.style.marginRight = '10px';
|
|
||||||
label.prepend(icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
listItem.appendChild(radioInput);
|
|
||||||
listItem.appendChild(label);
|
|
||||||
paymentList.appendChild(listItem);
|
|
||||||
|
|
||||||
// 点击整个区域也可以选择
|
|
||||||
listItem.addEventListener('click', () => {
|
|
||||||
// 移除所有选中样式
|
|
||||||
document.querySelectorAll('.payment-option').forEach(item => {
|
|
||||||
item.classList.remove('selected');
|
|
||||||
});
|
|
||||||
// 添加当前选中样式
|
|
||||||
listItem.classList.add('selected');
|
|
||||||
radioInput.checked = true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 添加提交按钮
|
|
||||||
const submitButton = document.createElement('button');
|
|
||||||
submitButton.type = 'button';
|
|
||||||
submitButton.textContent = '立即支付';
|
|
||||||
|
|
||||||
submitButton.onclick = function () {
|
|
||||||
const no = getQueryParam('no');
|
|
||||||
const selectedMethod = document.querySelector('input[name="paymentMethod"]:checked');
|
|
||||||
if (selectedMethod) {
|
|
||||||
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${selectedMethod.value}&no=${no}`;
|
|
||||||
} else {
|
|
||||||
alert('请选择支付方式');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const buttonContainer = document.createElement('div');
|
|
||||||
buttonContainer.style.textAlign = 'center';
|
|
||||||
buttonContainer.appendChild(submitButton);
|
|
||||||
paymentList.appendChild(buttonContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 页面加载时执行
|
|
||||||
// 监听页面可见性变化
|
|
||||||
document.addEventListener('visibilitychange', function() {
|
|
||||||
if (!document.hidden && localStorage.getItem('auto-redirect') == 2) {
|
|
||||||
// 页面从后台返回且处于支付状态
|
|
||||||
fetchPaymentMethods();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
window.onload = function() {
|
// 获取支付方式列表
|
||||||
if (localStorage.getItem('auto-redirect') && localStorage.getItem('auto-redirect') == 2) {
|
function fetchPaymentMethods() {
|
||||||
handlePaymentCallback(); // 如果是支付回调且不是自动跳转,处理支付结果
|
const id = getQueryParam("no");
|
||||||
|
if (id) {
|
||||||
|
fetch(`/pay/front/api/v1/payPage/list?id=${id}`, {
|
||||||
|
method: "POST",
|
||||||
|
})
|
||||||
|
.then(async (response) => {
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
console.log(data);
|
||||||
|
if (data.code !== 200) {
|
||||||
|
throw new Error("无效");
|
||||||
|
} else {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem('auto-redirect', 1); // 设置自动跳转标记
|
throw new Error("无效");
|
||||||
fetchPaymentMethods(); // 获取支付方式
|
|
||||||
}
|
}
|
||||||
};
|
})
|
||||||
|
.then((data) => {
|
||||||
|
// 处理返回的数据,例如渲染支付方式列表
|
||||||
|
if (data === null || data.data.length === 0) {
|
||||||
|
const pay = document.getElementById("pay");
|
||||||
|
pay.innerHTML = "<h3>支付环境异常,请检查</h3>";
|
||||||
|
} else if (data.data.length === 1) {
|
||||||
|
if (localStorage.getItem("auto-redirect") != 2) {
|
||||||
|
// 否则设置自动跳转标记,并跳转
|
||||||
|
localStorage.setItem("auto-redirect", 2);
|
||||||
|
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${data.data[0].pay_channel_id}&no=${id}`;
|
||||||
|
} else {
|
||||||
|
closeLoading();
|
||||||
|
renderPaymentMethods(data.data);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
closeLoading();
|
||||||
|
// 多种支付方式,展示支付界面
|
||||||
|
renderPaymentMethods(data.data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
closeLoading();
|
||||||
|
console.error("获取支付方式失败:", error);
|
||||||
|
const pay = document.getElementById("pay");
|
||||||
|
pay.innerHTML =
|
||||||
|
'<h3 style="color: red;">获取支付方式失败,请刷新重试</h3>';
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
closeLoading();
|
||||||
|
console.error("Order no not found in URL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
// 渲染支付方式列表
|
||||||
|
function renderPaymentMethods(paymentMethods) {
|
||||||
|
const pay = document.getElementById("pay");
|
||||||
|
pay.innerHTML = "<h3>请选择支付方式</h3>";
|
||||||
|
|
||||||
{{ else}}
|
const paymentList = document.getElementById("payment-list");
|
||||||
|
paymentList.innerHTML = "";
|
||||||
|
|
||||||
<body>
|
// 标记是否是第一个支付方式
|
||||||
<div class="payment-info" style="text-align: center;">
|
let isFirstMethod = true;
|
||||||
<h2 style="color: #ff0000;">支付异常</h2>
|
|
||||||
<p>{{.message}}</p>
|
paymentMethods.forEach((method) => {
|
||||||
<button onclick="window.location.href='/'">返回</button>
|
const listItem = document.createElement("li");
|
||||||
|
listItem.className = "payment-option";
|
||||||
|
|
||||||
|
const radioInput = document.createElement("input");
|
||||||
|
radioInput.type = "radio";
|
||||||
|
radioInput.name = "paymentMethod";
|
||||||
|
radioInput.value = method.pay_channel_id;
|
||||||
|
radioInput.id = `method-${method.pay_channel_id}`;
|
||||||
|
|
||||||
|
// 如果是第一个支付方式,默认选中
|
||||||
|
if (isFirstMethod) {
|
||||||
|
radioInput.checked = true;
|
||||||
|
listItem.classList.add("selected");
|
||||||
|
isFirstMethod = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const label = document.createElement("label");
|
||||||
|
label.htmlFor = `method-${method.pay_channel_id}`;
|
||||||
|
label.textContent = method.pay_name;
|
||||||
|
|
||||||
|
if (method.icon_url) {
|
||||||
|
const icon = document.createElement("img");
|
||||||
|
icon.src = method.icon_url;
|
||||||
|
icon.style.height = "24px";
|
||||||
|
icon.style.marginRight = "10px";
|
||||||
|
label.prepend(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
listItem.appendChild(radioInput);
|
||||||
|
listItem.appendChild(label);
|
||||||
|
paymentList.appendChild(listItem);
|
||||||
|
|
||||||
|
// 点击整个区域也可以选择
|
||||||
|
listItem.addEventListener("click", () => {
|
||||||
|
// 移除所有选中样式
|
||||||
|
document.querySelectorAll(".payment-option").forEach((item) => {
|
||||||
|
item.classList.remove("selected");
|
||||||
|
});
|
||||||
|
// 添加当前选中样式
|
||||||
|
listItem.classList.add("selected");
|
||||||
|
radioInput.checked = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 添加提交按钮
|
||||||
|
const submitButton = document.createElement("button");
|
||||||
|
submitButton.type = "button";
|
||||||
|
submitButton.textContent = "立即支付";
|
||||||
|
|
||||||
|
submitButton.onclick = function () {
|
||||||
|
const no = getQueryParam("no");
|
||||||
|
const selectedMethod = document.querySelector(
|
||||||
|
'input[name="paymentMethod"]:checked'
|
||||||
|
);
|
||||||
|
if (selectedMethod) {
|
||||||
|
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${selectedMethod.value}&no=${no}`;
|
||||||
|
} else {
|
||||||
|
alert("请选择支付方式");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const buttonContainer = document.createElement("div");
|
||||||
|
buttonContainer.style.textAlign = "center";
|
||||||
|
buttonContainer.appendChild(submitButton);
|
||||||
|
paymentList.appendChild(buttonContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听页面可见性变化
|
||||||
|
document.addEventListener("visibilitychange", function () {
|
||||||
|
if (!document.hidden && localStorage.getItem("auto-redirect") == 2) {
|
||||||
|
// 页面从后台返回且处于支付状态
|
||||||
|
fetchPaymentMethods();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 页面加载时执行
|
||||||
|
window.onload = function () {
|
||||||
|
alert(`return:${getQueryParam("return")}`);
|
||||||
|
if (
|
||||||
|
localStorage.getItem("auto-redirect") &&
|
||||||
|
localStorage.getItem("auto-redirect") == 2
|
||||||
|
) {
|
||||||
|
alert("查询支付状态");
|
||||||
|
handlePaymentCallback(); // 如果是支付回调且不是自动跳转,处理支付结果
|
||||||
|
} else {
|
||||||
|
localStorage.setItem("auto-redirect", 1); // 设置自动跳转标记
|
||||||
|
fetchPaymentMethods(); // 获取支付方式
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{{ else}}
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="payment-info" style="text-align: center">
|
||||||
|
<h2 style="color: #ff0000">支付异常</h2>
|
||||||
|
<p>{{.message}}</p>
|
||||||
|
<button onclick="window.location.href='/'">返回</button>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
</html>
|
||||||
</html>
|
|
||||||
{{end}}
|
{{end}}
|
Loading…
Reference in New Issue