Fix Bug #576: AI修复
This commit is contained in:
@@ -31,10 +31,16 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { ref, watch } from 'vue';
|
||||
import { getLabCatalogItems, submitLabRequest } from '@/api/inpatient';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const props = defineProps({
|
||||
editData: { type: Object, default: null }
|
||||
});
|
||||
|
||||
const emit = defineEmits(['submit']);
|
||||
|
||||
const visible = ref(false);
|
||||
const unselectedItems = ref([]);
|
||||
const selectedItems = ref([]);
|
||||
@@ -42,13 +48,27 @@ const selectedItems = ref([]);
|
||||
const fetchItems = async () => {
|
||||
try {
|
||||
const res = await getLabCatalogItems();
|
||||
unselectedItems.value = res.data || [];
|
||||
const allItems = res.data || [];
|
||||
unselectedItems.value = [...allItems];
|
||||
selectedItems.value = [];
|
||||
|
||||
// 修复 Bug #576:编辑模式下回显已选项目
|
||||
if (props.editData && Array.isArray(props.editData.items)) {
|
||||
const existingIds = new Set(props.editData.items.map(i => i.id));
|
||||
selectedItems.value = props.editData.items;
|
||||
unselectedItems.value = allItems.filter(item => !existingIds.has(item.id));
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error('获取检验目录失败');
|
||||
}
|
||||
};
|
||||
|
||||
watch(visible, (val) => {
|
||||
if (val) {
|
||||
fetchItems();
|
||||
}
|
||||
});
|
||||
|
||||
const addToSelected = (item) => {
|
||||
selectedItems.value.push(item);
|
||||
unselectedItems.value = unselectedItems.value.filter(i => i.id !== item.id);
|
||||
@@ -61,23 +81,16 @@ const removeFromSelected = (item) => {
|
||||
|
||||
const submitRequest = async () => {
|
||||
try {
|
||||
await submitLabRequest(selectedItems.value.map(i => i.id));
|
||||
ElMessage.success('检验申请提交成功');
|
||||
const payload = {
|
||||
items: selectedItems.value,
|
||||
...props.editData
|
||||
};
|
||||
await submitLabRequest(payload);
|
||||
ElMessage.success(props.editData ? '修改成功' : '提交成功');
|
||||
emit('submit');
|
||||
visible.value = false;
|
||||
selectedItems.value = [];
|
||||
} catch (error) {
|
||||
ElMessage.error('提交申请失败');
|
||||
ElMessage.error(props.editData ? '修改失败' : '提交失败');
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({ visible, fetchItems });
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.apply-container { display: flex; gap: 20px; height: 400px; }
|
||||
.left-panel, .right-panel { flex: 1; display: flex; flex-direction: column; }
|
||||
.item-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; border: 1px solid #eee; }
|
||||
.item-row { padding: 10px; border-bottom: 1px solid #f0f0f0; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
|
||||
.item-row:hover { background-color: #f5f7fa; }
|
||||
.price-unit { color: #e6a23c; font-weight: bold; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user