| | |
| | | > |
| | | <template #default="scope"> |
| | | <div class="item-name-cell"> |
| | | <span :class="{'required-item': scope.row.required}"> |
| | | <span :class="{ 'required-item': scope.row.required }"> |
| | | {{ scope.row.itemName }} |
| | | </span> |
| | | <el-tooltip |
| | |
| | | /> |
| | | <div v-else class="value-display-container"> |
| | | <span class="value-text" :title="scope.row.values[index]"> |
| | | {{ scope.row.values[index] || '-' }} |
| | | {{ scope.row.values[index] || "-" }} |
| | | </span> |
| | | <span v-if="scope.row.values[index] && scope.row.unit" class="unit-text"> |
| | | <span |
| | | v-if="scope.row.values[index] && scope.row.unit" |
| | | class="unit-text" |
| | | > |
| | | {{ scope.row.unit }} |
| | | </span> |
| | | </div> |
| | | <div v-if="scope.row.reference && scope.row.values[index]" class="validation-indicator"> |
| | | <div |
| | | v-if="scope.row.reference && scope.row.values[index]" |
| | | class="validation-indicator" |
| | | > |
| | | <i |
| | | v-if="isValueValid(scope.row, scope.row.values[index])" |
| | | class="el-icon-success valid-icon" |
| | |
| | | </div> |
| | | </template> |
| | | </el-table-column> |
| | | |
| | | <!-- <el-table-column |
| | | v-if="isEditing" |
| | | label="操作" |
| | | width="120" |
| | | fixed="right" |
| | | class-name="leave-alone" |
| | | > |
| | | <template #default> |
| | | <el-button link type="primary" @click="addColumn" size="small"> |
| | | 新增列 |
| | | </el-button> |
| | | </template> |
| | | </el-table-column> --> |
| | | </el-table> |
| | | |
| | | <!-- 统计信息 --> |
| | |
| | | <el-card shadow="never"> |
| | | <div class="stats-content"> |
| | | <span class="stats-title">数据统计:</span> |
| | | <span class="stats-item">总记录数: {{ dynamicColumns.length }} 个时间点</span> |
| | | <span class="stats-item" |
| | | >总记录数: {{ dynamicColumns.length }} 个时间点</span |
| | | > |
| | | <span class="stats-item">已填写: {{ filledCount }} 项</span> |
| | | <span class="stats-item">完成度: {{ completionRate }}%</span> |
| | | </div> |
| | |
| | | > |
| | | 删除 |
| | | </el-button> |
| | | <el-button type="primary" @click="confirmAddColumn" :loading="saveLoading"> |
| | | <el-button |
| | | type="primary" |
| | | @click="confirmAddColumn" |
| | | :loading="saveLoading" |
| | | > |
| | | 确定 |
| | | </el-button> |
| | | </span> |
| | |
| | | import UploadAttachment from "@/components/UploadAttachment"; |
| | | |
| | | export default { |
| | | name: 'BloodRoutinePanel', |
| | | name: "BloodRoutinePanel", |
| | | components: { |
| | | UploadAttachment, |
| | | UploadAttachment |
| | | }, |
| | | props: { |
| | | isEditing: { |
| | | type: Boolean, |
| | | default: false |
| | | }, |
| | | // 修改为 Object 类型,支持复杂数据结构 |
| | | initialData: { |
| | | type: Array, |
| | | default: () => [] |
| | | type: Object, |
| | | default: () => ({}) |
| | | }, |
| | | showStatistics: { |
| | | type: Boolean, |
| | |
| | | data() { |
| | | return { |
| | | tableData: [], |
| | | dynamicColumns: [ |
| | | { |
| | | label: '2024-12-27\n08:00', |
| | | key: 'time1', |
| | | date: '2024-12-27', |
| | | time: '08:00', |
| | | remark: '晨起检测' |
| | | } |
| | | ], |
| | | dynamicColumns: [], |
| | | attachments: [], |
| | | columnDialogVisible: false, |
| | | columnForm: { |
| | | date: '', |
| | | time: '', |
| | | remark: '' |
| | | date: "", |
| | | time: "", |
| | | remark: "" |
| | | }, |
| | | editingColumnIndex: null, |
| | | tableKey: 0, |
| | | tableLoading: false, |
| | | saveLoading: false, |
| | | // 内部数据状态 |
| | | internalData: {}, |
| | | columnRules: { |
| | | date: [ |
| | | { required: true, message: '请选择日期', trigger: 'change' } |
| | | ], |
| | | time: [ |
| | | { required: true, message: '请选择时间', trigger: 'change' } |
| | | ] |
| | | date: [{ required: true, message: "请选择日期", trigger: "change" }], |
| | | time: [{ required: true, message: "请选择时间", trigger: "change" }] |
| | | } |
| | | }; |
| | | }, |
| | |
| | | let count = 0; |
| | | this.tableData.forEach(row => { |
| | | row.values.forEach(value => { |
| | | if (value && value.toString().trim() !== '') { |
| | | if (value && value.toString().trim() !== "") { |
| | | count++; |
| | | } |
| | | }); |
| | |
| | | } |
| | | }, |
| | | watch: { |
| | | // 监听 initialData 变化,确保数据正确接收 |
| | | initialData: { |
| | | handler(newData) { |
| | | if (newData && Object.keys(newData).length > 0) { |
| | | this.internalData = { ...newData }; |
| | | this.initFromExternalData(); |
| | | } |
| | | }, |
| | | immediate: true, |
| | | deep: true |
| | | }, |
| | | isEditing(newVal) { |
| | | if (!newVal) { |
| | | this.$emit('data-change', { |
| | | type: 'blood_routine', |
| | | data: this.tableData, |
| | | columns: this.dynamicColumns, |
| | | attachments: this.attachments |
| | | }); |
| | | this.saveData(); |
| | | } |
| | | this.$nextTick(() => { |
| | | this.forceTableLayout(); |
| | |
| | | } |
| | | }, |
| | | methods: { |
| | | // 从外部数据初始化组件 |
| | | initFromExternalData() { |
| | | if (this.internalData.data && this.internalData.columns) { |
| | | this.tableData = this.internalData.data.map(item => ({ |
| | | ...item, |
| | | values: |
| | | item.values || new Array(this.internalData.columns.length).fill("") |
| | | })); |
| | | this.dynamicColumns = [...this.internalData.columns]; |
| | | } else { |
| | | // 如果没有外部数据,使用组件默认初始化 |
| | | this.initTableData(); |
| | | } |
| | | |
| | | // 初始化附件 |
| | | if (this.internalData.attachments) { |
| | | this.attachments = [...this.internalData.attachments]; |
| | | } |
| | | }, |
| | | |
| | | // 初始化默认表格数据 |
| | | initTableData() { |
| | | const medicalItems = [ |
| | | { |
| | | itemName: 'WBC', |
| | | unit: '×10⁹/L', |
| | | required: true, |
| | | reference: '3.5-9.5', |
| | | min: 3.5, |
| | | max: 9.5, |
| | | type: 'number' |
| | | }, |
| | | { |
| | | itemName: 'NEUT%', |
| | | unit: '%', |
| | | required: true, |
| | | reference: '40-75', |
| | | min: 40, |
| | | max: 75, |
| | | type: 'number' |
| | | }, |
| | | { |
| | | itemName: 'Hb', |
| | | unit: 'g/L', |
| | | required: true, |
| | | reference: '130-175', |
| | | min: 130, |
| | | max: 175, |
| | | type: 'number' |
| | | }, |
| | | { |
| | | itemName: '血小板', |
| | | unit: '×10⁹/L', |
| | | required: true, |
| | | reference: '125-350', |
| | | min: 125, |
| | | max: 350, |
| | | type: 'number' |
| | | } |
| | | ]; |
| | | const medicalItems = this.getMedicalItems(); |
| | | |
| | | // 如果没有动态列,初始化默认列 |
| | | if (this.dynamicColumns.length === 0) { |
| | | this.dynamicColumns = [ |
| | | { |
| | | label: `${new Date().toISOString().split("T")[0]}\n08:00`, |
| | | key: "time1", |
| | | date: new Date().toISOString().split("T")[0], |
| | | time: "08:00", |
| | | remark: "晨起检测" |
| | | } |
| | | ]; |
| | | } |
| | | |
| | | this.tableData = medicalItems.map(item => ({ |
| | | ...item, |
| | | values: new Array(this.dynamicColumns.length).fill('') |
| | | values: new Array(this.dynamicColumns.length).fill("") |
| | | })); |
| | | }, |
| | | |
| | | // 血常规检测项目定义 |
| | | getMedicalItems() { |
| | | return [ |
| | | { |
| | | itemName: "WBC", |
| | | unit: "×10⁹/L", |
| | | required: true, |
| | | reference: "3.5-9.5", |
| | | min: 3.5, |
| | | max: 9.5, |
| | | type: "number" |
| | | }, |
| | | { |
| | | itemName: "NEUT%", |
| | | unit: "%", |
| | | required: true, |
| | | reference: "40-75", |
| | | min: 40, |
| | | max: 75, |
| | | type: "number" |
| | | }, |
| | | { |
| | | itemName: "Hb", |
| | | unit: "g/L", |
| | | required: true, |
| | | reference: "130-175", |
| | | min: 130, |
| | | max: 175, |
| | | type: "number" |
| | | }, |
| | | { |
| | | itemName: "血小板", |
| | | unit: "×10⁹/L", |
| | | required: true, |
| | | reference: "125-350", |
| | | min: 125, |
| | | max: 350, |
| | | type: "number" |
| | | } |
| | | ]; |
| | | }, |
| | | |
| | | // 保存数据到父组件 |
| | | saveData() { |
| | | const dataToEmit = { |
| | | type: "blood_routine", |
| | | data: this.tableData, |
| | | columns: this.dynamicColumns, |
| | | attachments: this.attachments |
| | | }; |
| | | |
| | | this.$emit("data-change", dataToEmit); |
| | | }, |
| | | |
| | | getPlaceholder(row) { |
| | | return row.reference ? `参考: ${row.reference}` : '请输入数值'; |
| | | return row.reference ? `参考: ${row.reference}` : "请输入数值"; |
| | | }, |
| | | |
| | | isValueValid(row, value) { |
| | |
| | | addColumn() { |
| | | this.editingColumnIndex = null; |
| | | this.columnForm = { |
| | | date: new Date().toISOString().split('T')[0], |
| | | time: '08:00', |
| | | remark: '' |
| | | date: new Date().toISOString().split("T")[0], |
| | | time: "08:00", |
| | | remark: "" |
| | | }; |
| | | this.columnDialogVisible = true; |
| | | this.$nextTick(() => { |
| | |
| | | this.columnForm = { |
| | | date: column.date, |
| | | time: column.time, |
| | | remark: column.remark || '' |
| | | remark: column.remark || "" |
| | | }; |
| | | this.columnDialogVisible = true; |
| | | }, |
| | | |
| | | confirmAddColumn() { |
| | | this.$refs.columnFormB.validate((valid) => { |
| | | this.$refs.columnFormB.validate(valid => { |
| | | if (!valid) { |
| | | this.$message.warning('请完善时间点信息'); |
| | | this.$message.warning("请完善时间点信息"); |
| | | return; |
| | | } |
| | | |
| | |
| | | column.date = this.columnForm.date; |
| | | column.time = this.columnForm.time; |
| | | column.remark = this.columnForm.remark; |
| | | this.$message.success('时间点修改成功'); |
| | | this.$message.success("时间点修改成功"); |
| | | } else { |
| | | // 新增列 |
| | | const newIndex = this.dynamicColumns.length + 1; |
| | | const newColumn = { |
| | | label: `${this.columnForm.date}\n${this.columnForm.time}`, |
| | | key: `time${Date.now()}`, |
| | |
| | | remark: this.columnForm.remark |
| | | }; |
| | | |
| | | this.internalData.columns.push(newColumn); |
| | | this.dynamicColumns.push(newColumn); |
| | | this.tableData.forEach(row => { |
| | | row.values.push(''); |
| | | if (!row.values) row.values = []; |
| | | row.values.push(""); |
| | | }); |
| | | this.$message.success('时间点添加成功'); |
| | | this.$message.success("时间点添加成功"); |
| | | } |
| | | |
| | | this.columnDialogVisible = false; |
| | |
| | | |
| | | handleDeleteColumn() { |
| | | if (this.editingColumnIndex !== null) { |
| | | this.$confirm('确定要删除这个时间点吗?', '提示', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | this.$confirm("确定要删除这个时间点吗?", "提示", { |
| | | confirmButtonText: "确定", |
| | | cancelButtonText: "取消", |
| | | type: "warning" |
| | | }).then(() => { |
| | | this.dynamicColumns.splice(this.editingColumnIndex, 1); |
| | | this.tableData.forEach(row => { |
| | |
| | | }); |
| | | this.columnDialogVisible = false; |
| | | this.tableKey += 1; |
| | | this.$message.success('时间点删除成功'); |
| | | this.$message.success("时间点删除成功"); |
| | | }); |
| | | } |
| | | }, |
| | |
| | | handleDialogClosed() { |
| | | this.editingColumnIndex = null; |
| | | this.columnForm = { |
| | | date: '', |
| | | time: '', |
| | | remark: '' |
| | | date: "", |
| | | time: "", |
| | | remark: "" |
| | | }; |
| | | this.$refs.columnFormB && this.$refs.columnFormB.clearValidate(); |
| | | }, |
| | |
| | | }, |
| | | |
| | | handleValueChange(row, columnIndex) { |
| | | this.$emit('data-change', { |
| | | type: 'blood_routine', |
| | | data: this.tableData, |
| | | columns: this.dynamicColumns |
| | | }); |
| | | this.saveData(); |
| | | }, |
| | | |
| | | handleAttachmentChange(fileList) { |
| | | this.attachments = fileList; |
| | | this.$emit('attachment-change', { |
| | | type: 'blood_routine', |
| | | this.$emit("attachment-change", { |
| | | type: "blood_routine", |
| | | attachments: fileList |
| | | }); |
| | | }, |
| | | |
| | | forceTableLayout() { |
| | | this.$nextTick(() => { |
| | | const table = this.$el.querySelector('.el-table'); |
| | | const table = this.$el.querySelector(".el-table"); |
| | | if (table) { |
| | | window.dispatchEvent(new Event('resize')); |
| | | window.dispatchEvent(new Event("resize")); |
| | | } |
| | | }); |
| | | }, |
| | |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.initTableData(); |
| | | // 确保组件正确挂载后初始化数据 |
| | | this.$nextTick(() => { |
| | | if (Object.keys(this.internalData).length === 0) { |
| | | this.initTableData(); |
| | | } |
| | | this.forceTableLayout(); |
| | | }); |
| | | } |
| | | }; |
| | | </script> |
| | |
| | | flex-direction: column; |
| | | gap: 4px; |
| | | } |
| | | } |
| | | |
| | | /* 动画效果 */ |
| | | .fade-enter-active, .fade-leave-active { |
| | | transition: opacity 0.3s; |
| | | } |
| | | .fade-enter, .fade-leave-to { |
| | | opacity: 0; |
| | | } |
| | | </style> |