From d0c51ac702c57f2cae84a8d879a5b605f2dab630 Mon Sep 17 00:00:00 2001
From: weicd <weicd@yhzhg.cn>
Date: Thu, 28 Sep 2023 09:50:45 +0000
Subject: [PATCH] 修改

---
 eladmin-web-master/src/views/task/task/index.vue |  288 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 262 insertions(+), 26 deletions(-)

diff --git a/eladmin-web-master/src/views/task/task/index.vue b/eladmin-web-master/src/views/task/task/index.vue
index f770db3..0d92017 100644
--- a/eladmin-web-master/src/views/task/task/index.vue
+++ b/eladmin-web-master/src/views/task/task/index.vue
@@ -23,10 +23,10 @@
             <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%' : (parseFloat((curProject.completeTask / curProject.totalTask) * 100) ).toFixed(2)+ '%' }}</el-descriptions-item>
+            <el-descriptions-item label="任务完成比">{{ isNaN(curProject === null ? '0%' : (parseFloat((curProject.completeTask / curProject.totalTask) * 100)).toFixed(2)) ? 0 : curProject === null ? '0%' : (parseFloat((curProject.completeTask / curProject.totalTask) * 100)).toFixed(2) + '%' }}</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%' : (parseFloat((curProject.completeHours / curProject.totalHours) * 100)).toFixed(2) + '%' }}</el-descriptions-item>
+            <el-descriptions-item label="工时完成比">{{ isNaN(curProject === null ? '0%' : (parseFloat((curProject.completeHours / curProject.totalHours) * 100)).toFixed(2)) ? 0 : curProject === null ? '0%' : (parseFloat((curProject.completeHours / curProject.totalHours) * 100)).toFixed(2) + '%' }}</el-descriptions-item>
           </el-descriptions>
         </el-card>
       </div>
@@ -57,18 +57,40 @@
             :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"
-            :label="item.nickName"
-            :value="item.id"
+        <div class="block">
+          <el-cascader
+            v-model="query.userIds"
+            :options="options"
+            clearable
+            placeholder="任务负责人"
+            :show-all-levels="false"
+            style="width: 185px;"
           />
-        </el-select>
+        </div>
         <rrOperation :crud="crud" />
       </div>
+
+      <el-dialog
+        title="任务详情"
+        :visible.sync="dialogVisible"
+        width="800px"
+        @closed="calendarLoading = true"
+        @opened="monthClick('')"
+      >
+        <FullCalendar ref="fullCalendar" v-loading="calendarLoading" :options="calendarOptions" />
+      </el-dialog>
+
       <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
-      <crudOperation v-if="this.crud.query.flag" :permission="permission" />
+      <crudOperation v-if="this.crud.query.flag" :permission="permission">
+        <el-button
+          slot="right"
+          class="filter-item"
+          size="mini"
+          type="primary"
+          :disabled="taskDetailDisabled"
+          @click="draw"
+        >任务详情</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="500px">
         <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
@@ -141,31 +163,34 @@
             </el-input>
           </el-form-item>
           <el-form-item label="任务成员" prop="containUserList">
-            <el-select v-model="form.containUserList" multiple filterable clearable placeholder="请选择" style="width: 340px;" @change="getContainUserList">
-              <el-option
-                v-for="item in users"
-                :key="item.id"
-                :label="item.nickName"
-                :value="item.id"
-              >
-                <span style="float: left">{{ item.nickName }}</span>
-                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.levelName }}</span>
-              </el-option>
-            </el-select>
+            <div class="block">
+              <el-cascader
+                v-model="selectedValue"
+                :filterable="true"
+                :options="options"
+                :props="props"
+                clearable
+                placeholder="任务成员"
+                :show-all-levels="false"
+                style="width: 340px;"
+              />
+            </div>
           </el-form-item>
           <el-form-item label="任务负责人" prop="userId">
-            <el-select v-model="form.userIdList" :no-data-text=" '没有任务成员' " multiple filterable clearable placeholder="请选择" style="width: 340px;">
+            <el-select v-if="form.containUserList" v-model="form.userIdList" :no-data-text=" '没有任务成员' " multiple filterable clearable placeholder="请选择" style="width: 340px;">
               <el-option
                 v-for="item in users"
                 v-show="form.containUserList != undefined && form.containUserList.some(animal => animal === item.id)"
                 :key="item.id"
                 :label="item.nickName"
                 :value="item.id"
+                :show-all-levels="false"
               >
                 <span style="float: left">{{ item.nickName }}</span>
                 <span style="float: right; color: #8492a6; font-size: 13px">{{ item.levelName }}</span>
               </el-option>
             </el-select>
