董国庆
2 天以前 013c63b6a07231bb4456106e31715b0982167abd
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
<template>
    <div class="add-container" :loading="loading">
        <Card v-loading="loading">
            <div class="header-title" style="width: 100%;">
                <div class="header-title-left">
                    <img src="@/assets/public/headercard.png" />
                    <div>所属检测项</div>
                </div>
                <!-- <div class="header-title-right">
                    <el-button @click="showChoose = true" class="el-icon-circle-plus-outline" type="primary">
                        选择项目组</el-button>
                </div> -->
            </div>
            <Table :height="null" :data="tableData" :total="0">
                <template>
                    <el-table-column prop="teamName" label="所属项目组" />
                    <el-table-column prop="itemName" label="检测项名称" />
                    <el-table-column prop="itemCode" label="检测项编号" />
                    <el-table-column prop="remarks" label="备注" />
                    <el-table-column prop="createBy" label="创建人" />
                    <el-table-column prop="createTime" label="创建时间" />
                </template>
            </Table>
            <el-form ref="form" :model="form" :rules="rules" inline label-position="top" style="margin-top: 18px">
                <el-row :gutter="20">
                    <el-col :span="24">
                        <el-form-item prop="reportContent" label="报告内容">
                            <el-select v-model="form.reportContent" style="width: 100%;" placeholder="请选择报告内容">
                                <el-option label="国家标准" :value="1" />
                                <el-option label="分析方法开发" :value="2" />
                                <el-option label="方法验证报告" :value="3" />
                                <el-option label="方法确认" :value="4" />
                                <el-option label="操作规程" :value="5" />
                                <el-option label="方法转移记录清单" :value="6" />
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="reportCode" label="报告编号" style="margin-left: 100px;">
                            <el-input v-model="form.reportCode" style="width: 100%;" placeholder="请输入报告编号" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item prop="developPersonName" label="制定人">
                            <el-input v-model="form.developPersonName" style="width: 100%;" placeholder="请输入制定人" disabled />
                        </el-form-item>
                        <el-form-item prop="developDate" label="制定日期" style="margin-left: 100px;">
                            <el-date-picker :prefix-icon="null" v-model="form.developDate" type="date" disabled
                                placeholder="请选择日期" />
                        </el-form-item>
                    </el-col>
                </el-row>
 
                <div class="header-title" style="width: 100%;">
                    <div class="header-title-left">
                        <img src="@/assets/public/headercard.png" />
                        <div>报告正文</div>
                    </div>
                </div>
                <el-form-item prop="reportText" style="margin-top: 18px">
                    <ai-editor ref="materialEditor" :value="form.reportText" style="width: 100%;"
                        placeholder="请输入报告正文" />
                </el-form-item>
                <div class="header-title" style="width: 100%;">
                    <div class="header-title-left">
                        <img src="@/assets/public/headercard.png" />
                        <span class="noRequire">附件</span>
                    </div>
                </div>
                <el-form-item prop="name" style="margin-top: 18px">
                    <el-upload 
                        action="#" 
                        :file-list="fileList"
                        :http-request="handleUpload"
                        :before-upload="beforeUpload"
                        :on-remove="handleRemove">
                        <el-button size="small" type="primary">点击上传</el-button>
                        <div slot="tip" class="el-upload__tip">支持任意格式文件上传</div>
                    </el-upload>
                </el-form-item>
 
                <div class="end-btn" style="margin-top: 38px">
                    <el-button type="primary" @click="submit" :loading="loading">发送</el-button>
                    <el-button type="default" @click="save" :loading="loading">存草稿</el-button>
                </div>
            </el-form>
        </Card>
        <chooseProject @submit="getProjectData" :show="showChoose" @close="showChoose = false"></chooseProject>
    </div>
</template>
 
<script>
import { Card } from 'element-ui';
import AiEditor from '@/components/AiEditor'
import chooseProject from '@/components/chooseProject'
import { addDetail, getDetailInfo,updateDetail,getDetail  } from './service'
 
