yaozc
2023-07-07 c752e33fe402e2179e7e6795f567d41c044ca3c6
eladmin-web-master/src/views/task/taskUser/index.vue
@@ -36,6 +36,7 @@
            :value="item.value"
          />
        </el-select>
        <date-range-picker v-model="query.createTime" class="date-item" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
@@ -95,6 +96,14 @@
          <el-form-item label="任务工作量单位" prop="taskWorkloadUnit">
            {{ dict.label[standardWorkloadUnit][form.taskWorkloadUnit] }}
          </el-form-item>
          <el-form-item label="任务绩效类型" prop="taskPerformanceType">
            {{ dict.label[performanceType][form.taskPerformanceType] }}
          </el-form-item>
          <el-form-item label="强制更新" tool-tip prop="enable1">
            <el-tooltip content="不增减工作量的场合调整工时的话,需要选择此项。(有疑问请联系管理员,不要随便选。。。)" effect="dark" placement="bottom">
              <el-switch v-model="form.enable1" />
            </el-tooltip>
          </el-form-item>
          <el-form-item label="任务状态" prop="taskStatus">
            <el-select v-model="form.taskStatus" filterable placeholder="请选择" style="width: 340px;">
              <el-option
@@ -115,7 +124,16 @@
        </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
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        :summary-method="getSummaries"
        show-summary
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column :show-overflow-tooltip="true" prop="projectName" label="所属项目" fixed="left" width="140">
          <template slot-scope="scope">
@@ -149,6 +167,11 @@
            <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="taskPerformanceType" label="任务绩效类型" width="110">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.taskPerformanceType != null && scope.row.taskPerformanceType != ''">{{ dict.label[performanceType][scope.row.taskPerformanceType] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="taskProgress" label="任务进度" width="80">
          <template slot-scope="scope">
            {{ scope.row.taskProgress }}%
@@ -164,6 +187,7 @@
        <el-table-column v-if="checkPer(['admin','taskUser:edit','taskUser:del'])" label="操作" width="150px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation
              v-if="userRolesLevelMin == roleLevelSuper || userRolesLevelMin == roleLevelGeneral || scope.row.projectLiableUserIdList.indexOf($store.state.user.user.id) != -1 || scope.row.userId == $store.state.user.user.id"
              :data="scope.row"
              :permission="permission"
            />