+            <el-select v-else v-model="form.userIdList" :no-data-text=" '没有任务成员' " multiple filterable clearable placeholder="请选择" style="width: 340px;" />
           </el-form-item>
         </el-form>
         <div slot="footer" class="dialog-footer">
@@ -238,11 +263,15 @@
 import constant from '@/utils/constant'
 import crudUser from '@/api/system/user'
 import crudProject from '@/api/project/project'
+import '@fullcalendar/core/vdom'
+import FullCalendar from '@fullcalendar/vue'
+import dayGridPlugin from '@fullcalendar/daygrid'
+import moment from 'moment'
 
 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 },
+  components: { pagination, crudOperation, rrOperation, udOperation, FullCalendar },
   mixins: [presenter(), header(), form(defaultForm), crud()],
   dicts: [constant.PRIORITY, constant.TAST_CLASSIFICATION, constant.PERFORMANCE_TYPE, constant.STANDARD_WORKLOAD_UNIT, constant.TASK_STATUS],
   cruds() {
@@ -261,6 +290,7 @@
       }
     }
     return {
+      props: { multiple: true },
       permission: {
         add: ['admin', 'task:add'],
         edit: ['admin', 'task:edit'],
@@ -300,6 +330,89 @@
         taskStatus: [
           { required: true, message: '任务状态不能为空', trigger: 'change' }
         ]
+      },
+      calendarOptions: {
+        // 引入的插件
+        plugins: [dayGridPlugin],
+        // 日历头部按钮位置
+        headerToolbar: {
+          left: '',
+          center: 'title',
+          right: 'prev,today,next'
+        },
+        // 日历头部按钮中文转换
+        buttonText: {
+          today: '今天',
+          month: '月',
+          week: '周',
+          day: '天'
+        },
+        initialView: 'dayGridMonth',
+        locale: 'zh-ch',
+        firstDay: '1',
+        weekNumberCalculation: 'ISO',
+        eventColor: '#3d8eec',
+        timeGridEventMinHeight: '20',
+        aspectRatio: '1.5',
+        displayEventTime: false,
+        validRange: {},
+        allDaySlot: false,
+        eventLimit: true,
+        fixedWeekCount: false,
+        // eslint-disable-next-line no-dupe-keys
+        eventTimeFormat: {
+          hour: 'numeric',
+          minute: '2-digit',
+          hour12: false
+        },
+        slotLabelFormat: {
+          hour: '2-digit',
+          minute: '2-digit',
+          meridiem: false,
+          hour12: false
+        },
+        businessHours: {
+          dow: [1, 2, 3, 4, 5],
+          start: '0:00',
+          end: '24:00'
+        },
+        events: [],
+        // 事件
+        editable: false,
+        eventStartEditable: false,
+        eventDurationEditable: false,
+        selectable: false,
+        selectMirror: true,
+        selectMinDistance: 0,
+        weekends: true,
+        navLinks: true,
+        selectHelper: false,
+        selectEventOverlap: false,
+        dayMaxEvents: true,
+        // dateClick: this.handleDateClick, // 点击日期触发
+        // eventsSet: this.handleEvents,
+        // eventClick: this.handleEventClick, // 点击日程触发
+        // eventDrop: this.handleEventDrop,
+        eventResize: this.eventResize,
+        height: 'auto',
+        customButtons: {
+          prev: {
+            click: () => {
+              this.monthClick('prev')
+            }
+          },
+          today: {
+            text: '今天',
+            click: () => {
+              this.monthClick('')
+            }
+          },
+          next: {
+            click: () => {
+              this.monthClick('next')
+            }
+          }
+        }
       },
       queryTypeOptions: [
         { key: 'name', display_name: '名称' },
@@ -354,7 +467,42 @@
       // tag标签
       inputVisible: false,
       inputValue: null,
-      containUserList: []
+      containUserList: [],
+      userList: [],
+      options: [],
+      selectedValue: [],
+      queryUser: [],
+      dialogVisible: false,
+      taskDetailDisabled: true,
+      calendarLoading: true
+    }
+  },
+  watch: {
+    'selectedValue': function(newVal) {
+      this.form.containUserList = []
+      for (let i = 0; i < newVal.length; i++) {
+        var temp = []
+        temp = newVal[i]
+        if (!this.form.containUserList.includes(temp[newVal[i].length - 1])) {
+          // 如果不在
+          this.form.containUserList.push(temp[newVal[i].length - 1])
+        }
+      }
+    },
+    'crud.selections': function(newVal) {
+      this.taskDetailDisabled = true
+      if (newVal.length === undefined) {
+        this.taskDetailDisabled = false
+      }
+      if (newVal.length > 1) {
+        this.taskDetailDisabled = true
+      }
+      if (newVal.length === 1) {
+        this.taskDetailDisabled = false
+      }
+    },
+    'queryUser': function(newVal) {
+      // this.query.userId = newVal[newVal.length - 1]
     }
   },
   created() {
@@ -368,8 +516,27 @@
     this.getTags()
   },
   methods: {
+    [CRUD.HOOK.afterSubmit]() {
+      this.form.containUserList = []
+      this.selectedValue = null
+    },
+    [CRUD.HOOK.afterEditError]() {
+      this.form.containUserList = []
+      this.selectedValue = null
+    },
+    [CRUD.HOOK.afterEditCancel]() {
+      this.form.containUserList = []
+      this.selectedValue = null
+    },
+    [CRUD.HOOK.afterAddCancel]() {
+      this.form.containUserList = []
+      this.selectedValue = null
+    },
+    [CRUD.HOOK.afterAddError]() {
+      this.form.containUserList = []
+      this.selectedValue = null
+    },
     getContainUserList(e) {
-      console.log(e)
       this.form.containUserList = e
     },
     getTags() {
@@ -386,7 +553,13 @@
       const userRolesLevel = this.$store.state.user.user.roles.map(({ level }) => level)
       // 用户最大角色级别
       this.userRolesLevelMin = Math.min(...userRolesLevel)
+
       return true
+    },
+    [CRUD.HOOK.beforeToEdit]() {
+      crudUser.getUserPidDept(this.form.containUserList).then(res => {
+        this.selectedValue = res
+      })
     },
     [CRUD.HOOK.beforeSubmit]() {
       if (!this.form.taskStatus) {
@@ -409,6 +582,50 @@
       crudTask.getAll({ projectId: this.form.projectId }).then(res => {
         // 父级任务列表
         this.pidTasks = res
+      })
+    },
+    // 日期点击
+    handleDateClick(selectInfo) {
+      console.log('handleDateClick.info:', selectInfo)
+    },
+    handleEventClick(info) {
+      if (info.event._def.extendedProps.type === 1) {
+        this.$router.push({
+          path: '/attendance/attendance',
+          query: { date: info.event._def.extendedProps.date1 }
+        })
+      } else {
+        this.$router.push({ path: '/task/taskDaliy', query: { date: info.event._def.extendedProps.date1 }})
+      }
+    },
+    // 箭头点击事件
+    monthClick(type) {
+      if (this.crud.selections[0].id !== null) {
+        crudTask.getTaskValidRange(this.crud.selections[0].id).then(res => {
+          this.calendarOptions.validRange = res
+
+          const calendarApi = this.$refs['fullCalendar'].getApi()
+          if (type === 'prev') {
+            calendarApi.prev()
+          } else if (type === 'next') {
+            calendarApi.next()
+          } else {
+            calendarApi.gotoDate(res.start)
+          }
+          this.getTaskCalendarInfo(moment(calendarApi.view.currentStart).format('YYYY-MM-DD').toString())
+          this.calendarLoading = false
+        })
+      }
+    },
+    // 获取任务信息
+    getTaskCalendarInfo(month) {
+      crudTask.getTaskCalendarInfo(month, this.crud.selections[0].id).then(res => {
+        this.calendarOptions.events = res.map(function(obj) {
+          return obj
+        })
+        setTimeout(() => {
+          console.log(this.calendarOptions.events)
+        }, 1000)
       })
     },
     queryByProjectId(project) {
@@ -440,7 +657,8 @@
     },
     handleInputConfirm() {
       const inputValue = this.inputValue
-      if (inputValue !== '') {
+      console.log(inputValue)
+      if (inputValue !== '' && inputValue !== null && inputValue !== ' ') {
         this.form.tagList.push(inputValue)
       }
       this.inputVisible = false
@@ -465,6 +683,10 @@
       crudUser.getAll().then(res => {
         // 用户列表
         this.users = res
+      })
+
+      crudUser.getUserDept().then(res => {
+        this.options = res
       })
     },
     getUserNameById(userId) {
@@ -535,6 +757,9 @@
         results = await crudTask.getNames({ projectId: this.crud.query.projectId, name: queryString })
         cb(results)
       }
+    },
+    draw() {
+      this.dialogVisible = true
     }
   }
 }
@@ -556,4 +781,15 @@
     margin-left: 10px;
     vertical-align: bottom;
   }
+
+  .block{
+    display: inline-block;
+    vertical-align: middle;
+    margin: 0 3px 10px 0;
+
+      input {
+      height: 30.5px;
+      line-height: 30.5px;
+      }
+    }
 </style>

--
Gitblit v1.9.3