Ver código fonte

物资登记单表单验证

jbb 2 anos atrás
pai
commit
e2a71031a4

+ 1 - 1
src/views/system/MaterialRegistration.vue

@@ -268,7 +268,7 @@ import moment from 'moment'
                     // console.log('>>>>', this.queryParam)
                     if (res.success) {
                      this.$refs.AddMaterialRegistration.formState = res.result
-                     this.$refs.AddMaterialRegistration.buyTime = moment( res.result.buyTime)
+                     this.$refs.AddMaterialRegistration.formState.buyTime = moment( res.result.buyTime)
                     }else{
                        this.$message.error(res.message);
                     }

+ 18 - 16
src/views/system/modules/AddMaterialRegistration.vue

@@ -25,22 +25,22 @@
               </a-form-model-item>
             </a-col>
             <a-col :md="6" :sm="8">
-              <a-form-model-item label="型号"  >
+              <a-form-model-item label="型号"  prop="model" >
                 <a-input placeholder="请输入" v-model="formState.model"/>
               </a-form-model-item>
             </a-col>
-            <a-col :md="6" :sm="8">
+            <a-col :md="6" :sm="8" >
               <a-form-model-item label="购买日期" prop="buyTime" >
-                 <a-date-picker   style="width: 100%" placeholder="请选择购买日期" v-model="buyTime" />
+                 <a-date-picker   style="width: 100%" placeholder="请选择购买日期" v-model="formState.buyTime" />
               </a-form-model-item>
             </a-col>
-            <a-col :md="6" :sm="8">
+            <a-col :md="6" :sm="8" >
               <a-form-model-item label="购买数量"  prop="buyNum" >
                  <a-input placeholder="请输入购买数量" v-model="formState.buyNum"/>
               </a-form-model-item>
             </a-col>
-            <a-col :md="6" :sm="8">
-              <a-form-model-item label="单位"  >
+            <a-col :md="6" :sm="8"  >
+              <a-form-model-item label="单位"  prop="unit">
                 <a-input placeholder="请输入单位" v-model="formState.unit"/>
               </a-form-model-item>
             </a-col>
@@ -50,22 +50,22 @@
               </a-form-model-item>
             </a-col>
             <a-col :md="6" :sm="8">
-              <a-form-model-item label="使用者" prop="useId" >
+              <a-form-model-item label="使用者" prop="useId">
                 <a-input placeholder="请输入" v-model="formState.useId"/>
                </a-form-model-item>
             </a-col>
             <a-col :md="6" :sm="8">
-              <a-form-model-item label="状态"  >
+              <a-form-model-item label="状态"   prop="type">
                   <a-input placeholder="请输入" v-model="formState.type"/>
               </a-form-model-item>
             </a-col>
             <a-col :md="6" :sm="8">
-              <a-form-model-item label="供货方"  >
+              <a-form-model-item label="供货方"   prop="supply">
                  <a-input placeholder="请输入供货方" v-model="formState.supply"/>
               </a-form-model-item>
             </a-col>
             <a-col :md="6" :sm="8">
-              <a-form-model-item label="来源"  >
+              <a-form-model-item label="来源"  prop="source">
                  <a-input placeholder="请输入来源" v-model="formState.source"/>
               </a-form-model-item>
             </a-col>
@@ -307,12 +307,18 @@ export default {
          validatorRules: {
            code:[{required: true, message: '编号不能为空!'}],
            name:[{required: true, message: '设备名称不能为空!'}],
+           model:[{required: true, message: '型号不能为空!'}],
+           buyTime:[{required: true, message: '购买日期不能为空!'}],
+           unit:[{required: true, message: '单位不能为空!'}],
            buyNum:[
              {required: true, message: '购买数量不能为空!'},
              { pattern: new RegExp(/^[1-9]\d*$/, "g"), message: '购买数量只能输入数字!'}
            ],
-           amount:[ { pattern: new RegExp(/^[1-9]\d*$/, "g"), message: '购买金额只能输入数字!'}],
+           amount:[ {required: true, message: '购买金额不能为空!'}, { pattern: new RegExp(/^[1-9]\d*$/, "g"), message: '购买金额只能输入数字!'}],
            useId:[{required: true, message: '使用者不能为空!'}],
+           type:[{required: true, message: '状态不能为空!'}],
+           supply:[{required: true, message: '供货方不能为空!'}],
+           source:[{required: true, message: '来源不能为空!'}],
         },
         List:[],
         List1:[],
@@ -338,13 +344,9 @@ export default {
      },
     handleSubmit(){
          this.$refs.formRef.validate(valid => {
-          if(this.buyTime == '' || !this.buyTime){
-            this.$message.error('请选择购买时间');
-            return;
-          }
           if (valid) {
-            this.formState.buyTime = moment(this.buyTime).format('YYYY-MM-DD');
             var newObj = this.formState
+            newObj.buyTime= moment(this.formState.buyTime).format('YYYY-MM-DD')
             newObj.syMaterialBList = this.List
             newObj.syMaterialCList  =this.List1
             newObj.syMaterialBList.map(item =>{