yaozc
2023-07-07 c752e33fe402e2179e7e6795f567d41c044ca3c6
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
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.name" clearable placeholder="名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.projectDistinguish" clearable filterable placeholder="项目区分" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[projectDistinguish]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.projectTypeId" clearable filterable placeholder="项目类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in projectTypeList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
        <el-select v-model="query.liableUserId" v-permission="permission.master" clearable filterable placeholder="责任人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in userList"
            :key="item.id"
            :label="item.nickName"
            :value="item.id"
          />
        </el-select>
        <el-select v-model="query.projectStatus" clearable filterable placeholder="项目状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[projectStatus]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.approveStatus" clearable filterable placeholder="批准状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[approveStatus]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <el-button
          slot="right"
          v-permission="permission.admit"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-check"
          :disabled="crud.selections.length === 0"
          @click="projectAdmit(crud.selections)"
        >承认</el-button>
        <el-button
          slot="right"
          v-permission="permission.admit"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-close"
          :disabled="crud.selections.length === 0"
          style="margin-left: 4px !important;"
          @click="projectDisavow(crud.selections)"
        >未承认</el-button>
        <el-button
          slot="right"
          v-permission="permission.seeTask"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-view"
          :disabled="crud.selections.length !== 1"
          style="margin-left: 4px !important;"
          @click="toSeeTask(crud.selections[0])"
        >
          查看任务
        </el-button>
        <el-button
          slot="right"
          v-permission="permission.seeCost"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-view"
          :disabled="crud.selections.length !== 1"
          style="margin-left: 4px !important;"
          @click="toSeeCost(crud.selections[0])"
        >
          人力成本
        </el-button>
        <el-button
          slot="right"
          v-permission="permission.seeCost"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-view"
          :disabled="crud.selections.length !== 1"
          style="margin-left: 4px !important;"
          @click="toSeeCostOther(crud.selections[0])"
        >
          其他成本
        </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="690px">
        <el-form ref="form" :model="form" :rules="rules" :inline="true" size="small" label-width="110px">
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name" style="width: 523px;" />
          </el-form-item>
          <el-form-item label="项目类型" prop="projectTypeId">
            <el-select v-model="form.projectTypeId" clearable filterable placeholder="请选择" style="width: 200px;" :disabled="disabledFlagByApprove" @change="projectTypeChange">
              <el-option
                v-for="item in projectTypeList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="项目区分" prop="projectDistinguish">
            <el-select v-model="form.projectDistinguish" clearable filterable placeholder="请选择" style="width: 200px;" :disabled="disabledFlagByApprove">
              <el-option
                v-for="item in dict[projectDistinguish]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="需求说明">
            <el-input v-model="form.requirement" :rows="3" type="textarea" style="width: 523px;" />
          </el-form-item>
          <el-form-item label="报价单金" prop="quotationPrice">
            <money-input :key="random" v-model="form.quotationPrice" :width="200" :disabled="disabledFlagByApprove" />
          </el-form-item>
          <el-form-item label="报价币种" prop="unitCurrency">
            <el-select v-model="form.unitCurrency" clearable filterable placeholder="请选择" style="width: 200px;" :disabled="disabledFlagByApprove">
              <el-option
                v-for="item in dict[standardUnitCurrency]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="绩效单金" prop="performancePrice">
            <money-input :key="random" v-model="form.performancePrice" :width="200" :disabled="disabledFlagByApprove" />
          </el-form-item>
          <el-form-item label="绩效币种">
            <el-select v-model="standardUnitCurrencyRenminbi" clearable filterable placeholder="请选择" style="width: 200px;" disabled>
              <el-option
                v-for="item in dict[standardUnitCurrency]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="绩效目标" prop="performanceObjectives">
            <el-input :key="random" v-model="form.performanceObjectives" style="width: 200px;" :disabled="disabledFlagByApprove">
              <template slot="append">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="合同总金额" prop="contractPrice">
            <money-input :key="random" v-model="form.contractPrice" :width="200" />
          </el-form-item>
          <el-form-item label="计划开始日期" prop="planStartDate">
            <el-date-picker v-model="form.planStartDate" type="date" :picker-options="pickerOptionsStart" placeholder="选择日期" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="计划结束日期" prop="planEndDate">
            <el-date-picker v-model="form.planEndDate" type="date" :picker-options="pickerOptionsEnd" placeholder="选择日期" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="责任人">
            <el-select v-model="form.liableUserIdList" clearable filterable multiple placeholder="请选择" style="width: 200px;">
              <el-option
                v-for="item in userList"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
                :disabled="!item.enabled"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="form.id != null" label="项目状态" prop="projectStatus">
            <el-select v-model="form.projectStatus" clearable filterable placeholder="请选择" style="width: 200px;">
              <el-option
                v-for="item in dict[projectStatus]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注" prop="remarks">
            <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 523px;" />
          </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="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 150%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" fixed="left" />
        <el-table-column :show-overflow-tooltip="true" prop="name" label="名称" fixed="left" width="240" />
        <el-table-column :show-overflow-tooltip="true" prop="projectTypeName" label="项目类型" width="110">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.projectTypeName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="projectDistinguish" label="项目区分" width="100">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[projectDistinguish][scope.row.projectDistinguish] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="requirement" label="需求说明" width="140" />
        <el-table-column v-if="checkPer([permission.master])" :show-overflow-tooltip="true" prop="contractPrice" label="合同总金额" width="100">
          <template slot-scope="scope">
            {{ scope.row.contractPrice != null && scope.row.contractPrice != '' ? crud.toMoney(scope.row.contractPrice) : '' }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="实际 / 计划任务总工时" width="140">
          <template slot-scope="scope">
            {{ scope.row.actualTaskTime }} / {{ scope.row.totalTaskTime }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="已完成 / 已分配任务总工时" width="170">
          <template slot-scope="scope">
            {{ scope.row.completedTaskTime }} / {{ scope.row.divideTaskTime }}
          </template>
        </el-table-column>
        <el-table-column v-if="checkPer([permission.master])" label="报价">
          <el-table-column :show-overflow-tooltip="true" prop="quotationPrice" label="单金" width="100">
            <template slot-scope="scope">
              {{ crud.toMoney(scope.row.quotationPrice) }}
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="unitCurrency" label="币种" width="100">
            <template slot-scope="scope">
              <el-tag>{{ dict.label[standardUnitCurrency][scope.row.unitCurrency] }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" label="计划总金额" width="100">
            <template slot-scope="scope">
              {{ crud.toMoney(scope.row.quotationPrice * scope.row.totalTaskTime / 160) }}
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" label="实际总金额" width="100">
            <template slot-scope="scope">
              {{ crud.toMoney(scope.row.quotationPrice * scope.row.actualTaskTime / 160) }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="绩效">
          <el-table-column :show-overflow-tooltip="true" prop="performancePrice" label="单金" width="100">
            <template slot-scope="scope">
              {{ crud.toMoney(scope.row.performancePrice) }}
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" label="币种" width="100">
            <el-tag>{{ dict.label[standardUnitCurrency][standardUnitCurrencyRenminbi] }}</el-tag>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" label="计划总金额" width="100">
            <template slot-scope="scope">
              {{ crud.toMoney(scope.row.performancePrice * scope.row.totalTaskTime / 160) }}
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" label="实际总金额" width="100">
            <template slot-scope="scope">
              {{ crud.toMoney(scope.row.performancePrice * scope.row.actualTaskTime / 160) }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="performanceObjectives" label="绩效目标" width="80">
          <template slot-scope="scope">
            <span :style="{ color: scope.row.performancePrice * scope.row.totalTaskTime * (1 - scope.row.performanceObjectives / 100) < scope.row.totalLaborCost ? 'red' : '' }">
              {{ (scope.row.performanceObjectives ? scope.row.performanceObjectives : 0) + '%' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="计划成本">
          <el-table-column :show-overflow-tooltip="true" prop="totalLaborCost" label="人力成本" width="110">
            <template slot-scope="scope">
              <span :style="{ color: scope.row.performancePrice * scope.row.totalTaskTime < scope.row.totalLaborCost ? 'red' : '' }">
                {{ crud.toMoney(scope.row.totalLaborCost) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="totalOtherCost" label="其他成本" width="110">
            <template slot-scope="scope">
              {{ crud.toMoney(scope.row.totalOtherCost) }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="实际成本">
          <el-table-column :show-overflow-tooltip="true" prop="actualLaborCost" label="人力成本" width="110">
            <template slot-scope="scope">
              <span :style="{ color: scope.row.performancePrice * scope.row.actualTaskTime < scope.row.actualLaborCost ? 'red' : '' }">
                {{ crud.toMoney(scope.row.actualLaborCost) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="actualLaborCost" label="其他成本" width="110">
            未实装
          </el-table-column>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="liableUserName" label="责任人" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.liableUserName != null && scope.row.liableUserName != ''">
              {{ scope.row.liableUserName }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="planStartDate" label="计划开始日期" width="100">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.planStartDate) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="planEndDate" label="计划结束日期" width="100">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.planEndDate) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="projectStatus" label="项目状态" width="80">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[projectStatus][scope.row.projectStatus] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="approveStatus" label="批准状态" width="80">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[approveStatus][scope.row.approveStatus] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注" width="140" />
        <el-table-column :show-overflow-tooltip="true" prop="createTime" label="创建时间" width="140" />
        <el-table-column v-if="checkPer(['admin','project:edit','project:del'])" label="操作" width="210px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            >
              <el-popover
                slot="left"
                :ref="`admit_${scope.row.id}`"
                v-permission="permission.admit"
                width="160"
                placement="top"
              >
                <p>确定承认此项目吗?</p>
                <div style="text-align: right; margin: 0">
                  <el-button size="mini" type="text" @click="canel(scope.row)">取消</el-button>
                  <el-button type="primary" size="mini" @click="projectAdmit(scope.row)">确定</el-button>
                </div>
                <el-button slot="reference" type="primary" icon="el-icon-check" size="mini" />
              </el-popover>
              <el-popover
                slot="left"
                :ref="`disavow_${scope.row.id}`"
                v-permission="permission.admit"
                width="170"
                placement="top"
              >
                <p>确定未承认此项目吗?</p>
                <div style="text-align: right; margin: 0">
                  <el-button size="mini" type="text" @click="canel(scope.row)">取消</el-button>
                  <el-button type="primary" size="mini" @click="projectDisavow(scope.row)">确定</el-button>
                </div>
                <el-button slot="reference" type="primary" icon="el-icon-close" size="mini" style="margin-left: 3px;" />
              </el-popover>
            </udOperation>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
 
<script>
import crudProject from '@/api/project/project'
import crudUser from '@/api/system/user'
import crudProjectType from '@/api/project/projectType'
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 moneyInput from '@/views/assembly/moneyInput/index.vue'
import constant from '@/utils/constant'
 
const defaultForm = { id: null, name: null, projectTypeId: null, projectDistinguish: null, requirement: null, unitCurrency: null, performanceObjectives: null, quotationPrice: null, performancePrice: null, contractPrice: null, liableUserId: null, liableUserIdList: [], planStartDate: null, planEndDate: null, projectStatus: null, approveStatus: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'Project',
  components: { pagination, crudOperation, rrOperation, udOperation, moneyInput },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.STANDARD_UNIT_CURRENCY, constant.PROJECT_DISTINGUISH, constant.PROJECT_STATUS, constant.APPROVE_STATUS],
  cruds() {
    return CRUD({ title: '项目详情', url: 'api/project', idField: 'id', sort: 'id,desc', crudMethod: { ...crudProject }})
  },
  data() {
    // 指针重指向
    const _this = this
    // 金额(十亿内)验证
    var priceValidate = (rule, value, callback) => {
      if (value != null && value !== '' && (isNaN(value) || Number(value) < 0 || Number(value) > 1000000000)) {
        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', 'project:add'],
        edit: ['admin', 'project:edit'],
        del: ['admin', 'project:del'],
        download: ['admin', 'project:download'],
        admit: ['admin', 'project:admit'],
        seeTask: ['admin', 'project:seeTask'],
        seeCost: ['admin', 'project:seeCost'],
        master: ['admin', 'project:master']
      },
      rules: {
        name: [
          { required: true, message: '名称不能为空', trigger: 'blur' },
          { max: 100, message: '最大长度 100 个字符', trigger: 'blur' }
        ],
        projectTypeId: [
          { required: true, message: '项目类型不能为空', trigger: 'change' }
        ],
        projectDistinguish: [
          { required: true, message: '项目区分不能为空', trigger: 'change' }
        ],
        unitCurrency: [
          { required: true, message: '单价币种不能为空', trigger: 'change' }
        ],
        quotationPrice: [
          { required: true, message: '报价单金不能为空', trigger: 'blur' },
          { validator: priceValidate, trigger: 'blur' }
        ],
        performancePrice: [
          { required: true, message: '绩效单金不能为空', trigger: 'blur' },
          { validator: priceValidate, trigger: 'blur' }
        ],
        performanceObjectives: [
          { required: true, message: '绩效目标不能为空', trigger: 'blur' },
          { validator: proportionValidate, trigger: 'blur' }
        ],
        projectStatus: [
          { required: true, message: '项目状态不能为空', trigger: 'change' }
        ],
        approveStatus: [
          { required: true, message: '批准状态不能为空', trigger: 'change' }
        ]
      },
      queryTypeOptions: [
        { key: 'name', display_name: '名称' },
        { key: 'projectTypeId', display_name: '项目类型' },
        { key: 'projectDistinguish', display_name: '项目区分' },
        { key: 'liableUserId', display_name: '责任人' },
        { key: 'projectStatus', display_name: '项目状态' },
        { key: 'approveStatus', display_name: '批准状态' }
      ],
      // 标准单价币种
      standardUnitCurrency: constant.STANDARD_UNIT_CURRENCY,
      // 标准单价币种:人民币
      standardUnitCurrencyRenminbi: constant.STANDARD_UNIT_CURRENCY_RENMINBI,
      // 项目状态
      projectStatus: constant.PROJECT_STATUS,
      // 批准状态
      approveStatus: constant.APPROVE_STATUS,
      // 项目区分
      projectDistinguish: constant.PROJECT_DISTINGUISH,
      // 角色级别:普通用户
      roleLevelOrdinary: constant.ROLE_LEVEL_ORDINARY,
      // 用户最大角色级别
      userRolesLevelMin: null,
      // 随机数
      random: 0,
      // 项目类型列表
      projectTypeList: [],
      // 用户列表
      userList: [],
      // 选中的id
      ids: [],
      // 是否显示
      disabled: true,
      // 选中结束时间之后不可选
      pickerOptionsStart: {
        disabledDate: (time) => {
          return _this.form.planEndDate != null && _this.form.planEndDate !== '' ? time.getTime() > new Date(_this.form.planEndDate).getTime() : false
        }
      },
      // 选中开始时间之后不可选
      pickerOptionsEnd: {
        disabledDate: (time) => {
          return _this.form.planStartDate != null && _this.form.planStartDate !== '' ? time.getTime() < new Date(_this.form.planStartDate).getTime() : false
        }
      },
      // 表单禁用标记(承认状态)
      disabledFlagByApprove: false
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 用户角色级别数组
      const userRolesLevel = this.user.roles.map(({ level }) => level)
      // 用户最大角色级别
      this.userRolesLevelMin = Math.min(...userRolesLevel)
      // 获取项目类型
      this.getPackageTypeAll()
      // 获取责任人
      this.getUserListAll()
      return true
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      // 判断表单承认状态
      if (this.form.approveStatus === constant.APPROVE_STATUS_ACKNOWLEDGED) {
        // 表单禁用标记(承认状态)
        this.disabledFlagByApprove = true
      } else {
        // 表单禁用标记(承认状态)
        this.disabledFlagByApprove = false
      }
      // 随机数
      this.random = Math.random()
    },
    // 获取项目类型
    getPackageTypeAll() {
      // 获取项目类型
      crudProjectType.getAll().then(res => {
        // 项目类型列表
        this.projectTypeList = res
      }).catch(() => {
 
      })
    },
    // 获取责任人
    getUserListAll() {
      // 获取责任人
      crudUser.getAll().then(res => {
        // 用户列表
        this.userList = res
      }).catch(() => {
 
      })
    },
    // 项目类型改变
    projectTypeChange() {
      // 通过id获取项目类型信息
      crudProjectType.getAll({ id: this.form.projectTypeId }).then(res => {
        // 单价币种赋值
        this.form.unitCurrency = res[0].standardUnitCurrency
        // 单价金额赋值
        this.form.quotationPrice = res[0].standardQuotationPrice
        // 单价金额赋值
        this.form.performancePrice = res[0].standardPerformancePrice
        // 绩效目标赋值
        this.form.performanceObjectives = res[0].standardPerformanceObjectives
        // 随机数
        this.random = Math.random()
      })
    },
    // 取消
    canel(data) {
      this.$refs[`admit_${data.id}`].showPopper = false
      this.$refs[`disavow_${data.id}`].showPopper = false
    },
    // 项目承认
    projectAdmit(row) {
      // 选中的id
      this.ids = []
      // 判断是多个项目承认还是单个项目承认
      if (row.id !== undefined) {
        this.$refs[`admit_${row.id}`].showPopper = false
        // 选中的id
        this.ids.push(row.id)
        // 项目承认
        crudProject.editAdmit(this.ids).then(res => {
          // 刷新数据
          this.crud.refresh()
        })
      } else {
        // 确认框
        this.$confirm('此操作将承认' + row.length + '个项目, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'success'
        }).then(() => {
          // 循环选中数据
          for (let i = 0; i < row.length; i++) {
            // 选中的id
            this.ids.push(row[i].id)
            // 判断循环是否结束
            if (i === row.length - 1) {
              // 项目承认
              crudProject.editAdmit(this.ids).then(res => {
                // 消息提示
                this.$message({
                  type: 'success',
                  message: '项目已承认!'
                })
                // 刷新数据
                this.crud.refresh()
              })
            }
          }
        }).catch(() => {
          // 消息提示
          this.$message({
            type: 'info',
            message: '已取消项目承认'
          })
        })
      }
    },
    // 项目未承认
    projectDisavow(row) {
      // 选中的id
      this.ids = []
      // 判断是多个项目未承认还是单个项目未承认
      if (row.id !== undefined) {
        this.$refs[`disavow_${row.id}`].showPopper = false
        // 选中的id
        this.ids.push(row.id)
        // 项目未承认
        crudProject.editDisavow(this.ids).then(res => {
          // 刷新数据
          this.crud.refresh()
        })
      } else {
        // 确认框
        this.$confirm('此操作将未承认' + row.length + '个项目, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'success'
        }).then(() => {
          // 循环选中数据
          for (let i = 0; i < row.length; i++) {
            // 选中的id
            this.ids.push(row[i].id)
            // 判断循环是否结束
            if (i === row.length - 1) {
              // 项目承认
              crudProject.editDisavow(this.ids).then(res => {
                // 消息提示
                this.$message({
                  type: 'success',
                  message: '项目未承认!'
                })
                // 刷新数据
                this.crud.refresh()
              })
            }
          }
        }).catch(() => {
          // 消息提示
          this.$message({
            type: 'info',
            message: '已取消项目未承认'
          })
        })
      }
    },
    // 查看任务
    toSeeTask(data) {
      // 跳转页面
      this.$router.push({
        name: 'ProjectTask',
        params: {
          projectId: data.id
        }
      })
    },
    // 查看人力成本
    toSeeCost(data) {
      // 跳转页面
      this.$router.push({
        name: 'ProjectCost',
        params: {
          projectId: data.id
        }
      })
    },
    // 查看其他成本
    toSeeCostOther(data) {
      // 跳转页面
      this.$router.push({
        name: 'ProjectCostOther',
        params: {
          projectId: data.id
        }
      })
    },
    // 钩子:提交 - 之前
    [CRUD.HOOK.beforeSubmit]() {
      // 责任人ID
      this.form.liableUserId = null
      // 循环责任人ID列表
      for (let i = 0; i < this.form.liableUserIdList.length; i++) {
        // 责任人ID
        this.form.liableUserId = this.form.liableUserId === null ? '-' + this.form.liableUserIdList[i] + '-' : this.form.liableUserId + ',' + '-' + this.form.liableUserIdList[i] + '-'
      }
    }
  }
}
</script>
 
<style scoped>
 
</style>