PaymentCenter/front/templates/payPage.html

148 lines
4.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>收银台页面</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
}
p {
color: #666;
}
ul {
list-style: none;
padding: 0;
}
li {
margin: 10px 0;
}
</style>
</head>
{{if eq .code 200 }}
<body>
<!-- 页面内容 -->
{{/*<h1>收银台页面</h1>*/}}
<p>订单号:{{ .id }}</p>
<p>订单金额:{{ .amount }} 元</p>
<ul id="payment-list"></ul>
</body>
<script>
// 从 URL 中提取参数
function getQueryParam(param) {
const queryString = window.location.search.substring(1);
const params = queryString.split('&');
for (let i = 0; i < params.length; i++) {
const [key, value] = params[i].split('=');
if (key === param) {
return decodeURIComponent(value);
}
}
return null;
}
// 获取支付方式列表
function fetchPaymentMethods() {
const id = getQueryParam('no');
console.log('Order no:', id);
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 => {
console.log('Received payment methods:', data);
// 处理返回的数据,例如渲染支付方式列表
renderPaymentMethods(data.data);
})
.catch(error => {
console.error('data', data);
});
} else {
console.error('Order no not found in URL');
}
}
// 渲染支付方式列表
function renderPaymentMethods(paymentMethods) {
const paymentList = document.getElementById('payment-list');
paymentList.innerHTML = '';
paymentMethods.forEach(method => {
const listItem = document.createElement('li');
const radioInput = document.createElement('input');
radioInput.type = 'radio';
radioInput.name = 'paymentMethod';
radioInput.value = method.pay_channel_id;
listItem.appendChild(radioInput);
listItem.appendChild(document.createTextNode(method.pay_name));
paymentList.appendChild(listItem);
});
// 添加提交按钮
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('请选择支付方式');
}
};
paymentList.appendChild(submitButton);
}
// 在页面加载时调用 fetchPaymentMethods 函数
window.onload = fetchPaymentMethods;
</script>
{{ else}}
<body>
<p>{{.message}}</p>
</body>
{{end}}
</html>