export default {
    components: {
        AiEditor,
        chooseProject
    },
    data() {
        return {
            loading: false,
            form: {
                reportCode: "",
                reportContent: "",
                reportText: "",
                developPerson: "",
                developPersonName: "",
                developDate: "",
                itemId: "",
                status: 1,
                itemId: "",
                qaReportFiles: [],
                commitPersonId: null,
            },
            tableData: [],
            fileList: [], // 附件列表
            showChoose: false,
            rules: {
                reportContent: [
                    { required: true, message: '请选择报告内容', trigger: 'change' }
                ],
                itemId: [
                    { required: true, message: '请选择检测项', trigger: 'change' }
                ]
            },
            queryForm: {}
        }
    },
 
    mounted() {
        this.form.developPerson = JSON.parse(sessionStorage.getItem('userInfo')).nickName;
        this.form.developPersonName = JSON.parse(sessionStorage.getItem('userInfo')).nickName;
        this.form.commitPersonId = JSON.parse(sessionStorage.getItem('userInfo')).userId
        this.form.developDate = new Date().toISOString().split('T')[0];
 
        this.form.itemId=this.$route.query.itemId
        if(this.form.itemId){
            getDetail(this.form.itemId).then(res=>{
                if(res){
                    let item={
                        teamName:res.projectTeamVO.teamName,
                        teamId:res.teamId,
                        remark:res.remark,
 
                        itemName:res.itemName,
                        itemCode:res.itemCode,
                        createBy:res.createBy,
                        createTime:res.createTime
                    }
                   this.tableData = [{ ...item }]
                }
            })
        }
        console.log('this.$route.query.itemId',this.$route.query)
        
        if (this.$route.query.id) {
            this.getDetail()
        }
    },
 
    methods: {
        getDetail() {
            getDetailInfo({id:this.$route.query.id}).then(res => {
                if (res) {
                    this.form = {
                        ...res,
                        reportContent: Number(res.reportContent)
                    }
                    // this.tableData = [{ ...res.data.projectTeam, staffName: res.data.staffNames }]
                    this.fileList = res.qaReportFiles || []
                } else {
                    this.$message.error(res.message || '获取详情失败')
                }
            })
        },
        getProjectData(data) {
            this.tableData = [data]
            this.$forceUpdate()
            this.showChoose = false
        },
        submit() {
            this.$refs.form.validate((valid) => {
                if (!valid) return
                
                if (this.$refs.materialEditor.getContent() == '<p></p>') {
                    this.$message.error('请输入报告正文')
                    return
                }
                
                let data = {
                    ...this.form,
                    reportText: this.$refs.materialEditor.getContent(),
                    status: 1, // 待审核状态
                }
 
                this.loading = true
                if (this.$route.query.id) {
                    console.log('data updateDetail',data)
                    updateDetail({ ...data, id: this.$route.query.id }).then(res => {
                        if (res.code === 200) {
                            this.$message.success('修改成功')
                            this.$router.back()
                        } else {
                            this.$message.error(res.message || '修改失败')
                        }
                    }).finally(() => {
                        this.loading = false
                    })
                } else {
                    console.log('data addDetail',data)
                    addDetail(data).then(res => {
                        if (res.code === 200) {
                            this.$message.success('发布成功')
                            this.$router.back()
                        } else {
                            this.$message.error(res.message || '发布失败')
                        }
                    }).finally(() => {
                        this.loading = false
                    })
                }
            })
        },
        save() {
            this.$refs.form.validate((valid) => {
                if (!valid) return
                
                let data = {
                    ...this.form,
                    reportText: this.$refs.materialEditor.getContent(),
                    status: -1, // 草稿箱状态
                }
 
                this.loading = true
                if (this.$route.query.id) {
                    // 编辑草稿
                    updateDetail({ ...data, id: this.$route.query.id }).then(res => {
                        if (res.code === 200) {
                            this.$message.success('草稿保存成功')
                            this.$router.back()
                        } else {
                            this.$message.error(res.message || '保存失败')
                        }
                    }).finally(() => {
                        this.loading = false
                    })
                } else {
                    // 新增草稿
                    addDetail(data).then(res => {
                        if (res.code === 200) {
                            this.$message.success('草稿保存成功')
                            this.$router.back()
                        } else {
                            this.$message.error(res.message || '保存失败')
                        }
                    }).finally(() => {
                        this.loading = false
                    })
                }
            })
        },
        beforeUpload(file) {
            return true;
        },
        handleUpload(options) {
            const file = options.file;
            const fileObj = {
                fileName: file.name,
                fileSize: file.size,
                createTime: new Date().toISOString(),
                createBy: JSON.parse(sessionStorage.getItem('userInfo')).userId,
                reportType: 1,
                status: 1,
                id: Date.now().toString(),
                fileUrl: 'https://example.com/default-file-url'
            };
            
            this.fileList.push({
                name: file.name,
                url: fileObj.fileUrl
            });
            
            this.form.qaReportFiles.push(fileObj);
            
            this.$message.success('文件上传成功');
        },
        handleRemove(file) {
            const index = this.fileList.findIndex(item => item.name === file.name);
            if (index !== -1) {
                this.fileList.splice(index, 1);
                this.form.qaReportFiles.splice(index, 1);
            }
        },
    },
}
</script>
 
<style lang="less" scoped>
.header-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
    gap: 13px;
 
    .header-title-left {
        display: flex;
        align-items: center;
        gap: 13px;
        margin-top: 38px;
 
        img {
            width: 12px;
            height: 19px;
        }
 
        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;
            }
        }
 
        span {
            flex-shrink: 0;
            font-weight: bold;
            font-size: 18px;
            color: #222222;
            line-height: 27px;
            font-family: "Source Han Sans CN Bold Bold";
        }
    }
 
    .header-title-left :first-child {
        margin-top: 0;
    }
}
 
.header-title:first-child {
    .header-title-left {
        margin-top: 0;
    }
}
 
.end-btn {
    display: flex;
    align-items: center;
    gap: 10px;
 
    button {
        width: 180px;
        height: 36px;
        // background: #409EFF; 
    }
}
</style>