zhouwx
2025-03-24 3f6bf89b1985b6668f02ffcc9af577b412e92e45
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
<template>
  <div class="riskBox">
    <el-form ref="formRef" :model="state.formData" :rules="state.rules" class="register-form" label-position="top">
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item prop="timeRange" label="技术服务期限">
            <el-date-picker
                v-model="state.formData.timeRange"
                style="width: 100%"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="YYYY-MM-DD 00:00:00"
                size="large"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="investigationPlanDate" label="计划现场勘验时间">
            <el-date-picker
                style="width: 100%"
                v-model="state.formData.investigationPlanDate"
                type="date"
                value-format="YYYY-MM-DD 00:00:00"
                placeholder="选择日期"
                size="large"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="18">
          <div style="display: flex;align-items: center">项目组成员<el-icon style="margin-left: 10px;margin-right: 4px"><InfoFilled /></el-icon><span style="font-size: 13px">金属、非金属矿及其他矿采选业:安全、机械、电气、采矿、通风、地质、水工结构</span></div>
        </el-col>
      </el-row>
      <el-table  :data="state.planPersons" :border="true" style="margin: 20px 0">
        <el-table-column label="序号" width="60" align="center" type="index"></el-table-column>
        <el-table-column label="评价组成员" prop="person.name" align="center" :show-overflow-tooltip="true">
          <template #default="scope">
            <span v-if="scope.row.jobType === 2">{{ scope.row.person.name }} (组长)</span>
            <span v-else>{{scope.row.person.name}}</span>
          </template>
        </el-table-column>
        <el-table-column label="专业能力/资格证书" prop="person.certificateNo" align="center" :show-overflow-tooltip="true">
          <template #default="scope">
            {{ getCertNo(scope.row) }}
          </template>
        </el-table-column>
        <el-table-column label="承担工作" prop="work" align="center" class-name="small-padding fixed-width"></el-table-column>
        <el-table-column label="承诺后期前往现场勘验" prop="laterPromise" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            {{(scope.row.laterPromise==1 || scope.row.laterPromise==true)?'是':'否'}}
          </template>
        </el-table-column>
        <el-table-column label="未到现场勘验原因" prop="reason" align="center" class-name="small-padding fixed-width"></el-table-column>
        <el-table-column label="是否已告知" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-radio-group v-model="scope.row.informed" size="large" @change="(value)=>changePerson(value,scope.row)" :disabled="projectType==='view'">
              <el-radio :label="1" size="large">是</el-radio>
              <el-radio :label="0" size="large">否</el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
    <div style="display: flex;margin-top: 25px;">
      <el-button type="primary" style="margin-right: 20px" @click="exportWord">导出从业告知书word</el-button>
      <el-upload
          style="width: 250px"
          :disabled="projectType === 'view' || isEnd"
          accept=".pdf"
          :action="state.uploadUrl"
          :data="{moduleType: 12,projectId: props.projectId}"
          :headers="state.header"
          method="post"
          :limit="state.imgLimit"
          :before-upload="beforeUpload"
          :on-success="handleAvatarSuccess"
          v-model:file-list="state.fileList"
          :on-preview="handlePreview"
          :on-remove="handleRemove">
        <el-button type="primary">上传从业告知书pdf</el-button>
        <template #tip>
          <div class="el-upload__tip">只能上传pdf类型,最多上传1份</div>
        </template>
      </el-upload>
    </div>
  </div>
</template>
<script setup>
 
