zhouwx
2025-11-26 f7b5bcf402dcfb264cda9e09784fd0705c58b216
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<template>
  <div class="notice">
    <el-dialog
        v-model="dialogVisible"
        :title="title"
        width="900px"
        :before-close="handleClose"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
    >
      <el-form :model="state.form" size="default" ref="busRef" :rules="state.rules"  label-width="130px" >
        <el-row :gutter="24">
          <el-col :span="24">
            <el-form-item label="单位名称:" prop="companyId" v-if="state.isAdmin">
              <el-select v-model="state.form.companyId" placeholder="请选择" filterable clearable style="width: 100%" :disabled="title == '查看' || title == '编辑' || !state.isAdmin" @change="selectValueCom">
                <el-option
                    v-for="item in state.companyList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="申请人:"  prop="applyUserName">
              <el-input disabled v-model="state.form.applyUserName"  style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="部门:" prop="applyDeptName">
              <el-input disabled v-model="state.form.applyDeptName"  style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请日期:" prop="applyTime">
              <el-date-picker
                  disabled
                  v-model="state.form.applyTime"
                  type="date"
                  value-format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="印章类型:" prop="sealId">
              <el-select v-model="state.form.sealId" placeholder="请选择"  :disabled="title == '查看' ">
                <el-option
                    v-for="item in state.sealTypeList"
                    :key="item.id"
                    :label="item.sealName"
                    :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="盖章份数:" prop="amount">
              <el-input :disabled="title == '查看' "  v-model="state.form.amount" @input="state.form.amount = state.form.amount.replace(/[^0-9]/g,'')" placeholder="盖章份数"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="用章日期:" prop="useSealTime">
              <el-date-picker
                  :disabled="title == '查看' "
                  v-model="state.form.useSealTime"
                  type="date"
                  value-format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="15">
            <el-form-item label="用章事由:" prop="useSealCause">
              <el-input :disabled="title == '查看' "  v-model="state.form.useSealCause" type="textarea" :rows="3" placeholder="用章事由"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="是否为红头文件:" prop="isRed">
              <el-select v-model="state.form.isRed" placeholder="请选择" :disabled="title == '查看' ">
                <el-option
                    v-for="item in state.redList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="附件" prop="files">
              <el-upload :disabled="title == '查看' " accept=".jpg,.jpeg,.png,.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx" style="width: 100%" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)" :on-exceed="showTip"  v-model:file-list="state.fileList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles)" :on-preview="openFile">
                <el-button type="primary">点击上传</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" >
          <el-col :span="24" style="margin-left: 50px">
            <span style="font-size: 19px;font-weight: 600;">签字意见</span>
            <el-table :data="state.form.flows" :border="true" style="width: 90%;margin-top: 10px">
              <el-table-column label="流程名称" prop="flowName" width="220" align="center"></el-table-column>
              <el-table-column label="内容" align="center">
                <template #default="scope" v-if="title != '新增'">
                  <span>{{scope.row.approveDeptName}}/{{scope.row.approveUserName}} {{scope.row.approveTime}} {{scope.row.approveContent}} {{scope.row.approveMess}}</span>
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </el-form>
      <template #footer v-if="title !== '查看'">
        <span class="dialog-footer">
            <el-button @click="handleClose" size="default">取 消</el-button>
            <el-button type="primary"  @click="onSubmit" size="default" v-preReClick>确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import {onMounted, reactive, ref, toRefs} from 'vue'
import Cookies from "js-cookie";
import {getCompany} from "@/api/onlineEducation/company";
import {ElMessage, ElMessageBox} from "element-plus";
import {getUser} from "@/api/onlineEducation/user";
import {addObjective, editObject, getDept} from "@/api/qualityObjectives/object";
import {listUser} from "@/api/system/user";
import moment from "moment";
import {getToken} from "@/utils/auth";
import {getDepartById, getDeptInfo} from "@/api/orgStructure/depart";
import {getSealType} from "@/api/sealManage/type";
import {addSealApply, editSealApply} from "@/api/sealManage/apply";
import {getSealFlow} from "@/api/sealManage/process";
import {renderAsync} from "docx-preview";
 
