Browse Source

薪资调整-表单验证

jingbb 1 year ago
parent
commit
dab631591a

+ 38 - 19
src/views/oa/salary_management/personnelSalary/modules/ChangeBasicSalary.vue

@@ -81,8 +81,8 @@
               visible:false,
               loading:false,
               validatorRules: {
-                salaryIncrease: [{required: true}],
-                salaryReduction: [{required: true}],
+                salaryIncrease: [{required: true,message: '请输入!'}],
+                salaryReduction: [{required: true,message: '请输入!'}],
               },
           }
         },
@@ -94,24 +94,29 @@
             handleCancel(){
                 this.visible = false
                 this.formState = {}
+                this.validatorRules.salaryReduction[0].required = true
+                this.validatorRules.salaryIncrease[0].required = true
+                this.RlabelCol={offset: 1 }
+                this.IlabelCol={offset: 1 }
             },
             handleOk(){
-                if((!this.formState.salaryIncrease||this.formState.salaryIncrease=='')&&(!this.formState.salaryReduction||this.formState.salaryReduction=='')){
-                    this.$message.warning("请输入'加薪'或者'减薪'!")
-                }else{
-                    this.loading = true
-                    postAction('/salary/salaryChangeRecord/saveSalaryChangeRecord', this.formState).then((res) => {
-                        if (res.success) {
-                            this.$message.success('添加成功!');
-                            this.handleCancel()
-                            this.$emit('ok')
-                        } else {
-                            this.$message.error(res.message);
-                        }
-                    }).finally(() => {
-                        this.loading = false
-                    })
-                }
+                this.$refs.form.validate(valid => {
+                    if (valid) {
+                        this.loading = true
+                        postAction('/salary/salaryChangeRecord/saveSalaryChangeRecord', this.formState).then((res) => {
+                            if (res.success) {
+                                this.$message.success('添加成功!');
+                                this.handleCancel()
+                                this.$emit('ok')
+                            } else {
+                                this.$message.error(res.message);
+                            }
+                        }).finally(() => {
+                            this.loading = false
+                        })
+                    }
+                })
+                    
             },
             getData(record){
                 this.formState={
@@ -128,11 +133,25 @@
                     cardNo:record.cardNo,
                 }
             },
-            changeSalaryIncrease(){
+            changeSalaryIncrease(data){
                 this.formState.afterAdjustment=Number(this.formState.beforeAdjustment)+Number(this.formState.salaryIncrease)
+                if(!this.formState.salaryIncrease||this.formState.salaryIncrease==''){
+                    this.validatorRules.salaryReduction[0].required = true
+                }else{
+                    this.validatorRules.salaryReduction[0].required = false
+                }
+                this.validatorRules.salaryIncrease[0].required = true
+                this.$refs.form.clearValidate();
             },
             changeSalaryReduction(){
                 this.formState.afterAdjustment=Number(this.formState.beforeAdjustment)-Number(this.formState.salaryReduction)
+                if(!this.formState.salaryReduction||this.formState.salaryReduction==''){
+                    this.validatorRules.salaryIncrease[0].required = true
+                }else{
+                    this.validatorRules.salaryIncrease[0].required = false
+                }
+                this.validatorRules.salaryReduction[0].required = true
+                this.$refs.form.clearValidate();
             }
         }
     }