Browse Source

fix: 优化错误处理

carver 1 year ago
parent
commit
02c47d6cd0

+ 217 - 219
antbuilder/industry/hospitalV2/components/hospital-payment-detail-yibao/index.js

@@ -119,7 +119,7 @@ Component(
 					} else {
 						my.navigateBack();
 					}
-				}else{
+				} else {
 					my.hideLoading();
 					my.showToast({
 						type: "fail",
@@ -133,249 +133,247 @@ Component(
 			},
 
 			async handlePrePayConfirm() {
-				console.log(
-					"this.$page.data.query handlePrePayConfirm ==>",
-					this.$page.data.query
-				);
-				console.log("this.$page.data handlePrePayConfirm ==>", this.$page.data);
 				my.showLoading({ mask: true });
-					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,
-					});
-					if (!err) {
-						// 预结算成功
-						my.hideLoading();
-						const ybData = getYbParams(result);
-						this.setData({
+				const [err, result] = await prePayConfirm({
+					patientId,
+					clinicCode,
+					hisOrdNum,
+					orderSum,
+					payInsType: "2",
+					orderInsType,
+					payAuthNo,
+					authNo,
+					medicalCardInstId,
+					medicalCardId,
+					consumeType: isUserPersonalAccount ? 0 : 2,
+				});
+				if (!err) {
+					// 预结算成功
+					const ybData = await getYbParams(result);
+					this.setData(
+						{
 							preConfirmInfo: Object.assign(result, ybData),
 							isCulculate: false,
 							canPay: true,
-						});
+						},
+						() => {
+							my.hideLoading();
+						}
+					);
+				} else {
+					my.hideLoading();
+					my.showToast({
+						type: "fail",
+						content: err.info || "未知错误",
+						duration: 2000,
+						complete() {
+							my.navigateBack();
+						},
+					});
+				}
+			},
+		},
+
+		parseDetailItems(detailItems) {
+			const list = detailItems
+				? JSON.parse(decodeURIComponent(detailItems || ""))
+				: [];
+			const newList = list.map((item) => {
+				return {
+					label: `${item.itemName}*${item.itemNum}`,
+					// subLabel: `${item.unit || ""}`,
+					value: `${item.amount || 0}元`,
+				};
+			});
+			return newList || [];
+		},
+
+		async handleIsUserPersonalAccount(e) {
+			const _this = this;
+			const { valuex } = e.currentTarget.dataset;
+			const { hisOrderNo, hisPatientId } = this.$page.data.query;
+			const { preConfirmInfo, isUserPersonalAccount } = this.data;
+			if (isUserPersonalAccount === valuex) return;
+			my.showLoading();
+			this.setData(
+				{
+					isUserPersonalAccount: valuex,
+					isCulculate: true,
+				},
+				async () => {
+					const [err, result] = await revokeSettle({
+						hisOrderNo,
+						insuDivId: preConfirmInfo.insuDivId || "",
+						hisPatientId,
+						isInsV2: true,
+					});
+					if (!err) {
+						_this.handlePrePayConfirm();
 					} else {
-						my.hideLoading();
 						my.showToast({
 							type: "fail",
-							content: err.info || "未知错误",
+							content: "撤销预结算失败",
 							duration: 2000,
 							complete() {
+								my.hideLoading();
 								my.navigateBack();
 							},
 						});
 					}
 				}
-			},
+			);
+		},
 
-			parseDetailItems(detailItems) {
-				const list = detailItems
-					? JSON.parse(decodeURIComponent(detailItems || ""))
-					: [];
-				const newList = list.map((item) => {
-					return {
-						label: `${item.itemName}*${item.itemNum}`,
-						// subLabel: `${item.unit || ""}`,
-						value: `${item.amount || 0}元`,
-					};
-				});
-				return newList || [];
-			},
+		getPayDetail(query) {
+			let infoList = [];
+			if (query) {
+				infoList = [
+					{
+						title: "就诊信息",
+						list: [
+							// { label: "门诊类别", value: info.deptName },
+							{ label: "门诊科室", value: query.deptName },
+							{ label: "医生姓名", value: query.doctorName },
+							{ label: "处方时间", value: query.prescribeDate },
+							{
+								label: "费用总额",
+								value: parseFloat(query.total / 100, 2) || 0 + "元",
+								highlight: true,
+							},
+						],
+					},
+					{
+						title: "费用信息",
+						list: this.parseDetailItems(query.orderItems),
+					},
+				];
+				this.setData({ prescriptionList: infoList });
+			}
+		},
 