const dialogVisible = ref(false);
const title = ref("");
const busRef = ref();
const length = ref()
const emit = defineEmits(["getList"]);
const dataRef = ref();
const state = reactive({
  form: {
    id: '',
    companyId: null,
    applyUserId: null,
    applyDeptId: null,
    applyTime: "",
    sealId: null,
    amount: null,
    useSealTime: "",
    useSealCause: "",
    isRed: "",
    nextCheck: "",
    flows:[],
    files:[],
    applyUserName:'',
    applyDeptName:''
  },
  sealTypeList:[],
  redList:[
    {
      id: 0,
      name: '否'
    },
    {
      id: 1,
      name: '是'
    },
  ],
  uploadUrl: import.meta.env.VITE_APP_BASE_API + '/system/common/uploadFile',
  header: {
    Authorization: getToken()
  },
  rules: {
    companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }],
    sealId: [{ required: true, message: '请选择用章类型', trigger: 'blur' }],
    amount: [{ required: true, message: '请输入盖章份数', trigger: 'blur' }],
    useSealTime:  [{ required: true, message: '请选择用章日期', trigger: 'blur' }],
    useSealCause:[{ required: true, message: '请输入用章事由', trigger: 'blur' }],
    files:[{ required: true, message: '请上传附件', trigger: 'blur' }],
    // nextCheck: "",
    // flows:[],
  },
  isAdmin: false,
  companyList: [],
  deptList: [],
  fileList: [],
})
 
const openDialog = async (type, value,companyList) => {
  title.value = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' ;
  const userInfo = JSON.parse(Cookies.get('userInfo'))
  state.isAdmin = userInfo.userType === 0;
  state.form.companyName = userInfo.companyName
  state.form.companyId = userInfo.companyId
  if(type=='add'){
    //申请人信息
    state.form.applyUserId = userInfo.id
    state.form.applyUserName = userInfo.name
    state.form.applyDeptId = userInfo.deptId
    state.form.applyDeptName = userInfo.deptName
    const nowDate = new Date()
    state.form.applyTime = moment(nowDate).format('YYYY-MM-DD')
    const obj = {
      flowName: '申请人',
      approveUserId: state.form.applyUserId,
      approveDeptId: state.form.applyDeptId,
      approveUserName: state.form.applyUserName,
      approveDeptName: state.form.applyDeptName,
      approveContent: "提交",
      approveTime: state.form.applyTime,
      approveStatus: 1,
      status: null
    }
    state.form.flows[0]=obj
    if(!state.form.applyDeptId){
      ElMessage.warning('该用户无所属部门!')
      return
 
    }
    //部门负责人信息
    await getLeaderInfo()
    await getFlowList()
  }
  if(state.isAdmin){
    state.companyList = companyList
    state.form.companyId = null
  }
 
  if(type === 'edit' || type === 'review') {
    state.form = JSON.parse(JSON.stringify(value));
    state.form.compilationBy = state.form.compilationId
    state.form.leadBy = state.form.leadId
    state.form.qualityBy = state.form.qualityId
    if(state.isAdmin){
      state.form.companyId = value.companyId
      state.form.companyName = value.companyName
    }
    state.fileList = value.files.map(i => {
      return {
        name: i.fileName,
        path: i.filePath
      }
    })
  }
  await getSealTypeList()
 
  dialogVisible.value = true;
}
const getLeaderInfo = async ()=> {
  const res = await getDeptInfo(state.form.applyDeptId)
  if(res.code === 200){
 
    const obj = {
      flowName: '部门负责人',
      approveUserId: res.data.leaderUserId,
      approveDeptId: res.data.deptId,
      approveUserName: res.data.leaderName,
      approveDeptName: res.data.deptName,
      approveContent: '',
      approveMess:'',
      approveTime: null,
      approveStatus: null,
      status: null
    }
    state.form.flows[1]=obj
    state.form.nextCheck = res.data.leaderUserId
  }else{
    ElMessage.warning(res.message)
  }
}
 
const addObject = () => {
  state.form.qualityTargets.push({})
}
const getSealTypeList = async () => {
  const param = {
    pageNum: 1,
    pageSize: 999,
    companyId: state.form.companyId
  }
  const res = await getSealType(param)
  if(res.code === 200){
    state.sealTypeList = res.data.list
  }else {
    ElMessage.warning(res.message)
  }
}
const getFlowList = async () => {
  const param = {
    pageNum: 1,
    pageSize: 999,
    companyId: state.form.companyId
  }
 
  const res = await getSealFlow(param)
  if(res.code === 200){
    res.data.forEach(item => {
      item.approveDeptName = item.deptName
      item.approveDeptId = item.deptId
    })
    if(title.value == '新增'){
      state.form.flows = state.form.flows.concat(res.data)
    }
 
 
  }else {
    ElMessage.warning(res.message)
  }
}
const onSubmit = async () => {
  const valid = await busRef.value.validate();
  if(valid){
    if(title.value === '新增'){
      console.log('sta',state.form)
      state.form.flows[0].approveTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
      const {id, ...data} = JSON.parse(JSON.stringify(state.form))
      const res = await addSealApply(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '新增成功'
        });
      }else{
        ElMessage.warning(res.message)
      }
      emit("getList")
      busRef.value.clearValidate();
      reset();
      dialogVisible.value = false;
    }else if(title.value === '编辑'){
      const {...data} = JSON.parse(JSON.stringify(state.form))
      const res = await editSealApply(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '编辑成功'
        });
      }else{
        ElMessage.warning(res.message)
      }
      emit("getList")
      busRef.value.clearValidate();
      reset();
      dialogVisible.value = false;
    }
  }
}
 
