<template>
|
<div class="medical-panel">
|
<div class="panel-header">
|
<h3>肝功能肾功能记录表</h3>
|
<el-button
|
v-if="isEditing"
|
type="primary"
|
size="small"
|
@click="addColumn"
|
icon="el-icon-plus"
|
>
|
新增记录列
|
</el-button>
|
</div>
|
|
<el-table
|
:data="tableData"
|
border
|
style="width: 100%"
|
class="medical-table"
|
:key="tableKey"
|
v-fit-columns
|
@header-dragend="handleHeaderDragEnd"
|
>
|
<el-table-column
|
prop="itemName"
|
label="检测项目"
|
width="200"
|
fixed
|
class-name="leave-alone"
|
>
|
<template #default="scope">
|
<span :class="{ 'required-item': scope.row.required }">
|
{{ scope.row.itemName }}
|
</span>
|
</template>
|
</el-table-column>
|
|
<el-table-column
|
v-for="(col, index) in dynamicColumns"
|
:key="col.key"
|
:label="col.label"
|
:min-width="120"
|
:resizable="isEditing"
|
>
|
<template #default="scope">
|
<div class="cell-content">
|
<el-input
|
v-if="isEditing"
|
v-model="scope.row.values[index]"
|
size="small"
|
:placeholder="`请输入${scope.row.unit ? scope.row.unit : '数值'}`"
|
@blur="handleValueChange(scope.row, index)"
|
class="value-input"
|
/>
|
<span v-else class="value-display">
|
{{ scope.row.values[index] || "-" }}
|
<span
|
v-if="scope.row.values[index] && scope.row.unit"
|
class="unit"
|
>
|
{{ scope.row.unit }}
|
</span>
|
</span>
|
<span v-if="scope.row.reference" class="reference-range">
|
({{ scope.row.reference }})
|
</span>
|
</div>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<!-- 附件上传区域 -->
|
<div class="attachment-section">
|
<div class="attachment-title">
|
<i class="el-icon-paperclip"></i>
|
附件上传
|
<span class="attachment-tip">支持上传检验报告单等文件</span>
|
</div>
|
<upload-attachment
|
:file-list="attachments"
|
@change="handleAttachmentChange"
|
:limit="10"
|
:accept="'.pdf,.jpg,.jpeg,.png,.doc,.docx'"
|
/>
|
</div>
|
|
<!-- 列编辑对话框 -->
|
<el-dialog
|
title="编辑时间点"
|
:visible.sync="columnDialogVisible"
|
width="400px"
|
@closed="handleDialogClosed"
|
>
|
<el-form :model="columnForm" label-width="80px" ref="columnForm">
|
<el-form-item
|
label="日期"
|
prop="date"
|
:rules="[
|
{ required: true, message: '请选择日期', trigger: 'change' }
|
]"
|
>
|
<el-date-picker
|
v-model="columnForm.date"
|
type="date"
|
placeholder="选择日期"
|
value-format="yyyy-MM-dd"
|
style="width: 100%"
|
/>
|
</el-form-item>
|
<el-form-item
|
label="时间"
|
prop="time"
|
:rules="[
|
{ required: true, message: '请选择时间', trigger: 'change' }
|
]"
|
>
|
<el-time-picker
|
v-model="columnForm.time"
|
placeholder="选择时间"
|
value-format="HH:mm"
|
style="width: 100%"
|
/>
|
</el-form-item>
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="columnDialogVisible = false">取消</el-button>
|
<el-button type="primary" @click="confirmAddColumn">确定</el-button>
|
</span>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import UploadAttachment from "@/components/UploadAttachment";
|
|
export default {
|
name: "LiverKidneyPanel",
|
components: {
|
UploadAttachment
|
},
|
props: {
|
isEditing: {
|
type: Boolean,
|
default: false
|
},
|
// 修改 prop 定义,支持对象格式的初始数据
|
initialData: {
|
type: Object,
|
default: () => ({})
|
}
|
},
|
data() {
|
return {
|
tableData: [],
|
dynamicColumns: [],
|
attachments: [],
|
columnDialogVisible: false,
|
columnForm: {
|
date: "",
|
time: ""
|
},
|
tableKey: 0,
|
// 内部数据状态
|
internalData: {}
|
};
|
},
|
watch: {
|
// 监听 initialData 变化,确保数据正确接收 [5](@ref)
|
initialData: {
|
handler(newData) {
|
if (newData && Object.keys(newData).length > 0) {
|
this.internalData = { ...newData };
|
this.initFromExternalData();
|
}
|
},
|
immediate: true,
|
deep: true
|
},
|
isEditing(newVal) {
|
if (!newVal) {
|
this.saveData();
|
}
|
this.$nextTick(() => {
|
this.forceTableLayout();
|
});
|
},
|
dynamicColumns: {
|
handler() {
|
this.$nextTick(() => {
|
this.forceTableLayout();
|
});
|
},
|
deep: true
|
}
|
},
|
methods: {
|
// 从外部数据初始化组件 [9](@ref)
|
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: "血钠",
|
unit: "mmol/L",
|
required: true,
|
reference: "135-145"
|
},
|
{
|
itemName: "血钾",
|
unit: "mmol/L",
|
required: true,
|
reference: "3.5-5.5"
|
},
|
{ itemName: "BUN", unit: "mg/dL", required: true, reference: "<20" },
|
{ itemName: "肌酐", unit: "μmol/L", required: true, reference: "<100" },
|
{
|
itemName: "总胆红素",
|
unit: "μmol/L",
|
required: true,
|
reference: "<21"
|
},
|
{ itemName: "ALT", unit: "U/L", required: true, reference: "<50" },
|
{ itemName: "AST", unit: "U/L", required: true, reference: "<40" },
|
{ itemName: "GGT", unit: "U/L", required: true, reference: "<57" },
|
{ itemName: "ALP", unit: "U/L", required: true, reference: "<120" },
|
{ itemName: "PT", unit: "秒", required: true, reference: "9.4-12.5" },
|
{ itemName: "INR", unit: "", required: true, reference: "0.85-1.15" }
|
];
|
|
// 如果没有动态列,初始化默认列
|
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"
|
}
|
];
|
}
|
|
this.tableData = medicalItems.map(item => ({
|
...item,
|
values: new Array(this.dynamicColumns.length).fill("")
|
}));
|
},
|
|
// 保存数据到父组件 [2](@ref)
|
saveData() {
|
const dataToEmit = {
|
type: "liver_kidney",
|
data: this.tableData,
|
columns: this.dynamicColumns,
|
attachments: this.attachments
|
};
|
this.$emit("data-change", dataToEmit);
|
},
|
|
addColumn() {
|
this.columnForm = {
|
date: new Date().toISOString().split("T")[0],
|
time: "08:00"
|
};
|
this.columnDialogVisible = true;
|
},
|
|
confirmAddColumn() {
|
this.$refs.columnForm.validate(valid => {
|
if (!valid) {
|
this.$message.warning("请完善时间点信息");
|
return;
|
}
|
|
const newIndex = this.dynamicColumns.length + 1;
|
const newColumn = {
|
label: `${this.columnForm.date}\n${this.columnForm.time}`,
|
key: `time${newIndex}`,
|
date: this.columnForm.date,
|
time: this.columnForm.time
|
};
|
this.internalData.columns.push(newColumn);
|
|
this.dynamicColumns.push(newColumn);
|
|
// 为所有行新增一个空值
|
this.tableData.forEach(row => {
|
if (!row.values) {
|
row.values = [];
|
}
|
row.values.push("");
|
});
|
|
this.columnDialogVisible = false;
|
this.$message.success("时间点添加成功");
|
this.tableKey += 1;
|
});
|
},
|
|
handleDialogClosed() {
|
this.columnForm = {
|
date: "",
|
time: ""
|
};
|
this.$refs.columnForm && this.$refs.columnForm.clearValidate();
|
},
|
|
handleValueChange(row, columnIndex) {
|
this.saveData();
|
},
|
|
handleAttachmentChange(fileList) {
|
this.attachments = fileList;
|
this.$emit("attachment-change", {
|
type: "liver_kidney",
|
attachments: fileList
|
});
|
},
|
|
forceTableLayout() {
|
this.$nextTick(() => {
|
const table = this.$el.querySelector(".el-table");
|
if (table && table.querySelector("colgroup")) {
|
this.$nextTick(() => {
|
window.dispatchEvent(new Event("resize"));
|
});
|
}
|
});
|
},
|
|
handleHeaderDragEnd() {
|
this.forceTableLayout();
|
},
|
|
// 提供数据导出方法供父组件调用
|
exportData() {
|
return {
|
tableData: this.tableData,
|
columns: this.dynamicColumns,
|
exportTime: new Date().toISOString(),
|
attachments: this.attachments
|
};
|
}
|
},
|
mounted() {
|
// 确保组件正确挂载后初始化数据 [1](@ref)
|
this.$nextTick(() => {
|
if (Object.keys(this.internalData).length === 0) {
|
this.initTableData();
|
}
|
this.forceTableLayout();
|
});
|
}
|
};
|
</script>
|
|
<style scoped>
|
.medical-panel {
|
padding: 20px;
|
background: #fff;
|
border-radius: 4px;
|
overflow: hidden;
|
}
|
|
.panel-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 20px;
|
padding-bottom: 15px;
|
border-bottom: 1px solid #ebeef5;
|
}
|
|
.panel-header h3 {
|
margin: 0;
|
color: #303133;
|
font-size: 18px;
|
font-weight: 600;
|
}
|
|
.medical-table {
|
margin-bottom: 30px;
|
min-width: 100%;
|
}
|
|
.medical-table ::v-deep .el-table__body-wrapper {
|
overflow-x: auto;
|
}
|
|
.cell-content {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
min-height: 32px;
|
}
|
|
.value-input {
|
flex: 1;
|
margin-right: 8px;
|
}
|
|
.value-display {
|
font-weight: 500;
|
color: #303133;
|
}
|
|
.unit {
|
color: #909399;
|
font-size: 12px;
|
margin-left: 4px;
|
}
|
|
.reference-range {
|
color: #67c23a;
|
font-size: 12px;
|
font-style: italic;
|
margin-left: 8px;
|
}
|
|
.required-item::before {
|
content: "*";
|
color: #f56c6c;
|
margin-right: 4px;
|
}
|
|
.attachment-section {
|
margin-top: 30px;
|
padding: 20px;
|
border: 1px solid #ebeef5;
|
border-radius: 4px;
|
background: #fafafa;
|
}
|
|
.attachment-title {
|
font-weight: bold;
|
margin-bottom: 15px;
|
color: #409eff;
|
display: flex;
|
align-items: center;
|
}
|
|
.attachment-tip {
|
font-size: 12px;
|
color: #909399;
|
margin-left: 10px;
|
font-weight: normal;
|
}
|
|
@media (max-width: 768px) {
|
.medical-panel {
|
padding: 10px;
|
}
|
|
.panel-header {
|
flex-direction: column;
|
align-items: flex-start;
|
}
|
|
.panel-header h3 {
|
margin-bottom: 10px;
|
}
|
|
.cell-content {
|
flex-direction: column;
|
align-items: flex-start;
|
}
|
|
.reference-range {
|
margin-left: 0;
|
margin-top: 4px;
|
}
|
}
|
</style>
|