hn-hlw-app/utils/insurance-plugin.js
2026-07-27 11:26:39 +08:00

83 lines
2.4 KiB
JavaScript

import { toast } from './widget';
import userStore from '@/store/user';
import dayjs from 'dayjs';
// #ifdef MP
const authPayPlugin = requirePlugin('auth-pay-plugin');
// #endif
// #ifndef MP
const authPayPlugin = {}
// #endif
const orgId = 'H33048100004' // 医保机构id
export default {
init(opts = {}) {
const params = {
getErrorInfo: function (code, msg, traceId) {
my.alert({ content: msg });
}
}
if (typeof opts.payCallback === 'function') {
params.payComplete = (status, ampTraceId, finalStatus) => {
opts.payCallback(status, ampTraceId, finalStatus)
}
params.payCancelAuth = () => {
my.alert({
content: '用户取消操作',
buttonText: '我知道了',
success: () => {
uni.navigateBack()
}
});
}
}
if (typeof opts.archiveTokenCallback === 'function') {
params.getArchiveToken = token => {
opts.archiveTokenCallback(token)
}
}
// 初始化authPayPlugin的方法
authPayPlugin.initMethods(params)
},
async getArchiveToken(authCode, anotherIdNo, anotherName) {
const params = { authCode, orgId };
if (anotherIdNo) {
params.anotherIdNo = anotherIdNo
params.anotherName = anotherName
}
const token = await authPayPlugin.toArchive(params);
return token
},
async toAuthAndPay({ cardNo, medOrgOrd, authCode, anotherIdNo, anotherName }) {
const params = {
orgId,
cardNo,
cardType: '02',
medOrgOrd
}
const myProfile = userStore().myProfile;
const isFamilyPay = !(myProfile && myProfile.blhno === cardNo);
if (isFamilyPay && anotherIdNo && anotherName) {
params.anotherIdNo = anotherIdNo;
params.anotherName = anotherName;
} else if (isFamilyPay) {
if (!userStore().familyProfile.some(i => i.blhno == cardNo)) {
await userStore().getFamilyProfile();
if (!userStore().familyProfile.some(i => i.blhno == cardNo)) {
toast('亲情档案未找到,请检查是否已关联亲情档案');
return;
}
}
const member = userStore().familyProfile.find(i => i.blhno == cardNo);
params.anotherIdNo = member.anotherIdNo;
params.anotherName = member.anotherName;
}
authPayPlugin.toAuthAndPay({
// 授权获取的authCode
authCode,
params
});
}
}