BAOLH
2026-11-10 4d730af0447c686133130d0116a0fa3dd82c2dca
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
<template>
  <div class="app-container">
    <!-- 工具栏 -->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-select v-model="query.projectId" filterable clearable placeholder="所属项目" style="width: 185px;">
          <el-option v-for="item in projects" :key="`project_${item.id}`" :label="item.name" :value="item.id" />
        </el-select>
        <el-select v-model="query.reimburseType" filterable clearable placeholder="报销类型" style="width: 185px;">
          <el-option v-for="item in dict[dictReimburseType]" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-select v-model="query.expenseType" filterable clearable placeholder="费用类型" style="width: 185px;">
          <el-option v-for="item in dict[dictReimburseExpenseType]" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-select v-model="query.userId" filterable clearable placeholder="申请人" style="width: 185px;">
          <el-option v-for="item in users" :key="item.id" :label="item.nickName" :value="item.id" />
        </el-select>
        <el-date-picker
          v-model="query.startTime"
          type="daterange"
          clearable
          range-separator=" ~ "
          value-format="yyyy-MM-dd 00:00:00"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          style="width: 285px;"
          class="filter-item"
        />
        <!-- <el-date-picker
          v-model="query.endTime"
          type="daterange"
          clearable
          range-separator=" ~ "
          value-format="yyyy-MM-dd 00:00:00"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          style="width: 285px;"
          class="filter-item"
        /> -->
        <rrOperation :crud="crud" />
      </div>
      <!-- 如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right' -->
      <crudOperation :permission="permission">
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-circle-check"
          :disabled="crud.selections.length < 1 || !crud.selections.every(item => item.approvalStatus === dictReimburseApproveStatusReviewed)"
          style="margin-left: 4px !important;"
          @click="batchApprove(1, crud.selections)"
        >
          批量同意
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-error"
          :disabled="crud.selections.length < 1 || !crud.selections.every(item => item.approvalStatus === dictReimburseApproveStatusReviewed)"
          style="margin-left: 4px !important;"
          @click="batchApprove(2, crud.selections)"
        >
          批量拒绝
        </el-button>
      </crudOperation>
      <!-- 表单组件 -->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="申请人" prop="userId">
            <el-select v-model="form.userId" filterable clearable placeholder="请选择" style="width: 370px;" :disabled="disabledUser(form) || form.wecomSpNo !== null">
              <el-option
                v-for="item in users"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="审批者" prop="approvalUserId" :hidden="form.wecomSpNo !== null || (form.id == null && wecomApprovalVisible)">
            <el-select v-model="form.approvalUserId" filterable clearable placeholder="请选择" style="width: 370px;" :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null">
              <el-option
                v-for="item in approvalUsers"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="所属项目" prop="projectId">
            <el-select v-model="form.projectId" filterable clearable placeholder="请选择" style="width: 370px;" :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null">
              <el-option v-for="item in projects" :key="`project_${item.id}`" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="报销类型" prop="reimburseTypes">
            <el-select v-model="form.reimburseTypes" multiple filterable clearable placeholder="请选择" style="width: 370px;" :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null">
              <el-option v-for="item in dict[dictReimburseType]" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="报销原因" prop="reimburseReason">
            <el-input v-model="form.reimburseReason" placeholder="请输入" type="textarea" rows="3" style="width: 370px;" :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null" />
          </el-form-item>
          <el-form-item label="费用类型" prop="expenseTypes">
            <el-select v-model="form.expenseTypes" multiple filterable clearable placeholder="请选择" style="width: 370px;" :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null">
              <el-option v-for="item in dict[dictReimburseExpenseType]" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="开始时间" prop="startTime">
            <el-date-picker
              v-model="form.startTime"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd 00:00:00"
              style="width: 370px;"
              align="right"
              :picker-options="{
                disabledDate(time) {
                  return form.endTime ? time.getTime() > new Date(form.endTime).getTime() - 8.64e7 : false;
                }
              }"
              :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null"
            />
          </el-form-item>
          <el-form-item label="结束时间" prop="endTime">
            <el-date-picker
              v-model="form.endTime"
              type="date"
              placeholder="选择日期"
              style="width: 370px;"
              value-format="yyyy-MM-dd 23:59:59"
              align="right"
              :picker-options="{
                disabledDate(time) {
                  return form.startTime ? time.getTime() < new Date(form.startTime).getTime() - 8.64e7 : false;
                }
              }"
              :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null"
            />
          </el-form-item>
          <el-form-item label="费用金额" prop="expenseAmount">
            <el-input-number v-model="form.expenseAmount" placeholder="请输入" style="width: 370px;" :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null" />
          </el-form-item>
          <el-form-item label="费用说明" prop="expenseComment">
            <el-input v-model="form.expenseComment" placeholder="请输入" type="textarea" rows="3" style="width: 370px;" :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null" />
          </el-form-item>
          <el-form-item label="附件">
            <div style="line-height: 16px; margin: 8px 0;">
              <span class="upload-tips">*最多支持上传6个文件,每个文件大小限制10M以内。</span>
              <el-link type="primary" :href="locationOrigin + '/file/Template/projectReimburse.xlsx'" target="_blank">下载模版</el-link>
            </div>
            <file-upload key="file_key" ref="fileUpload" :file-url="form.filePath == null || form.filePath === '' ? null : form.filePath" :limit="6" :disabled="form.approvalStatus == dictReimburseApproveStatusAgree || form.approvalStatus == dictReimburseApproveStatusRefuse || form.wecomSpNo !== null" @fileInfo="getFileInfo" />
          </el-form-item>
          <el-form-item label="审批说明" prop="approvalDescription">
            <el-input v-model="form.approvalDescription" type="textarea" rows="3" disabled style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2 || fileUploadLoading" type="primary" @click="formSubmit">确认</el-button>
        </div>
      </el-dialog>
      <!-- 审批组件 -->
      <el-dialog :close-on-click-modal="false" :before-close="cancelApprove" :visible.sync="approveModal.visible" :title="approveModal.title" width="500px">
        <el-form ref="approveForm" :model="form" :rules="approveRules" size="small" label-width="80px">
          <el-form-item label="申请人">
            {{ form.userName }}
          </el-form-item>
          <el-form-item label="所属项目">
            {{ form.projectName }}
          </el-form-item>
          <el-form-item label="报销类型">
            {{ batchConversion(form.reimburseType, dict.label[dictReimburseType]) }}
          </el-form-item>
          <el-form-item label="报销原因">
            {{ form.reimburseReason }}
          </el-form-item>
          <el-form-item label="费用类型">
            {{ batchConversion(form.expenseType, dict.label[dictReimburseExpenseType]) }}
          </el-form-item>
          <el-form-item label="开始时间">
            {{ form.startTime }}
          </el-form-item>
          <el-form-item label="结束时间">
            {{ form.endTime }}
          </el-form-item>
          <el-form-item label="费用金额">
            {{ form.expenseAmount }}
          </el-form-item>
          <el-form-item label="费用说明">
            {{ form.expenseComment }}
          </el-form-item>
          <el-form-item v-if="form.approvalStatus === dictReimburseApproveStatusRefuse" label="退回原因" prop="approvalDescription">
            <div style="color: red;">*审核退回需要填写退回原因,请填写后再次点击审核退回</div>
            <el-input v-model="form.approvalDescription" type="textarea" :rows="3" style="width: 370px;" />
          </el-form-item>
        </el-form>
 
        <div slot="footer" class="dialog-footer">
          <el-button type="danger" style="margin-right: 10px;" :loading="approveModal.approveLoading" @click="handleApprove(1, form)">审核退回</el-button>
          <el-button v-if="form.approvalStatus !== dictReimburseApproveStatusRefuse" :loading="approveModal.approveLoading" type="success" @click="handleApprove(2, form)">审核通过</el-button>
        </div>
      </el-dialog>
      <!-- 表格渲染 -->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="userName" label="申请人">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.userName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="appUserName" label="审批者">
          <template slot-scope="scope">
            <el-popover
              v-if="scope.row.wecomSpNo && scope.row.event"
              placement="right-start"
              width="600"
              trigger="click"
            >
              <approvalLine :event-data="scope.row.event" :user-list="users" />
              <el-tag slot="reference" effect="dark">
                <i class="el-icon-search" />
                <span>详细</span>
              </el-tag>
            </el-popover>
 
            <el-tag v-else-if="scope.row.appUserName">{{ scope.row.appUserName }}</el-tag>
            <el-tag v-else>暂无</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="projectName" label="所属项目" min-width="140">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.projectName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="reimburseType" label="报销类型" min-width="140" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ batchConversion(scope.row.reimburseType, dict.label[dictReimburseType]) }}
          </template>
        </el-table-column>
        <el-table-column prop="expenseType" label="费用类型" min-width="140" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ batchConversion(scope.row.expenseType, dict.label[dictReimburseExpenseType]) }}
          </template>
        </el-table-column>
        <el-table-column prop="startTime" label="开始时间" min-width="100">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.startTime) }}
          </template>
        </el-table-column>
        <el-table-column prop="endTime" label="结束时间" min-width="100">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.endTime) }}
          </template>
        </el-table-column>
        <el-table-column prop="expenseAmount" label="费用金额" />
        <el-table-column prop="approvalStatus" label="审批状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.approvalStatus === dictReimburseApproveStatusReviewed" type="warning">{{ dict.label[dictReimburseApproveStatus][scope.row.approvalStatus] }}</el-tag>
            <el-tag v-if="scope.row.approvalStatus === dictReimburseApproveStatusAgree" type="success">{{ dict.label[dictReimburseApproveStatus][scope.row.approvalStatus] }}</el-tag>
            <el-tag v-if="scope.row.approvalStatus === dictReimburseApproveStatusRefuse" type="danger">{{ dict.label[dictReimburseApproveStatus][scope.row.approvalStatus] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="approvalDescription" label="审批说明" show-overflow-tooltip />
        <el-table-column prop="createTime" label="创建时间" min-width="140" />
        <el-table-column v-if="checkPer(permission.approve)" label="审核操作" width="180px" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.approvalUserId === $store.state.user.user.id && !scope.row.wecomSpNo"
              v-permission="permission.approve"
              :loading="crud.status.cu === 2"
              size="mini"
              type="primary"
              icon="el-icon-s-check"
              :disabled="!(scope.row.approvalStatus === dictReimburseApproveStatusReviewed)"
              @click="toApprove(scope.row)"
            >
              审核
            </el-button>
            <el-popover :ref="`popover_${scope.row.id}`" width="200">
              <p>确定撤销该记录?</p>
              <div style="text-align: right; margin: 0">
                <el-button size="mini" type="primary" @click="handleCanel(scope.row.id)">取消</el-button>
                <el-button :loading="revokeLoading" type="primary" size="mini" @click="handleRevoke(scope.row)">确定</el-button>
              </div>
              <el-button
                v-if="scope.row.approvalUserId === $store.state.user.user.id && !scope.row.wecomSpNo"
                slot="reference"
                v-permission="permission.approve"
                type="danger"
                icon="el-icon-edit-outline"
                size="mini"
                :disabled="scope.row.approvalStatus === dictReimburseApproveStatusReviewed"
              >
                撤销
              </el-button>
            </el-popover>
            <el-link v-if="scope.row.wecomSpNo" type="primary">请前往企微审核</el-link>
          </template>
        </el-table-column>
        <el-table-column v-if="checkPer(['admin','projectReimburse:edit','projectReimburse:del'])" label="操作" width="150px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation
              v-if="!scope.row.wecomSpNo"
              :data="scope.row"
              :permission="permission"
            />
            <el-button
              v-if="scope.row.wecomSpNo && user.id === scope.row.userId && scope.row.approvalStatus === dictReimburseApproveStatusRefuse"
              size="mini"
              type="primary"
              icon="el-icon-refresh-right"
              @click="reAdd(scope.row)"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
 
      <cp-approval-del-dialog ref="cpApprovalDelDialog" />
    </div>
  </div>
</template>
 
<script>
import crudProjectReimburse from '@/api/project/projectReimburse'
import crudUser from '@/api/system/user'
import crudTask from '@/api/task/task'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import approvalLine from '@/components/ApprovalLine'
import cpApprovalDelDialog from '@/components/CpApprovalDelDialog'
import fileUpload from '@/views/assembly/fileUpload'
import { mapGetters } from 'vuex'
import constant from '@/utils/constant'
 
const defaultForm = { id: null, userId: null, approvalUserId: null, projectId: null, reimburseType: null, reimburseReason: null, expenseType: null, startTime: null, endTime: null, expenseAmount: null, expenseComment: null, originFileName: null, filePath: null, approvalStatus: null, approvalDescription: null, createTime: null, createBy: null, updateTime: null, updateBy: null, wecomSpNo: null, event: null, userName: null, appUserName: null, projectName: null, reimburseTypes: null, expenseTypes: null }
export default {
  name: 'ProjectReimburse',
  components: { pagination, crudOperation, rrOperation, udOperation, approvalLine, fileUpload, cpApprovalDelDialog },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.REIMBURSE_APPROVE_STATUS, constant.REIMBURSE_TYPE, constant.REIMBURSE_EXPENSE_TYPE, constant.APPROVAL_SITE_TYPE],
  cruds() {
    return CRUD({ title: '项目报销', url: 'api/projectReimburse', idField: 'id', sort: 'id,desc', crudMethod: { ...crudProjectReimburse }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'projectReimburse:add'],
        edit: ['admin', 'projectReimburse:edit'],
        del: ['admin', 'projectReimburse:del'],
        download: ['admin', 'projectReimburse:download'],
        approve: ['admin', 'projectReimburse:approve']
      },
      rules: {
        userId: [
          { required: true, message: '申请人不能为空', trigger: 'change' }
        ],
        approvalUserId: [
          { required: true, message: '审批者不能为空', trigger: 'change' }
        ],
        projectId: [
          { required: true, message: '所属项目不能为空', trigger: 'change' }
        ],
        reimburseTypes: [
          { required: true, message: '报销类型不能为空', trigger: 'blur' }
        ],
        expenseTypes: [
          { required: true, message: '费用类型不能为空', trigger: 'blur' }
        ],
        startTime: [
          { required: true, message: '开始时间不能为空', trigger: 'blur' }
        ],
        endTime: [
          { required: true, message: '结束时间不能为空', trigger: 'blur' }
        ],
        expenseAmount: [
          { required: true, message: '费用金额不能为空', trigger: 'blur' }
        ]
      },
      approveRules: {
        approvalDescription: [
          { required: true, message: '退回原因不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'projectId', display_name: '所属项目' },
        { key: 'reimburseType', display_name: '报销类型' },
        { key: 'expenseType', display_name: '费用类型' },
        { key: 'userId', display_name: '申请人' }
      ],
      approveModal: {
        title: '报销审批',
        visible: false,
        approveLoading: false
      },
      // 撤销Loading
      revokeLoading: false,
      dictReimburseApproveStatus: constant.REIMBURSE_APPROVE_STATUS,
      dictReimburseApproveStatusReviewed: constant.REIMBURSE_APPROVE_STATUS_REVIEWED,
      dictReimburseApproveStatusAgree: constant.REIMBURSE_APPROVE_STATUS_AGREE,
      dictReimburseApproveStatusRefuse: constant.REIMBURSE_APPROVE_STATUS_REFUSE,
      dictReimburseType: constant.REIMBURSE_TYPE,
      dictReimburseExpenseType: constant.REIMBURSE_EXPENSE_TYPE,
      users: [],
      approvalUsers: [],
      projects: [],
      userRolesLevelMin: null,
      // 角色级别: 总经理
      roleLevelGenerl: constant.ROLE_LEVEL_GENERAL,
      // 企微审核判断
      wecomApprovalVisible: false,
      fileUploadLoading: false
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ]),
    locationOrigin() {
      return window.location.origin
    }
  },
  created() {
    const that = this
    that.getUsers()
    that.getApprovalUsers()
    that.getProjects()
    that.$on('dictReady', () => {
      const dictData = { ...that.dict }
      const filterData = dictData[constant.APPROVAL_SITE_TYPE].filter(item => item.value.toLowerCase() === 'wecom')
      if (filterData.length > 0) {
        that.wecomApprovalVisible = true
      }
    })
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      const that = this
      // 用户角色级别数组
      const userRolesLevel = that.user.roles.map(({ level }) => level)
      // 用户最大角色级别
      that.userRolesLevelMin = Math.min(...userRolesLevel)
      return true
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToAdd]() {
      const that = this
      // 转换报销类型和费用类型
      that.$set(that.form, 'reimburseTypes', [])
      that.$set(that.form, 'expenseTypes', [])
      // 判断用户最大角色级别是否大于总经理角色:赋值
      if (that.userRolesLevelMin > that.roleLevelGenerl) {
        // 表单赋值
        that.form.userId = that.user.id
      }
      if (that.wecomApprovalVisible) {
        that.form.approvalUserId = 0
      }
      return true
    },
    // 钩子:编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
      const that = this
      // 转换报销类型和费用类型
      that.$set(that.form, 'reimburseTypes', that.form.reimburseType.split(','))
      that.$set(that.form, 'expenseTypes', that.form.expenseType.split(','))
      return true
    },
    // 钩子:提交 - 之前
    [CRUD.HOOK.beforeSubmit]() {
      const that = this
      // 解除文件上传Loading
      that.fileUploadLoading = false
      // 转换报销类型和费用类型
      that.$set(that.form, 'reimburseType', that.form.reimburseTypes.join(','))
      that.$set(that.form, 'expenseType', that.form.expenseTypes.join(','))
      return true
    },
    // 钩子:提交 - 之后
    [CRUD.HOOK.afterSubmit]() {
      const that = this
      that.$set(that.form, 'reimburseTypes', undefined)
      that.$set(that.form, 'expenseTypes', undefined)
      return true
    },
    // 钩子:删除 - 之前
    [CRUD.HOOK.beforeDelete]() {
      const that = this
      if (that.crud.selections.some(selection => selection.wecomSpNo !== null && selection.wecomSpNo !== undefined && selection.wecomSpNo !== '')) {
        that.$refs.cpApprovalDelDialog.handleOpen()
        that.crud.delAllLoading = false
        return false
      }
      return true
    },
    // 钩子:新增取消 - 之前
    [CRUD.HOOK.afterAddCancel]() {
      const that = this
      that.$refs.fileUpload.clearFiles()
      return true
    },
    // 钩子:编辑取消 - 之前
    [CRUD.HOOK.afterEditCancel]() {
      const that = this
      that.$refs.fileUpload.clearFiles()
      return true
    },
 
    // 查询员工
    getUsers() {
      const that = this
      crudUser.getAll().then(res => {
        that.users = res
      })
    },
    // 查询审核人
    getApprovalUsers() {
      const that = this
      crudUser.getApprovalUsers().then(res => {
        that.approvalUsers = res
      })
    },
    // 获取项目列表
    getProjects() {
      const that = this
      // 获取项目列表
      crudTask.getProjects().then(res => {
        that.projects = res
      })
    },
 
    // 提交数据
    formSubmit() {
      const that = this
 
      that.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        that.fileUploadLoading = true
        that.$refs.fileUpload.submit()
      })
    },
 
    // 禁用
    disabledUser(data) {
      const that = this
      if (that.userRolesLevelMin > that.roleLevelGenerl) {
        return true
      }
      if (data.approvalStatus !== null && data.approvalStatus === that.dictReimburseApproveStatusAgree || data.approvalStatus === that.dictReimburseApproveStatusRefuse) {
        return true
      }
    },
 
    // 批量转换字符串
    batchConversion(str, dictData) {
      const finalStrArr = []
      str && str.split(',').forEach(item => {
        finalStrArr.push(dictData[item] || item)
      })
 
      return finalStrArr.join(',')
    },
 
    // 启动审批
    toApprove(data) {
      const that = this
 
      const form = JSON.parse(JSON.stringify(data))
      const approveFrom = that.form
      for (const key in form) {
        if (approveFrom.hasOwnProperty(key)) {
          approveFrom[key] = form[key]
        } else {
          that.$set(approveFrom, key, form[key])
        }
      }
      if (that.$refs['approveForm']) {
        that.$refs['approveForm'].clearValidate()
      }
      that.approveModal.visible = true
    },
 
    // 执行审批
    handleApprove(type, data) {
      const that = this
 
      const msg = type === 2 ? '通过' : '拒绝'
      that.$refs['approveForm'].validate(valid => {
        if (!valid) {
          return
        }
        // 判断通过状态
        if (type === 2) {
          that.form.approvalStatus = that.dictReimburseApproveStatusAgree
        } else {
          // 退回改状态显示退回原因
          that.form.approvalStatus = that.dictReimburseApproveStatusRefuse
          if (that.form.approvalDescription == null) {
            return
          }
        }
 
        that.approveModal.approveLoading = true
        that.crud.crudMethod.approve(that.form).then(() => {
          that.crud.refresh()
          that.$message({
            type: 'success',
            message: '审核' + msg + '成功'
          })
          that.cancelApprove()
        }).catch(() => {
          that.approveModal.approveLoading = false
        })
      })
    },
 
    // 取消撤销
    handleCanel(id) {
      const that = this
      that.$refs[`popover_${id}`].showPopper = false
    },
 
    // 执行撤销
    handleRevoke(data) {
      const that = this
 
      that.revokeLoading = true
      const form = JSON.parse(JSON.stringify(data))
      form.approvalStatus = that.dictReimburseApproveStatusReviewed
      that.crud.crudMethod.approve(form).then(() => {
        that.crud.refresh()
        that.revokeLoading = false
        that.$message({ type: 'success', message: '撤销成功' })
        that.$refs[`popover_${data.id}`].showPopper = false
      }).catch(err => {
        that.$message({
          type: 'error',
          message: err.response.data.message
        })
      })
    },
 
    // 取消审批
    cancelApprove() {
      const that = this
      that.approveModal.approveLoading = false
      if (that.$refs['approveForm']) {
        that.$refs['approveForm'].resetFields()
      }
      that.crud.resetForm()
      that.approveModal.visible = false
    },
 
    // 批量审核
    batchApprove(type, data) {
      const that = this
 
      const msg = type === 2 ? '批量拒绝' : '批量同意'
      const msgType = type === 2 ? 'error' : 'success'
      const msgConfig = type === 2 ? {
        showInput: true,
        inputValidator: (val) => {
          return val !== null && val.trim() !== ''
        },
        inputErrorMessage: '请输入拒绝原因'
      } : {
        showInput: false
      }
      // 确认框
      that.$prompt('此操作将' + msg + '审核内容是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: msgType,
        ...msgConfig
      }).then(reasonVal => {
        const ids = []
        // 循环数据
        for (let i = 0; i < data.length; i++) {
          // ID列表
          if (data[i].wecomSpNo) {
            continue
          }
          ids.push(data[i].id)
        }
        const paramType = type === 2 ? that.dictReimburseApproveStatusRefuse : that.dictReimburseApproveStatusAgree
        that.crud.crudMethod.batchApprove({ type: paramType, ids: ids, reason: reasonVal.value ? reasonVal.value.trim() : undefined }).then(res => {
          // 消息提示
          that.$message({
            type: 'success',
            message: msg + '!'
          })
          // 刷新数据
          that.crud.refresh()
        })
      })
    },
 
    // 获取文件信息
    getFileInfo(info) {
      const that = this
      // 判断返回数据
      if (info.length === 0) {
        // 表单文件路径赋值
        that.crud.form.filePath = null
        // 解除附件上传Loading
        that.fileUploadLoading = false
        // 表单提交
        that.crud.submitCU()
        // 终止
        return
      }
      // 循环返回数据
      for (let i = 0; i < info.length; i++) {
        // 判断循环下标
        if (i === 0) {
          // 表单文件路径赋值
          that.crud.form.filePath = info[i].response == null || info[i].response === '' ? info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : '/file/' + info[i].response.type + '/' + info[i].response.realName
        } else {
          // 表单文件路径赋值
          that.crud.form.filePath += info[i].response == null || info[i].response === '' ? ',' + info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : ',/file/' + info[i].response.type + '/' + info[i].response.realName
        }
        // 判断循环是否结束
        if (i === info.length - 1) {
          // 解除附件上传Loading
          that.fileUploadLoading = false
          // 表单提交
          that.crud.submitCU()
          return
        }
      }
    },
    // 再新增(企微)
    reAdd(data) {
      const that = this
      that.crud.toAdd()
      that.$set(that.form, 'userId', data.userId)
      that.$set(that.form, 'approvalUserId', data.approvalUserId)
      that.$set(that.form, 'projectId', data.projectId)
      that.$set(that.form, 'reimburseTypes', data.reimburseType.split(','))
      that.$set(that.form, 'reimburseReason', data.reimburseReason)
      that.$set(that.form, 'expenseTypes', data.expenseType.split(','))
      that.$set(that.form, 'startTime', data.startTime)
      that.$set(that.form, 'endTime', data.endTime)
      that.$set(that.form, 'expenseAmount', data.expenseAmount)
      that.$set(that.form, 'expenseComment', data.expenseComment)
      that.$set(that.form, 'filePath', data.filePath)
    }
  }
}
</script>
 
<style scoped>
  .upload-tips {
    color: red;
  }
</style>