Fix Bug #480: [住院护士站-医嘱执行] 非耗材类医嘱执行报"耗材库存"错误且全选逻辑联动异常

1. 修复模板结构错误:删除premature的</template>和多余的</div>标签,确保el-table正确渲染
2. 新增selectedRowIds独立维护选中行ID集合,不再依赖el-table内部selection状态,避免执行选中时联动触发全选
3. 更新所有选择事件处理器同步维护selectedRowIds
4. 补充index.vue缺失的ref/nextTick/provide导入

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
关羽
2026-05-10 17:13:43 +08:00
parent 3301343fd5
commit 39796189eb
2 changed files with 30 additions and 19 deletions

View File

@@ -68,9 +68,7 @@
</div>
</div>
</div>
</template>
</div>
<div
<div
style="padding: 10px; background-color: #eef9fd; height: 100%; overflow-y: auto"
v-loading="loading"
>
@@ -232,7 +230,7 @@ import {adviceCancel, adviceExecute, adviceNoExecute, getPrescriptionList} from
import {patientInfoList} from '../../components/store/patient.js';
import {lotNumberMatch} from '@/api/public';
import {formatDateStr} from '@/utils/index';
import {getCurrentInstance, nextTick, ref} from 'vue';
import {getCurrentInstance, nextTick, ref, provide} from 'vue';
const activeNames = ref([]);
const prescriptionList = ref([]);
@@ -242,6 +240,8 @@ const therapyEnum = ref(undefined);
const { proxy } = getCurrentInstance();
const loading = ref(false);
const chooseAll = ref(false);
// 独立维护选中行ID集合避免el-table内部selection状态异常导致联动全选
const selectedRowIds = ref(new Set());
const props = defineProps({
exeStatus: {
type: Number,
@@ -442,6 +442,7 @@ function handleGetPrescription() {
chooseAll.value = false;
} else {
prescriptionList.value = [];
selectedRowIds.value.clear();
// proxy.$message.warning('请选择患者');
}
}
@@ -530,10 +531,14 @@ function handleCancel() {
}
function getSelectRows() {
// 获取选中的医嘱信息
let list = [];
prescriptionList.value.forEach((item, index) => {
list = [...list, ...proxy.$refs['tableRef' + index][0].getSelectionRows()];
// 优先从独立维护的selectedRowIds集合中获取选中行避免el-table内部selection状态异常
const list = [];
prescriptionList.value.forEach((item) => {
item.forEach((row) => {
if (selectedRowIds.value.has(row.requestId)) {
list.push(row);
}
});
});
return list;
}
@@ -609,12 +614,14 @@ function handelSwicthChange(value) {
if (value) {
// 全选选中所有行并联动checkbox
item.forEach((row) => {
selectedRowIds.value.add(row.requestId);
tableRef[0].toggleRowSelection(row, true);
selectAllCheckboxesInRow(row);
});
} else {
// 取消全选取消选中所有行并联动checkbox
item.forEach((row) => {
selectedRowIds.value.delete(row.requestId);
tableRef[0].toggleRowSelection(row, false);
unselectAllCheckboxesInRow(row);
});
@@ -625,11 +632,14 @@ function handelSwicthChange(value) {
// 默认选中全部行
function defaultSelectAllRows() {
// 清空并重建选中集合
selectedRowIds.value.clear();
prescriptionList.value.forEach((item, index) => {
const tableRef = proxy.$refs['tableRef' + index];
if (tableRef && tableRef[0]) {
// 选中该表格的所有行
item.forEach((row) => {
selectedRowIds.value.add(row.requestId);
tableRef[0].toggleRowSelection(row, true);
// 同时选中该行内部的所有checkbox
selectAllCheckboxesInRow(row);
@@ -709,13 +719,14 @@ function checkAndToggleRowSelection(row) {
const tableRef = proxy.$refs['tableRef' + tableIndex];
if (tableRef && tableRef[0]) {
const isAllSelected = isAllCheckboxesSelected(row);
const selectedRows = tableRef[0].getSelectionRows();
const isCurrentlySelected = selectedRows.some((r) => r.requestId === row.requestId);
const isCurrentlySelected = selectedRowIds.value.has(row.requestId);
// 根据checkbox状态更新表格行选中状态
if (isAllSelected && !isCurrentlySelected) {
selectedRowIds.value.add(row.requestId);
tableRef[0].toggleRowSelection(row, true);
} else if (!isAllSelected && isCurrentlySelected) {
selectedRowIds.value.delete(row.requestId);
tableRef[0].toggleRowSelection(row, false);
}
}
@@ -728,9 +739,11 @@ function handleRowSelect(selection, row, tableIndex) {
const isSelected = selection.some((item) => item.requestId === row.requestId);
if (isSelected) {
selectedRowIds.value.add(row.requestId);
// 选中行时选中该行内部的所有checkbox
selectAllCheckboxesInRow(row);
} else {
selectedRowIds.value.delete(row.requestId);
// 取消选中行时取消选中该行内部的所有checkbox
unselectAllCheckboxesInRow(row);
}
@@ -747,11 +760,13 @@ function handleSelectAll(selection, tableIndex) {
if (selection.length > 0) {
// 全选时选中所有行内部的所有checkbox
tableData.forEach((row) => {
selectedRowIds.value.add(row.requestId);
selectAllCheckboxesInRow(row);
});
} else {
// 取消全选时取消选中所有行内部的所有checkbox
tableData.forEach((row) => {
selectedRowIds.value.delete(row.requestId);
unselectAllCheckboxesInRow(row);
});
}
@@ -763,16 +778,12 @@ function handleSelectAll(selection, tableIndex) {
// 更新全选开关状态
function updateChooseAllStatus() {
let allSelected = true;
prescriptionList.value.forEach((item, index) => {
const tableRef = proxy.$refs['tableRef' + index];
if (tableRef && tableRef[0]) {
const selectedRows = tableRef[0].getSelectionRows();
if (selectedRows.length !== item.length) {
prescriptionList.value.forEach((item) => {
item.forEach((row) => {
if (!selectedRowIds.value.has(row.requestId)) {
allSelected = false;
}
} else {
allSelected = false;
}
});
});
chooseAll.value = allSelected;
}

View File

@@ -51,7 +51,7 @@
</template>
<script setup>
import {getCurrentInstance} from 'vue';
import {getCurrentInstance, ref, nextTick, provide} from 'vue';
import PatientList from '../components/patientList.vue';
import PrescriptionList from './components/prescriptionList.vue';
import { RequestStatus } from '@/utils/medicalConstants';