import {defineEmits, defineProps, onMounted, reactive, ref, watchEffect} from "vue"
import {generateWordDocument} from "@/views/safetyReview/projectManage/components/exportWord";
import {ElMessage, ElMessageBox} from "element-plus"
import {Search} from '@element-plus/icons-vue'
import {addWorkRecord, editWorkRecord, getWorkDetail} from "@/api/projectManage/employNoticeRcd"
import {getWorks, editWorks} from "@/api/projectManage/evaPlan"
import Cookies from "js-cookie"
const props = defineProps(['projectId'])
const emit = defineEmits(["getNextStatus"])
import { useRoute } from 'vue-router'
import {getToken} from "@/utils/auth";
import {getFiles} from "@/api/projectManage/siteCheckRcd";
import {delAccessoryFile, getProjectDetail} from "@/api/projectManage/project";
import axios from "axios";
const route = useRoute()
const state = reactive({
  formData: {
    id: null,
    projectId: null,
    timeRange: [],
    serviceStartDate: '',
    serviceEndDate: '',
    investigationPlanDate: ''
  },
  projectId: null,
  planPersons: [],
  rules: {
    timeRange: [{required: true, message: '请选择技术服务期限', trigger: 'blur'}],
    investigationPlanDate: [{required: true, message: '请选择计划现场勘验时间', trigger: 'blur'}]
  },
  imgLimit: 1,
  uploadUrl: import.meta.env.VITE_APP_BASE_API + '/manage/accessory-file/uploadFile',
  header: {
    Authorization: getToken()
  },
  fileList: []
})
 
const isEnd = ref('')
const isAmin = ref(false)
const formRef = ref()
onMounted(() => {
  const userInfo = JSON.parse(Cookies.get('userInfo'))
  if(userInfo.identity === 0){
    isAmin.value = true;
  }
  if(props.projectId){
    getWorksList(props.projectId)
    getProcessFiles(props.projectId);
    getPDetail(props.projectId)
  }
  isEnd.value = Cookies.get('end')
 
});
 
const projectType = ref('');
const riskOpen = async (type,val) => {
  state.formData.projectId = val
  state.projectId = val
  projectType.value = route.query.type;
  isEnd.value = Cookies.get('end')
  // await getWorksList(val)
  if(type === 'detail' || type === 'edit' ){
    const res = await getWorkDetail({projectId: val})
    if(res.code == 200){
      state.formData = JSON.parse(JSON.stringify(res.data))
      state.formData.timeRange = [state.formData.serviceStartDate,state.formData.serviceEndDate]
      // state.fileList = res.data.accessoryFiles.map(item => {
      //   return {
      //     ...item,
      //     name: item.originName,
      //   }
      // })
    }else {
      ElMessage.warning(res.message)
    }
  }
  if(type === 'add' || type === 'clickEdit') {
    const valid = await formRef.value.validate();
    if(valid){
      if (isAmin.value) {
        ElMessage.warning("当前用户暂无权限");
        return;
      }
      state.formData.serviceStartDate = state.formData.timeRange[0]
      state.formData.serviceEndDate = state.formData.timeRange[1]
      if(type === 'add'){
        const {timeRange,id,...data} = JSON.parse(JSON.stringify(state.formData))
        const res = await addWorkRecord(data)
        if (res.code == 200) {
          ElMessage.success('保存成功')
          formRef.value.clearValidate();
          emit('getNextStatus', state.projectId);
        } else {
          ElMessage.warning(res.message)
        }
 
      }else if(type === 'clickEdit'){
        const {timeRange, ...data} = JSON.parse(JSON.stringify(state.formData))
        const res = await editWorkRecord(data);
        if (res.code == 200) {
          ElMessage.success('变更成功')
          formRef.value.clearValidate();
          // emit('getNextStatus', data.project.id);
        } else {
          ElMessage.warning(res.message)
        }
      }
    }
  }
}
 
const getWorksList = async (id) =>{
  const works = await getWorks({projectId: id ? id : props.projectId})
  if(works.code == 200){
    state.planPersons = works.data
  }else {
    ElMessage.warning(works.message)
  }
}
 
const getCertNo = (row)=>{
  const obj = JSON.parse(row.person.certificateNo)
  const noArr = Object.values(obj)
  return row.person.majorNames.map((item,index)=>{
    return item + '(' + noArr[index] + ')'
  }).join(',')
}
 
