churf
2023-08-23 bc5cdaed182da3914fdb215fe73d3755b06c3ea6
eladmin-web-master/src/views/task/taskDaliy/index.vue
@@ -172,7 +172,15 @@
            </el-select>
          </el-form-item>
          <el-form-item label="分配任务" prop="taskUserMongo">
            <el-select v-model="form.taskUserMongo.id" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
            <el-select v-if="formTaskUserIds.length > 0" :key="form.taskUserMongo.id" v-model="form.taskUserMongo.id" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
              <el-option
                v-for="item in formTaskUserIds"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
            <el-select v-else filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
              <el-option
                v-for="item in formTaskUserIds"
                :key="item.id"
@@ -259,6 +267,32 @@
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="提示"
        :visible.sync="centerDialogVisibleTaskHours"
        width="30%"
        center
      >
        <span>本次日报的消耗工时已超过任务工时,确定要继续吗?</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisibleTaskHours = false">取 消</el-button>
          <el-button type="primary" @click="submitDialogTaskHours">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="提示"
        :visible.sync="centerDialogVisibleTaskProgress"
        width="30%"
        center
      >
        <span>本次日报的任务进度比您原本的任务进度要少,确定要继续吗?</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisibleTaskProgress = false">取 消</el-button>
          <el-button type="primary" @click="submitDialogTaskProgress">确 定</el-button>
        </span>
      </el-dialog>
      <!--分页组件-->
      <pagination />
    </div>
