weicd
2023-09-28 d0c51ac702c57f2cae84a8d879a5b605f2dab630
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
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
<template>
  <div class="app-container">
    <!--工具栏-->
    <el-row v-loading="taskLoading" :gutter="15">
      <el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="7">
        <el-card class="box-card" shadow="never" style="width: 750px">
          <el-tabs v-model="tobeOver" style="height: 200px;" @tab-click="handleClickTobeTasked">
            <el-tab-pane :label="tobeTasked" name="first">
              <el-table
                :data="adventTasks"
                height="180"
                :show-header="false"
              >
                <el-table-column
                  prop="name"
                  :show-overflow-tooltip="true"
                  min-width="180px"
                />
                <el-table-column
                  prop="taskStartDate"
                  :show-overflow-tooltip="true"
                  min-width="180px"
                />
                <el-table-column
                  prop="taskEndDate"
                  :show-overflow-tooltip="true"
                  min-width="180px"
                />
                <el-table-column width="100px" style="align-items: center">
                  <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="quickFilling(scope.row)">填写日报</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :md="16" :lg="16" :xl="17" style="padding-left: 250px">
        <el-card class="box-card" shadow="never">
          <el-tabs v-model="activeName" style="height: 200px;">
            <el-tab-pane :label="tasking" name="first">
              <el-table
                v-if="ongoingTasks.length != 0"
                :data="ongoingTasks"
                height="180"
                :show-header="false"
                :stripe="true"
              >
                <el-table-column
                  prop="name"
                  :show-overflow-tooltip="true"
                  min-width="150px"
                />
                <el-table-column
                  prop="taskStartDate"
                  :show-overflow-tooltip="true"
                  min-width="180px"
                />
                <el-table-column
                  prop="taskEndDate"
                  :show-overflow-tooltip="true"
                  min-width="180px"
                />
                <el-table-column width="100px" style="align-items: center">
                  <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="quickFilling(scope.row)">填写日报</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <span v-else>暂无任务</span>
            </el-tab-pane>
            <el-tab-pane :label="tobeTask" name="second">
              <el-table
                v-if="taskNotStarted.length != 0"
                :data="taskNotStarted"
                height="180"
                :show-header="false"
              >
                <el-table-column
                  prop="name"
                  :show-overflow-tooltip="true"
                  min-width="180px"
                />
                <el-table-column
                  prop="taskStartDate"
                  :show-overflow-tooltip="true"
                  min-width="180px"
                />
                <el-table-column
                  prop="taskEndDate"
                  :show-overflow-tooltip="true"
                  min-width="180px"
                />
                <el-table-column width="100px" style="align-items: center">
                  <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="quickFilling(scope.row)">填写日报</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <span v-else>暂无任务</span>
            </el-tab-pane>
            <!--<el-tab-pane label="未分配任务" name="third" style=":display: false">未分配任务</el-tab-pane>-->
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
    <el-divider />
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-date-picker
          v-model="query.fillDates"
          type="daterange"
          clearable
          class="filter-item"
          value-format="yyyy-MM-dd"
          placeholder="请选择日报日期"
          range-separator=" ~ "
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 285px;"
        />
        <el-select v-model="query.projectId" filterable clearable placeholder="所属项目" :loading="loadingProject" style="width: 185px;" class="filter-item" @change="queryProjectChange" @keyup.enter.native="crud.toQuery" @clear="clearQueryTasks">
          <el-option
            v-for="item in queryProjects"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
        <el-select v-model="query.taskMongoId" filterable clearable placeholder="所属任务" :loading="loadingTast" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in queryTasks"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
        <el-input v-model="query.name" filterable clearable placeholder="任务名称" style="width: 185px;" class="filter-item" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <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="110px">
          <el-form-item label="所属员工" prop="userNickName">
            <el-input v-model="form.userNickName" style="width: 340px;" :disabled="true" />
          </el-form-item>
          <el-form-item label="所属项目" prop="projectId">
            <el-select v-if="queryProjects.length > 0" :key="form.projectId" v-model="form.projectId" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formProjectChange">
              <template v-if="loadingQueryProjectsOne" #prefix>
                <i class="el-icon-loading" />
              </template>
              <template v-if="!loadingQueryProjectsOne">
                <el-option
                  v-for="item in queryProjects"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </template>
            </el-select>
            <el-select v-else v-model="form" filterable clearable :placeholder="loadingQueryProjectsOne ? '加载中' : '请选择'" style="width: 340px;" :disabled="form.flag" @change="formProjectChange">
              <template v-if="loadingQueryProjectsOne" #prefix>
                <i class="el-icon-loading" />
              </template>
              <template v-if="!loadingQueryProjectsOne">
                <el-option
                  v-for="item in queryProjects"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </template>
            </el-select>
          </el-form-item>
          <el-form-item label="所属任务" prop="taskId">
            <el-select v-if="formTasks.length > 0" :key="form.taskId" v-model="form.taskId" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskChange">
              <template v-if="loadingQueryProjects" #prefix>
                <i class="el-icon-loading" />
              </template>
              <template v-if="!loadingQueryProjects">
                <el-option
                  v-for="item in formTasks"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </template>
            </el-select>
            <el-select v-else v-model="form" filterable clearable :placeholder="loadingQueryProjects ? '加载中' : '请选择'" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
              <template v-if="loadingQueryProjects" #prefix>
                <i class="el-icon-loading" />
              </template>
              <template v-if="!loadingQueryProjects">
                <el-option
                  v-for="item in formTasks"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </template>
            </el-select>
          </el-form-item>
          <el-form-item label="分配任务" prop="taskUserMongo">
            <el-select v-if="formTaskUserIds.length > 0" :key="form.taskUserMongo.id" v-model="form.taskUserMongo.id" :allow-create="true" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
              <template v-if="loadingQueryProjectsTwo" #prefix>
                <i class="el-icon-loading" />
              </template>
              <template v-if="!loadingQueryProjects">
                <el-option
                  v-for="item in formTaskUserIds"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </template>
            </el-select>
            <el-select v-else v-model="form" filterable clearable :placeholder="loadingQueryProjectsTwo ? '加载中' : '请选择'" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
              <template v-if="loadingQueryProjectsTwo" #prefix>
                <i class="el-icon-loading" />
              </template>
              <template v-if="!loadingQueryProjectsTwo">
                <el-option
                  v-for="item in formTaskUserIds"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </template>
            </el-select>
          </el-form-item>
          <el-form-item label="填写日期" prop="fillDate">
            <el-date-picker v-model="form.fillDate" type="date" style="width: 340px;" :disabled="form.taskUserMongo.id == null" @change="formDateChange" />
          </el-form-item>
          <el-form-item label="消耗工时" prop="consumedHours">
            <el-input v-model="form.consumedHours" style="width: 340px;" :disabled="disabledFlagBySettlement || form.fillDate == null" @input="watchFlagChange">
              <template slot="append">小时</template>
            </el-input>
          </el-form-item>
          <el-form-item>
            已消耗工时:{{ form.alreadyConsumedHours }} / 任务工时:{{ form.taskHours }}
          </el-form-item>
          <el-form-item label="任务进度" prop="taskProgress">
            <el-input v-model="form.taskProgress" style="width: 340px;" :disabled="disabledFlagBySettlement">
              <template slot="append">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 340px;" :disabled="disabledFlagBySettlement" />
          </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" type="primary" @click="checkForm(1)">确认</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 :show-overflow-tooltip="true" prop="fillDate" label="填写日期" fixed="left" min-width="100px">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.fillDate) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="userNickName" label="所属员工" fixed="left" min-width="100px">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.userNickName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="projectName" label="所属项目" min-width="140px">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.projectName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="taskName" label="所属任务" min-width="180px">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.taskName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="taskUserMongo.name" label="分配任务" min-width="180px">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.taskUserMongo.name }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="consumedHours" label="消耗工时" min-width="80px" />
        <el-table-column :show-overflow-tooltip="true" prop="taskProgress" label="任务进度" min-width="80px">
          <template slot-scope="scope">
            {{ scope.row.taskProgress }}%
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="settlementStatus" min-width="80px" label="结算状态">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[settlementStatus][scope.row.settlementStatus] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注" min-width="140px" />
        <el-table-column v-if="checkPer(['admin','task:divide','task:edit','task:del'])" label="操作" width="180px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column>
      </el-table>
 
      <el-dialog
        title="提示"
        :visible.sync="centerDialogVisibleTaskHours"
        width="30%"
        center
      >
        <span>本次日报的消耗工时已超过任务工时,确定要继续吗?</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisibleTaskHours = false">取 消</el-button>
          <el-button type="primary" @click="submitDialogTaskHours">确 定</el-button>
        </span>
      </el-dialog>
 
      <el-dialog
        title="提示"
        :visible.sync="centerDialogVisibleTaskProgress"
        width="30%"
        center
      >
        <span>本次日报的任务进度比您原本的任务进度要少,确定要继续吗?</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisibleTaskProgress = false">取 消</el-button>
          <el-button type="primary" @click="submitDialogTaskProgress">确 定</el-button>
        </span>
      </el-dialog>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
 