-			async handleIsUserPersonalAccount(e) {
-				const _this = this;
-				const { valuex } = e.currentTarget.dataset;
-				const { hisOrderNo, hisPatientId } = this.$page.data.query;
-				const { preConfirmInfo, isUserPersonalAccount } = this.data;
-				if (isUserPersonalAccount === valuex) return;
+		// 查看更多
+		openForm() {
+			this.setData({
+				expand: !this.data.expand,
+			});
+		},
+
+		medicareExpand() {
+			this.setData({
+				medicareExpand: !this.data.medicareExpand,
+			});
+		},
+
+		handleActionsheet() {
+			this.setData({
+				actionsheetVisible: !this.data.actionsheetVisible,
+			});
+		},
+
+		// 发起支付
+		async onPay(e) {
+			const { canPay } = this.data;
+			if (!canPay) return;
+			this._paying = true;
+			const {
+				hisPatientId,
+				age,
+				sex,
+				orderId,
+				hisOrderNo,
+				amount,
+				deptName,
+				doctorName,
+				doctorCode,
+				hisClinicCode,
+				total,
+				name,
+				orderInsType,
+				prescribeDate,
+				payInsType = "2",
+				medInsFee,
+				selfFee,
+				payName,
+				patName,
+				outTradeNo,
+			} = this.$page.data.query;
+			const {
+				preConfirmInfo: { invoiceNo, insuAdmDr, insUploadFeeResp },
+				isUserPersonalAccount,
+			} = this.data;
+			let result = false;
+			try {
 				my.showLoading();
-				this.setData(
+				// 门诊订单
+				result = await tradePay(
 					{
-						isUserPersonalAccount: valuex,
-						isCulculate: true,
+						useBalance: false,
+						useMedicare: true,
+						outTradeNo,
+						hisPatientId,
+						age,
+						sex,
+						orderId,
+						hisOrderNo,
+						amount,
+						deptName,
+						doctorName,
+						doctorCode,
+						total,
+						hisClinicCode,
+						name,
+						prescribeDate,
+						orderInsType,
+						payInsType,
+						totalFee: total,
+						medInsFee,
+						selfFee,
+						payName,
+						patName,
+						invoiceNo,
+						insuAdmDr,
+						insUploadFeeResp,
+						consumeType: isUserPersonalAccount ? 0 : 2,
 					},
-					async () => {
-						const [err, result] = await revokeSettle({
-							hisOrderNo,
-							insuDivId: preConfirmInfo.insuDivId || "",
-							hisPatientId,
-							isInsV2: true,
-						});
-						if (!err) {
-							_this.handlePrePayConfirm();
-						} else {
-							my.showToast({
-								type: "fail",
-								content: "撤销预结算失败",
-								duration: 2000,
-								complete() {
-									my.hideLoading();
-									my.navigateBack();
-								},
-							});
-						}
+					{
+						tradeType: "Outpatient",
 					}
 				);
-			},
-
-			getPayDetail(query) {
-				let infoList = [];
-				if (query) {
-					infoList = [
-						{
-							title: "就诊信息",
-							list: [
-								// { label: "门诊类别", value: info.deptName },
-								{ label: "门诊科室", value: query.deptName },
-								{ label: "医生姓名", value: query.doctorName },
-								{ label: "处方时间", value: query.prescribeDate },
-								{
-									label: "费用总额",
-									value: parseFloat(query.total / 100, 2) || 0 + "元",
-									highlight: true,
-								},
-							],
-						},
-						{
-							title: "费用信息",
-							list: this.parseDetailItems(query.orderItems),
-						},
-					];
-					this.setData({ prescriptionList: infoList });
-				}
-			},
-
-			// 查看更多
-			openForm() {
-				this.setData({
-					expand: !this.data.expand,
-				});
-			},
+			} catch (error) {
+				console.log("error ===>", error);
+			} finally {
+				my.hideLoading();
+			}
 
-			medicareExpand() {
-				this.setData({
-					medicareExpand: !this.data.medicareExpand,
-				});
-			},
+			if (result) {
+				this._paying = false;
+				console.log("pay result ===>", result);
+				// 支付成功后返回列表页
+				// my.navigateBack();
 
-			handleActionsheet() {
-				this.setData({
-					actionsheetVisible: !this.data.actionsheetVisible,
+				history.replace({
+					title: "支付成功",
+					query: {},
+					pageType: "hospital-payment-detail-yibao-result",
 				});
-			},
-
-			// 发起支付
-			async onPay(e) {
-				const { canPay } = this.data;
-				if (!canPay) return;
-				this._paying = true;
-				const {
-					hisPatientId,
-					age,
-					sex,
-					orderId,
-					hisOrderNo,
-					amount,
-					deptName,
-					doctorName,
-					doctorCode,
-					hisClinicCode,
-					total,
-					name,
-					orderInsType,
-					prescribeDate,
-					payInsType = "2",
-					medInsFee,
-					selfFee,
-					payName,
-					patName,
-					outTradeNo,
-				} = this.$page.data.query;
-				const {
-					preConfirmInfo: { invoiceNo, insuAdmDr, insUploadFeeResp },
-					isUserPersonalAccount,
-				} = this.data;
-				let result = false;
-				try {
-					my.showLoading();
-					// 门诊订单
-					result = await tradePay(
-						{
-							useBalance: false,
-							useMedicare: true,
-							outTradeNo,
-							hisPatientId,
-							age,
-							sex,
-							orderId,
-							hisOrderNo,
-							amount,
-							deptName,
-							doctorName,
-							doctorCode,
-							total,
-							hisClinicCode,
-							name,
-							prescribeDate,
-							orderInsType,
-							payInsType,
-							totalFee: total,
-							medInsFee,
-							selfFee,
-							payName,
-							patName,
-							invoiceNo,
-							insuAdmDr,
-							insUploadFeeResp,
-							consumeType: isUserPersonalAccount ? 0 : 2,
-						},
-						{
-							tradeType: "Outpatient",
-						}
-					);
-				} catch (error) {
-					console.log("error ===>", error);
-				} finally {
-					my.hideLoading();
-				}
-
-				if (result) {
-					this._paying = false;
-					console.log("pay result ===>", result);
-					// 支付成功后返回列表页
-					// my.navigateBack();
-
-					history.replace({
-						title: "支付成功",
-						query: {},
-						pageType: "hospital-payment-detail-yibao-result",
-					});
-				} else {
-					this._paying = false;
-				}
-			},
+			} else {
+				this._paying = false;
+			}
 		},
 	})
 );

+ 77 - 74
antbuilder/industry/hospitalV2/components/hospital-payment-detail-yibao/service.js

@@ -1,7 +1,7 @@
-import request from '../../service/request'; // 查询订单状态
+import request from "../../service/request"; // 查询订单状态
 
 function payDetail(data) {
-  return request.post('/miniProRequest.pay.payDetail', data);
+	return request.post("/miniProRequest.pay.payDetail", data);
 }
 
 /**
@@ -9,86 +9,89 @@ function payDetail(data) {
  * @param  {object} obj
  */
 function getYbParams(obj) {
-  if (!obj || !obj.insUploadFeeResp) return {};
-  const list = obj.insUploadFeeResp.split(":");
-  const params = {};
+	return new Promise((resolve) => {
+		if (!obj || !obj.insUploadFeeResp) {
+			resolve({});
+		}
+		const list = obj.insUploadFeeResp.split(":");
+		const params = {};
 
-  // 总额:feeSumamt
-  // 医保支付:fundPay
-  // 个人支付:psnAcctPay
-  // 现金支付:ownPayAmt
+		// 总额:feeSumamt
+		// 医保支付:fundPay
+		// 个人支付:psnAcctPay
+		// 现金支付:ownPayAmt
 
-  list.map((i, index) => {
-    if (i.includes("feeSumamt")) {
-      let innerList = i.split(",");
-      let value = "";
-      if (innerList[0].includes("feeSumamt")) {
-        value = innerList[1];
-      } else {
-        value = list[index + 1].split(",")[0];
-      }
-      params.feeSumamt = value
-        .replaceAll('"', "")
-        .replaceAll("}", "")
-        .replaceAll("{", "")
-        .replaceAll("\\", "");
-    }
+		list.map((i, index) => {
+			if (i.includes("feeSumamt")) {
+				let innerList = i.split(",");
+				let value = "";
+				if (innerList[0].includes("feeSumamt")) {
+					value = innerList[1];
+				} else {
+					value = list[index + 1].split(",")[0];
+				}
+				params.feeSumamt = value
+					.replaceAll('"', "")
+					.replaceAll("}", "")
+					.replaceAll("{", "")
+					.replaceAll("\\", "");
+			}
 
-    if (i.includes("fundPay")) {
-      let innerList = i.split(",");
-      let value = "";
-      if (innerList[0].includes("fundPay")) {
-        value = innerList[1];
-      } else {
-        value = list[index + 1].split(",")[0];
-      }
-      params.fundPay = value
-        .replaceAll('"', "")
-        .replaceAll("}", "")
-        .replaceAll("{", "")
-        .replaceAll("\\", "");
-    }
+			if (i.includes("fundPay")) {
+				let innerList = i.split(",");
+				let value = "";
+				if (innerList[0].includes("fundPay")) {
+					value = innerList[1];
+				} else {
+					value = list[index + 1].split(",")[0];
+				}
+				params.fundPay = value
+					.replaceAll('"', "")
+					.replaceAll("}", "")
+					.replaceAll("{", "")
+					.replaceAll("\\", "");
+			}
 
-    if (i.includes("ownPayAmt")) {
-      let innerList = i.split(",");
-      let value = "";
-      if (innerList[0].includes("ownPayAmt")) {
-        value = innerList[1];
-      } else {
-        value = list[index + 1].split(",")[0];
-      }
-      params.ownPayAmt = value
-        .replaceAll('"', "")
-        .replaceAll("}", "")
-        .replaceAll("{", "")
-        .replaceAll("\\", "");
-    }
+			if (i.includes("ownPayAmt")) {
+				let innerList = i.split(",");
+				let value = "";
+				if (innerList[0].includes("ownPayAmt")) {
+					value = innerList[1];
+				} else {
+					value = list[index + 1].split(",")[0];
+				}
+				params.ownPayAmt = value
+					.replaceAll('"', "")
+					.replaceAll("}", "")
+					.replaceAll("{", "")
+					.replaceAll("\\", "");
+			}
 
-    if (i.includes("psnAcctPay")) {
-      let innerList = i.split(",");
-      let value = "";
-      if (innerList[0].includes("psnAcctPay")) {
-        value = innerList[1];
-      } else {
-        value = list[index + 1].split(",")[0];
-      }
-      params.psnAcctPay = value
-        .replaceAll('"', "")
-        .replaceAll("}", "")
-        .replaceAll("{", "")
-        .replaceAll("\\", "");
-    }
-  });
-
-  return params;
+			if (i.includes("psnAcctPay")) {
+				let innerList = i.split(",");
+				let value = "";
+				if (innerList[0].includes("psnAcctPay")) {
+					value = innerList[1];
+				} else {
+					value = list[index + 1].split(",")[0];
+				}
+				params.psnAcctPay = value
+					.replaceAll('"', "")
+					.replaceAll("}", "")
+					.replaceAll("{", "")
+					.replaceAll("\\", "");
+			}
+		});
+		resolve(params);
+	});
 }
 
 function generateRandomFourDigitNumber() {
-  return Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000;
+	return Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000;
 }
 
 export default {
-  payDetail,
-  getYbParams,
-  generateRandomFourDigitNumber
-};
+	payDetail,
+	getYbParams,
+	generateRandomFourDigitNumber,
+};