@@ -389,13 +423,26 @@
      tobeTask: '未着手任务',
      tobeTasked: '临期任务',
      currentTask: null,
      taskLoading: true
      taskLoading: true,
      centerDialogVisibleTaskHours: false,
      centerDialogVisibleTaskProgress: false,
      confirmHours: false,
      confirmProgress: false,
      newValue: '',
      oldValue: '',
      resData: true
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  watch: {
    'form.consumedHours': function(newVal, oldVal) {
      this.newValue = newVal
      this.oldValue = oldVal
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
@@ -425,6 +472,145 @@
      this.getOngoingTasks()
      this.getTaskNotStarted()
      return true
    },
    // 新增与编辑前做的操作
    [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.afterSubmit]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterEditError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterEditCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterAddCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterAddError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToAdd]() {
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      // 判断用户最大角色级别是否是角色级别:超级管理员或角色级别:总经理
      if (this.userRolesLevelMin !== this.roleLevelSuper && this.userRolesLevelMin !== this.roleLevelGeneral) {
        // 表单赋值
        this.form.userId = this.user.id
        this.form.userNickName = this.user.nickName
        // 表单用户变更
        this.formUserChange()
        this.formTaskChange()
      }
      if (this.currentTask) {
        this.form.projectId = this.currentTask.projectId
        this.formProjectChange(() => {
          this.form.taskId = this.currentTask.taskId
          this.formTaskChange(() => { this.form.taskUserMongo.id = this.currentTask.id })
        })
        this.form.taskHours = this.currentTask.performanceHours
        this.form.alreadyConsumedHours = this.currentTask.alreadyConsumedHours
        this.form.flag = true
      }
    },
    // 钩子:编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      crudTask.getAllOfDaily({ projectId: this.form.projectId }).then(res => {
        // 检索任务列表
        this.formTasks = res
      })
      crudTaskUser.getAllTaskUser().then(res => {
        if (res === []) {
          this.formTaskUserIds = []
        }
        this.formTaskUserIds = res
        // 循环表单任务列表
        for (let i = 0; i < this.formTaskUserIds.length; i++) {
          // 判断是否为选中任务
          if (this.formTaskUserIds[i].id === this.form.taskUserMongo.id) {
            this.form.taskHours = this.formTaskUserIds[i].performanceHours
            this.form.alreadyConsumedHours = this.formTaskUserIds[i].alreadyConsumedHours
          }
        }
      })
    },
    [CRUD.HOOK.afterRefresh]() {
      this.taskLoading = false
    },
    [CRUD.HOOK.beforeSubmit]() {
      // 先check一下
      this.resData = this.getCheckResult(this.form.taskProgress, this.form.taskUserMongo.id)
      console.log(2)
      console.log(this.resData)
      if (this.resData === false && !this.confirmProgress) {
        // 为假
        this.centerDialogVisibleTaskProgress = true
        this.waitForPropertyConfirmProgress()
        return false
      }
      const result = (this.form.alreadyConsumedHours - 0) + (this.newValue - 0) - (this.oldValue - 0)
      if (result > this.form.taskHours && !this.confirmHours) {
        this.centerDialogVisibleTaskHours = true
        this.waitForPropertyConfirmHours()
        return false
      }
      return true
    },
    getCheckResult(taskProgress, taskUserId) {
      return (async function() {
        console.log(1)
        const result = await crudTaskDaliy.checkTaskHours({ 'taskProgress': taskProgress, 'taskUserId': taskUserId })
        console.log(3)
        return result
      })()
    },
    getAdventTasks() {
      crudTaskUser.getAdventTasks().then(res => {
@@ -479,103 +665,11 @@
        })
      }
    },
    // 新增与编辑前做的操作
    [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.afterSubmit]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    [CRUD.HOOK.afterEditError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    [CRUD.HOOK.afterEditCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    [CRUD.HOOK.afterAddCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    [CRUD.HOOK.afterAddError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToAdd]() {
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      // 判断用户最大角色级别是否是角色级别:超级管理员或角色级别:总经理
      if (this.userRolesLevelMin !== this.roleLevelSuper && this.userRolesLevelMin !== this.roleLevelGeneral) {
        // 表单赋值
        this.form.userId = this.user.id
        this.form.userNickName = this.user.nickName
        // 表单用户变更
        this.formUserChange()
        this.formTaskChange()
      }
      if (this.currentTask) {
        this.form.projectId = this.currentTask.projectId
        this.formProjectChange(() => {
          this.form.taskId = this.currentTask.taskId
          this.formTaskChange(() => { this.form.taskUserMongo.id = this.currentTask.id })
        })
        this.form.taskHours = this.currentTask.performanceHours
        this.form.alreadyConsumedHours = this.currentTask.alreadyConsumedHours
        this.form.flag = true
      }
    },
    // 钩子:编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      crudTask.getAllOfDaily({ projectId: this.form.projectId }).then(res => {
        // 检索任务列表
        this.formTasks = res
      })
      crudTaskUser.getAllTaskUser().then(res => {
        if (res === []) {
          this.formTaskUserIds = []
        }
        this.formTaskUserIds = res
        // 循环表单任务列表
        for (let i = 0; i < this.formTaskUserIds.length; i++) {
          // 判断是否为选中任务
          if (this.formTaskUserIds[i].id === this.form.taskUserMongo.id) {
            this.form.taskHours = this.formTaskUserIds[i].performanceHours
            this.form.alreadyConsumedHours = this.formTaskUserIds[i].alreadyConsumedHours
          }
        }
      })
    },
    formDateChange() {
      crudTaskDaliy.getDailyDetail({ taskUserId: this.form.taskUserMongo.id, fillDate: this.form.fillDate }).then(res => {
        this.form.taskProgress = res.taskProgress
        this.form.consumedHours = res.consumedHours
        this.form.remarks = res.remarks
      })
    },
    // 表单用户变更
@@ -613,7 +707,6 @@
        crudTask.getAllOfDaily({ projectId: this.form.projectId }).then(res => {
          // 检索任务列表
          this.formTasks = res
          if (cb) {
            cb()
          }
@@ -655,8 +748,32 @@
      this.currentTask = object
      this.crud.toAdd()
    },
    [CRUD.HOOK.afterRefresh]() {
      this.taskLoading = false
    submitDialogTaskHours() {
      this.centerDialogVisibleTaskHours = false
      this.confirmHours = true
    },
    submitDialogTaskProgress() {
      this.centerDialogVisibleTaskProgress = false
      this.confirmProgress = true
    },
    waitForPropertyConfirmHours() {
      new Promise(resolve => {
        this.$watch('confirmHours', (newValue) => {
          if (newValue === true) {
            console.log(newValue)
            resolve(this.crud.submitCU())
          }
        })
      })
    },
    waitForPropertyConfirmProgress() {
      new Promise(resolve => {
        this.$watch('confirmProgress', (newValue) => {
          if (newValue === true) {
            resolve(this.crud.submitCU())
          }
        })
      })
    }
  }
}