马宇豪
2024-03-25 9673c181dd7b3882cbde386422ffb9a2b1949693
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
<template>
    <div class="system-add-menu-container">
        <el-dialog v-model="ifShowApproveRuleDialog" :title="title" :close-on-click-modal="false" @close="clearFile()">
            <el-form v-if="disabled" :model="jsaForm" label-width="170px" ref="jsaFormRef" :rules="jsaFormRules">
                <el-row :gutter="20">
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                      <el-form-item label="jsa风险研判结论" prop="judgeRecord">
                        <el-input
                            v-model="jsaForm.judgeRecord"
                            :autosize="{ minRows: 3 }"
                            type="textarea"
                            placeholder="请输入jsa风险研判结论"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                      <el-form-item label="风险研判报告记录附件">
                        <el-upload accept="image/*" :auto-upload="true" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :limit='imgLimit' v-model:file-list="fileList" :http-request="upload" :action="uploadUrl" list-type="picture-card" :before-remove="beforeRemove" :before-upload="getUploadUrl">
                          <el-icon><Plus /></el-icon>
                          <template #tip>
                            <div class="el-upload__tip">上传jpg/png图片尺寸小于5M,最多可上传3张</div>
                          </template>
                        </el-upload>
                      </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div v-show="disabled" class="dialog-footer">
                    <el-button type="warning" @click="ifShowApproveRuleDialog = false" size="default" plain>取消</el-button>
                    <el-button type="primary" @click="submitApproveRule()" size="default">确认</el-button>
                </div>
            </template>
          <div class="d-container" v-if="!disabled">
            <div class="d-row">
              <div class="d-tit">jsa风险研判结论</div><div class="d-cont">{{detail.judgeRecord}}</div>
            </div>
            <div class="d-row">
              <div class="d-tit">风险研判报告记录附件</div>
              <div class="d-cont">
                <el-image v-for="item in detail.judgePicturePath?.split(',')" :preview-src-list="[item]" style="width: 150px; height: 150px;margin-right: 50px;margin-bottom: 20px" :src="item" fit="cover" />
              </div>
            </div>
            <div class="d-row">
              <div class="d-tit">研判人</div><div class="d-cont">{{detail.judgeUname}}</div>
            </div>
            <div class="d-row">
              <div class="d-tit">研判时间</div><div class="d-cont">{{detail.judgeTime}}</div>
            </div>
          </div>
        </el-dialog>
    </div>
</template>
 
