董国庆
7 天以前 069ef85293bb4baa74dd9251e8b3fd8cc4355410
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<template>
  <Card>
    <template style="position: relative">
      <div class="header-title">
        <div class="header-title-left">
          <img src="@/assets/public/headercard.png" />
          <div>所属实验调度</div>
        </div>
      </div>
 
      <div class="table-container">
        <el-table :data="experimentData" border style="width: 100%">
          <el-table-column type="index" label="序号" width="80"></el-table-column>
          <el-table-column prop="projectName" label="所属项目课题方案"></el-table-column>
          <el-table-column prop="experimentCode" label="实验编号"></el-table-column>
          <el-table-column prop="experimentName" label="实验名称"></el-table-column>
          <el-table-column prop="experimentDate" label="通知时间"></el-table-column>
          <el-table-column prop="experimentStartTime" label="实验开始时间"></el-table-column>
          <el-table-column prop="experimentEndTime" label="实验结束时间"></el-table-column>
          <el-table-column prop="participantsName" label="参加人员"></el-table-column>
          <el-table-column prop="status" label="状态">
            <template slot-scope="scope">
              <el-tag :type="getStatusType(scope.row.status)">
                {{ getStatusText(scope.row.status) }}
              </el-tag>
            </template>
          </el-table-column>
        </el-table>
      </div>
 
      <div class="header-title">
        <div class="header-title-left">
          <img src="@/assets/public/headercard.png" />
          <div>中止原因说明</div>
        </div>
      </div>
 
      <div class="content-box">
        <AiEditor
          ref="reasonEditor"
          :value="editorContent"
          height="200px"
          placeholder="请输入申请说明..."
        />
      </div>
 
      <div class="upload-section">
        <div class="upload-title">
          <span>上传文件</span>
        </div>
        <el-upload
          class="upload-demo"
          action=""
          :auto-upload="false"
          :on-change="handleFileChange"
          :file-list="fileList"
          :on-remove="handleFileRemove"
          multiple
          :limit="5"
        >
          <el-button size="small" type="primary">选择文件</el-button>
          <div slot="tip" class="el-upload__tip">支持格式:.rar .zip .doc .docx .pdf .jpg...</div>
        </el-upload>
      </div>
 
      <div class="footer-section">
        <div class="footer-content">
          <el-button type="primary" @click="openSignatureDialog" >提交</el-button>
          <el-checkbox v-model="agreement">我确认,已仔细实验说明,准确描述本次实验中止全部情况及原因,特此申请中止本次实验。</el-checkbox>
        </div>
      </div>
    </template>
 
    <!-- 签字确认弹窗 -->
    <el-dialog
      title="实验中止确认"
      :visible.sync="signatureDialogVisible"
      width="30%"
      :close-on-click-modal="false"
      @close="handleDialogClose"
    >
      <div class="signature-dialog">
        <div class="add-group">
          <div class="required">*</div>
          <span>签字确认</span>
          <el-button type="primary" class="el-icon-plus" @click="openSignature">签名</el-button>
        </div>
        <img
          v-if="imgSrc"
          :src="imgSrc"
          alt="签名"
          class="signature-preview"
        />
      </div>
 
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleDialogClose">取 消</el-button>
        <el-button type="primary" @click="handleConfirm">确 认</el-button>
      </div>
    </el-dialog>
 
    <SignatureCanvas
      :visible="signatureCanvasVisible"
      @confirm="handleSignatureConfirm"
    />
  </Card>
</template>
 
<script>
import AiEditor from '@/components/AiEditor'
import SignatureCanvas from "@/components/SignatureCanvas.vue"
import { getDetail, applicationTermination } from './service'
 