const handleClose = () => {
  busRef.value.clearValidate();
  reset();
  dialogVisible.value = false;
  emit("getList")
 
}
const reset = () => {
  state.form = {
    id: '',
    companyId: null,
    applyUserId: null,
    applyDeptId: null,
    applyTime: "",
    sealId: null,
    amount: null,
    useSealTime: "",
    useSealCause: "",
    isRed: "",
    nextCheck: "",
    flows:[],
    files:[],
    applyUserName:'',
    applyDeptName:''
  }
  state.peopleList = []
  state.companyList = []
  state.fileList = []
 
}
const handleDelete = (val) => {
  state.form.qualityTargets = state.form.qualityTargets.filter(item=> item != val)
}
 
const handleAvatarSuccess = (response,uploadFile) => {
  if(response.code == 200){
    state.form.files = state.fileList.map(item => {
      return {
        fileName: item.response ? item.response?.data.originName: item.name,
        filePath: item.response ? item.response?.data.path: item.path
      }
    })
  }else{
    // state.fileList = []
    // state.form.files = []
    ElMessage({
      type: 'warning',
      message: response.message
    })
  }
}
 
const showTip =()=>{
  ElMessage({
    type: 'warning',
    message: '超出文件上传数量'
  });
}
const picSize = async (rawFile) => {
  if(rawFile.size / 1024 / 1024 > 5){
    ElMessage({
      type: 'warning',
      message: '文件大小不能超过5M'
    });
    return false
  }
};
const handleRemove = async (file, uploadFiles) => {
  state.form.files = state.fileList.map(item => {
    return {
      fileName: item.response ? item.response?.data.originName: item.name,
      filePath: item.response ? item.response?.data.path: item.path
    }
  })
}
const selectValue = (val) => {
  state.peopleList.forEach(item => {
    if(item.name === val){
      state.form.compilationBy = item.id
    }
  })
}
 
const selectValueCom = (val) => {
  state.form.sealId = null
  state.companyList.forEach(item => {
    if(item.id === val){
      state.form.companyName = item.name
    }
  })
  getSealTypeList()
  getFlowList()
}
 
const openFile = async(file)=>{
  const path = file.path
  const ext = path.split('.').pop().toLowerCase();
  if (ext === 'doc' || ext === 'xls' || ext === 'xlsx'|| ext === 'ppt'|| ext === 'pptx')  {
    ElMessageBox.confirm('暂不支持线上预览.doc文件,是否下载查看?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
      window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
    }).catch(() => {
      console.log('取消预览')
    });
    return
  }else if(ext === 'docx'){
    try {
      // 1. 获取文件
      const response = await fetch(import.meta.env.VITE_APP_BASE_API + '/' + path);
      const arrayBuffer = await response.arrayBuffer();
      // 2. 创建新窗口
      const win = window.open('', '_blank')
      win.document.write(`
      <!DOCTYPE html>
      <html>
        <head>
          <title>预览</title>
          <style>
            body { margin: 20px; font-family: Arial; }
            .docx-container { width: 100%; height: 100%; }
          </style>
        </head>
        <body>
          <div id="container" class="docx-container"></div>
        </body>
      </html>
    `);
      // 3. 渲染 DOCX
      await renderAsync(arrayBuffer, win.document.getElementById('container'));
 
    } catch (error) {
      console.error('预览失败:', error);
      alert(`预览失败: ${error.message}`);
    }
  }else {
    window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
  }
 
}
defineExpose({
  openDialog
});
 
</script>
 
<style scoped lang="scss">
.notice{
  :deep(.el-form .el-form-item__label) {
    font-size: 15px;
  }
  .file {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
}
</style>