fix: 常用方、患者管理

This commit is contained in:
2025-12-26 09:19:22 +08:00
parent f4e51dc773
commit d4b9cc32d5
16 changed files with 6172 additions and 40 deletions

View File

@@ -85,9 +85,11 @@ export const usePrescriptionStore = defineStore('prescription', () => {
const selectedStoreId = ref<number | null>(null); // 用户选择的诊所ID
const sendMode = ref(0); // 0=默认(使用医生当前诊所),1=自定义(使用挂号诊所)
// 获取localStorage key(修改为在线复诊前缀)
const getStorageKey = () =>
`onlineConsultation-prescriptionData${currentRegisterId.value}`;
// 获取localStorage key(按类型分开存储)
const getStorageKey = (category?: number) => {
const cat = category ?? activeCategory.value;
return `onlineConsultation-prescriptionData_${cat}_${currentRegisterId.value}`;
};
// 计算属性
const totalProductCost = computed(() => {
@@ -201,6 +203,27 @@ export const usePrescriptionStore = defineStore('prescription', () => {
// 设置当前注册ID
currentRegisterId.value = registerId;
// 恢复之前保存的 activeCategory
const savedCategory = localStorage.getItem(
`onlineConsultation-activeCategory${registerId}`
);
if (savedCategory) {
activeCategory.value = Number.parseInt(savedCategory);
} else {
// 检查哪个存储键有数据
const chineseData = localStorage.getItem(
`onlineConsultation-prescriptionData_1_${registerId}`
);
const westData = localStorage.getItem(
`onlineConsultation-prescriptionData_2_${registerId}`
);
if (chineseData && JSON.parse(chineseData).length > 0) {
activeCategory.value = 1;
} else if (westData && JSON.parse(westData).length > 0) {
activeCategory.value = 2;
}
}
// 加载localStorage数据
loadFromLocalStorage();
@@ -228,6 +251,27 @@ export const usePrescriptionStore = defineStore('prescription', () => {
// 设置当前注册ID
currentRegisterId.value = registerId;
// 恢复之前保存的 activeCategory
const savedCategory = localStorage.getItem(
`onlineConsultation-activeCategory${registerId}`
);
if (savedCategory) {
activeCategory.value = Number.parseInt(savedCategory);
} else {
// 检查哪个存储键有数据
const chineseData = localStorage.getItem(
`onlineConsultation-prescriptionData_1_${registerId}`
);
const westData = localStorage.getItem(
`onlineConsultation-prescriptionData_2_${registerId}`
);
if (chineseData && JSON.parse(chineseData).length > 0) {
activeCategory.value = 1;
} else if (westData && JSON.parse(westData).length > 0) {
activeCategory.value = 2;
}
}
// 加载localStorage数据
loadFromLocalStorage();
@@ -458,6 +502,33 @@ export const usePrescriptionStore = defineStore('prescription', () => {
}
};
// 切换药品用法编辑状态
const toggleEditDrug = (index: number) => {
const newDrugs = [...currentDrugs.value];
newDrugs[index].isEditing = !newDrugs[index].isEditing;
updateCurrentDrugs(newDrugs);
};
// 保存药品用法编辑
const saveEditDrug = (index: number) => {
const newDrugs = [...currentDrugs.value];
const drug = newDrugs[index];
// 更新 ID 字段
drug.type_id = drug.use_type?.id;
drug.frequency_id = drug.use_frequency?.id;
drug.time_id = drug.use_num?.id;
drug.unit_id = drug.unit?.id;
drug.isEditing = false;
updateCurrentDrugs(newDrugs);
};
// 更新药品用法字段
const updateDrugUsage = (index: number, field: string, value: any) => {
const newDrugs = [...currentDrugs.value];
newDrugs[index][field] = value;
updateCurrentDrugs(newDrugs);
};
// 新药品操作
const selectNewDrugInfo = () => {
const check = currentDrugs.value.find((v) => v.id === newDrugInfo.value.id);
@@ -791,12 +862,26 @@ export const usePrescriptionStore = defineStore('prescription', () => {
};
const changeCategory = (categoryValue: number) => {
activeCategory.value = categoryValue;
updateCurrentDrugs([]);
// 先保存当前类型的药品数据
localStorage.setItem(
getStorageKey(activeCategory.value),
JSON.stringify(currentDrugs.value),
);
// 保存 Tab 类型
localStorage.setItem(
`onlineConsultation-activeCategory${currentRegisterId.value}`,
categoryValue.toString(),
);
activeCategory.value = categoryValue;
// 加载新类型对应的药品数据
const stored = localStorage.getItem(getStorageKey(categoryValue));
if (stored) {
currentDrugs.value.splice(0, currentDrugs.value.length, ...JSON.parse(stored));
} else {
currentDrugs.value.splice(0, currentDrugs.value.length);
}
};
// 工具函数
@@ -875,6 +960,9 @@ export const usePrescriptionStore = defineStore('prescription', () => {
updateDrugQuantity,
increment,
decrement,
toggleEditDrug,
saveEditDrug,
updateDrugUsage,
selectNewDrugInfo,
selectOldDrugInfo,
setSelectChineseIndex,