马宇豪
2024-11-12 77737f4e73f7267170b9b06fc73d1610c29c0661
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
<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="120px">
        <el-row :gutter="35">
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="证书名称" prop="certName">
              <el-input v-model.trim="form.certName" type="text" 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="certNo">
              <el-input v-model.trim="form.certNo" type="text" 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="issuingInstituion">
              <el-input v-model.trim="form.issuingInstituion" type="text" 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="issuingTime">
              <el-date-picker v-model="form.issuingTime" value-format="YYYY-MM-DD" type="date" placeholder="选择发证日期" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="有效期" prop="effectiveTime">
              <el-date-picker v-model="form.effectiveTime" value-format="YYYY-MM-DD" type="date" placeholder="选择发证日期" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="复审日期" prop="reviewTime">
              <el-date-picker v-model="form.reviewTime" value-format="YYYY-MM-DD" type="date" placeholder="选择发证日期" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="承包商重点人员" prop="keyPersonnelId">
              <el-select v-model="form.keyPersonnelId" filterable placeholder="请选择重点人员" clearable>
                <el-option v-for="(item,index) in contractorUserList" :key="index" :label="item.userName" :value="item.uuid"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
            <el-form-item label="证书照片路径" prop="filePath">
              <el-upload accept="image/*" :action="uploadUrl" :headers="header" method="post" :on-exceed="showTip" :on-success="handleAvatarSuccess" :limit='1' v-model:file-list="fileList" :before-upload="picSize" :on-remove="handleRemove" :before-remove="beforeRemove">
                <el-button type="primary">点击上传</el-button>
                <template #tip>
                  <div class="el-upload__tip">仅支持上传图片文件,尺寸小于5M,最多可上传1张</div>
                </template>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-if="title == '新增上报'? false : true">
            <el-form-item label="删除状态" prop="deleted">
              <el-radio-group v-model="form.deleted">
                <el-radio label="0">未删除</el-radio>
                <el-radio label="1">已删除</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <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 {userApi} from '/@/api/systemManage/user'
import Cookies from "js-cookie";
import {judgeReportApi} from "/@/api/dataUpload/saftyBaseInfo/judgeReport";
import {contractorApi} from "/@/api/dataUpload/contractorManage";
 
// 定义接口来定义对象的类型
interface DataState {
  title: string;
  isShowDialog: boolean;
  form: {
    uuid: string
    certName: string
    certNo: string
    issuingInstituion: string
    issuingTime: string
    effectiveTime: string
    reviewTime: string
    keyPersonnelId: string
    filePath: string
    deleted: string
  }
  rules:{},
  fileList: [],
  contractorUserList: []
  uploadUrl: string,
  header: {}
}
 
export default defineComponent({
  name: 'reportDialog',
  setup(props, context) {
    const formRef = ref()
    const checkFile = (rule: any, value: any, callback: any) => {
      if(state.fileList.length == 0){
        callback(new Error("请上传证书照片"))
      } else {
        callback();
      }
    }
    const state = reactive<DataState>({
      title: '',
      isShowDialog: false,
      form: {
        uuid: '',
        certName: '',
        certNo: '',
        issuingInstituion: '',
        issuingTime: '',
        effectiveTime: '',
        reviewTime: '',
        keyPersonnelId: '',
        filePath: '',
        deleted: '0'
      },
      rules:{
        certName: [{ required: true, message: '请选择证书名称', trigger: 'blur'}],
        certNo: [{ required: true, message: '请填写证书编号', trigger: 'blur'}],
        issuingInstituion: [{ required: true, message: '请填写发证机构', trigger: 'blur'}],
        issuingTime: [{ required: true, message: '请选择发证日期', trigger: 'blur'}],
        effectiveTime: [{ required: true, message: '请选择有效期', trigger: 'blur'}],
        reviewTime: [{ required: true, message: '请选择复审期', trigger: 'blur'}],
        keyPersonnelId: [{ required: true, message: '请选择重点人员', trigger: 'blur'}],
        filePath: [{ required: true,validator: checkFile, trigger: 'blur' }]
      },
      fileList: [],
      contractorUserList: [],
      uploadUrl: import.meta.env.VITE_API_URL + '/account/file/upload',
      header: {
        uid: Cookies.get('uid'),
        Authorization: Cookies.get('token')
      }
    })
 
    // 页面加载时
    onMounted(() => {
 
    })
    // 打开弹窗
    const open = (type: string, data: object) => {
      state.isShowDialog = true
      getUserList()
      if (type === 'add') {
        state.title = '新增上报'
        state.form = {
          uuid: '',
          certName: '',
          certNo: '',
          issuingInstituion: '',
          issuingTime: '',
          effectiveTime: '',
          reviewTime: '',
          keyPersonnelId: '',
          filePath: '',
          deleted: '0'
        }
        state.fileList = []
      }else{
        state.title = '重新上报';
        Object.keys(state.form).forEach(key => {
          if (Object.prototype.hasOwnProperty.call(data,key)) {
            state.form[key] = JSON.parse(JSON.stringify(data))[key];
          }
        })
        if(data.files !== ''){
          state.fileList = state.form.filePath.split(',').map((i,index) => {
            return {
              url:  i,
              name: '文件' + (index+1)
            }
          })
        }else{
          state.fileList = []
        }
        // state.form = {
        //   type: 1,
        //   uuid: data.uuid,
        //   name: '',
        //   remarks: '',
        //   evaluateTime: '',
        //   files: '',
        //   deleted: '0'
        // }
      }
    };
 
    const getUserList = async ()=>{
      const res = await contractorApi().getKeyUserInfoList({pageIndex: 1, pageSize: 999})
      if(res.data.code == 200){
        state.contractorUserList = res.data.data
      }else{
        ElMessage({
          type: 'warning',
          message: res.data.msg
        })
      }
    }
 
    // 图片上传
    const showTip =()=>{
      ElMessage({
        type: 'warning',
        message: '超出文件上传数量'
      });
    }
 
    const picSize = async(rawFile: any) => {
      if(rawFile.size / 1024 / 1024 > 5){
        ElMessage({
          type: 'warning',
          message: '文件大小不能超过5M'
        });
        return false
      }
    }
 
    const handleAvatarSuccess = (res:any, uploadFile: any) => {
      if(res){
          uploadFile.name = res
          state.form.filePath = res
        console.log(state.fileList,'list')
      }else{
        ElMessage({
          type: 'warning',
          message: '文件上传失败'
        })
      }
    }
 
    const handleRemove = (file, uploadFiles,type) => {
      state.form.files = ''
    }
 
    // 新增修改
    const onSubmit = async () => {
      formRef.value.validate(async (valid:Boolean) => {
        if(valid){
            const res = await contractorApi().addUserCertInfo([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:'请完善基本信息'
          })
        }
      })
    }
 
    return {
      formRef,
      showTip,
      picSize,
      handleAvatarSuccess,
      handleRemove,
      open,
      onSubmit,
      ...toRefs(state)
    };
  }
});
</script>