Browse Source

app添加已注册的个人账号会报错的问题

huangb 7 years ago
parent
commit
24ca806723
1 changed files with 31 additions and 47 deletions
  1. 31 47
      components/mobile/staffManagement/StaffAdd.vue

+ 31 - 47
components/mobile/staffManagement/StaffAdd.vue

@@ -49,8 +49,13 @@
                  placeholder="请输入UU号、手机或邮箱">
           <span @click="addApply"><i class="iconfont icon-sousuo"></i></span>
         </div>
-        <div class="list-content" v-if="showSearchUser">
-          <div v-if="bindUser">
+        <div class="list-content" v-if="searchNoData">
+          <div class="staff-list">
+            <span>您查找的用户不存在!</span>
+          </div>
+        </div>
+        <div class="list-content" v-else>
+          <div v-if="showSearchUser">
             <div class="staff-list">
               <div class="list-item"><span>UU账号:</span><span v-text="newUserInfo.userUU">100000721</span></div>
               <div class="list-item"><span>姓名:</span><span v-text="newUserInfo.userName">张洪别</span></div>
@@ -63,18 +68,10 @@
               <div class="agree handle" @click="sureBindNewUser()">确定绑定</div>
             </div>
           </div>
-          <div class="staff-list" v-if="reBindError">
-            <span>该用户已绑定到当前企业,不可重复绑定!</span>
-          </div>
-          <div class="staff-list" v-if="illegalError">
+          <div class="staff-list" v-else-if="bindSelf">
             <span>不可对自己进行绑定!</span>
           </div>
         </div>
-        <div class="list-content" v-else>
-          <div class="staff-list">
-            <span>您查找的用户不存在!</span>
-          </div>
-        </div>
       </div>
     </div>
     <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
@@ -95,12 +92,11 @@
         timeoutCount: 0,
         newPhoneCheck: false,
         newEmailCheck: false,
-        showSearchUser: true,
+        showSearchUser: false,
         searchKeyword: '',
         newUserInfo: '',
-        reBindError: false,
-        illegalError: false,
-        bindUser: false
+        bindSelf: false,
+        searchNoData: false
       }
     },
     components: {
@@ -211,41 +207,27 @@
         if (this.searchKeyword) {
           this.$http.get('/basic/user/searchUser', {params: {keyWord: this.searchKeyword}}).then(response => {
             if (response.data) {
-              this.showSearchUser = true
-              this.newUserInfo = response.data
-              this.bindUser = true
-              this.illegalError = false
-              this.reBindError = false
-              if (this.newUserInfo.userUU === this.userInfo.userUU) {
+              this.searchNoData = false
+              if (response.data.userUU === this.userInfo.userUU) {
                 //不可自己绑定自己
-                this.illegalError = true
-                this.bindUser = false
+                this.bindSelf = true
+                this.showSearchUser = false
               } else {
-                for (var i = 0; i < this.newUserInfo.enterprises.length; i++) {
-                  if (this.newUserInfo.enterprises[i].current) {
-                    for (var j = 0; j < this.userInfo.enterprises.length; j++) {
-                      //该用户已绑定到当前企业,不可重复绑定
-                      if (this.newUserInfo.enterprises[i].uu === this.userInfo.enterprises[j].uu) {
-                        this.reBindError = true
-                        this.bindUser = false
-                      }
-                    }
-                  }
-                }
+                this.showSearchUser = true
+                this.bindSelf = false
+                this.newUserInfo = response.data
               }
             } else {
               // 未搜索到结果
+              this.searchNoData = true
               this.showSearchUser = false
-              this.bindUser = false
-              this.reBindError = false
-              this.illegalError = false
+              this.bindSelf = false
             }
           }).catch (err =>{
             if (err) {
+              this.searchNoData = true
               this.showSearchUser = false
-              this.bindUser = false
-              this.reBindError = false
-              this.illegalError = false
+              this.bindSelf = false
             }
           })
         }
@@ -253,12 +235,14 @@
       // 确定绑定已注册用户
       sureBindNewUser () {
         let isFlag = false
-        if (this.newUserInfo.enterprises.length) {
-          this.newUserInfo.enterprises.forEach(item => {
-            if (item.uu === this.user.data.enterprise.uu) {
-              isFlag = true
-            }
-          })
+        if (this.newUserInfo.enterprises) {
+          if (this.newUserInfo.enterprises.length) {
+            this.newUserInfo.enterprises.forEach(item => {
+              if (item.uu === this.user.data.enterprise.uu) {
+                isFlag = true
+              }
+            })
+          }
         }
         if (isFlag) {
           this.onRemind('该用户已绑定到当前企业,不可重复绑定!')
@@ -266,7 +250,7 @@
           this.$http.get('/basic/user/bindUser', {params: {userUU: this.newUserInfo.userUU}})
             .then(response => {
               if (response) {
-                this.onRemind('增加用户成功' + this.newUserInfo.userName)
+                this.onRemind('增加' + this.newUserInfo.userName +'用户成功')
                 this.$router.push('/mobile/user/staff')
               }
             })