赵士淞
2023-05-09 b8441a1ac74d2c3325dd36d69ced511f19cd760b
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
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-select v-model="query.userId" filterable clearable placeholder="所属员工" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in users"
            :key="item.id"
            :label="item.nickName"
            :value="item.id"
          />
        </el-select>
        <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="所属项目" style="width: 185px;" class="filter-item" @change="queryProjectChange" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in queryProjects"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
        <el-select v-model="query.taskId" filterable clearable placeholder="所属任务" 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>
        <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="fillDate">
            <el-date-picker v-model="form.fillDate" type="date" style="width: 340px;" :disabled="disabledFlagBySettlement" />
          </el-form-item>
          <el-form-item label="所属员工" prop="userId">
            <el-select v-model="form.userId" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="disabledFlagBySettlement || (userRolesLevelMin != roleLevelSuper && userRolesLevelMin != roleLevelGeneral)" @change="formUserChange">
              <el-option
                v-for="item in users"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
                :disabled="!item.enabled"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="所属项目" prop="projectId">
            <el-select v-model="form.projectId" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="disabledFlagBySettlement || crud.status.edit == crudStatusPrepared" @change="formProjectChange">
              <el-option
                v-for="item in formProjects"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="所属任务" prop="taskId">
            <el-select v-model="form.taskId" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="disabledFlagBySettlement" @change="formTaskChange">
              <el-option
                v-for="item in formTasks"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="消耗工时" prop="consumedHours">
            <el-input v-model="form.consumedHours" style="width: 340px;" :disabled="disabledFlagBySettlement">
              <template slot="append">小时</template>
            </el-input>
          </el-form-item>
          <el-form-item>
            已消耗工时:{{ form.alreadyConsumedHours }} / 任务工时:{{ form.taskHours }}
          </el-form-item>
          <el-form-item label="消耗工作量" prop="consumedWorkload">
            <el-input v-model="form.consumedWorkload" style="width: 340px;" :disabled="disabledFlagBySettlement" />
          </el-form-item>
          <el-form-item label="消耗工作量单位">
            {{ dict.label[standardWorkloadUnit][form.consumedWorkloadUnit] }}
          </el-form-item>
          <el-form-item label="任务进度" prop="taskProgress">
            <el-input v-model="form.taskProgress" style="width: 340px;" :disabled="disabledFlagBySettlement">
              <template slot="prepend"><i class="i el-icon-search" @click="showInner" /></template>
              <template slot="append">%</template>
            </el-input>
          </el-form-item>
          <el-form-item v-if="(userRolesLevelMin == roleLevelSuper || userRolesLevelMin == roleLevelGeneral) && crud.status.edit == crudStatusPrepared" label="结算状态" prop="settlementStatus">
            <el-select v-model="form.settlementStatus" filterable placeholder="请选择" style="width: 340px;" :disabled="disabledFlagBySettlement">
              <el-option
                v-for="item in dict[settlementStatus]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </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="crud.submitCU">确认</el-button>
        </div>
        <el-dialog
          width="30%"
          title="日报详细"
          :visible.sync="innerVisible"
          append-to-body
        >
          <el-table ref="tableInner" v-loading="innerLoading" :data="innerData" size="small" style="width: 100%;">
            <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="taskHours" label="分配工时" min-width="80px" />
            <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>
        </el-dialog>
      </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="consumedHours" label="消耗工时" min-width="80px" />
        <el-table-column :show-overflow-tooltip="true" prop="consumedWorkload" label="消耗工作量" min-width="80px" />
        <el-table-column :show-overflow-tooltip="true" prop="taskWorkloadUnit" label="消耗工作量单位" min-width="110px">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.taskWorkloadUnit != null && scope.row.taskWorkloadUnit != ''">{{ dict.label[standardWorkloadUnit][scope.row.taskWorkloadUnit] }}</el-tag>
          </template>
        </el-table-column>
        <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 prop="createTime" label="创建时间" min-width="140px" />
        <el-table-column v-if="checkPer(['admin','taskDaliy:edit','taskDaliy:del'])" label="操作" width="150px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation
              v-if="userRolesLevelMin == roleLevelSuper || userRolesLevelMin == roleLevelGeneral || scope.row.userId == user.id"
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <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 crudUser from '@/api/system/user'
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, 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' }
        ],
        userId: [
          { required: true, message: '所属员工不能为空', trigger: 'change' }
        ],
        projectId: [
          { required: true, message: '所属项目不能为空', trigger: 'change' }
        ],
        taskId: [
          { required: true, message: '所属任务不能为空', trigger: 'change' }
        ],
        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: '所属任务' }
      ],
      // 字典:标准工作量单位
      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: [],
      // 检索任务列表
      queryTasks: [],
      // 表单项目列表
      formProjects: [],
      // 表单任务列表
      formTasks: [],
      // 表单禁用标记(结算状态)
      disabledFlagBySettlement: false,
      // 内侧弹出框
      innerVisible: false,
      // 内侧数据
      innerData: [],
      // 内侧数据加载
      innerLoading: false
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  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.getAll({ 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.getUser()
      // 获取检索项目
      this.getQueryProject()
      return true
    },
    // 获取用户
    getUser() {
      // 获取用户
      crudUser.getAll().then(res => {
        // 用户列表
        this.users = res
      })
    },
    // 获取检索项目
    getQueryProject() {
      // 获取项目
      crudProject.getRelevant().then(res => {
        // 检索项目列表
        this.queryProjects = res
      })
    },
    // 检索项目变更
    queryProjectChange() {
      // 检索赋值
      this.$set(this.query, 'taskId', null)
      // 判断检索项目是否为空
      if (this.query.projectId == null || this.query.projectId === '') {
        // 检索任务列表
        this.queryTasks = []
      } else {
        // 获取任务
        crudTask.getAll({ projectId: this.query.projectId }).then(res => {
          // 检索任务列表
          this.queryTasks = res
        })
      }
    },
    // 新增与编辑前做的操作
    [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.beforeToAdd]() {
      // 判断用户最大角色级别是否是角色级别:超级管理员或角色级别:总经理
      if (this.userRolesLevelMin !== this.roleLevelSuper && this.userRolesLevelMin !== this.roleLevelGeneral) {
        // 表单赋值
        this.form.userId = this.user.id
        // 表单用户变更
        this.formUserChange()
      }
    },
    // 钩子:编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
      // 获取项目
      crudProject.getPartake({ taskUserId: this.form.userId, approveStatus: constant.APPROVE_STATUS_ACKNOWLEDGED }).then(res => {
        // 表单项目列表
        this.formProjects = res
      })
      // 获取任务
      crudTask.getPartake({ taskUserId: this.form.userId, projectId: this.form.projectId }).then(res => {
        // 表单任务列表
        this.formTasks = res
        // 表单任务变更
        this.formTaskChange()
      })
    },
    // 表单用户变更
    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() {
      // 表单赋值
      this.form.taskId = null
      // 判断表单项目是否为空
      if (this.form.projectId == null || this.form.projectId === '') {
        // 表单任务列表
        this.formTasks = []
      } else {
        // 获取任务
        crudTask.getPartake({ taskUserId: this.form.userId, projectId: this.form.projectId }).then(res => {
          // 表单任务列表
          this.formTasks = res
        })
      }
    },
    // 表单任务变更
    formTaskChange() {
      // 循环表单任务列表
      for (let i = 0; i < this.formTasks.length; i++) {
        // 判断是否为选中任务
        if (this.formTasks[i].id === this.form.taskId) {
          // 表单赋值
          this.form.consumedWorkloadUnit = this.formTasks[i].planWorkloadUnit
          break
        }
        // 判断循环是否结束
        if (i === this.formTasks.length - 1) {
          // 表单赋值
          this.form.consumedWorkloadUnit = null
        }
      }
      // 查询任务的总消耗工时
      crudTaskDaliy.taskTotalConsumedHours({ userId: this.form.userId, projectId: this.form.projectId, taskId: this.form.taskId }).then(res => {
        // 表单赋值
        this.form.alreadyConsumedHours = res
      })
      // 查询任务分配
      crudTaskUser.getAll({ userId: this.form.userId, projectId: this.form.projectId, taskId: this.form.taskId }).then(res => {
        // 表单赋值
        this.form.taskHours = res[0].taskHours
      })
    },
    showInner() {
      // 显示内部对话框
      this.innerVisible = true
      this.innerLoading = true
      crudTaskDaliy.getTaskDaliyWithHours({ userId: this.form.userId, projectId: this.form.projectId, taskId: this.form.taskId, page: 0, size: 5, sort: 'fillDate,desc' }).then(res => {
        this.innerData = res.content
        this.innerLoading = false
      })
    }
  }
}
</script>
 
<style scoped>
 
</style>