董国庆
2025-04-30 4e616ca3ca65adf17bf570d622e74b34a43a3a9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<template>
  <Card>
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      inline
      label-position="top"
    >
     
 
      
      
     
      <div class="header-title" style="margin-bottom: 38px">
        <div class="header-title-left">
          <img src="@/assets/public/headercard.png" />
          <div>所属实验调度</div>
        </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 prop="index" label="所属项目课题方案" width="200"></el-table-column>
        <el-table-column prop="sampleCode" label="实验编号"></el-table-column>
        <el-table-column prop="testData" label="实验名称"></el-table-column>
        <el-table-column prop="testData" label="通知时间"></el-table-column>
        <el-table-column prop="testData" label="实验开始时间"></el-table-column>
        <el-table-column prop="testData" label="实验结束时间"></el-table-column>
        <el-table-column prop="testData" label="参加人员"></el-table-column>
        <el-table-column prop="testData" label="状态"></el-table-column>
      </Table>
      <div class="header-title">
        <div class="header-title-left">
          <img src="@/assets/public/headercard.png" />
          <div>本次检验结果总表</div>
        </div>
      </div>
      <div class="header-title">
        <div class="header-title-left">
          <img src="@/assets/public/headercard.png" />
          <span>本次检验结果</span>
        </div>
      </div>
 
      <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";
    }
    div {
      flex-shrink: 0;
      font-weight: bold;
      font-size: 18px;
      color: #222222;
      line-height: 27px;
      font-family: "Source Han Sans CN Bold Bold";
 
      &:before {
        content: "*";
        color: #f56c6c;
        margin-right: 4px;
      }
    }
  }
}
 
.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>