Explorar o código

Function: 机构公用组件

chris %!s(int64=4) %!d(string=hai) anos
pai
achega
5dc7722fb7

+ 17 - 15
src/views/modules/common/org-component.vue

@@ -48,29 +48,23 @@
         orgList: []
       }
     },
-    // watch: {
-    //   orgId: function (newValues) {
-    //     this.dataForm.orgId = newValues
-    //   }
-    // },
+    watch: {
+      orgId (val) {
+        this.dataForm.orgId = val
+        this.init()
+      }
+    },
     methods: {
       async init () {
-        let orgId = this.orgId
+        // let that = this
         this.$http({
           url: this.$http.adornUrl(`/user-service/org/queryTree`),
           method: 'get'
         }).then(({data}) => {
           this.orgList = data && data.code === '200' ? data.data : []
         }).then(() => {
-          if (orgId) {
-            this.$http({
-              url: this.$http.adornUrl(`/user-service/org/info/${orgId}`),
-              method: 'get'
-            }).then(({data}) => {
-              if (data && data.code === '200') {
-                this.menuListTreeSetCurrentNode()
-              }
-            })
+          if (this.dataForm.orgId) {
+            this.menuListTreeSetCurrentNode()
           }
         })
       },
@@ -78,6 +72,14 @@
         this.dataForm.orgId = data.orgId
         this.dataForm.orgName = data.name
         this.$emit('orgSelected', data.orgId)
+      },
+      menuListTreeSetCurrentNode () {
+        this.$refs.menuListTree.setCurrentKey(this.dataForm.orgId)
+        if (this.dataForm.orgId === '0') {
+          this.dataForm.orgName = ''
+        } else {
+          this.dataForm.orgName = (this.$refs.menuListTree.getCurrentNode() || {})['name']
+        }
       }
     }
   }

+ 3 - 3
src/views/modules/sys/user-add-or-update.vue

@@ -116,9 +116,9 @@
           mobile: [
             { required: true, message: '手机号不能为空', trigger: 'blur' },
             { validator: validateMobile, trigger: 'blur' }
-          // ],
-          // orgId: [
-          //   { required: true, message: '所属机构不能为空', trigger: 'blur' }
+          ],
+          orgId: [
+            { required: true, message: '所属机构不能为空', trigger: 'blur' }
           ]
         }
       }