<template>
|
<div class="medical-panel">
|
<div class="panel-header">
|
<h3>血常规记录表</h3>
|
<div class="panel-actions">
|
<el-button
|
v-if="isEditing"
|
type="primary"
|
size="small"
|
@click="addColumn"
|
icon="el-icon-plus"
|
>
|
新增记录列
|
</el-button>
|
<el-tooltip content="刷新表格布局" placement="top">
|
<el-button
|
size="small"
|
@click="forceTableLayout"
|
icon="el-icon-refresh"
|
>
|
刷新布局
|
</el-button>
|
</el-tooltip>
|
</div>
|
</div>
|
|
<el-table
|
:data="tableData"
|
border
|
style="width: 100%"
|
class="medical-table"
|
v-fit-columns
|
:key="tableKey"
|
@header-dragend="handleHeaderDragEnd"
|
v-loading="tableLoading"
|
>
|
<el-table-column
|
prop="itemName"
|
label="检测项目"
|
width="200"
|
fixed
|
class-name="leave-alone"
|
>
|
<template #default="scope">
|
<div class="item-name-cell">
|
<span :class="{'required-item': scope.row.required}">
|
{{ scope.row.itemName }}
|
</span>
|
<el-tooltip
|
v-if="scope.row.reference"
|
:content="`参考范围: ${scope.row.reference}`"
|
placement="top"
|
>
|
<i class="el-icon-info reference-icon"></i>
|
</el-tooltip>
|
</div>
|
</template>
|
</el-table-column>
|
|
<el-table-column
|
v-for="(col, index) in dynamicColumns"
|
:key="col.key"
|
:label="col.label"
|
:min-width="140"
|
:resizable="isEditing"
|
header-align="center"
|
align="center"
|
>
|
<template #default="scope">
|
<div class="cell-content-wrapper">
|
<el-input
|
v-if="isEditing"
|
v-model="scope.row.values[index]"
|
size="small"
|
:placeholder="getPlaceholder(scope.row)"
|
@blur="handleValueChange(scope.row, index)"
|
class="value-input"
|
:title="scope.row.values[index]"
|
/>
|
<div v-else class="value-display-container">
|
<span class="value-text" :title="scope.row.values[index]">
|
{{ scope.row.values[index] || '-' }}
|
</span>
|
<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">
|
<i
|
v-if="isValueValid(scope.row, scope.row.values[index])"
|
class="el-icon-success valid-icon"
|
title="数值在正常范围内"
|
></i>
|
<i
|
v-else
|
class="el-icon-warning invalid-icon"
|
title="数值超出正常范围"
|
></i>
|
</div>
|
</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>
|
|
<!-- 统计信息 -->
|
<div v-if="showStatistics" class="statistics-section">
|
<el-card shadow="never">
|
<div class="stats-content">
|
<span class="stats-title">数据统计:</span>
|
<span class="stats-item">总记录数: {{ dynamicColumns.length }} 个时间点</span>
|
<span class="stats-item">已填写: {{ filledCount }} 项</span>
|
<span class="stats-item">完成度: {{ completionRate }}%</span>
|
</div>
|
</el-card>
|
</div>
|
|
<!-- 附件上传区域 -->
|
<div class="attachment-section">
|
<div class="attachment-header">
|
<i class="el-icon-paperclip"></i>
|
<span class="attachment-title">附件上传</span>
|
<span class="attachment-tip">支持上传检验报告单等文件 (最多10个)</span>
|
</div>
|
<upload-attachment
|
:file-list="attachments"
|
@change="handleAttachmentChange"
|
:limit="10"
|
:accept="'.pdf,.jpg,.jpeg,.png,.doc,.docx'"
|
/>
|
</div>
|
|
<!-- 列编辑对话框 -->
|
<el-dialog
|
:title="`${editingColumnIndex !== null ? '编辑' : '新增'}时间点`"
|
:visible.sync="columnDialogVisible"
|
width="450px"
|
@closed="handleDialogClosed"
|
>
|
<el-form
|
:model="columnForm"
|
label-width="80px"
|
ref="columnForm"
|
:rules="columnRules"
|
>
|
<el-form-item label="日期" prop="date">
|
<el-date-picker
|
v-model="columnForm.date"
|
type="date"
|
placeholder="选择日期"
|
value-format="yyyy-MM-dd"
|
style="width: 100%"
|
:disabled-date="disableFutureDates"
|
/>
|
</el-form-item>
|
<el-form-item label="时间" prop="time">
|
<el-time-picker
|
v-model="columnForm.time"
|
placeholder="选择时间"
|
value-format="HH:mm"
|
style="width: 100%"
|
/>
|
</el-form-item>
|
<el-form-item label="备注" prop="remark">
|
<el-input
|
v-model="columnForm.remark"
|
type="textarea"
|
:rows="2"
|
placeholder="可选填写时间点备注信息"
|
maxlength="100"
|
show-word-limit
|
/>
|
</el-form-item>
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="columnDialogVisible = false">取消</el-button>
|
<el-button
|
v-if="editingColumnIndex !== null"
|
type="danger"
|
@click="handleDeleteColumn"
|
>
|
删除
|
</el-button>
|
<el-button type="primary" @click="confirmAddColumn" :loading="saveLoading">
|
确定
|
</el-button>
|
</span>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import UploadAttachment from "@/components/UploadAttachment";
|
|
export default {
|
name: 'BloodRoutinePanel',
|
components: {
|
UploadAttachment,
|
},
|
props: {
|
isEditing: {
|
type: Boolean,
|
default: false
|
},
|
initialData: {
|
type: Array,
|
default: () => []
|
},
|
showStatistics: {
|
type: Boolean,
|
default: true
|
}
|
},
|
data() {
|
return {
|
tableData: [],
|
dynamicColumns: [
|
{
|
label: '2024-12-27\n08:00',
|
key: 'time1',
|
date: '2024-12-27',
|
time: '08:00',
|
remark: '晨起检测'
|
}
|
],
|
attachments: [],
|
columnDialogVisible: false,
|
columnForm: {
|
date: '',
|
time: '',
|
remark: ''
|
},
|
editingColumnIndex: null,
|
tableKey: 0,
|
tableLoading: false,
|
saveLoading: false,
|
columnRules: {
|
date: [
|
{ required: true, message: '请选择日期', trigger: 'change' }
|
],
|
time: [
|
{ required: true, message: '请选择时间', trigger: 'change' }
|
]
|
}
|
};
|
},
|
computed: {
|
filledCount() {
|
let count = 0;
|
this.tableData.forEach(row => {
|
row.values.forEach(value => {
|
if (value && value.toString().trim() !== '') {
|
count++;
|
}
|
});
|
});
|
return count;
|
},
|
completionRate() {
|
const total = this.tableData.length * this.dynamicColumns.length;
|
return total > 0 ? Math.round((this.filledCount / total) * 100) : 0;
|
}
|
},
|
watch: {
|
isEditing(newVal) {
|
if (!newVal) {
|
this.$emit('data-change', {
|
type: 'blood_routine',
|
data: this.tableData,
|
columns: this.dynamicColumns,
|
attachments: this.attachments
|
});
|
}
|
this.$nextTick(() => {
|
this.forceTableLayout();
|
});
|
},
|
dynamicColumns: {
|
handler() {
|
this.$nextTick(() => {
|
this.forceTableLayout();
|
});
|
},
|
deep: true,
|
immediate: true
|
}
|
},
|
methods: {
|
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'
|
}
|
];
|
|
this.tableData = medicalItems.map(item => ({
|
...item,
|
values: new Array(this.dynamicColumns.length).fill('')
|
}));
|
},
|
|
getPlaceholder(row) {
|
return row.reference ? `参考: ${row.reference}` : '请输入数值';
|
},
|
|
isValueValid(row, value) {
|
if (!value || !row.min || !row.max) return true;
|
const numValue = parseFloat(value);
|
return !isNaN(numValue) && numValue >= row.min && numValue <= row.max;
|
},
|
|
addColumn() {
|
this.editingColumnIndex = null;
|
this.columnForm = {
|
date: new Date().toISOString().split('T')[0],
|
time: '08:00',
|
remark: ''
|
};
|
this.columnDialogVisible = true;
|
this.$nextTick(() => {
|
this.$refs.columnForm && this.$refs.columnForm.clearValidate();
|
});
|
},
|
|
editColumn(index) {
|
this.editingColumnIndex = index;
|
const column = this.dynamicColumns[index];
|
this.columnForm = {
|
date: column.date,
|
time: column.time,
|
remark: column.remark || ''
|
};
|
this.columnDialogVisible = true;
|
},
|
|
confirmAddColumn() {
|
this.$refs.columnForm.validate((valid) => {
|
if (!valid) {
|
this.$message.warning('请完善时间点信息');
|
return;
|
}
|
|
this.saveLoading = true;
|
|
if (this.editingColumnIndex !== null) {
|
// 编辑现有列
|
const column = this.dynamicColumns[this.editingColumnIndex];
|
column.label = `${this.columnForm.date}\n${this.columnForm.time}`;
|
column.date = this.columnForm.date;
|
column.time = this.columnForm.time;
|
column.remark = this.columnForm.remark;
|
this.$message.success('时间点修改成功');
|
} else {
|
// 新增列
|
const newIndex = this.dynamicColumns.length + 1;
|
const newColumn = {
|
label: `${this.columnForm.date}\n${this.columnForm.time}`,
|
key: `time${Date.now()}`,
|
date: this.columnForm.date,
|
time: this.columnForm.time,
|
remark: this.columnForm.remark
|
};
|
|
this.dynamicColumns.push(newColumn);
|
this.tableData.forEach(row => {
|
row.values.push('');
|
});
|
this.$message.success('时间点添加成功');
|
}
|
|
this.columnDialogVisible = false;
|
this.saveLoading = false;
|
this.tableKey += 1;
|
});
|
},
|
|
handleDeleteColumn() {
|
if (this.editingColumnIndex !== null) {
|
this.$confirm('确定要删除这个时间点吗?', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}).then(() => {
|
this.dynamicColumns.splice(this.editingColumnIndex, 1);
|
this.tableData.forEach(row => {
|
row.values.splice(this.editingColumnIndex, 1);
|
});
|
this.columnDialogVisible = false;
|
this.tableKey += 1;
|
this.$message.success('时间点删除成功');
|
});
|
}
|
},
|
|
handleDialogClosed() {
|
this.editingColumnIndex = null;
|
this.columnForm = {
|
date: '',
|
time: '',
|
remark: ''
|
};
|
this.$refs.columnForm && this.$refs.columnForm.clearValidate();
|
},
|
|
disableFutureDates(time) {
|
return time.getTime() > Date.now();
|
},
|
|
handleValueChange(row, columnIndex) {
|
this.$emit('data-change', {
|
type: 'blood_routine',
|
data: this.tableData,
|
columns: this.dynamicColumns
|
});
|
},
|
|
handleAttachmentChange(fileList) {
|
this.attachments = fileList;
|
this.$emit('attachment-change', {
|
type: 'blood_routine',
|
attachments: fileList
|
});
|
},
|
|
forceTableLayout() {
|
this.$nextTick(() => {
|
const table = this.$el.querySelector('.el-table');
|
if (table) {
|
window.dispatchEvent(new Event('resize'));
|
}
|
});
|
},
|
|
handleHeaderDragEnd() {
|
this.forceTableLayout();
|
},
|
|
exportData() {
|
return {
|
tableData: this.tableData,
|
columns: this.dynamicColumns,
|
statistics: {
|
filledCount: this.filledCount,
|
completionRate: this.completionRate,
|
totalColumns: this.dynamicColumns.length
|
},
|
exportTime: new Date().toISOString(),
|
attachments: this.attachments
|
};
|
}
|
},
|
mounted() {
|
this.initTableData();
|
}
|
};
|
</script>
|
|
<style scoped>
|
.medical-panel {
|
padding: 20px;
|
background: #fff;
|
border-radius: 8px;
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
}
|
|
.panel-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 24px;
|
padding-bottom: 16px;
|
border-bottom: 1px solid #ebeef5;
|
}
|
|
.panel-header h3 {
|
margin: 0;
|
color: #303133;
|
font-size: 20px;
|
font-weight: 600;
|
}
|
|
.panel-actions {
|
display: flex;
|
gap: 12px;
|
align-items: center;
|
}
|
|
.medical-table {
|
margin-bottom: 24px;
|
border-radius: 4px;
|
overflow: hidden;
|
}
|
|
.medical-table ::v-deep .el-table__body-wrapper {
|
overflow-x: auto;
|
}
|
|
.item-name-cell {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
}
|
|
.reference-icon {
|
color: #909399;
|
font-size: 14px;
|
cursor: help;
|
margin-left: 8px;
|
}
|
|
.required-item::before {
|
content: "*";
|
color: #f56c6c;
|
margin-right: 4px;
|
}
|
|
.cell-content-wrapper {
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
gap: 8px;
|
min-height: 32px;
|
}
|
|
.value-input {
|
flex: 1;
|
min-width: 80px;
|
}
|
|
.value-display-container {
|
display: flex;
|
align-items: center;
|
gap: 4px;
|
}
|
|
.value-text {
|
font-weight: 500;
|
color: #303133;
|
max-width: 80px;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
|
.unit-text {
|
color: #909399;
|
font-size: 12px;
|
flex-shrink: 0;
|
}
|
|
.validation-indicator {
|
flex-shrink: 0;
|
}
|
|
.valid-icon {
|
color: #67c23a;
|
font-size: 14px;
|
}
|
|
.invalid-icon {
|
color: #e6a23c;
|
font-size: 14px;
|
}
|
|
.statistics-section {
|
margin-bottom: 20px;
|
}
|
|
.stats-content {
|
display: flex;
|
gap: 20px;
|
align-items: center;
|
flex-wrap: wrap;
|
}
|
|
.stats-title {
|
font-weight: 600;
|
color: #303133;
|
}
|
|
.stats-item {
|
color: #606266;
|
font-size: 14px;
|
}
|
|
.attachment-section {
|
margin-top: 24px;
|
padding: 20px;
|
border: 1px solid #ebeef5;
|
border-radius: 4px;
|
background: #fafafa;
|
}
|
|
.attachment-header {
|
display: flex;
|
align-items: center;
|
gap: 8px;
|
margin-bottom: 16px;
|
}
|
|
.attachment-title {
|
font-weight: 600;
|
color: #409eff;
|
}
|
|
.attachment-tip {
|
font-size: 12px;
|
color: #909399;
|
}
|
|
/* 响应式设计 */
|
@media (max-width: 768px) {
|
.medical-panel {
|
padding: 12px;
|
}
|
|
.panel-header {
|
flex-direction: column;
|
align-items: flex-start;
|
gap: 12px;
|
}
|
|
.panel-actions {
|
width: 100%;
|
justify-content: flex-end;
|
}
|
|
.stats-content {
|
flex-direction: column;
|
align-items: flex-start;
|
gap: 8px;
|
}
|
|
.cell-content-wrapper {
|
flex-direction: column;
|
gap: 4px;
|
}
|
}
|
|
/* 动画效果 */
|
.fade-enter-active, .fade-leave-active {
|
transition: opacity 0.3s;
|
}
|
.fade-enter, .fade-leave-to {
|
opacity: 0;
|
}
|
</style>
|