Ver Fonte

fix: 优化路由参数传递

carver há 1 ano atrás
pai
commit
97c0730eb4

+ 40 - 41
antbuilder/industry/hospitalV2/components/hospital-payment-detail-yibao/index.js

@@ -1,4 +1,5 @@
 import qs from "qs";
+import { percent2percent25 } from "../hospital-payment-detail/service";
 import { getYbParams, generateRandomFourDigitNumber } from "./service";
 import { tradePay } from "../../utils/tradePay";
 import {
@@ -136,55 +137,53 @@ Component(
 				);
 				console.log("this.$page.data handlePrePayConfirm ==>", this.$page.data);
 				my.showLoading({ mask: true });
-				try {
-					const {
-						hisOrderNo: hisOrdNum,
-						hisPatientId: patientId,
-						hisClinicCode: clinicCode,
-						total: orderSum,
-						orderInsType,
-					} = this.$page.data.query;
-					const {
-						payAuthNo,
-						authNo,
-						medicalCardInstId,
-						medicalCardId,
-						isUserPersonalAccount,
-					} = this.data;
+				const {
+					hisOrderNo: hisOrdNum,
+					hisPatientId: patientId,
+					hisClinicCode: clinicCode,
+					total: orderSum,
+					orderInsType,
+				} = this.$page.data.query;
+				const {
+					payAuthNo,
+					authNo,
+					medicalCardInstId,
+					medicalCardId,
+					isUserPersonalAccount,
+				} = this.data;
 
-					const [err, result] = await prePayConfirm({
-						patientId,
-						clinicCode,
-						hisOrdNum,
-						orderSum,
-						payInsType: "2",
-						orderInsType,
-						payAuthNo,
-						authNo,
-						medicalCardInstId,
-						medicalCardId,
-						consumeType: isUserPersonalAccount ? 0 : 2,
+				const [err, result] = await prePayConfirm({
+					patientId,
+					clinicCode,
+					hisOrdNum,
+					orderSum,
+					payInsType: "2",
+					orderInsType,
+					payAuthNo,
+					authNo,
+					medicalCardInstId,
+					medicalCardId,
+					consumeType: isUserPersonalAccount ? 0 : 2,
+				});
+				if (!err) {
+					// 预结算成功
+					my.hideLoading();
+					const ybData = getYbParams(result);
+					this.setData({
+						preConfirmInfo: Object.assign(result, ybData),
+						isCulculate: false,
+						canPay: true,
 					});
-					if (!err) {
-						// 预结算成功
-						const ybData = getYbParams(result);
-						this.setData({
-							preConfirmInfo: Object.assign(result, ybData),
-							isCulculate: false,
-							canPay: true,
-						});
-					} else {
-						console.log("err ==>", err, typeof err, JSON.stringify(err));
-						my.navigateBack();
-					}
-				} finally {
+				} else {
 					my.hideLoading();
+					console.log("err ==>", err, typeof err, JSON.stringify(err));
+					my.navigateBack();
 				}
 			},
 
 			parseDetailItems(detailItems) {
 				const list = detailItems
-					? JSON.parse(decodeURIComponent(detailItems || ""))
+					? JSON.parse(decodeURIComponent(percent2percent25(detailItems) || ""))
 					: [];
 				const newList = list.map((item) => {
 					return {

+ 7 - 13
antbuilder/industry/hospitalV2/components/hospital-payment-detail/index.js

@@ -1,4 +1,4 @@
-import { payDetail } from "./service";
+import { payDetail, percent2percent25 } from "./service";
 import { tradePay } from "../../utils/tradePay";
 import history from "../../utils/history";
 import { getYbParams } from "../hospital-payment-detail-yibao/service";
@@ -113,20 +113,10 @@ Component(
 				this.subscribe = ref;
 			},
 
-			// 如果路由参数中包含%,则decode时会报错;需要先把 % 替换成 %25
-			percent2percent25(URI) {
-				if (URI.indexOf("%") > -1) {
-					return URI.replace(/%/g, "%25");
-				} else {
-					return URI;
-				}
-			},
-
 			payDetail(send) {
 				const { orderItems } = send;
-				console.log("orderItems", orderItems);
 				const status0OrderItems = JSON.parse(
-					decodeURIComponent(this.percent2percent25(orderItems) || "")
+					decodeURIComponent(percent2percent25(orderItems) || "")
 				);
 				const newSend = Object.assign({}, send);
 				delete newSend["orderItems"];
@@ -307,6 +297,7 @@ Component(
 
 			async onYbPay() {
 				const query = this.$page.data.query;
+				console.log("query ==>", query);
 				await getSubscribeAuth();
 				my.getAuthCode({
 					scopes: ["nhsamp", "auth_user"], // 主动授权:auth_user,静默授权:auth_base。或者其它scopes
@@ -314,7 +305,10 @@ Component(
 						if (res.authCode) {
 							history.push({
 								title: "确认支付",
-								query: Object.assign(query, { authCode: res.authCode }),
+								query: Object.assign(query, {
+									authCode: res.authCode,
+									orderItems: percent2percent25(query.orderItems),
+								}),
 								pageType: "hospital-payment-detail-yibao",
 							});
 						}

+ 11 - 1
antbuilder/industry/hospitalV2/components/hospital-payment-detail/service.js

@@ -4,6 +4,16 @@ function payDetail(data) {
   return request.post('/miniProRequest.pay.payDetail', data);
 }
 
+// 如果路由参数中包含%,则decode时会报错;需要先把 % 替换成 %25
+function percent2percent25(URI) {
+  if (URI.indexOf("%") > -1) {
+    return URI.replace(/%/g, "%25");
+  } else {
+    return URI;
+  }
+}
+
 export default {
-  payDetail
+  payDetail,
+  percent2percent25
 };