yaozc
2023-07-24 5927ea578ac13e6e63bf74bbe83fc0d204c6a94c
eladmin-web-master/src/views/task/task/index.vue
@@ -4,32 +4,36 @@
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <el-select v-model="query.projectId" filterable placeholder="所属项目" style="width: 400px;" class="filter-item" @change="queryByProjectId">
        <el-select v-model="curProject" value-key="id" filterable placeholder="所属项目" style="width: 400px;" class="filter-item" @change="queryByProjectId">
          <el-option
            v-for="item in projects"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
            :value="item"
          >
            <span style="float: left">{{ item.name }}</span>
          </el-option>
        </el-select>
      </div>
      <div style="margin-bottom: 20px;">
        <el-card class="box-card">
          <el-descriptions title="项目信息">
            <el-descriptions-item label="用户名">kooriookami</el-descriptions-item>
            <el-descriptions-item label="手机号">18100000000</el-descriptions-item>
            <el-descriptions-item label="居住地">苏州市</el-descriptions-item>
            <el-descriptions-item label="备注">
              <el-tag size="small">学校</el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="联系地址">江苏省苏州市吴中区吴中大道 1188 号</el-descriptions-item>
          <el-descriptions title="项目信息" :column="3">
            <el-descriptions-item label="项目开始时间">{{ curProject === null ? '' : curProject.planStartDate }}</el-descriptions-item>
            <el-descriptions-item label="项目结束时间">{{ curProject === null ? '' : curProject.planEndDate }}</el-descriptions-item>
            <el-descriptions-item label="剩余天数">{{ curProject === null ? '0' : '0' }}</el-descriptions-item>
            <el-descriptions-item label="总任务数">{{ curProject === null ? '0' : curProject.totalTask }}</el-descriptions-item>
            <el-descriptions-item label="完成任务数">{{ curProject === null ? '0' : curProject.completeTask }}</el-descriptions-item>
            <el-descriptions-item label="任务完成比">{{ curProject === null ? '0%' : (curProject.completeTask / curProject.totalTask) * 100 + '%' }}</el-descriptions-item>
            <el-descriptions-item label="总工时数">{{ curProject === null ? '0.0' : curProject.totalHours }}</el-descriptions-item>
            <el-descriptions-item label="完成工时数">{{ curProject === null ? '0.0' : curProject.completeHours }}</el-descriptions-item>
            <el-descriptions-item label="工时完成比">{{ curProject === null ? '0%' : (curProject.completeHours / curProject.totalHours) * 100 + '%' }}</el-descriptions-item>
          </el-descriptions>
        </el-card>
      </div>
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-autocomplete v-model="query.name" class="filter-item" :fetch-suggestions="querySearch" placeholder="名称" style="width: 185px;" />
        <el-select v-model="query.taskStatus" filterable clearable placeholder="任务状态" style="width: 185px;" class="filter-item">
        <el-select v-model="query.taskStatuses" multiple collapse-tags filterable clearable placeholder="任务状态" style="width: 185px;" class="filter-item">
          <el-option
            v-for="item in dict[taskStatus]"
            :key="item.id"
@@ -45,7 +49,15 @@
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.userId" filterable clearable placeholder="所属员工" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
        <el-select v-model="query.tagList" multiple collapse-tags filterable clearable placeholder="任务分类" style="width: 185px;" class="filter-item">
          <el-option
            v-for="item in tags"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
        <el-select v-model="query.userIds" multiple collapse-tags filterable clearable placeholder="所属员工" style="width: 185px;" class="filter-item">
          <el-option
            v-for="item in users"
            :key="item.id"
@@ -61,7 +73,7 @@
      <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="projectId">
            <el-select v-model="form.projectId" disabled placeholder="请选择" style="width: 340px;" @change="projectChange">
            <el-select v-model="form.projectId" disabled placeholder="请选择" style="width: 340px;">
              <el-option
                v-for="item in projects"
                :key="item.id"
@@ -83,11 +95,10 @@
                :disabled="item.id == form.id"
              />
            </el-select>
            {{ form.parent.id }}
          </el-form-item>
          <el-form-item label="任务分类" prop="taskClassification">
            <el-tag
              v-for="(tag, id) in form.tags"
              v-for="(tag, id) in form.tagList"
              :key="id"
              closable
              :disable-transitions="false"
