123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- import qs from "qs";
- import { percent2percent25 } from "../hospital-payment-detail/service";
- import { getYbParams, generateRandomFourDigitNumber } from "./service";
- import { tradePay } from "../../utils/tradePay";
- import {
- prePayConfirm,
- getPayAuthInfo,
- revokeSettle,
- } from "../../../../core/utils/ywtService";
- import history from "../../utils/history";
- import { createSubscribe } from "applet-page-component";
- Component(
- createSubscribe({
- onShow() {
- this.init("onShow");
- },
- })({
- props: {},
- data: {
- authCode: undefined,
- canPay: false,
- prescriptionList: [],
- actionsheetVisible: false,
- isUserPersonalAccount: true, // 默认使用个账
- isCulculate: false,
- preConfirmInfo: {},
- },
- didMount() {
- this.init("didMount");
- },
- didUnmount() {
- this._paying = false;
- },
- methods: {
- init(type) {
- this.getPayDetail(this.$page.data.query);
- this.hanldeGetPayAuthInfo(type);
- },
- async hanldeGetPayAuthInfo(type) {
- if (this._paying) return;
- const app = getApp();
- const {
- hisOrderNo: hisOrdNum,
- authCode,
- reqBizNo,
- } = this.$page.data.query;
- const _this = this;
- const ramdonNum = generateRandomFourDigitNumber();
- const userId = app.globalData.ywtUserId || "";
- const queryReqBizNo = reqBizNo || `${hisOrdNum}-${userId}-${ramdonNum}`;
- const query = Object.assign(this.$page.data.query, {
- reqBizNo: queryReqBizNo,
- });
- const qsResult = `?${qs.stringify(query)}`;
- const callUrl = encodeURIComponent(
- `antbuilder/industry/hospitalV2/pages/page-no-pull/index${qsResult}`
- );
- if (type === "onShow") {
- my.getAuthCode({
- scopes: ["nhsamp", "auth_user"], // 主动授权:auth_user,静默授权:auth_base。或者其它scopes
- success: (res) => {
- if (res.authCode) {
- _this.requestGetPayAuthInfo(
- res.authCode,
- callUrl,
- queryReqBizNo,
- type
- );
- }
- },
- });
- } else {
- this.requestGetPayAuthInfo(authCode, callUrl, queryReqBizNo, type);
- }
- },
- async requestGetPayAuthInfo(authCode, callUrl, reqBizNo, lifeType) {
- my.showLoading({ mask: true });
- const _this = this;
- const [err, result] = await getPayAuthInfo({
- authCode,
- callUrl,
- reqBizNo,
- });
- if (!err) {
- my.hideLoading();
- const { payAuthNo, authNo, medicalCardInstId, medicalCardId } =
- result;
- if (result.authNo) {
- this.setData(
- {
- payAuthNo,
- authNo,
- medicalCardInstId,
- medicalCardId,
- isCulculate: true,
- },
- () => {
- _this.handlePrePayConfirm();
- }
- );
- return;
- }
- if (result.authUrl && lifeType === "didMount") {
- // 跳转医保授权页面
- my.ap.openURL({
- url: result.authUrl,
- fail(e) {
- console.log("err", e);
- my.navigateBack();
- },
- });
- } else {
- my.navigateBack();
- }
- } else {
- console.log("err ==>", err);
- my.hideLoading();
- my.showToast({
- type: "fail",
- content: err.info || "未知错误",
- duration: 2000,
- complete() {
- my.navigateBack();
- },
- });
- }
- },
- async handlePrePayConfirm() {
- 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 [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(percent2percent25(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.showToast({
- type: "fail",
- content: err.info || "撤销预结算失败",
- duration: 2000,
- complete() {
- my.hideLoading();
- my.navigateBack();
- },
- });
- }
- }
- );
- },
- 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,
- });
- },
- 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();
- // 门诊订单
- 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;
- }
- },
- },
- })
- );
|