import { payDetail, percent2percent25 } from "./service"; import { tradePay } from "../../utils/tradePay"; import history from "../../utils/history"; import { getYbParams } from "../hospital-payment-detail-yibao/service"; import { reportApi, reportCmPV_YL } from "../../utils/cloudMonitorHelper"; import { getSubscribeAuth, prePayConfirm, } from "../../../../core/utils/ywtService"; import { createSubscribe } from "applet-page-component"; Component( createSubscribe({ onShow() { this.payDetail(this.$page.data.query); }, })({ props: {}, data: { order: { orderItems: [ // { // itemName: '项目名称', // itemNum: 2, // amount: 999.99, // }, ], depName: "", outTradeNo: "", tradeNo: "", type: null, // 1-挂号费订单 2-充值订单 3-诊间缴费订单 userName: "", cardNum: "", amount: 0, createTime: "", payTime: "", payType: null, // 1-自费 2-医保 3-其他 status: null, // 0-待支付 1-已支付 9-已取消 medicareBinded: false, idNum: "", customInfo: "", payDetails: "", payDate: "", doctorName: "", reportRemind: "", checkRemind: "", medicineRemind: "", refundRemind: "", receiptRemind: "", }, // 订单项 fromItem: [ { label: "就诊人", key: "name", }, { label: "病人ID号", key: "hisPatientId", }, { label: "就诊科室", key: "deptName", }, { label: "医生", key: "doctorName", }, // { // label: "费用日期", // key: "payDate", // }, // { // label: "支付单号", // key: "outTradeNo", // }, { label: "开单时间", key: "prescribeDate", }, // { // label: "付款时间", // key: "payTime", // }, ], medicareExpand: false, expand: false, medicare: { total: 0, own: 0, detail: {}, }, checkRemind: {}, }, didMount() { this.payDetail(this.$page.data.query); /* 服务办结,门诊缴费 */ reportApi("门诊缴费"); /* 服务预警,门诊缴费 */ reportCmPV_YL({ title: "门诊缴费", }); }, methods: { saveSubscribe(ref) { this.subscribe = ref; }, payDetail(send) { const { orderItems } = send; const status0OrderItems = JSON.parse( decodeURIComponent(percent2percent25(orderItems) || "") ); const newSend = Object.assign({}, send); delete newSend["orderItems"]; payDetail(newSend).then((data) => { const payDetails = JSON.parse(data.payDetails || "{}"); const detail = payDetails["医保支付"] || {}; let total = 0; Object.entries(detail).forEach(([k, v]) => { detail[k] = numFix(v); total += v * 1; }); this.setData({ order: Object.assign({}, this.data.order, data, { orderItems: data.orderItems ? data.orderItems : status0OrderItems, }), medicare: { total: numFix(total), own: numFix(payDetails["自费支付金额"]) || "0.00", detail, }, checkRemind: JSON.parse(data.checkRemind || "{}"), }); }); }, async handlePrePayConfirm() { return new Promise(async (resolve) => { const { hisOrderNo: hisOrdNum, hisPatientId: patientId, hisClinicCode: clinicCode, total: orderSum, orderInsType, } = this.$page.data.query; const { payAuthNo = "", authNo = "", medicalCardInstId = "", medicalCardId = "", } = this.data; const [err, result] = await prePayConfirm({ patientId, clinicCode, hisOrdNum, orderSum, payInsType: "1", orderInsType, payAuthNo, authNo, medicalCardInstId, medicalCardId, }); if (!err) { // 预结算成功 const ybData = await getYbParams(result); const preConfirmInfo = Object.assign(result, ybData); this.setData( { preConfirmInfo, }, resolve(preConfirmInfo) ); } }); }, // 查看更多 openForm() { this.setData({ expand: !this.data.expand, }); }, medicareExpand() { this.setData({ medicareExpand: !this.data.medicareExpand, }); }, // 发起支付 async onPay(e) { const { medicareBinded = false } = e.target.dataset; const { orderInsType, medInsFee, selfFee, payName, patName } = this.$page.data.query; const { order: oreder } = this.data; let result = false; const { invoiceNo = "" } = await this.handlePrePayConfirm(); try { my.showLoading(); // 获取授权 await getSubscribeAuth(); if (oreder.type === 1) { result = await tradePay( { type: oreder.type, idNum: oreder.outTradeNo, depName: oreder.depName, }, { tradeType: "Appointment", } ); } else if (oreder.type === 2) { // 充值 result = await tradePay( { type: oreder.type, idNum: oreder.outTradeNo, amount: oreder.amount, }, { tradeType: "Appointment", } ); } else { // 门诊订单 const { hisPatientId, age, sex, orderId, hisOrderNo, amount, deptName, doctorName, doctorCode, total, hisClinicCode, name, prescribeDate, } = oreder; result = await tradePay( { useBalance: !medicareBinded, useMedicare: medicareBinded, outTradeNo: oreder.outTradeNo, hisPatientId, age, sex, orderId, hisOrderNo, amount, deptName, doctorName, doctorCode, total, hisClinicCode, name, prescribeDate, // 新增参数 invoiceNo, orderInsType, totalFee: total, payInsType: "1", medInsFee, selfFee, payName, patName, }, { tradeType: "Outpatient", } ); } } catch (error) { console.log("error ===>", error); } finally { my.hideLoading(); } // 支付成功刷新页面 this.payDetail(this.$page.data.query); if (result) { // 支付成功后返回列表页 my.navigateBack(); } }, 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 success: (res) => { if (res.authCode) { history.push({ title: "确认支付", query: Object.assign(query, { authCode: res.authCode, orderItems: percent2percent25(query.orderItems), }), pageType: "hospital-payment-detail-yibao", }); } }, }); }, hrefTo() { my.ap.navigateToAlipayPage({ path: "alipays://platformapi/startapp?appId=77700284&page=pages/medical/index?chInfo=YY_xiaochengxu", }); }, toH5(e) { const { url } = e.target.dataset; history.toH5(url); }, }, }) ); function numFix(val) { const num = val * 1; return num.toFixed(2); }