This commit is contained in:
wyuu 2025-10-31 09:51:46 +08:00
commit 8a13951dc8
3 changed files with 83 additions and 39 deletions

10
pnpm-lock.yaml generated
View File

@ -56,6 +56,9 @@ importers:
jsencrypt: jsencrypt:
specifier: 3.3.2 specifier: 3.3.2
version: 3.3.2 version: 3.3.2
mitt:
specifier: ^3.0.1
version: 3.0.1
nprogress: nprogress:
specifier: 0.2.0 specifier: 0.2.0
version: 0.2.0 version: 0.2.0
@ -1918,6 +1921,9 @@ packages:
resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==}
engines: {node: '>=16 || 14 >=14.17'} engines: {node: '>=16 || 14 >=14.17'}
mitt@3.0.1:
resolution: {integrity: sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==}
mixin-deep@1.3.2: mixin-deep@1.3.2:
resolution: {integrity: sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==} resolution: {integrity: sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
@ -4608,6 +4614,8 @@ snapshots:
minipass@7.1.2: {} minipass@7.1.2: {}
mitt@3.0.1: {}
mixin-deep@1.3.2: mixin-deep@1.3.2:
dependencies: dependencies:
for-in: 1.0.2 for-in: 1.0.2
@ -5460,7 +5468,7 @@ snapshots:
debug: 4.4.0 debug: 4.4.0
eslint: 9.27.0 eslint: 9.27.0
eslint-scope: 8.3.0 eslint-scope: 8.3.0
eslint-visitor-keys: 4.2.0 eslint-visitor-keys: 4.2.1
espree: 10.3.0 espree: 10.3.0
esquery: 1.6.0 esquery: 1.6.0
lodash: 4.17.21 lodash: 4.17.21

View File

@ -1,13 +1,16 @@
<!--仪器组件的封装--> <!--仪器组件的封装-->
<template> <template>
<SelectTable v-model:data="modelValue" :fields="yqFields" :tableData="instrOptions" label="yqmc" size="small" <SelectTable v-model:data="modelValue" :fields="props.fields" :tableData="instrOptions" label="yqmc" size="small"
value="yq" objKey="yq" :border="true" :width="props.width" placeholder="请选择仪器" :clearable="false" @getDataValue="getDataValue" /> value="yq" objKey="yq" :border="true" :width="props.width" placeholder="请选择仪器" :clearable="false" @getDataValue="getDataValue" />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import SelectTable from '@/components/SelectTable/index.vue'; import SelectTable from '@/components/SelectTable/index.vue';
import { getGroupInstrdList } from '@/api/liswork/work/LisWork'; import { getGroupInstrdList } from '@/api/liswork/work/LisWork';
import { Emits, Props } from '@/types'; import { Emits,Props,Field } from '@/types';
import { ref, watch, onMounted } from 'vue';
const modelValue = ref<string | null>('');
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
placeholder: "请选择", placeholder: "请选择",
@ -18,17 +21,25 @@ const props = withDefaults(defineProps<Props>(), {
border: false, border: false,
width: "100%", width: "100%",
dictType: '', dictType: '',
clearable: true clearable: true,
}); fields: () => [
const modelValue = ref('');
const yqFields = ref([
{ prop: 'yq', label: '代号', width: 80, enablePinyinSearch: true }, { prop: 'yq', label: '代号', width: 80, enablePinyinSearch: true },
{ prop: 'yqmc', label: '名称', width: 150, enablePinyinSearch: true }, { prop: 'yqmc', label: '名称', width: 150, enablePinyinSearch: true },
]); ] as Field[]
const instrOptions = ref<{ yq: string; yqmc: string }[]>([]) });
const instrOptions = ref<Array<{ yq: string; yqmc: string }>>([]);
const emits = defineEmits<Emits>(); const emits = defineEmits<Emits>();
// 当父组件使用 v-model:data 绑定时,props.data 代表父传入的值。
// 需要将其同步到内部的 modelValue,以便 SelectTable 的 v-model:data 能正确反向绑定。
watch(() => props.data, (newVal) => {
// 仅当内部值与外部值不一致时进行同步,避免不必要覆盖用户交互时的临时值。
if (newVal !== modelValue.value) {
modelValue.value = newVal ?? '';
}
});
const getYqConfig = () => { const getYqConfig = () => {
getGroupInstrdList() getGroupInstrdList()
.then((res: any) => { .then((res: any) => {
@ -45,7 +56,7 @@ const getDataValue = (val: any) => {
emits('getDataValue', val); emits('getDataValue', val);
}; };
const handleDataEcho = () => { const handleDataEcho = (val: any) => {
// if (modelValue.value === null || modelValue.value === undefined) { // if (modelValue.value === null || modelValue.value === undefined) {
// modelValue.value = ''; // modelValue.value = '';
// emits('update:data', null); // emits('update:data', null);
@ -57,26 +68,33 @@ const handleDataEcho = () => {
// } else { // } else {
// emits('update:data', ''); // emits('update:data', '');
// } // }
emits('update:data', modelValue.value); emits('update:data', val);
}; };
// 监听表格数据和字典类型变化 // 监听表格数据和字典类型变化
watch(() => instrOptions, (newVal) => { watch(() => instrOptions, (newVal) => {
if (newVal) { if (newVal) {
handleDataEcho(); handleDataEcho(newVal);
} }
}, { deep: true }); }, { deep: true });
// 监听绑定值数据变化,重新处理 // 监听绑定值数据变化,重新处理
watch(() => modelValue, (newVal) => { watch(() => modelValue, (newVal) => {
if (newVal) {
// 数据回显 // 数据回显
handleDataEcho(); handleDataEcho(newVal);
}
}, { deep: true }); }, { deep: true });
onMounted(() => { onMounted(() => {
getYqConfig(); getYqConfig();
// 初始化时同步一次父级值(如果有)到内部 modelValue
if (props.data !== undefined && props.data !== null) {
modelValue.value = props.data as any;
}
}); });

View File

@ -1,6 +1,6 @@
<template> <template>
<!--报告单设定--> <!--报告单设定-->
<el-form ref="form" :model="formData" label-width="80px" size="small"> <el-form ref="form" :model="formData" label-width="80px">
<el-form-item label="仪器" prop="yq"> <el-form-item label="仪器" prop="yq">
<YQSelectTable v-model:data="formData.yq" width="200px" @getDataValue="getList"/> <YQSelectTable v-model:data="formData.yq" width="200px" @getDataValue="getList"/>
</el-form-item> </el-form-item>
@ -11,7 +11,7 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-table :data="tableData" border width="100%" height="700px" @selection-change="handSelectionChange"> <el-table ref="reportTable" :data="tableData" border width="100%" height="700px" @row-click="onRowClick" highlight-current-row>
<el-table-column label="仪器" prop="yq" align="center"> <el-table-column label="仪器" prop="yq" align="center">
<template #default="scope"> <template #default="scope">
{{ formatInstr(scope.row.yq) }} {{ formatInstr(scope.row.yq) }}
@ -25,8 +25,8 @@
</el-table-column> </el-table-column>
<el-table-column label="医疗机构" prop="yljg" align="center"></el-table-column> <el-table-column label="医疗机构" prop="yljg" align="center"></el-table-column>
<el-table-column label="使用类型" prop="type" align="center"> <el-table-column label="使用类型" prop="type" align="center">
<template #default="{ row }"> <template #default="scope">
<el-select v-model="row.type" placeholder="请选择" class="full-width-input"> <el-select v-model="scope.row.type" placeholder="请选择" class="full-width-input" @change="handleRowChange(scope.row, scope.$index)">
<el-option label="默认" value="1"></el-option> <el-option label="默认" value="1"></el-option>
<el-option label="参数" value="2"></el-option> <el-option label="参数" value="2"></el-option>
<el-option label="根据项目来判断" value="3"></el-option> <el-option label="根据项目来判断" value="3"></el-option>
@ -34,8 +34,8 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="使用条件" prop="condition" align="center"> <el-table-column label="使用条件" prop="condition" align="center">
<template #default="{ row }"> <template #default="scope">
<el-input v-model="row.condition" placeholder="请输入使用条件" class="full-width-input"></el-input> <el-input v-model="scope.row.condition" placeholder="请输入使用条件" class="full-width-input" @change="handleRowChange(scope.row, scope.$index)"></el-input>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -45,10 +45,9 @@
import {addReportService,queryReportService,updateReportService,deleteReportService} from '@/api/liswork/xtwh/ReportSetting'; import {addReportService,queryReportService,updateReportService,deleteReportService} from '@/api/liswork/xtwh/ReportSetting';
import { LabReportInstr } from '@/types/index'; import { LabReportInstr } from '@/types/index';
import YQSelectTable from '@/components/SelectTable/YQSelectTable/index.vue'; import YQSelectTable from '@/components/SelectTable/YQSelectTable/index.vue';
import { ElMessage } from 'element-plus'; import { ElMessage,ElMessageBox } from 'element-plus';
import { formatInstr,getYqData } from '@/hooks/lisData/index'; import { formatInstr,getYqData } from '@/hooks/lisData/index';
const formData = ref({ const formData = ref({
yq: '' yq: ''
}); });
@ -57,6 +56,11 @@ const tableData = ref<LabReportInstr[]>([]);
//选中行的数据 //选中行的数据
const selectedRows = ref<LabReportInstr>(); const selectedRows = ref<LabReportInstr>();
//序号最大值
const maxXh = computed(() => {
return tableData.value.length > 0 ? Math.max(...tableData.value.map(item => item.xh)) : 0;
});
//新增数据 //新增数据
const handAdd = () => { const handAdd = () => {
if(formData.value.yq === ''){ if(formData.value.yq === ''){
@ -65,7 +69,7 @@ const handAdd = () => {
} }
const newReport: LabReportInstr = { const newReport: LabReportInstr = {
yq: formData.value.yq, yq: formData.value.yq,
xh: tableData.value.length + 1, xh: maxXh.value + 1,
bgdh: '', bgdh: '',
yljg: '1', yljg: '1',
type: '1', type: '1',
@ -77,26 +81,38 @@ const handAdd = () => {
//删除数据 //删除数据
const handDelete = async () => { const handDelete = async () => {
const res = await deleteReportService([selectedRows.value?.xh || '']); await ElMessageBox.confirm('是否要删除选中的数据?','Warning',
{
confirmButtonText: 'OK',
cancelButtonText: 'Cancel',
type: 'warning',
}
);
await deleteReportService({yq: selectedRows.value?.yq, xh: selectedRows.value?.xh,bgdh: selectedRows.value?.bgdh});
ElMessage.success('删除成功'); ElMessage.success('删除成功');
getList();
}; };
//保存数据 //保存数据
const handSave = async () => { const handSave = async () => {
let updateReports = tableData.value.filter(item => item.type === '1');
if(updateReports.length > 1){
ElMessage.error('默认的报告单类型不能有两个,请修改后再保存');
return;
}
updateReports = tableData.value.filter(item => item.type === '2' && item.condition.trim() === '');
if(updateReports.length > 0){
ElMessage.error('参数类型的使用条件不能为空,请修改后再保存');
return;
}
//过滤数据,只需要新增的数据 //过滤数据,只需要新增的数据
let newReports = tableData.value.filter(item => item.status === 'new'); let newReports = tableData.value.filter(item => item.status === 'new');
let res = await addReportService(newReports); let res = await addReportService(newReports);
console.log('res',res);
if(res.code !== '0'){
ElMessage.error('保存失败:' + res.message);
return;
}
newReports = tableData.value.filter(item => item.status === 'update'); newReports = tableData.value.filter(item => item.status === 'update');
console.log('更新的数据',newReports);
res = await updateReportService(newReports); res = await updateReportService(newReports);
if(res.code !== '0'){ ElMessage.success('保存成功');
ElMessage.error('修改保存失败:' + res.message); getList();
return;
}
} }
//刷新数据 //刷新数据
@ -112,11 +128,13 @@ const handleRowChange = (row: LabReportInstr, index: number) => {
} }
}; };
const handSelectionChange = (selection: LabReportInstr[]) => { const reportTable = ref<any>(null);
selectedRows.value = selection[0]; const onRowClick = (row: LabReportInstr) => {
if (reportTable.value) {
selectedRows.value = row;
}
}; };
onMounted(() => { onMounted(() => {
getYqData(); getYqData();
}); });