shish 11 miesięcy temu
rodzic
commit
d1670abf7a
2 zmienionych plików z 24 dodań i 292 usunięć
  1. 23 81
      hdh5/admin/ghs/pay.vue
  2. 1 211
      hdh5/api/payment/index.js

+ 23 - 81
hdh5/admin/ghs/pay.vue

@@ -2,7 +2,7 @@
 	<view class="pay-container">
 		<!-- 顶部导航栏 -->
 		<view class="nav-bar">
-			<view class="nav-title">扫码付款</view>
+			<view class="nav-title">付款</view>
 		</view>
 
 		<!-- 支付金额区域 -->
@@ -12,7 +12,7 @@
 				<text class="currency">¥</text>
 				<text class="amount">{{ displayAmount }}</text>
 			</view>
-			<view class="amount-tip">请输入支付金额</view>
+			<view class="amount-tip">请输入金额</view>
 		</view>
 
 		<!-- 支付方式展示 -->
@@ -72,14 +72,13 @@
 </template>
 
 <script>
-import { createPaymentOrder, requestPayment } from '@/api/payment';
-
+import { } from '@/api/payment';
 export default {
-	name: 'PayPage',
+	name: 'pay',
 	data() {
 		return {
-			currentAmount: '0.00',
-			displayAmount: '0.00',
+			currentAmount: '0',
+			displayAmount: '0',
 			keyboardKeys: [
 				[
 					{ type: 'number', value: '1' },
@@ -133,12 +132,12 @@ export default {
 				this.addDecimal();
 			}
 		},
-
 		// 添加数字
 		addNumber(num) {
-			if (this.currentAmount === '0.00') {
+			if (this.currentAmount === '0' || this.currentAmount === '0.00') {
 				this.currentAmount = num;
-				this.displayAmount = num;
+				this.hasDecimal = false;
+				this.decimalPlaces = 0;
 			} else {
 				if (this.hasDecimal) {
 					if (this.decimalPlaces < 2) {
@@ -153,7 +152,6 @@ export default {
 			}
 			this.updateDisplay();
 		},
-
 		// 添加小数点
 		addDecimal() {
 			if (!this.hasDecimal) {
@@ -162,7 +160,6 @@ export default {
 				this.updateDisplay();
 			}
 		},
-
 		// 删除数字
 		deleteNumber() {
 			if (this.currentAmount.length > 1) {
@@ -174,6 +171,10 @@ export default {
 					// 删除普通数字
 					if (this.hasDecimal && this.currentAmount.split('.')[1]) {
 						this.decimalPlaces--;
+						// 如果删除后没有小数位了,重置状态
+						if (this.decimalPlaces === 0) {
+							this.hasDecimal = false;
+						}
 					}
 					this.currentAmount = this.currentAmount.slice(0, -1);
 				}
@@ -184,13 +185,17 @@ export default {
 			}
 			this.updateDisplay();
 		},
-
 		// 更新显示金额
 		updateDisplay() {
 			let amount = parseFloat(this.currentAmount) || 0;
-			this.displayAmount = amount.toFixed(2);
+			// 如果没有输入小数点,不显示小数部分
+			if (!this.hasDecimal) {
+				this.displayAmount = Math.floor(amount).toString();
+			} else {
+				// 如果有小数点,显示两位小数
+				this.displayAmount = amount.toFixed(2);
+			}
 		},
-
 		// 设置金额
 		setAmount(amount) {
 			const numAmount = parseFloat(amount);
@@ -199,90 +204,27 @@ export default {
 				this.hasDecimal = this.currentAmount.includes('.');
 				if (this.hasDecimal) {
 					this.decimalPlaces = this.currentAmount.split('.')[1].length;
+				} else {
+					this.decimalPlaces = 0;
 				}
 				this.updateDisplay();
 			}
 		},
-
 		// 处理支付
 		async handlePay() {
 			if (!this.canPay) return;
-
 			const amount = parseFloat(this.currentAmount);
-			
-			try {
-				uni.showLoading({
-					title: '支付中...'
-				});
-
-				// 模拟支付请求
-				const result = await this.requestPayment(amount);
-				
-				uni.hideLoading();
-
-				if (result.success) {
-					// 支付成功,跳转到成功页面
-					uni.navigateTo({
-						url: `/admin/ghs/success?amount=${this.displayAmount}&orderId=${this.orderId || this.generateOrderId()}`
-					});
-				} else {
-					// 支付失败,显示弹框
-					this.paymentResult = {
-						success: false,
-						amount: this.displayAmount,
-						message: result.message
-					};
-					this.showPaymentModal = true;
-				}
-
-			} catch (error) {
-				uni.hideLoading();
-				uni.showToast({
-					title: '支付失败',
-					icon: 'none'
-				});
-			}
 		},
-
 		// 请求支付
 		async requestPayment(amount) {
-			try {
-				// 创建支付订单
-				const orderResult = await createPaymentOrder({
-					amount: amount,
-					paymentMethod: 'alipay',
-					orderId: this.orderId || this.generateOrderId(),
-					description: '扫码支付'
-				});
-
-				if (!orderResult.success) {
-					throw new Error(orderResult.message);
-				}
-
-				// 发起支付
-				const paymentResult = await requestPayment({
-					orderId: orderResult.data.orderId,
-					paymentMethod: 'alipay'
-				});
 
-				return paymentResult;
-			} catch (error) {
-				console.error('支付请求失败:', error);
-				return {
-					success: false,
-					message: error.message || '支付失败,请重试'
-				};
-			}
 		},
-
 		// 生成订单ID
 		generateOrderId() {
 			const timestamp = Date.now();
 			const random = Math.floor(Math.random() * 10000);
 			return `ORDER${timestamp}${random}`;
-		},
-
-
+		}
 	}
 }
 </script>

+ 1 - 211
hdh5/api/payment/index.js

@@ -1,211 +1 @@
-/**
- * 支付相关 API
- */
-
-import https from '@/plugins/luch-request_0.0.7/request'
-
-/**
- * 创建支付订单
- * @param {Object} orderData 订单数据
- * @param {number} orderData.amount 支付金额
- * @param {string} orderData.paymentMethod 支付方式
- * @param {string} orderData.orderId 订单ID
- * @param {string} orderData.description 订单描述
- */
-export const createPaymentOrder = (orderData) => {
-	return https.post('/api/payment/create', {
-		amount: orderData.amount,
-		paymentMethod: orderData.paymentMethod,
-		orderId: orderData.orderId,
-		description: orderData.description,
-		timestamp: Date.now()
-	}).then(response => {
-		// 确保返回格式与原来一致
-		if (response.statusCode === 200) {
-			return {
-				success: true,
-				data: response.data.data || response.data,
-				message: '订单创建成功'
-			};
-		} else {
-			return {
-				success: false,
-				message: response.data.message || '订单创建失败'
-			};
-		}
-	}).catch(error => {
-		return {
-			success: false,
-			message: error.message || '网络错误,请重试'
-		};
-	});
-};
-
-/**
- * 发起支付
- * @param {Object} paymentData 支付数据
- * @param {string} paymentData.orderId 订单ID
- * @param {string} paymentData.paymentMethod 支付方式
- */
-export const requestPayment = (paymentData) => {
-	return new Promise((resolve) => {
-		// 只支持支付宝支付
-		if (paymentData.paymentMethod === 'alipay') {
-			alipayPay(paymentData).then(resolve).catch((error) => {
-				resolve({
-					success: false,
-					message: error.message || '支付失败,请重试'
-				});
-			});
-		} else {
-			resolve({
-				success: false,
-				message: '不支持的支付方式'
-			});
-		}
-	});
-};
-
-/**
- * 支付宝支付
- * @param {Object} paymentData 支付数据
- */
-const alipayPay = (paymentData) => {
-	return new Promise((resolve) => {
-		// 模拟支付宝支付流程
-		uni.showLoading({
-			title: '正在调起支付宝...'
-		});
-
-		setTimeout(() => {
-			uni.hideLoading();
-			
-			// 模拟支付结果(实际项目中需要调用真实的支付宝API)
-			const success = Math.random() > 0.1; // 90%成功率
-			
-			if (success) {
-				// 支付成功,更新订单状态
-				updateOrderStatus(paymentData.orderId, 'paid');
-				
-				resolve({
-					success: true,
-					message: '支付成功',
-					transactionId: generateTransactionId()
-				});
-			} else {
-				resolve({
-					success: false,
-					message: '支付失败,请重试'
-				});
-			}
-		}, 2000);
-	});
-};
-
-/**
- * 更新订单状态
- * @param {string} orderId 订单ID
- * @param {string} status 订单状态
- */
-const updateOrderStatus = (orderId, status) => {
-	https.post('/api/order/update-status', {
-		orderId,
-		status,
-		timestamp: Date.now()
-	}).catch((error) => {
-		console.error('更新订单状态失败:', error);
-	});
-};
-
-/**
- * 查询支付结果
- * @param {string} orderId 订单ID
- */
-export const queryPaymentResult = (orderId) => {
-	return https.get('/api/payment/query', { orderId }).then(response => {
-		if (response.statusCode === 200) {
-			return {
-				success: true,
-				data: response.data.data || response.data
-			};
-		} else {
-			return {
-				success: false,
-				message: '查询支付结果失败'
-			};
-		}
-	}).catch(error => {
-		return {
-			success: false,
-			message: error.message
-		};
-	});
-};
-
-
-
-/**
- * 生成交易ID
- */
-const generateTransactionId = () => {
-	const timestamp = Date.now();
-	const random = Math.floor(Math.random() * 10000);
-	return `TXN${timestamp}${random}`;
-};
-
-/**
- * 格式化金额
- * @param {number} amount 金额
- * @param {number} decimals 小数位数
- */
-export const formatAmount = (amount, decimals = 2) => {
-	return parseFloat(amount).toFixed(decimals);
-};
-
-/**
- * 验证金额格式
- * @param {string} amount 金额字符串
- */
-export const validateAmount = (amount) => {
-	const amountRegex = /^\d+(\.\d{1,2})?$/;
-	const numAmount = parseFloat(amount);
-	
-	return amountRegex.test(amount) && numAmount > 0 && numAmount <= 999999.99;
-};
-
-/**
- * 获取支付方式配置
- */
-export const getPaymentMethods = () => {
-	return [
-		{
-			id: 'alipay',
-			name: '支付宝',
-			description: '安全便捷的支付方式',
-			icon: 'alipay',
-			enabled: true
-		}
-	];
-};
-
-/**
- * 处理扫码结果
- * @param {string} scanResult 扫码结果
- */
-export const parseScanResult = (scanResult) => {
-	try {
-		// 解析扫码结果,提取订单信息
-		const url = new URL(scanResult);
-		const params = new URLSearchParams(url.search);
-		
-		return {
-			orderId: params.get('orderId'),
-			amount: params.get('amount'),
-			description: params.get('description'),
-			merchantId: params.get('merchantId')
-		};
-	} catch (error) {
-		console.error('解析扫码结果失败:', error);
-		return null;
-	}
-};
+import https from '@/plugins/luch-request_0.0.7/request'