浏览代码

用户订单微信支付

jiayubo 1 周之前
父节点
当前提交
a3db753b95
共有 2 个文件被更改,包括 26 次插入13 次删除
  1. 2 1
      config.js
  2. 24 12
      pages_home/pages/Volunteerside/goodsDetails.vue

+ 2 - 1
config.js

@@ -2,7 +2,8 @@
 const config = {
 	// baseUrl: 'https://vue.ruoyi.vip/prod-api',
 	//cloud后台网关地址
-	baseUrl: 'http://192.168.100.95:9527',
+	baseUrl: 'http://192.168.100.95:9527',//嵘哥
+	baseUrl: 'http://192.168.100.121:9527',//龙哥
 	// baseUrl: 'https://zybooks.tech/prod-api',
 	mapKey:'KFEBZ-P2GKZ-A5PX4-7Q6Y7-KXOBF-XCB4C',
 	appName: '金邻助家',

+ 24 - 12
pages_home/pages/Volunteerside/goodsDetails.vue

@@ -202,7 +202,6 @@
 	import {
 		onMounted,
 		ref,
-		nextTick,
 		reactive,
 		computed,
 	} from "vue";
@@ -518,13 +517,13 @@
 		const orderData = {
 			orders: {
 				serviceOnePrice: businessPrice.value,
-				serviceTotalPrice: computeMoney.value, //需要传获取到的总价
-				serviceCategory: serviceCategory.value, //大类别参数
-				totalTimes: totalTimes.value, //点击的次数
+				serviceTotalPrice: computeMoney.value,
+				serviceCategory: serviceCategory.value,
+				totalTimes: totalTimes.value,
 				serviceStartDate: "2025-04-18",
 				startTime: "8:00",
 				serviceDuration: 4,
-				paymentMethod: paymentMethod.value, // Use the selected payment method
+				paymentMethod: paymentMethod.value,
 				volunteerId: volunteerId.value,
 				remark: remark.value,
 				businessManagementId: businessManagementId.value,
@@ -540,27 +539,40 @@
 				workStartTime: item.time
 			});
 		});
+
 		try {
 			const res = await ordersCreateOrder(orderData);
 			if (res.code == 200) {
+				if (paymentMethod.value === 2) { // 微信支付
+					// 调用微信支付
+					const [err, payRes] = await uni.requestPayment({
+						...res.data,
+						package: res.data.packageValue,
+					});
+					if (err) {
+						throw new Error('微信支付失败');
+					}
+				}
+				
 				uni.showToast({
 					title: '支付成功',
-					icon: 'success', // 或者 'none'
-					duration: 1500, // 显示时间,单位毫秒,默认1500
-					mask: true, // 是否显示透明蒙层,防止触摸穿透,默认false
+					icon: 'success',
+					duration: 1500,
+					mask: true,
 				});
 				setTimeout(() => {
 					uni.reLaunch({
 						url: '/pages/index'
 					});
-				}, 1500)
+				}, 1500);
 			}
 		} catch (error) {
+			console.error('支付失败:', error);
 			uni.showToast({
 				title: '支付失败',
-				icon: 'error', // 或者 'none'
-				duration: 1500, // 显示时间,单位毫秒,默认1500
-				mask: true, // 是否显示透明蒙层,防止触摸穿透,默认false
+				icon: 'error',
+				duration: 1500,
+				mask: true,
 			});
 		}
 	};