From 6b1c6be17e4c0cbb9bf0bc76d2c4c18b996496c7 Mon Sep 17 00:00:00 2001
From: churf <123456>
Date: Wed, 23 Aug 2023 06:49:44 +0000
Subject: [PATCH] 表单校验效果优化
---
eladmin-web-master/src/views/task/taskDaliy/index.vue | 106 +++++++++++++++++++++++++++++-----------------------
1 files changed, 59 insertions(+), 47 deletions(-)
diff --git a/eladmin-web-master/src/views/task/taskDaliy/index.vue b/eladmin-web-master/src/views/task/taskDaliy/index.vue
index a1e14f3..974cec6 100644
--- a/eladmin-web-master/src/views/task/taskDaliy/index.vue
+++ b/eladmin-web-master/src/views/task/taskDaliy/index.vue
@@ -180,7 +180,7 @@
:value="item.id"
/>
</el-select>
- <el-select v-else filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
+ <el-select v-else v-model="form" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
<el-option
v-for="item in formTaskUserIds"
:key="item.id"
@@ -218,7 +218,7 @@
</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>
+ <el-button :loading="crud.status.cu === 2" type="primary" @click="checkForm(1)">确认</el-button>
</div>
</el-dialog>
<!--表格渲染-->
@@ -442,6 +442,12 @@
'form.consumedHours': function(newVal, oldVal) {
this.newValue = newVal
this.oldValue = oldVal
+ },
+ 'confirmProgress': function(newVal) {
+ this.confirmProgress = newVal
+ },
+ 'confirmHours': function(newVal) {
+ this.confirmHours = newVal
}
},
methods: {
@@ -584,33 +590,58 @@
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
- })()
+ checkForm(flag) {
+ crudTaskDaliy.checkTaskHours({ 'taskProgress': this.form.taskProgress, 'taskUserId': this.form.taskUserMongo.id, 'fillDate': this.form.fillDate }).then(res => {
+ if (res === false && !this.confirmProgress) {
+ flag++
+ // 为假
+ this.centerDialogVisibleTaskProgress = true
+ if (this.confirmProgress) {
+ // 如果确定了
+ const result = (this.form.alreadyConsumedHours - 0) + (this.newValue - 0) - (this.oldValue - 0)
+ if (result > this.form.taskHours && !this.confirmHours) {
+ this.centerDialogVisibleTaskHours = true
+ if (this.confirmHours) {
+ this.crud.submitCU()
+ } else {
+ if (flag > 1) {
+ return
+ } else {
+ this.checkForm()
+ }
+ }
+ } else {
+ this.crud.submitCU()
+ }
+ } else {
+ if (flag > 1) {
+ return
+ } else {
+ // 没确定
+ this.checkForm()
+ }
+ }
+ } else {
+ flag++
+ // 判读时间
+ const result = (this.form.alreadyConsumedHours - 0) + (this.newValue - 0) - (this.oldValue - 0)
+ if (result > this.form.taskHours && !this.confirmHours) {
+ this.centerDialogVisibleTaskHours = true
+ if (this.confirmHours) {
+ this.crud.submitCU()
+ } else {
+ if (flag > 1) {
+ return
+ } else {
+ this.checkForm()
+ }
+ }
+ } else {
+ this.crud.submitCU()
+ }
+ }
+ })
},
getAdventTasks() {
crudTaskUser.getAdventTasks().then(res => {
@@ -755,25 +786,6 @@
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())
- }
- })
- })
}
}
}
--
Gitblit v1.9.3