|
|
@@ -43,7 +43,7 @@
|
|
|
width="100"
|
|
|
v-if="!view">
|
|
|
<template slot-scope="scope">
|
|
|
- <!-- <el-button @click="editRow(scope.row, scope.$index)" type="text" size="mini">编辑</el-button> -->
|
|
|
+ <el-button @click="editRow(scope.row, scope.$index)" type="text" size="mini">编辑</el-button>
|
|
|
<el-button @click="deleteRow(scope.$index)" type="text" size="mini">删除</el-button>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
@@ -84,7 +84,7 @@
|
|
|
>
|
|
|
</el-date-picker>
|
|
|
</el-form-item>
|
|
|
-
|
|
|
+
|
|
|
<el-form-item
|
|
|
label="事件发生的医院及科室"
|
|
|
label-width="110px"
|
|
|
@@ -103,9 +103,9 @@
|
|
|
></el-input>
|
|
|
</el-form-item>
|
|
|
|
|
|
- <el-form-item
|
|
|
- label="事件详细描述"
|
|
|
- label-width="110px"
|
|
|
+ <el-form-item
|
|
|
+ label="事件详细描述"
|
|
|
+ label-width="110px"
|
|
|
prop="eventDesc"
|
|
|
>
|
|
|
<el-input
|
|
|
@@ -116,9 +116,9 @@
|
|
|
></el-input>
|
|
|
</el-form-item>
|
|
|
|
|
|
- <el-form-item
|
|
|
- label="图片上传"
|
|
|
- label-width="110px"
|
|
|
+ <el-form-item
|
|
|
+ label="图片上传"
|
|
|
+ label-width="110px"
|
|
|
prop="eventImage"
|
|
|
:rules="{
|
|
|
required: true,
|
|
|
@@ -144,9 +144,9 @@
|
|
|
</el-upload>
|
|
|
</el-form-item>
|
|
|
|
|
|
- <el-form-item
|
|
|
- label="其他意见"
|
|
|
- label-width="110px"
|
|
|
+ <el-form-item
|
|
|
+ label="其他意见"
|
|
|
+ label-width="110px"
|
|
|
prop="eventOpinion"
|
|
|
>
|
|
|
<el-input
|
|
|
@@ -267,14 +267,14 @@ export default {
|
|
|
this.$message.error(`最多上传 ${this.limit}个文件`);
|
|
|
return Promise.reject(new Error('文件数量超出限制'));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 3. 文件类型校验(虽然accept属性已限制,但这里再做一层校验确保安全性)
|
|
|
const isImage = /\.(jpg|jpeg|png|gif)$/i.test(file.name);
|
|
|
if (!isImage) {
|
|
|
this.$message.error('请上传图片格式的文件');
|
|
|
return Promise.reject(new Error('文件类型不是图片'));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 4. 执行文件上传
|
|
|
return uploadFile({
|
|
|
module: this.module,
|
|
|
@@ -282,13 +282,13 @@ export default {
|
|
|
}).then((res) => {
|
|
|
if (res.data) {
|
|
|
// 将上传成功的文件添加到表单中
|
|
|
- const uploadedFile = {
|
|
|
- ...file,
|
|
|
- url: res.data.storePath,
|
|
|
+ const uploadedFile = {
|
|
|
+ ...file,
|
|
|
+ url: res.data.storePath,
|
|
|
...res.data,
|
|
|
status: 'success' // 标记为成功状态
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
// 检查文件是否已存在,避免重复添加
|
|
|
const existingIndex = this.form.eventImage.findIndex(item => item.uid === file.uid);
|
|
|
if (existingIndex === -1) {
|
|
|
@@ -296,7 +296,7 @@ export default {
|
|
|
} else {
|
|
|
this.form.eventImage.splice(existingIndex, 1, uploadedFile);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return res.data;
|
|
|
}
|
|
|
return Promise.reject(new Error('上传失败,未返回数据'));
|
|
|
@@ -307,6 +307,10 @@ export default {
|
|
|
},
|
|
|
beforeRemove (file) {
|
|
|
if (file.id) {
|
|
|
+ // 原明细仍可能被取消编辑或被流程引用,编辑时仅移除草稿中的引用。
|
|
|
+ if (this.type === 'edit' && (this.currentItem.eventImage || []).some(item => item.id === file.id)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
return removeFile({
|
|
|
fileId: file.id
|
|
|
}).then(() => {
|
|
|
@@ -370,50 +374,50 @@ export default {
|
|
|
try {
|
|
|
// 1. 先进行表单基本验证
|
|
|
await this.validateForm();
|
|
|
-
|
|
|
+
|
|
|
// 2. 额外验证图片上传是否有效
|
|
|
// if (!this.form.eventImage || this.form.eventImage.length === 0) {
|
|
|
// this.$message.error('请上传图片');
|
|
|
// return;
|
|
|
// }
|
|
|
-
|
|
|
+
|
|
|
// // 3. 检查是否有上传中的图片或上传失败的图片
|
|
|
- // const hasInvalidFile = this.form.eventImage.some(file =>
|
|
|
+ // const hasInvalidFile = this.form.eventImage.some(file =>
|
|
|
// file.status === 'uploading' || file.status === 'fail'
|
|
|
// );
|
|
|
-
|
|
|
+
|
|
|
// if (hasInvalidFile) {
|
|
|
// this.$message.error('存在图片正在上传中或上传失败,请等待上传完成或重新上传');
|
|
|
// return;
|
|
|
// }
|
|
|
-
|
|
|
+
|
|
|
// console.log('表单验证通过,图片上传有效');
|
|
|
-
|
|
|
+
|
|
|
// 4. 深拷贝form对象,避免引用问题
|
|
|
const newForm = JSON.parse(JSON.stringify(this.form));
|
|
|
-
|
|
|
+
|
|
|
// 5. 过滤出有效的图片数据(只保留成功上传的图片)
|
|
|
- newForm.eventImage = newForm.eventImage.filter(file =>
|
|
|
+ newForm.eventImage = newForm.eventImage.filter(file =>
|
|
|
file.status === 'success' && file.url
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
console.log('newForm', newForm);
|
|
|
-
|
|
|
+
|
|
|
// 6. 更新表格数据
|
|
|
if(this.type === 'add') {
|
|
|
this.tableData.push(newForm);
|
|
|
} else {
|
|
|
- this.tableData[this.currentIndex] = newForm;
|
|
|
+ this.$set(this.tableData, this.currentIndex, newForm);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
console.log('this.tableData', this.tableData);
|
|
|
-
|
|
|
+
|
|
|
// 7. 更新父组件数据
|
|
|
this.updateRowInfo();
|
|
|
-
|
|
|
+
|
|
|
// 8. 保存成功后关闭弹窗并重置表单
|
|
|
this.handleClose();
|
|
|
-
|
|
|
+
|
|
|
// 重置form
|
|
|
// this.form = {
|
|
|
// eventType: '',
|
|
|
@@ -453,4 +457,4 @@ export default {
|
|
|
padding-left: 10px;
|
|
|
padding-right: 10px;
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|