166 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
			
		
		
	
	
			166 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
| {{define "payPage.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>
 | |
|             /* 段落样式 */
 | |
|             p {
 | |
|                 color: #666666;
 | |
|                 margin-bottom: 10px;
 | |
|             }
 | |
| 
 | |
|             /* 无序列表样式 */
 | |
|             ul {
 | |
|                 list-style: none;
 | |
|                 padding: 0;
 | |
|             }
 | |
| 
 | |
|             /* 列表项样式 */
 | |
|             li {
 | |
|                 margin: 10px 0;
 | |
|             }
 | |
| 
 | |
|             /* 按钮样式 */
 | |
|             button {
 | |
|                 background-color: #007BFF;
 | |
|                 color: #fff;
 | |
|                 border: none;
 | |
|                 padding: 10px 20px;
 | |
|                 cursor: pointer;
 | |
|                 transition: background-color 0.3s ease;
 | |
|             }
 | |
| 
 | |
|             /* 按钮悬停样式 */
 | |
|             button:hover {
 | |
|                 background-color: #0056b3;
 | |
|             }
 | |
| 
 | |
| 
 | |
|         </style>
 | |
|     </head>
 | |
| 
 | |
|     {{if eq .code  200 }}
 | |
|     <body>
 | |
|     <!-- 页面内容 -->
 | |
|     <div>
 | |
|         <p>{{.desc}}</p>
 | |
|         <p>交易号:{{ .id }}</p>
 | |
|         <p>交易金额:{{ .amount }} 元</p>
 | |
|     </div>
 | |
|     <div>
 | |
|         <div id="pay"></div>
 | |
|         <!-- 支付方式列表 -->
 | |
|         <ul id="payment-list"></ul>
 | |
|     </div>
 | |
| 
 | |
|     </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 => {
 | |
|                         // 处理返回的数据,例如渲染支付方式列表
 | |
|                         if (data === null || data.data.length === 0) {
 | |
|                             const pay = document.getElementById('pay');
 | |
|                             pay.innerHTML = '<h3>支付环境异常,请检查</h3>';
 | |
|                         } else {
 | |
|                             renderPaymentMethods(data.data);
 | |
|                         }
 | |
| 
 | |
|                     })
 | |
|                     .catch(error => {
 | |
|                         console.error('data', data);
 | |
| 
 | |
|                     });
 | |
|             } else {
 | |
|                 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 = '';
 | |
|             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>
 | |
| 
 | |
| {{end}} |