<script lang="ts">
import { reactive, toRefs, ref } from 'vue';
import { ElMessage } from 'element-plus/es';
import { approveRuleApi } from '/@/api/specialWorkSystem/approveRule';
import { Edit, View, Plus, Delete, Refresh, Search, Download } from '@element-plus/icons-vue';
import {ElMessageBox, UploadProps} from "element-plus";
import {workApplyApi} from "/@/api/specialWorkSystem/workApply";
import axios from "axios";
interface dataState {
    title: string;
    disabled: boolean;
    ifShowApproveRuleDialog: boolean;
    jsaForm: {
        workApplyId: number | null;
        judgeRecord: string
        judgePicturePath: Array<string>
    };
    jsaFormRules: {};
    fileList: Array<file>,
    uploadUrl: string,
    dialogVisible: Boolean,
    dialogImageUrl: string | null,
    imgLimit: number,
    detail:{}
}
interface file {
  url: string
}
export default {
    name: 'jsaReportDialog',
    components: { Plus },
    setup(props: any, context: any) {
        const jsaFormRef = ref();
        const approveLevelDialogRef = ref();
        const state = reactive<dataState>({
            title: '',
            disabled: true,
            ifShowApproveRuleDialog: false,
            jsaForm: {
              workApplyId: null,
              judgeRecord: '',
              judgePicturePath: []
            },
            jsaFormRules: {
              judgeRecord: [{ required: true, message: '请填写jsa风险研判结论', trigger: 'blur' }]
            },
            fileList: [],
            imgLimit: 3,
            uploadUrl: '',
            dialogVisible: false,
            dialogImageUrl: null,
            detail: {}
        });
 
        const showReportDialog = (type: string, value: {}) => {
            state.ifShowApproveRuleDialog = true;
            if (type === '上传') {
                state.disabled = true;
                state.title = '上传风险研判报告';
                console.log(value.id,'id')
                state.jsaForm = {
                  workApplyId: value.id,
                  judgeRecord: '',
                  judgePicturePath: []
                };
            } else {
                state.disabled = false;
                state.title = '查看风险研判报告';
                getReport(value.id.toString())
            }
        };
 
        const getReport = async(id:string) => {
          let res = await workApplyApi().viewJsaReport({id:id});
          if (res.data.code === '200') {
            state.detail = res.data.data
          } else {
            ElMessage({
              type: 'warning',
              message: res.data.msg
            });
          }
        }
 
        const submitApproveRule = () => {
            jsaFormRef.value.validate(async (valid: Boolean) => {
                if (valid) {
                    state.jsaForm.judgePicturePath = state.jsaForm.judgePicturePath.join(',')
                    let res = await workApplyApi().uploadJsaReport(state.jsaForm);
                    if (res.data.code === '200') {
                        ElMessage({
                            type: 'success',
                            message: '研判报告上传成功',
                            duration: 2000
                        });
                        state.ifShowApproveRuleDialog = false;
                        state.jsaForm.judgePicturePath = []
                        state.fileList = []
                        context.emit('refresh');
                    } else {
                        ElMessage({
                            type: 'warning',
                            message: res.data.msg
                        });
                      state.jsaForm.judgePicturePath = state.jsaForm.judgePicturePath.split(',')
                    }
                } else {
                    ElMessage({
                        type: 'warning',
                        message: '请完善基本信息'
                    });
                }
            });
        };
 
      const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
        console.log(uploadFile);
      };
 
      const handlePictureCardPreview = (uploadFile: { url: string }) => {
        state.dialogImageUrl = uploadFile.url!;
        state.dialogVisible = true;
      };
 
      const getUploadUrl = async (rawFile: any) => {
        // const fileSize = rawFile.size / 1024 / 1024 < 5 ? '1' : '0'
        if(rawFile.size / 1024 / 1024 > 5){
          ElMessage({
            type: 'warning',
            message: '文件大小不能超过5M。'
          });
          return Promise.reject(false)
        }else{
          const res = await workApplyApi().getUpload9Url(rawFile.name);
          state.jsaForm.judgePicturePath.push(res.data.data.fileName)
          state.uploadUrl = res.data.data.uploadUrl;
        }
      };
 
      const upload = async (params: any) => {
        let reader = new FileReader();
        reader.readAsArrayBuffer(params.file);
        reader.onload = async () => {
          axios
              .put(state.uploadUrl, reader.result, {
                header: { 'Content-Type': 'multipart/form-data' }
              })
              .then(() => {
                // if (state.fileList.length === 2) {
                //     state.fileList.splice(0, 1);
                // }
                console.log(state.jsaForm.judgePicturePath,'judgePicturePath')
              });
        };
      };
 
      const beforeRemove = (file: {}, fileList: []) => {
        if (file && file.status === "success") {
          const result = new Promise((resolve, reject) => {
            ElMessageBox.confirm('此操作将删除该图片, 是否继续?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            })
                .then(() => {
                  const list = JSON.parse(JSON.stringify(state.jsaForm.judgePicturePath))
                  fileList.map((item, index) => {
                    if (item.uid === file.uid) {
                      fileList.splice(index, 1)
                      state.jsaForm.judgePicturePath.splice(index, 1)
                      // 请求删除接口
                      deletePic(list[index])
                    }
                  })
                })
                .catch(() => {
                  reject(false);
                });
          });
          return result;
        }
      };
 
      // 删除图片接口
      const deletePic = async(fileName:string)=>{
        const res = await workApplyApi().deleteFile({fileName: fileName})
        if (res.data.code === '200') {
          ElMessage({
            type: 'success',
            message: '删除成功!'
          });
        } else {
          ElMessage({
            type: 'warning',
            message: res.data.msg
          });
        }
      }
 
      const showTip =()=>{
        ElMessage({
          type: 'warning',
          message: '超出文件上传数量'
        });
      }
 
      const clearFile = ()=>{
        state.fileList = []
      }
 
        return {
            ...toRefs(state),
            Plus,
            jsaFormRef,
            approveLevelDialogRef,
            getReport,
            submitApproveRule,
            showReportDialog,
            handlePreview,
            getUploadUrl,
            upload,
            showTip,
            handlePictureCardPreview,
            beforeRemove,
          clearFile
        };
    }
};
</script>
 
<style scoped lang="scss">
$homeNavLengh: 8;
.home-container {
    height: calc(100vh - 144px);
    box-sizing: border-box;
    overflow: hidden;
    .homeCard {
        width: 100%;
        padding: 20px;
        box-sizing: border-box;
        background: #fff;
        border-radius: 4px;
 
        .main-card {
            width: 100%;
            height: 100%;
            .cardTop {
                display: flex;
                align-items: center;
                justify-content: space-between;
                margin-bottom: 20px;
                .mainCardBtn {
                    margin: 0;
                }
            }
            .pageBtn {
                height: 60px;
                display: flex;
                align-items: center;
                justify-content: right;
 
                .demo-pagination-block + .demo-pagination-block {
                    margin-top: 10px;
                }
                .demo-pagination-block .demonstration {
                    margin-bottom: 16px;
                }
            }
        }
        &:last-of-type {
            height: calc(100% - 100px);
        }
    }
    .el-row {
        display: flex;
        align-items: center;
        margin-bottom: 20px;
        &:last-child {
            margin-bottom: 0;
        }
        .grid-content {
            align-items: center;
            min-height: 36px;
        }
 
        .topInfo {
            display: flex;
            align-items: center;
            font-size: 16px;
            font-weight: bold;
 
            & > div {
                white-space: nowrap;
                margin-right: 20px;
            }
        }
    }
}
 
.d-container{
  width: 100%;
  .d-row{
    width: 100%;
    display: flex;
    align-items: flex-start;
    .d-tit{
      width: 150px;
      text-align: right;
      padding-right: 12px;
    }
    .d-cont{
      width: calc(100% - 150px);
      border: 1px solid #dcdfe6;
      margin-bottom: 22px;
      border-radius: var(--el-input-border-radius,var(--el-border-radius-base));
      padding: 5px 11px;
    }
  }
}
 
:deep(.el-date-editor) {
    width: 100%;
}
</style>