374 lines
8.7 KiB
Vue
Raw Normal View History

2026-07-27 11:26:39 +08:00
<template>
2026-08-04 16:45:11 +08:00
<full-page :pageStyle="`background: ${themeBg};`">
<view v-if="logined" class="container">
<view class="header">
<text class="title">选择就诊人</text>
<button class="scan-button rounded-sm" :disabled="scanning" @click="scanInsuranceCode">扫医保码</button>
2026-07-27 11:26:39 +08:00
</view>
<view class="patient-list">
<view v-for="patient in patientList" :key="patient.id" class="patient-card"
2026-08-04 16:45:11 +08:00
:class="{ 'patient-card--selected': selectedPatientId === patient.id }" @click="toggle(patient.id)">
2026-07-27 11:26:39 +08:00
<view class="patient-info">
2026-08-04 16:45:11 +08:00
<view class="name">
2026-07-27 11:26:39 +08:00
{{ patient.name }}
<text v-if="patient.isSelf" class="self-tag">本人</text>
</view>
2026-08-04 16:45:11 +08:00
<view class="details">
2026-07-27 11:26:39 +08:00
<text v-if="patient.sex">{{ patient.sex }}</text>
<text v-if="patient.age" class="age">{{ patient.age }}</text>
</view>
</view>
2026-08-04 16:45:11 +08:00
<uni-icons v-if="selectedPatientId === patient.id" type="checkbox-filled" :color="themeColor" :size="22" />
2026-07-27 11:26:39 +08:00
</view>
<view v-if="!patientList.length" class="empty-text">暂无就诊人</view>
</view>
</view>
<re-login v-else height="80vh" />
<template v-if="logined" #footer>
<view class="footer">
2026-08-04 16:45:11 +08:00
<view class="button-group">
<button class="action-button add-button rounded" @click="toAddPatient">+ 新增就诊人</button>
<button class="action-button next-button rounded" @click="nextStep">下一步</button>
2026-07-27 11:26:39 +08:00
</view>
2026-08-04 16:45:11 +08:00
<view class="manage-link" @click="toPatientManagement">
2026-07-27 11:26:39 +08:00
<text>最多添加10位就诊人点击就诊人管理</text>
2026-08-04 16:45:11 +08:00
<uni-icons type="right" :color="themeSecondary" :size="16" />
2026-07-27 11:26:39 +08:00
</view>
</view>
</template>
</full-page>
</template>
<script setup>
import { computed, ref, watch } from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app";
import useElder from "@/hooks/useElder";
import useUser from "@/hooks/useUser";
2026-07-31 16:21:41 +08:00
import { bindHisPatient, getHisCustomer, getScannedCard } from "@/utils/api";
2026-07-30 16:48:56 +08:00
import { set } from "@/utils/cache";
2026-07-27 11:26:39 +08:00
import { toast } from "@/utils/widget";
2026-08-04 16:45:11 +08:00
import { themeBg, themeColor, themeSecondary } from "@/utils/theme-config";
2026-07-27 11:26:39 +08:00
import reLogin from "@/components/re-login.vue";
import ybPlugin from "@/utils/insurance-plugin";
import fullPage from "@/components/full-page.vue";
const {
logined,
getAuthCode,
myProfile,
familyProfile,
getProfileData,
2026-07-31 16:21:41 +08:00
storeId,
2026-07-27 11:26:39 +08:00
patientList: storePatientList,
loadPatientList,
} = useUser();
const titleMap = {
YB: "医保处方",
ZF: "自费处方",
};
const selectedPatientId = ref("");
const preferredCertNo = ref("");
const feeType = ref("");
2026-07-31 16:21:41 +08:00
const scanning = ref(false);
2026-07-27 11:26:39 +08:00
const patientList = computed(() => {
2026-07-31 16:21:41 +08:00
const list = storePatientList.value
.filter(patient => !patient.isTemporary)
.sort((a, b) => {
return new Date(a.createTime).getTime() - new Date(b.createTime).getTime();
});
2026-07-27 11:26:39 +08:00
return feeType.value === "YB" ? list.filter(patient => patient.isSelf) : list;
});
const currentProfile = computed(() => {
return patientList.value.find(patient => patient.id === selectedPatientId.value);
});
onLoad(options => {
feeType.value = options.feeType;
preferredCertNo.value = options.socialno || "";
uni.setNavigationBarTitle({
title: titleMap[options.feeType] || "",
});
ybPlugin.init({
archiveTokenCallback: () => {
const certNo = currentProfile.value ? currentProfile.value.certNo : "";
uni.redirectTo({
url: `/pages/consult/index?socialno=${certNo}&feeType=${feeType.value}`,
});
},
});
});
onShow(async () => {
if (logined.value) {
await loadPatientList();
selectDefaultPatient();
}
});
watch(logined, value => {
if (value) loadPatientList();
});
function selectDefaultPatient() {
const selectedExists = patientList.value.some(patient => patient.id === selectedPatientId.value);
if (selectedExists) return;
const preferred = patientList.value.find(patient => patient.certNo === preferredCertNo.value);
const self = patientList.value.find(patient => patient.isSelf);
selectedPatientId.value = (preferred || self || patientList.value[0] || {}).id || "";
}
watch(patientList, selectDefaultPatient, { immediate: true });
2026-07-31 16:21:41 +08:00
function scanCode() {
return new Promise((resolve, reject) => {
uni.scanCode({
onlyFromCamera: true,
scanType: ["qrCode"],
success: resolve,
fail: reject,
});
});
}
async function scanInsuranceCode() {
if (scanning.value) return;
scanning.value = true;
try {
const scanResult = await scanCode();
const id = typeof scanResult.result === "string" ? scanResult.result.trim() : "";
if (!/^[a-f\d]{24}$/i.test(id)) {
toast("医保二维码无效");
return;
}
const res = await getScannedCard({ id, storeId: storeId.value });
if (!res || !res.success || !res.data) {
toast((res && res.message) || "获取医保信息失败");
return;
}
if (!res.data.Name || !res.data.IDNum || !res.data.CardNum || !res.data.CardIDCode) {
toast("医保信息不完整,请重新读卡");
return;
}
set("current-scanned-card", res.data, 300);
uni.navigateTo({
url: `/pages/member/detail?type=ybQrcode&feeType=${feeType.value}`,
});
2026-07-31 18:26:48 +08:00
} catch (error) { }
scanning.value = false;
2026-07-31 16:21:41 +08:00
}
2026-07-27 11:26:39 +08:00
async function nextStep() {
if (!currentProfile.value) {
toast("请选择就诊人");
return;
}
2026-07-30 16:48:56 +08:00
let hisArchive = null;
if (feeType.value === 'YB') {
2026-07-27 11:26:39 +08:00
const authCode = await getAuthCode("nhsamp");
2026-07-30 16:48:56 +08:00
const psnToken = await ybPlugin.getArchiveToken(authCode);
if (psnToken) {
hisArchive = await bindInsurance(psnToken, currentProfile.value.certNo, currentProfile.value.name, currentProfile.value.mobile);
} else {
toast('获取医保授权失败');
return
2026-07-27 11:26:39 +08:00
}
2026-07-30 16:48:56 +08:00
} else {
hisArchive = await getHisArchive(currentProfile.value.certNo);
2026-07-27 11:26:39 +08:00
}
2026-07-30 16:48:56 +08:00
set("current-his-archive", hisArchive);
2026-07-27 11:26:39 +08:00
uni.navigateTo({
url: `/pages/consult/disease-description?socialno=${currentProfile.value.certNo}&feeType=${feeType.value}`,
});
}
async function bindInsurance(psnToken, idCard, name, mobile) {
2026-07-30 16:48:56 +08:00
const { success, list, tmbxx, message } = await bindHisPatient({ idCard, name, mobile, psnToken });
2026-07-27 11:26:39 +08:00
const patients = Array.isArray(list) ? list : [];
const patient = patients.find(item => item.socialno === idCard) || patients[0] || null;
if (!success || !patient) {
2026-07-30 16:48:56 +08:00
toast(message || "医保建档失败");
2026-07-27 11:26:39 +08:00
return Promise.reject(message || "医保建档失败");
}
if (patient.isyb !== "1") {
2026-07-30 16:48:56 +08:00
toast("医保建档失败");
return Promise.reject("医保建档失败");
2026-07-27 11:26:39 +08:00
}
2026-07-30 16:48:56 +08:00
patient.tmbxx = tmbxx;
return patient;
}
2026-07-27 11:26:39 +08:00
2026-07-30 16:48:56 +08:00
async function getHisArchive(idCard) {
const { success, list, tmbxx, message } = await getHisCustomer(idCard);
const patients = Array.isArray(list) ? list : [];
const patient = patients.find(item => item.socialno === idCard);
if (!success || !patient) {
toast(message || "获取档案信息失败");
return Promise.reject(message || "获取档案信息失败");
2026-07-27 11:26:39 +08:00
}
2026-07-30 16:48:56 +08:00
patient.tmbxx = tmbxx;
return patient;
2026-07-27 11:26:39 +08:00
}
function toggle(patientId) {
selectedPatientId.value = patientId;
}
function toAddPatient() {
uni.navigateTo({
url: `/pages/member/detail`,
});
}
function toPatientManagement() {
uni.navigateTo({ url: "/pages/member/list" });
}
</script>
<style lang="scss" scoped>
.container {
min-height: 100%;
box-sizing: border-box;
padding: 0 16rpx 24rpx;
}
.header {
height: 104rpx;
padding: 0 34rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
.title {
font-size: 28rpx;
2026-08-04 16:45:11 +08:00
color: #344743;
2026-07-27 11:26:39 +08:00
}
.scan-button {
width: 164rpx;
height: 64rpx;
margin: 0;
padding: 0;
2026-08-04 16:45:11 +08:00
background: #0f9f8d;
2026-07-27 11:26:39 +08:00
color: #fff;
font-size: 26rpx;
2026-08-04 16:45:11 +08:00
line-height: 62rpx;
2026-07-27 11:26:39 +08:00
}
.scan-button::after,
.action-button::after {
border: none;
}
.patient-list {
2026-08-04 16:45:11 +08:00
background: #e8f8f5;
2026-07-27 11:26:39 +08:00
}
.patient-card {
min-height: 118rpx;
box-sizing: border-box;
padding: 18rpx 34rpx;
background: #fff;
display: flex;
align-items: center;
justify-content: space-between;
}
.patient-card+.patient-card {
margin-top: 8rpx;
}
2026-08-04 16:45:11 +08:00
.patient-card--selected {
background: #e8f8f5;
box-shadow: inset 4rpx 0 0 #0f9f8d;
}
2026-07-27 11:26:39 +08:00
.patient-info {
display: flex;
flex-direction: column;
}
.name {
font-size: 28rpx;
line-height: 40rpx;
color: #333;
}
.self-tag {
2026-08-04 16:45:11 +08:00
color: #0f9f8d;
2026-07-27 11:26:39 +08:00
}
.details {
margin-top: 4rpx;
font-size: 24rpx;
line-height: 34rpx;
color: #9a9a9a;
}
.age {
margin-left: 10rpx;
}
.empty-text {
padding: 80rpx 0;
background: #fff;
text-align: center;
font-size: 26rpx;
color: #999;
}
.footer {
padding: 18rpx 24rpx 12rpx;
background: #fff;
box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.06);
}
.button-group {
display: flex;
gap: 22rpx;
}
.action-button {
2026-08-04 16:45:11 +08:00
height: 88rpx;
2026-07-27 11:26:39 +08:00
margin: 0;
padding: 0;
font-size: 28rpx;
2026-08-04 16:45:11 +08:00
line-height: 88rpx;
2026-07-27 11:26:39 +08:00
}
.add-button {
width: 244rpx;
2026-08-04 16:45:11 +08:00
border: 2rpx solid #0f9f8d;
2026-07-27 11:26:39 +08:00
background: #fff;
2026-08-04 16:45:11 +08:00
color: #0f9f8d;
2026-07-27 11:26:39 +08:00
}
.next-button {
flex: 1;
2026-08-04 16:45:11 +08:00
background: #0f9f8d;
2026-07-27 11:26:39 +08:00
color: #fff;
}
.manage-link {
2026-08-04 16:45:11 +08:00
padding: 24rpx 0;
2026-07-27 11:26:39 +08:00
display: flex;
align-items: center;
justify-content: center;
2026-08-04 16:45:11 +08:00
font-size: 24rpx;
color: #344743;
2026-07-27 11:26:39 +08:00
}
</style>