Browse Source

解决页面唯一性字段验证bug

oyq28 3 years ago
parent
commit
5824d022a6

+ 23 - 2
imcs-ui/src/views/zuihou/prepareProductMgr/frockMgr/components/Edit.vue

@@ -177,6 +177,7 @@ export default {
       tableData: [],
       tableData: [],
       zoneList: [],     
       zoneList: [],     
       tenant: this.initTenant(),
       tenant: this.initTenant(),
+      oldVal: {},
       screenWidth: 0,
       screenWidth: 0,
       width: this.initWidth(),
       width: this.initWidth(),
       confirmDisabled: false,
       confirmDisabled: false,
@@ -192,10 +193,29 @@ export default {
           { required: true, message: this.$t("rules.require"), trigger: 'blur' },
           { required: true, message: this.$t("rules.require"), trigger: 'blur' },
         ],
         ],
         no: [
         no: [
-          { required: true, message: this.$t("rules.require"), trigger: 'blur' },
+          { required: true, message: this.$t("rules.require"), trigger: 'blur' }, 
+          { validator: (rule, value, callback) => {		
+				    if(this.type === "edit" && value === this.oldVal.no){
+        			return callback()
+      			}			 
+                if (value.trim().length > 0) {					
+                  frockMgrApi.checkField({"no":value})
+                    .then((response) => {
+                      const res = response.data
+                      if (res.data) {
+                        callback('物料编码重复')
+                      } else {
+                        callback()
+                      }
+                    })
+                } else {
+                  callback()
+                }                
+               }, trigger: 'blur'
+              }         
         ],
         ],
         name: [
         name: [
-        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' },
+        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' },          
         ],
         ],
         model: [
         model: [
         	{ required: true, message: this.$t("rules.require"), trigger: 'blur' },
         	{ required: true, message: this.$t("rules.require"), trigger: 'blur' },
@@ -348,6 +368,7 @@ export default {
         }
         }
     		// 根据id,查询规格列表数据
     		// 根据id,查询规格列表数据
     		//this.getSpecsList(val)
     		//this.getSpecsList(val)
+        this.oldVal = { ...val }
     	}
     	}
       // 字典表
       // 字典表
       this.dicts = dicts
       this.dicts = dicts

+ 43 - 3
imcs-ui/src/views/zuihou/prepareProductMgr/material/components/Edit.vue