@@ -188,13 +212,14 @@
import crudProject from '@/api/project/project'
import crudTask from '@/api/task/task'
import crudUser from '@/api/system/user'
import DateRangePicker from '@/components/DateRangePicker'
const defaultForm = { id: null, userId: null, projectId: null, taskId: null, taskStartDate: null, taskEndDate: null, taskHours: null, taskWorkload: null, taskStatus: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null, divideUserIds: [] }
const defaultForm = { id: null, userId: null, projectId: null, taskId: null, taskStartDate: null, taskEndDate: null, taskHours: null, taskWorkload: null, taskStatus: null, enable1: false, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null, divideUserIds: [] }
export default {
  name: 'TaskUser',
  components: { pagination, crudOperation, rrOperation, udOperation },
  components: { pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.TASK_STATUS, constant.STANDARD_WORKLOAD_UNIT],
  dicts: [constant.TASK_STATUS, constant.STANDARD_WORKLOAD_UNIT, constant.PERFORMANCE_TYPE],
  cruds() {
    return CRUD({ title: '任务分配', url: 'api/taskUser', idField: 'id', sort: 'taskStartDate,desc', crudMethod: { ...crudTaskUser }})
  },
@@ -248,7 +273,8 @@
        { key: 'projectId', display_name: '所属项目' },
        { key: 'taskId', display_name: '所属任务' },
        { key: 'userId', display_name: '所属员工' },
        { key: 'taskStatus', display_name: '任务状态' }
        { key: 'taskStatus', display_name: '任务状态' },
        { key: 'createTime', display_name: '创建时间' }
      ],
      // 任务开始时间选项
      taskStartDatePickerOptions: {
@@ -268,8 +294,14 @@
      taskStatus: constant.TASK_STATUS,
      // 字典:标准工作量单位
      standardWorkloadUnit: constant.STANDARD_WORKLOAD_UNIT,
      // 字典:绩效对象
      performanceType: constant.PERFORMANCE_TYPE,
      // 字典:批准状态-未承认
      approveStatusUnrecognized: constant.APPROVE_STATUS_UNRECOGNIZED,
      // 角色级别:超级管理员
      roleLevelSuper: constant.ROLE_LEVEL_SUPER,
      // 角色级别:总经理
      roleLevelGeneral: constant.ROLE_LEVEL_GENERAL,
      // 角色级别:普通用户
      roleLevelOrdinary: constant.ROLE_LEVEL_ORDINARY,
      // CRUD状态
@@ -359,10 +391,81 @@
        })
      }
    },
    // 表格统计
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        // 6号单元格
        if (index === 6) {
          // 消耗工时
          let consumedHours = 0
          const consumedHoursValues = data.map(item => Number(item['consumedHours']))
          if (!consumedHoursValues.every(value => isNaN(value))) {
            consumedHours = consumedHoursValues.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
          }
          // 任务工时
          let taskHours = 0
          const taskHoursValues = data.map(item => Number(item['taskHours']))
          if (!taskHoursValues.every(value => isNaN(value))) {
            taskHours = taskHoursValues.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
          }
          sums[index] = consumedHours + ' / ' + taskHours
        }
        // 7号单元格
        if (index === 7) {
          // 消耗工作量
          let consumedWorkload = 0
          const consumedWorkloadValues = data.map(item => Number(item['consumedWorkload']))
          if (!consumedWorkloadValues.every(value => isNaN(value))) {
            consumedWorkload = consumedWorkloadValues.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
          }
          // 任务工作量
          let taskWorkload = 0
          const taskWorkloadValues = data.map(item => Number(item['taskWorkload']))
          if (!taskWorkloadValues.every(value => isNaN(value))) {
            taskWorkload = taskWorkloadValues.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
          }
          sums[index] = consumedWorkload + ' / ' + taskWorkload
        }
      })
      return sums
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToAdd]() {
      // 表单赋值
      this.form.taskWorkloadUnit = null
      this.form.taskPerformanceType = null
      // 表单任务列表
      this.formTasks = []
    },
    // 钩子:编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
@@ -370,8 +473,8 @@
      crudTask.getAll({ projectId: this.form.projectId }).then(res => {
        // 表单任务列表
        this.formTasks = res
        // 表单任务变更
        this.formTaskChange()
        // // 表单任务变更
        // this.formTaskChange()
      })
    },
    // 表单项目变更
@@ -400,6 +503,7 @@
          this.form.taskStartDate = this.formTasks[i].planStartTime
          this.form.taskEndDate = this.formTasks[i].planEndTime
          this.form.taskWorkloadUnit = this.formTasks[i].planWorkloadUnit
          this.form.taskPerformanceType = this.formTasks[i].performanceType
          break
        }
        // 判断循环是否结束
@@ -408,6 +512,7 @@
          this.form.taskStartDate = null
          this.form.taskEndDate = null
          this.form.taskWorkloadUnit = null
          this.form.taskPerformanceType = null
        }
      }
      // 判断是否是否是新增
@@ -420,6 +525,27 @@
        // 表单赋值
        this.form.divideUserIds = res
      })
    },
    // 钩子:提交 - 之前
    [CRUD.HOOK.beforeSubmit]() {
      this.form.enable = this.form.enable1
      // 判断用户角色
      if (this.userRolesLevelMin === this.roleLevelSuper || this.userRolesLevelMin === this.roleLevelGeneral) {
        return true
      } else {
        // 检索选中项目信息
        const chooseProject = this.projects.filter((item) => {
          return item.id === this.form.projectId
        })
        // 判断是否是项目责任人
        if ((chooseProject.length === 1 && chooseProject[0].liableUserIdList.indexOf(this.$store.state.user.user.id) !== -1) || this.form.userId === this.$store.state.user.user.id) {
          return true
        } else {
          // 消息提示
          this.crud.notify('您不是当前项目责任人,无法添加/修改任务分配', CRUD.NOTIFICATION_TYPE.WARNING)
          return false
        }
      }
    }
  }
}