马宇豪
2024-01-26 c694cffc8541d921e5256d33e14e3237454de950
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
<template>
  <div class="system-add-user-container">
    <el-dialog :title="title" v-model="isShowDialog" width="50%">
      <el-form :model="form" size="default" ref="formRef" :rules="rules" label-width="160px">
        <el-row :gutter="35">
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="工艺名称" prop="craftName">
              <el-input v-model.trim="form.craftName" placeholder="工艺名称" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="工艺简介" prop="craftContent">
              <el-input v-model.trim="form.craftContent" :autosize="{ minRows: 1 }" type="textarea" placeholder="工艺简介" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="主要生产设备" prop="mainProdEquip">
              <el-input v-model.trim="form.mainProdEquip" :autosize="{ minRows: 1 }" type="textarea" placeholder="主要生产设备" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="重点部位" prop="keyParts">
              <el-input v-model.trim="form.keyParts" placeholder="重点部位" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="重大危险源" prop="hazardCode">
              <el-input v-model.trim="form.hazardCode" :autosize="{ minRows: 1 }" type="textarea" placeholder="重大危险源" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="涉及的危险化学品">
              <el-input v-model.trim="form.msds" :autosize="{ minRows: 1 }" type="textarea" placeholder="涉及的危险化学品" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="工艺危险特点">
              <el-input v-model.trim="form.hazardCharacter" placeholder="工艺危险特点" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="重点监控工艺参数指标">
              <el-input v-model.trim="form.parameterIndex" placeholder="重点监控工艺参数指标" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="现有安全控制手段">
              <el-input v-model.trim="form.controlMean" placeholder="现有安全控制手段" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="反应类型">
              <el-input v-model.trim="form.reactionType" placeholder="反应类型" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="重点监控单元">
              <el-input v-model.trim="form.keyMonitorUnit" placeholder="重点监控单元" clearable></el-input>
            </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/*" multiple list-type="picture-card" :action="uploadUrl" :headers="header" method="post" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :on-success="handleAvatarSuccess" :limit='2' v-model:file-list="fileList" :before-upload="picSize" :on-remove="handleRemove" :before-remove="beforeRemove">
                <el-icon><Plus /></el-icon>
                <template #tip>
                  <div class="el-upload__tip">上传图片尺寸小于2M,最多可上传2张</div>
                </template>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-dialog v-model="imgDialog">
        <img width="100%" :src="imageUrl" alt="Preview Image" />
      </el-dialog>
      <template #footer>
        <span class="dialog-footer">
            <el-button @click="isShowDialog = !isShowDialog" size="default">取 消</el-button>
            <el-button type="primary" v-throttle @click="onSubmit" size="default">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
 
<script lang="ts">
import { reactive, toRefs, onMounted, defineComponent, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import axios from "axios";
import {workApplyApi} from "/@/api/specialWorkSystem/workApply";
import Cookies from "js-cookie";
import {judgeReportApi} from "/@/api/dataUpload/saftyBaseInfo/judgeReport";
 
// 定义接口来定义对象的类型
interface DataState {
  title: string
  isShowDialog: boolean
  form: {
    uuid: string
    craftName: string
    craftContent: string
    mainProdEquip: string
    keyParts: string
    hazardCode: string
    msds: string
    hazardCharacter: string
    parameterIndex: string
    controlMean: string
    craftDraw: string
    reactionType: string
    keyMonitorUnit: string
  }
  rules:{},
  fileList: [],
  uploadUrl: string,
  header: {},
  imgDialog: boolean,
  imageUrl: string
}
 
export default defineComponent({
  name: 'reportDialog',
  setup(props, context) {
    const formRef = ref()
    const state = reactive<DataState>({
      title: '',
      isShowDialog: false,
      form: {
        uuid: '',
        craftName: '',
        craftContent: '',
        mainProdEquip: '',
        keyParts: '',
        hazardCode: '',
        msds: '',
        hazardCharacter: '',
        parameterIndex: '',
        controlMean: '',
        craftDraw: '',
        reactionType: '',
        keyMonitorUnit: ''
      },
      rules:{
        craftName: [{ required: true, message: '请填写工艺名称', trigger: 'blur' }],
        craftContent: [{ required: true, message: '请填写工艺简介', trigger: 'blur' }],
        mainProdEquip: [{ required: true, message: '请填写主要生产设备', trigger: 'blur' }],
        keyParts: [{ required: true, message: '请填写重点部位', trigger: 'blur' }],
        hazardCode: [{ required: true, message: '请填写重大危险源', trigger: 'blur' }]
      },
      fileList: [],
      uploadUrl: import.meta.env.VITE_API_URL + '/account/file/upload',
      header: {
        uid: Cookies.get('uid'),
        Authorization: Cookies.get('token')
      },
      imgDialog: false,
      imageUrl: ''
    })
 
    // 页面加载时
    onMounted(() => {
 
    })
    // 打开弹窗
    const open = (type: string, data: object) => {
      state.isShowDialog = true;
      if (type === 'add') {
        state.title = '新增上报'
        state.form = {
          uuid: '',
          craftName: '',
          craftContent: '',
          mainProdEquip: '',
          keyParts: '',
          hazardCode: '',
          msds: '',
          hazardCharacter: '',
          parameterIndex: '',
          controlMean: '',
          craftDraw: '',
          reactionType: '',
          keyMonitorUnit: ''
        }
      }else{
        state.title = '重新上报'
        state.form = {
          uuid: data.uuid,
          craftName: '',
          craftContent: '',
          mainProdEquip: '',
          keyParts: '',
          hazardCode: '',
          msds: '',
          hazardCharacter: '',
          parameterIndex: '',
          controlMean: '',
          craftDraw: '',
          reactionType: '',
          keyMonitorUnit: ''
        }
      }
      state.fileList=[]
    };
 
    // 新增修改
    const onSubmit = async () => {
      formRef.value.validate(async (valid:Boolean) => {
        if(valid){
            state.form.craftDraw = state.fileList.map(i=>i.name).join(',')
            const res = await judgeReportApi().addProduct([state.form])
            if(res.data.code == '200'){
              ElMessage({
                type:'success',
                message:'数据上报成功'
              })
              state.isShowDialog = false
              state.fileList = []
            }else{
              ElMessage({
                type:'warning',
                message:res.data.msg
              })
            }
            context.emit('refresh')
        }else{
          ElMessage({
            type:'warning',
            message:'请完善基本信息'
          })
        }
      })
    }
 
    // 图片上传
    const showTip =()=>{
      ElMessage({
        type: 'warning',
        message: '超出文件上传数量'
      });
    }
 
    const picSize = async(rawFile: any) => {
      if(rawFile.size / 1024 / 1024 > 2){
        ElMessage({
          type: 'warning',
          message: '文件大小不能超过2M'
        });
        return false
      }
    }
 
    const handleAvatarSuccess = (res:any, uploadFile: any) => {
      if(res){
        uploadFile.name = res
      }else{
        ElMessage({
          type: 'warning',
          message: '文件上传失败'
        })
      }
    }
 
    const handlePictureCardPreview = (uploadFile) => {
      state.imageUrl = uploadFile.url
      state.imgDialog = true;
    }
 
    const handleRemove = (file, uploadFiles,type) => {
      state.fileList = uploadFiles
    }
 
 
    return {
      formRef,
      showTip,
      picSize,
      handleAvatarSuccess,
      handlePictureCardPreview,
      handleRemove,
      open,
      onSubmit,
      ...toRefs(state)
    };
  }
});
</script>