@@ -187,12 +198,19 @@
            <el-tag>{{ dict.label[performanceType][scope.row.performanceType] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="taskClassification" label="任务分类" width="160">
        <el-table-column :show-overflow-tooltip="true" prop="tagList" label="任务分类" width="240">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[taskClassification][scope.row.taskClassification] }}</el-tag>
            <template>
              <el-tag v-for="tag in scope.row.tagList" :key="tag">{{ tag }}</el-tag>
            </template>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="description" label="描述" width="180" />
        <el-table-column :show-overflow-tooltip="true" prop="tagList" label="任务负责人" width="240">
          <template slot-scope="scope">
            <el-tag v-for="userId in scope.row.userIdList" :key="userId">{{ getUserNameById(userId) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="description" label="描述" />
        <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" />
@@ -216,7 +234,7 @@
import crudUser from '@/api/system/user'
import crudProject from '@/api/project/project'
const defaultForm = { id: null, name: null, projectId: null, userIdList: [], parent: { id: null }, priority: null, tags: [], performanceType: null, description: null, planStartTime: null, planEndTime: null, planHours: null, pieceRate: 0, planWorkload: 0, planWorkloadUnit: null, taskStatus: null, remarks: null, version: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
const defaultForm = { id: null, name: null, projectId: null, userIdList: [], parent: { id: null }, priority: null, tagList: [], performanceType: null, description: null, planStartTime: null, planEndTime: null, planHours: null, pieceRate: 0, planWorkload: 0, planWorkloadUnit: null, taskStatus: null, remarks: null, version: null }
export default {
  name: 'Task',
  components: { pagination, crudOperation, rrOperation, udOperation },
@@ -314,6 +332,8 @@
      userRolesLevelMin: null,
      // 项目列表
      projects: [],
      // 当前项目
      curProject: null,
      // 父级任务列表
      pidTasks: [],
      // 员工列表
@@ -348,15 +368,29 @@
      return true
    },
    [CRUD.HOOK.beforeSubmit]() {
      if (this.form.parent.id === null || this.form.parent.id === '') {
      if (!this.form.taskStatus) {
        this.form.taskStatus = 'task_status_not_started'
      }
      if (this.form.parent.id === undefined || this.form.parent.id === null || this.form.parent.id === '') {
        this.form.parent = null
      }
      return true
    },
    queryByProjectId(projectId) {
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToCU]() {
      this.form.projectId = this.crud.query.projectId
      // 父级任务列表
      this.pidTasks = []
      crudTask.getAll({ projectId: this.form.projectId }).then(res => {
        // 父级任务列表
        this.pidTasks = res
      })
    },
    queryByProjectId(project) {
      this.crud.resetQuery(false)
      this.crud.query.projectId = projectId
      this.crud.query.projectId = project.id
      this.crud.toQuery()
      this.getProjectTotal()
    },
    getTags() {
      crudTask.getTags().then(res => {
@@ -365,7 +399,7 @@
      })
    },
    handleClose(id) {
      this.form.tags.splice(id, 1)
      this.form.tagList.splice(id, 1)
    },
    showInput() {
      this.inputVisible = true
@@ -376,7 +410,7 @@
    handleInputConfirm() {
      const inputValue = this.inputValue
      if (inputValue) {
        this.form.tags.push(inputValue)
        this.form.tagList.push(inputValue)
      }
      this.inputVisible = false
      this.inputValue = ''
@@ -402,10 +436,17 @@
        this.users = res
      })
    },
    getUserNameById(userId) {
      const userList = this.users.filter(user => user.id === userId)
      return userList.length === 0 ? '' : userList[0].nickName
    },
    // 获取项目
    getProject() {
      // 获取项目
      crudProject.getRelevant().then(res => {
      crudProject.getRelevant({
        'projectStatusIn': ['project_status_not_started', 'project_status_under_way'],
        'approve_status': 'approve_status_acknowledged'
      }).then(res => {
        // 项目列表
        this.projects = res
      })
@@ -414,14 +455,28 @@
    load(tree, treeNode, resolve) {
      resolve(tree.children)
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToCU]() {
      this.form.projectId = this.crud.query.projectId
      // 父级任务列表
      this.pidTasks = []
      crudTask.getAll({ projectId: this.form.projectId }).then(res => {
        // 父级任务列表
        this.pidTasks = res
    getProjectTotal() {
      this.curProject.totalTask = 0
      this.curProject.totalHours = 0.0
      this.curProject.completeTask = 0
      this.curProject.completeHours = 0.0
      crudTask.getProjectTotal({ 'projectId': this.crud.query.projectId }).then(res => {
        let totalTask = 0
        let totalHours = 0.0
        let completeTask = 0
        let completeHours = 0.0
        res.forEach(item => {
          totalTask += item.count
          totalHours += item.planHours
          if (item._id === 'task_status_completed') {
            completeTask += item.count
            completeHours += item.planHours
          }
        })
        this.curProject.totalTask = totalTask
        this.curProject.totalHours = totalHours
        this.curProject.completeTask = completeTask
        this.curProject.completeHours = completeHours
      })
    },
    // 项目变更