<template>
|
<Card>
|
<el-form
|
ref="form"
|
:model="form"
|
:rules="rules"
|
inline
|
label-position="top"
|
>
|
<div style="padding-left: 25px">
|
<el-form-item prop="recordNo" label="原始检验记录编号">
|
<el-input v-model="form.recordNo" placeholder="请输入" />
|
</el-form-item>
|
</div>
|
|
<div class="header-title" style="margin-bottom: 38px">
|
<div class="header-title-left">
|
<img src="@/assets/public/headercard.png" />
|
<span>检测项信息</span>
|
</div>
|
</div>
|
<div style="padding-left: 25px">
|
<el-form-item prop="testItemName" label="检测项名字">
|
<el-input v-model="form.testItemName" placeholder="请输入" />
|
</el-form-item>
|
<el-form-item prop="testItemNo" label="检测项编号">
|
<el-input v-model="form.testItemNo" placeholder="请输入" />
|
</el-form-item>
|
<el-form-item prop="testMethodName" label="检测方法名字">
|
<el-input v-model="form.testMethodName" placeholder="请输入" />
|
</el-form-item>
|
<el-form-item prop="testMethodNo" label="检测方法编号">
|
<el-input v-model="form.testMethodNo" placeholder="请输入" />
|
</el-form-item>
|
</div>
|
|
<div class="header-title" style="margin-bottom: 38px">
|
<div class="header-title-left">
|
<img src="@/assets/public/headercard.png" />
|
<span>一 、检测标准</span>
|
</div>
|
</div>
|
<div class="header-title" style="margin-bottom: 38px">
|
<div class="header-title-left">
|
<img src="@/assets/public/headercard.png" />
|
<span>二 、检测仪器</span>
|
</div>
|
</div>
|
<div class="header-title" style="margin-bottom: 38px">
|
<div class="header-title-left">
|
<img src="@/assets/public/headercard.png" />
|
<span>三 、检测试剂</span>
|
</div>
|
</div>
|
<div class="header-title" style="margin-bottom: 38px">
|
<div class="header-title-left">
|
<img src="@/assets/public/headercard.png" />
|
<span>四 、检测步骤</span>
|
</div>
|
</div>
|
|
<div class="header-title" style="margin-bottom: 38px">
|
<div class="header-title-left">
|
<img src="@/assets/public/headercard.png" />
|
<span>五 、检测数据及参照</span>
|
</div>
|
<el-button type="primary" class="el-icon-plus" @click="handleAddTask">添加检测数据</el-button>
|
</div>
|
|
<Table :data="taskTableData" :total="0" :height="null" class="rwuTable">
|
<el-table-column type="index" label="序号" width="80"></el-table-column>
|
<el-table-column prop="sampleCode" label="检测样编号"></el-table-column>
|
<el-table-column prop="testData" label="检测数据"></el-table-column>
|
<el-table-column label="检测图片" width="200">
|
<template slot-scope="scope">
|
<div class="image-preview" v-if="scope.row.photos && scope.row.photos.length">
|
<el-image
|
v-for="(photo, index) in scope.row.photos"
|
:key="index"
|
:src="photo.url"
|
:preview-src-list="getPhotoUrls(scope.row.photos)"
|
fit="cover"
|
class="preview-image"
|
>
|
<div slot="error" class="image-slot">
|
<i class="el-icon-picture-outline"></i>
|
</div>
|
</el-image>
|
</div>
|
<span v-else>无图片</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="检测图谱" width="200">
|
<template slot-scope="scope">
|
<div v-if="scope.row.spectrums && scope.row.spectrums.length">
|
<el-link
|
v-for="(spectrum, index) in scope.row.spectrums"
|
:key="index"
|
type="primary"
|
:href="spectrum.url"
|
target="_blank"
|
class="spectrum-link"
|
>
|
{{ spectrum.name }}
|
</el-link>
|
</div>
|
<span v-else>无图谱</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="createTime" label="添加时间" width="180"></el-table-column>
|
<el-table-column label="操作" width="150">
|
<template slot-scope="scope">
|
<el-button type="text" @click="handleEditTask(scope.row)">编辑</el-button>
|
<el-button type="text" @click="handleDeleteTask(scope.row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</Table>
|
|
<div class="header-title">
|
<div class="header-title-left">
|
<img src="@/assets/public/headercard.png" />
|
<span>六 、检测结果预算</span>
|
</div>
|
</div>
|
<Table :data="taskTableData" :total="0" :height="null" class="rwuTable">
|
<el-table-column type="index" label="序号" width="80"></el-table-column>
|
<el-table-column prop="sampleCode" label="检测样编号"></el-table-column>
|
<el-table-column prop="testData" label="检测数据"></el-table-column>
|
<el-table-column label="检测结果" >
|
<template slot-scope="scope">
|
<el-input v-model="scope.row.testResult" placeholder="请输入检测结果"></el-input>
|
</template>
|
</el-table-column>
|
</Table>
|
|
<div class="add-project-footer">
|
<el-button type="primary" class="save-btn">发送</el-button>
|
<el-button>存草稿</el-button>
|
</div>
|
</el-form>
|
<!-- 添加检测数据弹窗 -->
|
<add-dialog
|
ref="addDialog"
|
:visible.sync="dialogVisible"
|
@success="handleTaskSubmit"
|
/>
|
</Card>
|
</template>
|
|
<script>
|
import AddDialog from './components/addDialog.vue'
|
import moment from 'moment'
|
|
export default {
|
name: "AddProject",
|
components: {
|
AddDialog
|
},
|
data() {
|
return {
|
dialogVisible: false,
|
isEdit: false,
|
currentEditIndex: -1,
|
form: {
|
recordNo: '',
|
testItemName: '',
|
testItemNo: '',
|
testMethodName: '',
|
testMethodNo: ''
|
},
|
rules: {
|
recordNo: [{ required: true, message: "请输入原始检验记录编号", trigger: "blur" }],
|
testItemName: [{ required: true, message: "请输入检测项名字", trigger: "blur" }],
|
testItemNo: [{ required: true, message: "请输入检测项编号", trigger: "blur" }],
|
testMethodName: [{ required: true, message: "请输入检测方法名字", trigger: "blur" }],
|
testMethodNo: [{ required: true, message: "请输入检测方法编号", trigger: "blur" }]
|
},
|
taskTableData: []
|
};
|
},
|
methods: {
|
handleAddTask() {
|
this.isEdit = false;
|
this.currentEditIndex = -1;
|
this.dialogVisible = true;
|
},
|
handleEditTask(row) {
|
this.isEdit = true;
|
this.currentEditIndex = this.taskTableData.findIndex(item => item === row);
|
|
const editData = {
|
sampleCode: row.sampleCode,
|
testData: row.testData,
|
testTypes: [],
|
photos: [],
|
spectrums: []
|
};
|
|
if (row.photos && row.photos.length > 0) {
|
editData.testTypes.push('photo');
|
editData.photos = row.photos.map(photo => ({
|
name: photo.name,
|
url: photo.url,
|
raw: null
|
}));
|
}
|
if (row.spectrums && row.spectrums.length > 0) {
|
editData.testTypes.push('spectrum');
|
editData.spectrums = row.spectrums.map(spectrum => ({
|
name: spectrum.name,
|
url: spectrum.url,
|
raw: null
|
}));
|
}
|
|
this.$nextTick(() => {
|
this.dialogVisible = true;
|
this.$refs.addDialog.setFormData(editData);
|
});
|
},
|
handleDeleteTask(row) {
|
this.$confirm("确认删除该检测数据吗?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
const index = this.taskTableData.findIndex((item) => item === row);
|
if (index > -1) {
|
const item = this.taskTableData[index];
|
if (item.photos) {
|
item.photos.forEach(photo => {
|
if (photo.url.startsWith('blob:')) {
|
URL.revokeObjectURL(photo.url);
|
}
|
});
|
}
|
if (item.spectrums) {
|
item.spectrums.forEach(spectrum => {
|
if (spectrum.url.startsWith('blob:')) {
|
URL.revokeObjectURL(spectrum.url);
|
}
|
});
|
}
|
|
this.taskTableData.splice(index, 1);
|
this.$message.success("删除成功");
|
}
|
})
|
.catch(() => {});
|
},
|
handleTaskSubmit(formData) {
|
const photos = formData.photos.map(file => ({
|
name: file.name,
|
url: file.url || URL.createObjectURL(file.raw)
|
}));
|
|
const spectrums = formData.spectrums.map(file => ({
|
name: file.name,
|
url: file.url || URL.createObjectURL(file.raw)
|
}));
|
|
const newData = {
|
sampleCode: formData.sampleCode,
|
testData: formData.testData,
|
testResult: '',
|
photos,
|
spectrums,
|
createTime: this.isEdit ? this.taskTableData[this.currentEditIndex].createTime : moment().format('YYYY-MM-DD HH:mm:ss')
|
};
|
|
if (this.isEdit && this.currentEditIndex > -1) {
|
const oldData = this.taskTableData[this.currentEditIndex];
|
if (oldData.photos) {
|
oldData.photos.forEach(photo => {
|
if (photo.url.startsWith('blob:') && !photos.find(p => p.url === photo.url)) {
|
URL.revokeObjectURL(photo.url);
|
}
|
});
|
}
|
if (oldData.spectrums) {
|
oldData.spectrums.forEach(spectrum => {
|
if (spectrum.url.startsWith('blob:') && !spectrums.find(s => s.url === spectrum.url)) {
|
URL.revokeObjectURL(spectrum.url);
|
}
|
});
|
}
|
|
this.taskTableData.splice(this.currentEditIndex, 1, newData);
|
this.$message.success('更新成功');
|
} else {
|
this.taskTableData.push(newData);
|
this.$message.success('添加成功');
|
}
|
|
this.dialogVisible = false;
|
this.isEdit = false;
|
this.currentEditIndex = -1;
|
},
|
getPhotoUrls(photos) {
|
return photos.map(photo => photo.url);
|
}
|
}
|
};
|
</script>
|
|
<style scoped lang="less">
|
.el-form--inline .el-form-item {
|
margin-right: 83px;
|
}
|
|
.header-title {
|
display: flex;
|
align-items: center;
|
flex-wrap: wrap;
|
gap: 13px;
|
margin-top: 38px;
|
|
.header-title-left {
|
display: flex;
|
align-items: center;
|
gap: 13px;
|
|
img {
|
width: 12px;
|
height: 19px;
|
}
|
|
span {
|
flex-shrink: 0;
|
font-weight: bold;
|
font-size: 18px;
|
color: #222222;
|
line-height: 27px;
|
font-family: "Source Han Sans CN Bold Bold";
|
}
|
}
|
}
|
|
.rwuTable {
|
width: 85%;
|
padding-left: 40px;
|
}
|
|
.add-project-footer {
|
margin-top: 43px;
|
|
button {
|
width: 220px;
|
}
|
|
.save-btn {
|
margin-right: 20px;
|
}
|
}
|
|
.image-preview {
|
display: flex;
|
gap: 8px;
|
flex-wrap: wrap;
|
|
.preview-image {
|
width: 50px;
|
height: 50px;
|
border-radius: 4px;
|
cursor: pointer;
|
}
|
|
.image-slot {
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
width: 100%;
|
height: 100%;
|
background: #f5f7fa;
|
color: #909399;
|
}
|
}
|
|
.spectrum-link {
|
display: block;
|
margin-bottom: 5px;
|
|
&:last-child {
|
margin-bottom: 0;
|
}
|
}
|
</style>
|