const changePerson = async (value,row)=>{
  const params = {
    id: row.id,
    projectId: row.projectId,
    informed: value
  }
  const res = await editWorks(params)
  if(res.code === 200){
    console.log(res.message)
  }else{
    ElMessage.warning(res.message)
  }
  await getWorksList(props.projectId)
}
const beforeUpload = (file) => {
  let fileType = file.name.substring(file.name.lastIndexOf(".") + 1);
  if (fileType === 'pdf') {
  } else {
    ElMessage.error("文件类型必须为pdf格式")
    return false
  }
}
const handleAvatarSuccess = (res) => {
  if(res.code === 200){
    getProcessFiles()
    ElMessage({
      type: 'success',
      message: '文件上传成功'
    })
  }else {
    state.fileList.splice(state.fileList.indexOf(uploadFile),1)
    ElMessage({
      type: 'warning',
      message: res.message
    })
  }
}
const handleRemove = async (file, uploadFiles) => {
  if (file && file.status === 'success') {
    ElMessageBox.confirm(
        '确定删除该附件?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(async () => {
          let accessoryFileId = "";
          if (file.id) {
            accessoryFileId = file.id
          } else {
            accessoryFileId = file.response.data.id
          }
          const res = await delAccessoryFile(accessoryFileId)
          if (res.code == 200) {
            ElMessage({
              type: 'success',
              message: '文件已删除'
            })
            await getProcessFiles()
          } else {
            ElMessage({
              type: 'warning',
              message: res.message
            })
          }
        })
        .catch(() => {
          getProcessFiles()
        })
  }
}
 
const getProcessFiles = async (id)=>{
  const res = await getFiles({projectId: id ? id : props.projectId ,moduleType: 12})
  if(res.code == 200){
    if(res.data && res.data.length>0){
      state.fileList = res.data.map(i=>{
        return {
          name: i.originName,
          url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
          id: i.id,
          projectId: i.projectId,
          moduleType: i.moduleType
        }
      })
    }else{
      state.fileList = []
    }
  }else {
    ElMessage.warning(res.message)
  }
}
const handlePreview = (file) => {
  const url = file.url
  window.open(url)
}
 
const templatePath = '/example.docx'
const exportWord = async () => {
  const data = state.formData
  for (let key in projectDeatil.value) {
    if (projectDeatil.value.hasOwnProperty(key)) {
      if(key != 'agency')
      data[key] = projectDeatil.value[key];
    }
  }
  const agencyInfo = projectDeatil.value.agency
  for (let key in agencyInfo) {
    if (agencyInfo.hasOwnProperty(key)) {
      if(key != 'address'  && key != 'name' )
      data[key] = agencyInfo[key];
    }
  }
  data.leaderName = projectDeatil.value.leader.name
  data.leaderPhone = projectDeatil.value.leader.phone
 
  data.type = '安全评价'
  data.to = data.city + '应急管理局'
  data.notice = '系统告知'
  data.investigationPlanDate = state.formData.investigationPlanDate.substring(0,10)
  data.serviceStartDate = state.formData.serviceStartDate.substring(0,10)
  data.serviceEndDate = state.formData.serviceEndDate.substring(0,10)
  data.tableData = state.planPersons.map(item => {
    return {
      ...item,
      name: item.person.name
    }
  })
  console.log('res',data)
  const date = new Date()
  const options = {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit'
  }
  data.time = date.toLocaleDateString('zh-CN',options).replace(/\//g, '年')
                                                              .replace(/年(\d{2})年/, '年$1月')
                                                              .replace(/月(\d{2})$/, '月$1日')
  try {
    generateWordDocument(templatePath, data, '从业告知书.docx');
  } catch (error){
    ElMessage({
      type: 'warning',
      message: '失败'
    });
  }
}
 
const projectDeatil = ref()
const getPDetail = async (val) => {
  const res = await getProjectDetail(val)
  if(res.code == 200){
    projectDeatil.value = res.data
 
  }else {
    ElMessage.warning(res.message)
  }
 
}
 
 
defineExpose({
  riskOpen
});
 
 
</script>
<style scoped lang="scss">
.riskBox{
  :deep(.el-form .el-form-item__label) {
    font-size: 15px;
  }
}
 
</style>