import { getYbParams } from "./service"; import { tradePay } from "../../utils/tradePay"; import { prePayConfirm } from "../../../../core/utils/ywtService"; import history from "../../utils/history"; // import { reportApi, reportCmPV_YL } from "../../utils/cloudMonitorHelper"; // import { getSubscribeAuth } from "../../../../core/utils/ywtService"; // import { createSubscribe } from "applet-page-component"; Component({ props: {}, data: { authCode: undefined, canPay: true, prescriptionList: [ ], actionsheetVisible: false, isUserPersonalAccount: true, isCulculate: false }, didMount() { this.getPayDetail(this.$page.data.query); this.handlePrePayConfirm() }, methods: { saveSubscribe(ref) { this.subscribe = ref; }, async handlePrePayConfirm() { my.showLoading({ mask: true }); try { const { hisOrderNo: hisOrdNum, hisPatientId: patientId, hisClinicCode: clinicCode, authCode, total: orderSum, orderInsType } = this.$page.data.query const [err, result] = await prePayConfirm({ patientId, clinicCode, hisOrdNum, orderSum, payInsType: '2', orderInsType, authCode, }) if (!err) { // 预结算成功 this.setData({ }); } else { throw `${err}` } } catch (error) { console.log('error ===>', error) } finally { my.hideLoading() } }, 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 || []; }, handleIsUserPersonalAccount(e) { my.showLoading(); const _this = this const { valuex } = e.currentTarget.dataset; this.setData({ isUserPersonalAccount: valuex, isCulculate: true }, () => { setTimeout(() => { my.hideLoading() _this.setData({ isCulculate: false }) }, 3000) }) }, getPayDetail(query) { console.log("query ==>", 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 }); } return; my.getAuthCode({ scopes: ["nhsamp", "auth_user"], // 主动授权:auth_user,静默授权:auth_base。或者其它scopes success: (res) => { if (res.authCode) { // 认证成功 // 调用自己的服务端接口,让服务端进行后端的授权认证,并且利用session,需要解决跨域问题 my.request({ url: "https://isv.com/auth", // 该url是您自己的服务地址,实现的功能是服务端拿到authcode去开放平台进行token验证 data: { authcode: res.authCode, }, success: () => { // 授权成功并且服务器端登录成功 }, fail: () => { // 根据自己的业务场景来进行错误处理 }, }); } }, }); }, // 查看更多 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 { medicareBinded = false } = e.target.dataset; const { order: oreder } = this.data; let result = false; try { my.showLoading(); 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, }, { tradeType: "Outpatient", } ); } } catch (error) { console.log("error ===>", error); } finally { my.hideLoading(); } if (result) { // 支付成功后返回列表页 my.navigateBack(); } }, }, });