门诊医生站->医嘱:新增独立的西药处方单补充

This commit is contained in:
2025-11-27 09:41:59 +08:00
parent 065f7052c6
commit 50a2ef9e00

View File

@@ -760,13 +760,10 @@
<el-table-column label="" align="center" prop="groupId" width="60">
<template #header>
<el-checkbox
v-model="checkAll"
:model-value="getCheckAllState(prescription.id)"
@change="
(value) => {
prescriptionList.forEach((item, index) => {
groupIndexList.push(index);
item.check = value;
});
handleCheckAllChange(value, prescription.id);
}
"
/>
@@ -776,7 +773,7 @@
v-model="scope.row.check"
@dblclick.stop=""
placeholder=""
@change="(value) => handleCheckBoxChange(value, scope.$index, scope.row)"
@change="(value) => handleCheckBoxChange(value, scope.$index, scope.row, prescription.id)"
/>
</template>
</el-table-column>
@@ -1091,6 +1088,7 @@ const westernPrescriptions = ref([]); // 西药处方列表
const currentPrescriptionId = ref(null); // 当前活跃的处方ID
const prescriptionCounter = ref(0); // 处方计数器
const allPrescriptionsData = ref({}); // 存储所有处方的数据,格式: { prescriptionId: [...prescriptionList] }
const allPrescriptionCheckStates = ref({}); // 存储每个处方的选中状态,格式: { prescriptionId: { checkedIndexes: [], checkAll: false } }
onMounted(() => {
document.addEventListener('keydown', escKeyListener);
// 初始化时自动创建第一个西药处方
@@ -1361,32 +1359,80 @@ function getListInfo(addNewRow) {
// 更新 allPrescriptionsData
allPrescriptionsData.value = prescriptionGroups;
// 更新西药处方列表
// 更新西药处方列表 - 保持原有顺序,只更新数据
const existingPrescriptionIds = Object.keys(prescriptionGroups);
if (existingPrescriptionIds.length > 0 && existingPrescriptionIds[0] !== 'default') {
// 如果有保存的处方数据,重建处方列表
westernPrescriptions.value = existingPrescriptionIds.map((id, index) => {
const info = prescriptionInfoMap[id] || {};
// 查找是否已存在该处方,保留其属性
const existing = westernPrescriptions.value.find(p => p.id === id);
return {
id: id,
name: info.prescriptionNo ? `西药方${index + 1}` : `西药方${index + 1}`,
prescriptionNo: info.prescriptionNo || '',
conditionDefinitionId: existing?.conditionDefinitionId || conditionDefinitionId.value,
accountId: existing?.accountId || accountId.value,
expandOrder: existing?.expandOrder || []
};
// 保存当前处方的ID用于后续恢复
const savedCurrentPrescriptionId = currentPrescriptionId.value;
// 遍历前端已有的处方列表,保持原有顺序,只更新数据
const updatedPrescriptions = [];
const processedBackendIds = new Set(); // 记录已处理的后端ID
// 1. 首先处理前端已有的处方(保持原有顺序)
westernPrescriptions.value.forEach((prescription, index) => {
const info = prescriptionInfoMap[prescription.id] || {};
// 检查这个前端处方是否有对应的后端数据
if (existingPrescriptionIds.includes(prescription.id)) {
// 如果后端有这个ID的数据说明处方已保存更新数据但保持顺序和名称
processedBackendIds.add(prescription.id);
updatedPrescriptions.push({
...prescription,
prescriptionNo: info.prescriptionNo || prescription.prescriptionNo || '',
// 保持原有名称,不要改变
name: prescription.name || `西药方${index + 1}`
});
} else {
// 如果后端没有这个ID的数据可能是前端创建的临时处方保持原样
updatedPrescriptions.push(prescription);
}
});
// 设置当前活跃处方
if (!currentPrescriptionId.value || !existingPrescriptionIds.includes(currentPrescriptionId.value)) {
currentPrescriptionId.value = existingPrescriptionIds[0];
// 2. 处理后端有但前端没有的处方(可能是新保存的处方,需要映射到前端)
existingPrescriptionIds.forEach((prescriptionId) => {
if (!processedBackendIds.has(prescriptionId)) {
const info = prescriptionInfoMap[prescriptionId] || {};
// 这是新保存的处方,查找是否有对应的前端临时处方
// 通过查找最近保存的数据来确定
const prescriptionData = prescriptionGroups[prescriptionId] || [];
if (prescriptionData.length > 0) {
// 尝试找到对应的前端处方(通过数据匹配)
// 如果找不到,就在末尾添加
const newPrescription = {
id: prescriptionId,
name: `西药方${updatedPrescriptions.length + 1}`,
prescriptionNo: info.prescriptionNo || '',
conditionDefinitionId: conditionDefinitionId.value,
accountId: accountId.value,
expandOrder: []
};
updatedPrescriptions.push(newPrescription);
}
}
});
// 3. 更新处方列表,保持原有顺序
westernPrescriptions.value = updatedPrescriptions;
// 4. 恢复当前活跃处方
if (savedCurrentPrescriptionId && existingPrescriptionIds.includes(savedCurrentPrescriptionId)) {
currentPrescriptionId.value = savedCurrentPrescriptionId;
} else if (updatedPrescriptions.length > 0) {
// 如果当前处方不存在,选择第一个已保存的处方
const firstSavedPrescription = updatedPrescriptions.find(p => existingPrescriptionIds.includes(p.id));
if (firstSavedPrescription) {
currentPrescriptionId.value = firstSavedPrescription.id;
} else {
currentPrescriptionId.value = updatedPrescriptions[0].id;
}
}
// 加载当前处方的数据
// 5. 加载当前处方的数据
prescriptionList.value = [...(allPrescriptionsData.value[currentPrescriptionId.value] || [])];
prescriptionCounter.value = westernPrescriptions.value.length;
// 6. 更新处方计数器
prescriptionCounter.value = Math.max(prescriptionCounter.value, westernPrescriptions.value.length);
}
if (props.activeTab == 'prescription' && addNewRow) {
@@ -2274,24 +2320,47 @@ function handleSaveBatch(prescriptionId) {
switchToActivePrescription(prescriptionId);
}
// 确保使用对应处方的数据
const targetPrescriptionId = prescriptionId || currentPrescriptionId.value;
if (!targetPrescriptionId) {
proxy.$modal.msgWarning('请先创建处方');
return;
}
// 从对应处方的数据中获取列表,而不是使用全局的 prescriptionList
const currentPrescriptionData = allPrescriptionsData.value[targetPrescriptionId] || [];
// 验证费用性质是否已选择
if (!accountId.value) {
const prescription = westernPrescriptions.value.find(p => p.id === targetPrescriptionId);
if (!prescription || !prescription.accountId) {
proxy.$modal.msgWarning('请先选择费用性质');
return;
}
if (expandOrder.value.length > 0) {
// 获取对应处方的展开状态
const prescriptionExpandOrder = prescription.expandOrder || [];
if (prescriptionExpandOrder.length > 0) {
proxy.$modal.msgWarning('请先点击确定确认当前医嘱');
return;
}
if (prescriptionList.value[0].isEdit && !prescriptionList.value[0].adviceType) {
prescriptionList.value.shift();
// 处理空行
if (currentPrescriptionData.length > 0 && currentPrescriptionData[0].isEdit && !currentPrescriptionData[0].adviceType) {
currentPrescriptionData.shift();
isAdding.value = false;
updateExpandOrder([]);
// 更新存储的数据
allPrescriptionsData.value[targetPrescriptionId] = [...currentPrescriptionData];
// 如果当前显示的就是这个处方,同步到 prescriptionList
if (currentPrescriptionId.value === targetPrescriptionId) {
prescriptionList.value = [...currentPrescriptionData];
}
}
let saveList = prescriptionList.value
// 使用对应处方的数据来过滤和保存
let saveList = currentPrescriptionData
.filter((item) => {
return item.statusEnum == 1 && !item.isSaved;
// 确保只保存属于当前处方的数据
return item.statusEnum == 1 && !item.isSaved && (item.prescriptionId === targetPrescriptionId || !item.prescriptionId);
})
.map((item) => {
// 为每个医嘱项设置minUnitQuantity值避免后端null值异常
@@ -2331,6 +2400,18 @@ function handleSaveBatch(prescriptionId) {
savePrescription({ adviceSaveList: saveList }).then((res) => {
if (res.code === 200) {
proxy.$modal.msgSuccess('保存成功');
// 保存成功后,更新当前处方的数据
currentPrescriptionData.forEach(item => {
if (saveList.find(saved => saved.uniqueKey === item.uniqueKey)) {
item.isSaved = true;
}
});
// 更新存储的数据
allPrescriptionsData.value[targetPrescriptionId] = [...currentPrescriptionData];
// 如果当前显示的就是这个处方,同步到 prescriptionList
if (currentPrescriptionId.value === targetPrescriptionId) {
prescriptionList.value = [...currentPrescriptionData];
}
getListInfo(false);
nextId.value = 1;
}
@@ -2999,18 +3080,49 @@ function sortPrescriptionList() {
// return prescriptionList.value.filter((item) => item.check);
// }
// 处理行chexkbox选中
function handleCheckBoxChange(value, index, row) {
// 获取指定处方的全选状态
function getCheckAllState(prescriptionId) {
const prescriptionData = allPrescriptionsData.value[prescriptionId] || [];
if (prescriptionData.length === 0) return false;
return prescriptionData.every(item => item.check === true);
}
// 处理处方的全选/取消全选
function handleCheckAllChange(value, prescriptionId) {
const prescriptionData = allPrescriptionsData.value[prescriptionId] || [];
// 更新该处方所有行的选中状态
prescriptionData.forEach((item) => {
item.check = value;
});
// 更新存储的数据
allPrescriptionsData.value[prescriptionId] = [...prescriptionData];
// 如果当前显示的就是这个处方,同步到 prescriptionList
if (currentPrescriptionId.value === prescriptionId) {
prescriptionList.value = [...prescriptionData];
}
}
// 处理行checkbox选中
function handleCheckBoxChange(value, index, row, prescriptionId) {
// 获取对应处方的数据
const prescriptionData = allPrescriptionsData.value[prescriptionId] || [];
// 选中将当前行索引记录下来,取消将当前行索引删除
if (value) {
groupIndexList.value.push(index);
if (!groupIndexList.value.includes(index)) {
groupIndexList.value.push(index);
}
} else {
groupIndexList.value.splice(groupIndexList.value.indexOf(index), 1);
const indexPos = groupIndexList.value.indexOf(index);
if (indexPos > -1) {
groupIndexList.value.splice(indexPos, 1);
}
}
// 如果选中或取消行有组号,将全部相同组号的行全部选中,并记录或删除这些行的索引
if (row.groupId) {
// 获取组号相同行
let sameGroupIdList = prescriptionList.value.filter((item) => {
// 获取组号相同行(在当前处方内)
let sameGroupIdList = prescriptionData.filter((item) => {
return item.groupId == row.groupId;
});
// 如果只有一个组号的情况不做处理
@@ -3021,18 +3133,30 @@ function handleCheckBoxChange(value, index, row) {
// 排除掉当前选中行
if (row.uniqueKey != item.uniqueKey) {
// 同步选中状态
let currentIndex = prescriptionList.value.findIndex((k) => k.uniqueKey == item.uniqueKey);
prescriptionList.value[currentIndex].check = value;
if (value) {
groupIndexList.value.push(currentIndex); // 或使用索引或唯一标识
} else if (!value) {
groupIndexList.value.splice(groupIndexList.value.indexOf(currentIndex), 1);
let currentIndex = prescriptionData.findIndex((k) => k.uniqueKey == item.uniqueKey);
if (currentIndex !== -1) {
prescriptionData[currentIndex].check = value;
if (value) {
if (!groupIndexList.value.includes(currentIndex)) {
groupIndexList.value.push(currentIndex);
}
} else {
const indexPos = groupIndexList.value.indexOf(currentIndex);
if (indexPos > -1) {
groupIndexList.value.splice(indexPos, 1);
}
}
}
}
});
// 更新存储的数据
allPrescriptionsData.value[prescriptionId] = [...prescriptionData];
// 如果当前显示的就是这个处方,同步到 prescriptionList
if (currentPrescriptionId.value === prescriptionId) {
prescriptionList.value = [...prescriptionData];
}
}
}
console.log(groupIndexList.value);
}
// 校验每个组号数量是否大于5和对应分组金额是否大于500