export default {
  name: 'StopExperiment',
  components: {
    AiEditor,
    SignatureCanvas
  },
  data() {
    return {
      id: null,
      experimentData: [],
      editorContent: '',
      fileList: [],
      agreement: false,
      signatureDialogVisible: false,
      signatureCanvasVisible: false,
      imgSrc: "",
      loading: false
    }
  },
  created() {
    this.id = this.$route.query.id
    if (this.id) {
      this.getExperimentDetail()
    } else {
      this.$message.error('参数错误,缺少实验ID')
    }
  },
  methods: {
    // 获取实验详情
    async getExperimentDetail() {
      try {
        this.loading = true
        const res = await getDetail({ id: this.id })
        if (res) {
          const data = res
          this.experimentData = [{...data.experimentDispatch}]
        } else {
          this.$message.warning('未获取到实验详情')
        }
      } catch (error) {
        console.error('获取实验详情失败:', error)
        this.$message.error('获取实验详情失败')
      } finally {
        this.loading = false
      }
    },
    handleFileChange(file, fileList) {
      // this.fileList = fileList
      this.fileList = [{uid: Date.now(),
         name: '实验中止申请表.txt', 
         raw: file, 
         size: file.size, 
         url:'https://example.com/files/default-stop-application.pdf',
         status: 'success'}]
    },
    handleFileRemove(file, fileList) {
      this.fileList = fileList
    },
    getEditorContent() {
      return this.$refs.reasonEditor.getContent()
    },
    validateForm() {
      const content = this.getEditorContent()
      if (!content || content === '<p></p>' || content.trim() === '<p></p>') {
        this.$message.error('请填写中止原因说明')
        return false
      }
      if (!this.agreement) {
        this.$message.error('请先勾选确认申请说明')
        return false
      }
      return true
    },
    openSignatureDialog() {
      if (!this.validateForm()) return
      this.signatureDialogVisible = true
    },
    handleDialogClose() {
      this.signatureDialogVisible = false
      this.imgSrc = ""
    },
    openSignature() {
      this.signatureCanvasVisible = true
    },
    handleSignatureConfirm(imageData) {
      this.signatureCanvasVisible = false
      // this.imgSrc = imageData
      this.imgSrc = 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
    },
    async handleConfirm() {
      if (!this.imgSrc) {
        this.$message.warning("请先完成签名确认")
        return
      }
      if (this.validateForm()) {
        try {
          this.loading = true
          
          // 处理多个文件,将文件路径和名称通过逗号拼接
          let filePaths = '';
          let fileNames = '';
          
          if (this.fileList.length > 0) {
            // 模拟文件路径
            filePaths = this.fileList.map(file => file.url).join(',')
            
            // 文件名称通过逗号拼接
            fileNames = this.fileList.map(file => file.name).join(',')
          }
          
          const formData = {
            id: this.id,                     // 实验方案id
            stopReason: this.getEditorContent(), // 中止原因
            commitSign: this.imgSrc,         // 提交签字
            stopFile: filePaths,             // 中止文件路径,多个文件路径通过逗号拼接
            stopFileName: fileNames          // 中止文件名称,多个文件名称通过逗号拼接
          }
          
          console.log('提交的数据:', formData)
          
          await applicationTermination(formData)
          this.$message.success('提交成功')
          this.handleDialogClose()
          // 提交成功后返回列表页
          this.$router.go(-1)
        } catch (error) {
          console.error('提交失败:', error)
          this.$message.error('提交失败')
        } finally {
          this.loading = false
        }
      }
    },
    getStatusType(status) {
      const statusMap = {
        "-1": "info",
        "1": "warning",
        "2": "success",
        "3": "info"
      };
      return statusMap[status] || "info";
    },
    getStatusText(status) {
      const statusMap = {
        "-1": "草稿箱",
        "1": "待确认",
        "2": "已确认",
        "3": "已封存"
      };
      return statusMap[status] || "未知";
    }
  }
}
</script>
 
<style scoped lang="less">
.header-title {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-top: 38px;
  margin-bottom: 20px;
 
  .header-title-left {
    display: flex;
    align-items: center;
    gap: 13px;
 
    img {
      width: 12px;
      height: 19px;
    }
 
    span {
      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;
      }
    }
  }
}
.header-title:first-child {
  margin-top: 0;
}
 
.table-container {
  margin: 0 25px;
}
 
.content-box {
  padding: 0 25px;
  margin-bottom: 30px;
  width: 65%;
}
 
.upload-section {
  padding: 0 25px;
  margin-bottom: 30px;
 
  .upload-title {
    margin-bottom: 15px;
    span {
      font-size: 14px;
      color: #222222;
      // &::before {
      //   content: "*";
      //   color: #f56c6c;
      //   margin-right: 4px;
      // }
    }
  }
 
  .el-upload__tip {
    color: #909399;
    font-size: 12px;
    margin-top: 8px;
  }
}
 
.footer-section {
  padding: 20px 25px;
  // border-top: 1px solid #e4e7ed;
  margin-top: 60px;
 
  .footer-content {
    display: flex;
    align-items: center;
    gap: 20px;
 
    .el-button {
      width: 120px;
    }
  }
}
 
.signature-dialog {
  padding: 0 20px;
 
  .add-group {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
 
    .required {
      color: #f56c6c;
      margin-right: 4px;
    }
 
    span {
      margin-right: 15px;
      font-size: 14px;
      color: #303133;
    }
  }
 
  .signature-preview {
    width: 200px;
    height: 100px;
    border: 2px dashed #049c9a;
    border-radius: 4px;
    object-fit: contain;
  }
}
 
.dialog-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 20px;
 
  .el-button {
    width: 150px;
    margin: 0 10px;
  }
}
</style>