<script>
import crudTaskDaliy from '@/api/task/taskDaliy'
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 { mapGetters } from 'vuex'
import constant from '../../../utils/constant'
import crudProject from '@/api/project/project'
import crudTask from '@/api/task/task'
import crudTaskUser from '@/api/task/taskUser'
 
const defaultForm = { id: null, projectId: null, taskId: null, taskMongoId: null, taskUserMongo: {}, userId: null, fillDate: null, consumedHours: null, alreadyConsumedHours: 0, taskHours: 0, consumedWorkload: null, consumedWorkloadUnit: null, taskProgress: null, settlementStatus: constant.SETTLEMENT_STATUS_UNSETTLED, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'TaskDaliy',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.STANDARD_WORKLOAD_UNIT, constant.SETTLEMENT_STATUS],
  cruds() {
    return CRUD({ title: '任务日报', url: 'api/taskDaliy', idField: 'id', sort: 'fillDate,desc', crudMethod: { ...crudTaskDaliy }})
  },
  data() {
    // 时长(万内)验证
    var durationValidate = (rule, value, callback) => {
      const reg = /^([0-9]|[1-9]\d{1,3})(\.\d{1,2})?$/
      if (value != null && value !== '' && !reg.test(value)) {
        callback(new Error('请输入 一万 以内的正整数或两位小数'))
      } else {
        callback()
      }
    }
    // 比例(百内)验证
    var proportionValidate = (rule, value, callback) => {
      const reg = /^([0-9]|[1-9]\d)(\.\d{1,2})?$|100$/
      if (value != null && value !== '' && !reg.test(value)) {
        callback(new Error('请输入 一百 以内的正整数或两位小数'))
      } else {
        callback()
      }
    }
    return {
      permission: {
        add: ['admin', 'taskDaliy:add'],
        edit: ['admin', 'taskDaliy:edit'],
        del: ['admin', 'taskDaliy:del'],
        download: ['admin', 'taskDaliy:download']
      },
      rules: {
        fillDate: [
          { required: true, message: '填写日期不能为空', trigger: 'change' }
        ],
        userNickName: [
          { required: true, message: '所属员工不能为空', trigger: 'change' }
        ],
        projectId: [
          { required: true, message: '所属项目不能为空', trigger: 'blur' }
        ],
        taskId: [
          { required: true, message: '所属任务不能为空', trigger: 'blur' }
        ],
        taskUserMongo: [
          { required: true, message: '分配任务不能为空', trigger: 'blur' }
        ],
        consumedHours: [
          { required: true, message: '消耗工时不能为空', trigger: 'blur' },
          { validator: durationValidate, trigger: 'blur' }
        ],
        consumedWorkload: [
          { validator: durationValidate, trigger: 'blur' }
        ],
        taskProgress: [
          { required: true, message: '任务进度不能为空', trigger: 'blur' },
          { validator: proportionValidate, trigger: 'blur' }
        ],
        settlementStatus: [
          { required: true, message: '结算状态不能为空', trigger: 'change' }
        ]
      },
      queryTypeOptions: [
        { key: 'userId', display_name: '所属员工' },
        { key: 'projectId', display_name: '所属项目' },
        { key: 'taskId', display_name: '所属任务' },
        { key: 'taskUserId', display_name: '分配任务' },
        { key: 'TaskUserName', display_name: '任务名称' },
        { key: 'taskMongoId', display_name: '任务名称' }
      ],
      // 字典:标准工作量单位
      standardWorkloadUnit: constant.STANDARD_WORKLOAD_UNIT,
      // 字典:结算状态
      settlementStatus: constant.SETTLEMENT_STATUS,
      // 角色级别:超级管理员
      roleLevelSuper: constant.ROLE_LEVEL_SUPER,
      // 角色级别:总经理
      roleLevelGeneral: constant.ROLE_LEVEL_GENERAL,
      // CRUD状态
      crudStatusPrepared: CRUD.STATUS.PREPARED,
      // 用户最大角色级别
      userRolesLevelMin: null,
      // 用户列表
      users: [],
      // 检索项目列表
      queryProjects: [],
      adventTasks: [],
      ongoingTasks: [],
      taskNotStarted: [],
      // 检索任务列表
      queryTasks: [],
      // 表单项目列表
      formProjects: [],
      // 表单任务列表
      formTasks: [],
      // 三级任务
      formTaskUserIds: [],
      // 表单禁用标记(结算状态)
      disabledFlagBySettlement: false,
      // 当前月份
      currentMonth: new Date(),
      // 当前TAB
      activeName: 'first',
      tobeOver: 'first',
      tasking: '进行中任务',
      tobeTask: '未着手任务',
      tobeTasked: '临期任务',
      currentTask: null,
      taskLoading: true,
      centerDialogVisibleTaskHours: false,
      centerDialogVisibleTaskProgress: false,
      confirmHours: false,
      confirmProgress: false,
      newValue: '',
      oldValue: '',
      tempValue: '',
      resData: true,
      userIds: [],
      watchFlg: false,
      editVar: '',
      loadingProject: true,
      loadingTast: false,
      loadingQueryProjectsOne: false,
      loadingQueryProjects: false,
      loadingQueryProjectsTwo: false
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  watch: {
    'form.consumedHours': function(newVal, oldVal) {
      if (newVal === 0 && this.userIds.includes(this.form.taskUserMongo.id)) {
        this.form.alreadyConsumedHours = this.tempValue
      }
      if (this.crud.status.edit === 1 && newVal === 0) {
        this.form.alreadyConsumedHours = this.form.alreadyConsumedHours - (this.editVar - 0)
      }
      if (this.watchFlg) {
        this.form.alreadyConsumedHours = (this.form.alreadyConsumedHours) - (oldVal - 0) + (newVal - 0)
        this.watchFlg = false
      }
    },
    'confirmProgress': function(newVal) {
      this.confirmProgress = newVal
    },
    'confirmHours': function(newVal) {
      this.confirmHours = newVal
    },
    'crud.status.edit': function() {
      this.editVar = this.form.consumedHours
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 判断传参是否为空
      if (this.$route.params.projectId != null && this.$route.params.projectId !== '' && this.crud.query.projectId === undefined) {
        // 检索条件赋值
        this.$set(this.crud.query, 'projectId', Number(this.$route.params.projectId))
        // 获取任务列表
        crudTask.getAllOfDaily({ projectId: this.query.projectId }).then(res => {
          // 检索任务列表
          this.queryTasks = res
        })
      }
      // 判断传参是否为空
      if (this.$route.params.taskId != null && this.$route.params.taskId !== '' && this.crud.query.taskId === undefined) {
        // 检索条件赋值
        this.$set(this.crud.query, 'taskId', Number(this.$route.params.taskId))
      }
      // 用户角色级别数组
      const userRolesLevel = this.user.roles.map(({ level }) => level)
      // 用户最大角色级别
      this.userRolesLevelMin = Math.min(...userRolesLevel)
      // 获取检索项目
      this.getQueryProject()
      this.getAdventTasks()
      this.getOngoingTasks()
      this.getTaskNotStarted()
      return true
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      // 判断表单结算状态
      if (this.form.settlementStatus === constant.SETTLEMENT_STATUS_SETTLED) {
        // 表单禁用标记(结算状态)
        this.disabledFlagBySettlement = true
      } else {
        // 表单禁用标记(结算状态)
        this.disabledFlagBySettlement = false
      }
      // 随机数
      this.random = Math.random()
    },
    [CRUD.HOOK.afterSubmit]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.form.alreadyConsumedHours = 0
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterEditError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.form.alreadyConsumedHours = 0
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterEditCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.form.alreadyConsumedHours = 0
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterAddCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.form.alreadyConsumedHours = 0
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterAddError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.form.alreadyConsumedHours = 0
      this.confirmHours = false
      this.confirmProgress = false
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToAdd]() {
      this.formTasks = []
      this.formTaskUserIds = []
      this.form.taskId = null
      this.form.taskUserMongo.id = null
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      // 判断用户最大角色级别是否是角色级别:超级管理员或角色级别:总经理
      if (this.userRolesLevelMin !== this.roleLevelSuper && this.userRolesLevelMin !== this.roleLevelGeneral) {
        // 表单赋值
        this.form.userId = this.user.id
        this.form.userNickName = this.user.nickName
 
        // 表单用户变更
        this.formUserChange()
        this.formTaskChange()
      }
      if (this.currentTask) {
        this.form.projectId = this.currentTask.projectId
        this.formProjectChange(() => {
          this.form.taskId = this.currentTask.taskId
          this.formTaskChange(() => { this.form.taskUserMongo.id = this.currentTask.id })
        })
        this.form.taskHours = this.currentTask.performanceHours
        this.form.alreadyConsumedHours = this.currentTask.alreadyConsumedHours
        this.tempValue = this.currentTask.alreadyConsumedHours
        this.form.flag = true
      }
    },
    // 钩子:编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      this.loadingQueryProjects = true
      this.loadingQueryProjectsTwo = true
      crudTask.getAllOfDaily({ projectId: this.form.projectId }).then(res => {
        // 检索任务列表
 
        this.formTasks = res
        this.$nextTick().then(() => {
          this.loadingQueryProjects = false
        })
      })
      crudTaskUser.getAllTaskUser(this.form.taskUserMongo.id).then(res => {
        if (res === []) {
          this.formTaskUserIds = []
        }
        this.formTaskUserIds = res
        this.$nextTick().then(() => {
          this.loadingQueryProjectsTwo = false
        })
 
        for (let i = 0; i < this.formTaskUserIds.length; i++) {
          this.userIds.push(this.formTaskUserIds[i].id)
        }
 
        // 循环表单任务列表
        for (let i = 0; i < this.formTaskUserIds.length; i++) {
          // 判断是否为选中任务
          if (this.formTaskUserIds[i].id === this.form.taskUserMongo.id) {
            this.form.taskHours = this.formTaskUserIds[i].performanceHours
            this.form.alreadyConsumedHours = this.formTaskUserIds[i].alreadyConsumedHours
            this.tempValue = this.formTaskUserIds[i].alreadyConsumedHours
          }
        }
      })
    },
    [CRUD.HOOK.afterRefresh]() {
      this.taskLoading = false
    },
    [CRUD.HOOK.beforeSubmit]() {
      if (!this.userIds.includes(this.form.taskUserMongo.id)) {
        // 置换一下
        var taskUserMongoName = this.form.taskUserMongo.id
        this.form.taskUserMongo.name = taskUserMongoName
        this.form.taskUserMongo.id = null
      }
    },
    checkForm(flag) {
      if (this.form.taskUserMongo.id === undefined) {
        this.$message({
          showClose: true,
          message: '分配任务不能为空',
          type: 'error'
        })
        return
      } else if (this.form.fillDate === undefined) {
        this.$message({
          showClose: true,
          message: '填写日期不能为空',
          type: 'error'
        })
        return
      } else if (this.form.consumedHours === undefined || this.form.consumedHours === 0) {
        this.$message({
          showClose: true,
          message: '请填写任务时长',
          type: 'error'
        })
        return
      } else if (this.form.taskProgress === undefined) {
        this.$message({
          showClose: true,
          message: '任务进度不能为空',
          type: 'error'
        })
        return
      }
      crudTaskDaliy.checkTaskHours({ 'taskProgress': this.form.taskProgress, 'taskUserId': this.form.taskUserMongo.id, 'fillDate': this.form.fillDate }).then(res => {
        if (res === false && !this.confirmProgress) {
          flag++
          // 为假
          this.centerDialogVisibleTaskProgress = true
          if (this.confirmProgress) {
            // 如果确定了
            const result = this.form.alreadyConsumedHours
            if (result > this.form.taskHours && !this.confirmHours) {
              this.centerDialogVisibleTaskHours = true
              if (this.confirmHours) {
                this.crud.submitCU()
              } else {
                if (flag > 1) {
                  return
                } else {
                  this.checkForm()
                }
              }
            } else {
              this.crud.submitCU()
            }
          } else {
            if (flag > 1) {
              return
            } else {
              // 没确定
              this.checkForm()
            }
          }
        } else {
          flag++
          // 判断时间
          const result = this.form.alreadyConsumedHours
          if (result > this.form.taskHours && !this.confirmHours) {
            this.centerDialogVisibleTaskHours = true
            if (this.confirmHours) {
              this.crud.submitCU()
            } else {
              if (flag > 1) {
                return
              } else {
                this.checkForm()
              }
            }
          } else {
            this.crud.submitCU()
          }
        }
      })
    },
    watchFlagChange() {
      this.watchFlg = true
    },
    getAdventTasks() {
      crudTaskUser.getAdventTasks().then(res => {
        this.adventTasks = res
      })
    },
    getOngoingTasks() {
      crudTaskUser.getOngoingTasks().then(res => {
        this.ongoingTasks = res
      })
    },
    getTaskNotStarted() {
      crudTaskUser.getTaskNotStarted().then(res => {
        this.taskNotStarted = res
      })
    },
    handleClick(tab, event) {
      console.log(tab, event)
    },
    handleClickTobeTasked(tab, event) {
      console.log(tab, event)
    },
    // 获取检索项目
    getQueryProject() {
      this.loadingProject = true
      this.queryProjects = []
      this.loadingQueryProjectsOne = true
      // 获取项目
      crudProject.getRelevantOfDaily().then(res => {
        // this.formProjects = res
        // 检索项目列表
        this.queryProjects = res
        this.loadingProject = false
        this.$nextTick().then(() => {
          this.loadingQueryProjectsOne = false
        })
      })
 
      // 获取任务列表
      crudTask.getAllOfDaily({ projectId: this.query.projectId }).then(res => {
        // 检索任务列表
        this.queryTasks = res
      })
    },
    // 检索项目变更
    queryProjectChange() {
      this.queryTasks = []
      this.loadingTast = true
      // 检索赋值
      this.$set(this.query, 'taskId', null)
      // 判断检索项目是否为空
      if (this.query.projectId === null || this.query.projectId === '') {
        // 检索任务列表
        this.queryTasks = []
      } else {
        // 获取任务
        crudTask.getAllOfDaily({ projectId: this.query.projectId }).then(res => {
          // 检索任务列表
          this.queryTasks = res
          this.loadingTast = false
        })
      }
    },
    clearQueryTasks() {
      this.loadingTast = false
    },
    formDateChange() {
      crudTaskDaliy.getDailyDetail({ taskUserId: this.form.taskUserMongo.id, fillDate: this.form.fillDate }).then(res => {
        if (res === '') {
          this.form.alreadyConsumedHours = this.tempValue
          this.form.consumedHours = 0
        } else {
          this.form.alreadyConsumedHours = this.tempValue
          this.form.consumedHours = res.consumedHours
          this.form.taskProgress = res.taskProgress
        }
        if (!this.userIds.includes(this.form.taskUserMongo.id)) {
          this.form.consumedHours = 0
          this.form.taskProgress = 0
          this.form.alreadyConsumedHours = 0
        }
      })
    },
    // 表单用户变更
    formUserChange() {
      // 表单赋值
      this.form.projectId = null
      this.form.taskId = null
      // 判断表单用户是否为空
      if (this.form.userId == null || this.form.userId === '') {
        // 表单项目列表
        this.formProjects = []
        // 表单任务列表
        this.formTasks = []
      } else {
        // 获取项目
        crudProject.getPartake({ taskUserId: this.form.userId, approveStatus: constant.APPROVE_STATUS_ACKNOWLEDGED }).then(res => {
          // 表单项目列表
          this.formProjects = res
        })
      }
    },
    // 表单项目变更
    formProjectChange(cb) {
      // 表单赋值
      this.form.taskId = null
      this.form.taskUserMongo = {}
      this.form.taskHours = 0
      this.form.alreadyConsumedHours = 0
      this.form.consumedHours = null
      this.form.taskProgress = null
      this.form.remarks = null
      // 判断表单项目是否为空
      if (this.form.projectId == null || this.form.projectId === '') {
        // 表单任务列表
        this.formTasks = []
      } else {
        this.loadingQueryProjects = true
        this.loadingQueryProjectsTwo = true
        this.formTasks = []
        this.formTaskUserIds = []
        this.form.taskId = null
        this.form.taskUserMongo.id = null
        // 获取任务
        crudTask.getAllOfDaily({ projectId: this.form.projectId }).then(res => {
          // 检索任务列表
          this.formTasks = res
          this.$nextTick().then(() => {
            this.loadingQueryProjects = false
          })
          if (cb) {
            cb()
          }
        })
      }
    },
    // 表单任务变更
    formTaskChange(cb) {
      this.formTaskUserIds = []
      this.form.taskUserMongo.id = null
      this.loadingQueryProjectsTwo = true
      // 循环表单任务列表
      for (let i = 0; i < this.formTasks.length; i++) {
        // 判断是否为选中任务
        if (this.formTasks[i].id === this.form.taskId) {
          crudTask.getRelevantTaskUser({ 'taskId': this.form.taskId }).then(res => {
            if (res === []) {
              this.formTaskUserIds = []
            }
            for (let i = 0; i < res.length; i++) {
              this.userIds.push(res[i].id)
            }
            this.formTaskUserIds = res
            this.$nextTick().then(() => {
              this.loadingQueryProjectsTwo = false
            })
            this.form.taskProgress = res.taskProgress
            this.form.consumedHours = res.consumedHours
            if (cb) {
              cb()
            }
          })
        }
      }
    },
    formTaskUserChange() {
      this.form.consumedHours = 0
      this.form.fillDate = null
      // this.form.taskProgress = 0
      this.form.alreadyConsumedHours = 0
      this.form.taskHours = 0
      console.log('ddd:' + this.form.taskUserMongo.id)
      // 循环表单任务列表
      for (let i = 0; i < this.formTaskUserIds.length; i++) {
        // 判断是否为选中任务
        if (this.formTaskUserIds[i].id === this.form.taskUserMongo.id) {
          this.form.taskHours = this.formTaskUserIds[i].performanceHours
          this.form.alreadyConsumedHours = this.formTaskUserIds[i].alreadyConsumedHours
          this.tempValue = this.formTaskUserIds[i].alreadyConsumedHours
        }
      }
 
      this.getTaskProgress(this.form.taskUserMongo.id)
    },
    quickFilling(object) {
      this.currentTask = object
      this.crud.toAdd()
      this.getTaskProgress(object.id)
    },
    getTaskProgress(id) {
      // 任务更改查询任务进度
      crudTaskDaliy.getDailyTaskProgress({ taskUserId: id }).then(res => {
        if (res !== '') {
          this.form.taskProgress = res.taskProgress
        } else {
          this.form.taskProgress = 0
        }
      })
    },
    submitDialogTaskHours() {
      this.centerDialogVisibleTaskHours = false
      this.confirmHours = true
    },
    submitDialogTaskProgress() {
      this.centerDialogVisibleTaskProgress = false
      this.confirmProgress = true
    }
  }
}
</script>
 
<style scoped>
  adventTable tr:first-child {
    display: none;
  }
</style>