@@ -95,10 +95,11 @@
 	  },
 	  },
 	  data () {
 	  data () {
 	    return {
 	    return {
-	    	loading: false,
+	      loading: false,
 	      type: 'add',
 	      type: 'add',
 	      tableData: [],
 	      tableData: [],
 	      zoneList: [],
 	      zoneList: [],
+		  oldVal: {},
 	      materialTypeShowFlag: false,
 	      materialTypeShowFlag: false,
 	      tenant: this.initTenant(),
 	      tenant: this.initTenant(),
 	      screenWidth: 0,
 	      screenWidth: 0,
@@ -115,10 +116,48 @@
             { required: true, message: this.$t("rules.require"), trigger: 'blur' }
             { required: true, message: this.$t("rules.require"), trigger: 'blur' }
           ],
           ],
 	        meterialCode: [
 	        meterialCode: [
-	        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' }
+	        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' },
+				{ validator: (rule, value, callback) => {
+				if(this.type === "edit" && value === this.oldVal.meterialCode){					
+        			return callback()
+      			}			 
+                if (value.trim().length > 0) {					
+                  MaterialApi.checkField({"meterialCode":value})
+                    .then((response) => {
+                      const res = response.data
+                      if (res.data) {
+                        callback('物料编码重复')
+                      } else {
+                        callback()
+                      }
+                    })
+                } else {
+                  callback()
+                }                
+              }, trigger: 'blur'
+            }
 	        ],
 	        ],
 	        tradeMark: [
 	        tradeMark: [
-	        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' }
+	        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' },
+				{ validator: (rule, value, callback) => {		
+				if(this.type === "edit" && value === this.oldVal.tradeMark){
+        			return callback()
+      			}			 
+                if (value.trim().length > 0) {					
+                  MaterialApi.checkField({"tradeMark":value})
+                    .then((response) => {
+                      const res = response.data
+                      if (res.data) {
+                        callback('材料牌号重复')
+                      } else {
+                        callback()
+                      }
+                    })
+                } else {
+                  callback()
+                }                
+               }, trigger: 'blur'
+              }
 	        ],
 	        ],
 	        specification: [
 	        specification: [
 	        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' }
 	        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' }
@@ -236,6 +275,7 @@
 	    setTenant (val, dicts) {
 	    setTenant (val, dicts) {
 	    	if(val){
 	    	if(val){
 	    		this.tenant = { ...val }
 	    		this.tenant = { ...val }
+				this.oldVal = {... val }
 	    		/*if("04" === this.tenant.category.key){
 	    		/*if("04" === this.tenant.category.key){
 	            this.materialTypeShowFlag = true;
 	            this.materialTypeShowFlag = true;
 	        }else{
 	        }else{

+ 46 - 3
imcs-ui/src/views/zuihou/prepareProductMgr/trayMgr/components/Edit.vue

@@ -10,7 +10,7 @@
   >
   >
     <el-form ref="form" :model="tenant" :rules="rules" label-position="right" label-width="130px">
     <el-form ref="form" :model="tenant" :rules="rules" label-position="right" label-width="130px">
     	<!--所属产线-->
     	<!--所属产线-->
-      <el-form-item v-if="$store.state.account.user.roles.indexOf('舱体') < 0 || $store.state.account.user.roles.indexOf('框体') < 0" label='所属产线:' prop="zoneId">
+      <el-form-item v-if="$store.state.account.user.roles.indexOf('舱体') < 0 && $store.state.account.user.roles.indexOf('框体') < 0" label='所属产线:' prop="zoneId">
         <el-select
         <el-select
           v-model="tenant.zoneId"
           v-model="tenant.zoneId"
            :placeholder='$t("common.pleaseSelect")'
            :placeholder='$t("common.pleaseSelect")'
@@ -100,6 +100,7 @@ export default {
       type: 'add',
       type: 'add',
       zoneList: [],
       zoneList: [],
       tableData: [],
       tableData: [],
+      oldVal: {},
       tenant: this.initTenant(),
       tenant: this.initTenant(),
       screenWidth: 0,
       screenWidth: 0,
       width: this.initWidth(),
       width: this.initWidth(),
@@ -110,13 +111,51 @@ export default {
       roles: [],
       roles: [],
       rules: {
       rules: {
         name: [
         name: [
-        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' }
+        	{ required: true, message: this.$t("rules.require"), trigger: 'blur' },
+           { validator: (rule, value, callback) => {		
+				    if(this.type === "edit" && value === this.oldVal.name){
+        			return callback()
+      			}			 
+            if (value.trim().length > 0) {					
+                  trayMgrApi.checkField({"name":value})
+                    .then((response) => {
+                      const res = response.data
+                      if (res.data) {
+                        callback('托盘名称重复')
+                      } else {
+                        callback()
+                      }
+                    })
+                } else {
+                  callback()
+                }                
+               }, trigger: 'blur'
+            }
         ],
         ],
         zoneId: [
         zoneId: [
           { required: true, message: this.$t("rules.require"), trigger: 'blur' }
           { required: true, message: this.$t("rules.require"), trigger: 'blur' }
         ],
         ],
         no: [
         no: [
-          { required: true, message: this.$t("rules.require"), trigger: 'blur' }
+          { required: true, message: this.$t("rules.require"), trigger: 'blur' },
+          { validator: (rule, value, callback) => {		
+				    if(this.type === "edit" && value === this.oldVal.no){
+        			return callback()
+      			}			 
+            if (value.trim().length > 0) {					
+                  trayMgrApi.checkField({"no":value})
+                    .then((response) => {
+                      const res = response.data
+                      if (res.data) {
+                        callback('物料编码重复')
+                      } else {
+                        callback()
+                      }
+                    })
+                } else {
+                  callback()
+                }                
+               }, trigger: 'blur'
+            }
         ],
         ],
         num: [
         num: [
           { required: true, message: this.$t("rules.require"), trigger: 'blur' }
           { required: true, message: this.$t("rules.require"), trigger: 'blur' }
@@ -166,6 +205,9 @@ export default {
         res = res.data;
         res = res.data;
         if (res.isSuccess) {
         if (res.isSuccess) {
           this.zoneList = res.data;
           this.zoneList = res.data;
+          if(this.zoneList.length == 1){
+             this.zoneId = this.zoneList[0].id
+          }
         }
         }
       });
       });
     },
     },
@@ -239,6 +281,7 @@ export default {
     	}
     	}
       // 字典表
       // 字典表
       this.dicts = dicts
       this.dicts = dicts
+      this.oldVal = {...val }
     },
     },
     close () {
     close () {
       this.$emit('close')
       this.$emit('close')