Browse Source

添加后台绑定用户到企业操作

huxz 7 years ago
parent
commit
c900655941

+ 244 - 1
sso-manage-console-web/src/components/accounts/enterprises/EnterpriseMembers.vue

@@ -51,6 +51,13 @@
             刷新
             刷新
           </button>
           </button>
 
 
+          <button
+            type="button"
+            class="btn btn-default btn-refresh btn-bind"
+            @click="showBindDialog">
+            绑定用户
+          </button>
+
           <div class="pagination-area">
           <div class="pagination-area">
             <el-pagination
             <el-pagination
               background
               background
@@ -65,6 +72,56 @@
         </el-row>
         </el-row>
       </el-footer>
       </el-footer>
     </el-container>
     </el-container>
+
+    <!-- 绑定用户对话框 -->
+    <el-dialog
+      title="绑定用户"
+      :visible.sync="isBindUser"
+      width="450px"
+      :show-close="true"
+      :append-to-body="true">
+      <!-- 对话框内容 -->
+      <el-row type="flex" class="row-bg">
+        <el-select v-model="key" placeholder="请选择">
+          <el-option
+            v-for="item in items"
+            :key="item.value"
+            :label="item.label"
+            :value="item.value">
+          </el-option>
+        </el-select>
+        <div class="input-group search-group" style="width: 242px;margin-left: 5px;">
+          <el-input placeholder="请输入内容" v-model="keyword"></el-input>
+          <span class="input-group-btn">
+            <button class="btn btn-default btn-search" type="button" @click="searchAndSelectAdmin">搜索</button>
+          </span>
+        </div>
+      </el-row>
+      <!-- 用户信息展示 -->
+      <div class="selected-user-info">
+        <div class="row">
+          <div class="message-label">UU号</div>
+          <div class="message-value" v-text="bindUserInfo.userUU">U0516</div>
+        </div>
+        <div class="row">
+          <div class="message-label">姓名</div>
+          <div class="message-value" v-text="bindUserInfo.realName || bindUserInfo.vipName">陈正亮</div>
+        </div>
+        <div class="row">
+          <div class="message-label">手机号</div>
+          <div class="message-value" v-text="bindUserInfo.mobile">13600001122</div>
+        </div>
+        <div class="row">
+          <div class="message-label">邮箱</div>
+          <div class="message-value" v-text="bindUserInfo.email">1891141208@qq.com</div>
+        </div>
+      </div>
+      <!-- 对话框尾部 -->
+      <span slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="bindUserToCurrentEnterprise">确 定</el-button>
+        <el-button @click="isBindUser = false">取 消</el-button>
+      </span>
+    </el-dialog>
   </div>
   </div>
 </template>
 </template>
 
 
@@ -73,6 +130,26 @@
   import axios from '@/assets/js/axios'
   import axios from '@/assets/js/axios'
   import * as types from '@/store/mutation-types'
   import * as types from '@/store/mutation-types'
 
 
+  const keys = [
+    {
+      label: 'UU号',
+      value: 'userUU'
+    },
+    {
+      label: '手机号',
+      value: 'mobile'
+    },
+    {
+      label: '邮箱',
+      value: 'email'
+    }
+  ]
+
+  function bindUserToEnterprise (spaceUU, userUu) {
+    const params = { userUu }
+    return axios.put(`/api/user/space/${spaceUU}/addUserToSpace`, {}, { params })
+  }
+
   export default {
   export default {
     name: 'enterprise-members',
     name: 'enterprise-members',
     data () {
     data () {
@@ -83,7 +160,12 @@
           spaceUU: null
           spaceUU: null
         },
         },
         total: 0,
         total: 0,
-        userList: []
+        userList: [],
+        isBindUser: false,
+        items: keys,
+        key: 'userUU',
+        keyword: '',
+        bindUserInfo: {}
       }
       }
     },
     },
     computed: {
     computed: {
@@ -140,6 +222,49 @@
         axios.put(`/api/user/space/${this.enterprise.spaceUU}/unbindUser`, {}, {params}).then(
         axios.put(`/api/user/space/${this.enterprise.spaceUU}/unbindUser`, {}, {params}).then(
           success).catch(error)
           success).catch(error)
       },
       },
+      showBindDialog () {
+        this.isBindUser = true
+        this.key = 'userUU'
+        this.keyword = ''
+        this.bindUserInfo = {}
+      },
+      searchAndSelectAdmin () {
+        const params = { spaceUU: this.enterprise.spaceUU, key: this.key, keyword: this.keyword }
+
+        const error = error => {
+          console.log(error)
+        }
+
+        axios.get('/api/user//searchUserFromOthers', { params })
+        .then(userList => {
+          // 展示查询到的用户信息
+          if (userList && userList.length > 0) {
+            this.bindUserInfo = userList[0]
+          } else {
+            this.$message.info('没有找到对应非当前企业的用户信息!')
+          }
+        })
+        .catch(error)
+      },
+      bindUserToCurrentEnterprise () {
+        const spaceUU = this.enterprise.spaceUU
+        const userUU = this.bindUserInfo.userUU
+
+        const success = result => {
+          if (result) {
+            this.fetchData()
+            this.isBindUser = false
+            this.$message.success('绑定成功')
+          }
+        }
+        const error = response => {
+          this.$message.error(response)
+        }
+
+        bindUserToEnterprise(spaceUU, userUU)
+          .then(success)
+          .catch(error)
+      },
       routeToUserDetail (user) {
       routeToUserDetail (user) {
         const routeLocation = {name: 'UserBasicInfo', params: user, replace: true}
         const routeLocation = {name: 'UserBasicInfo', params: user, replace: true}
         this.$router.push(routeLocation)
         this.$router.push(routeLocation)
@@ -174,9 +299,79 @@
     font-size: 13px;
     font-size: 13px;
     font-family: "Microsoft YaHei", sans-serif;
     font-family: "Microsoft YaHei", sans-serif;
   }
   }
+  .btn-bind {
+    width: 80px;
+    margin-left: 15px;
+  }
   .pagination-area {
   .pagination-area {
     padding: 17px 0 17px 150px;
     padding: 17px 0 17px 150px;
   }
   }
+  .selected-user-info {
+    margin-top: 20px;
+    margin-bottom: 50px;
+  }
+  .selected-user-info .row {
+    margin: 15px 0;
+    height: 34px;
+  }
+  .selected-user-info .row div {
+    display: inline-block;
+  }
+  .selected-user-info .row .message-label {
+    padding: 10px;
+    width: 90px;
+    height: 34px;
+    line-height: 14px;
+
+    color: #000000;
+    font-size: 14px;
+    font-weight: normal;
+    font-family: "SimHei", sans-serif;
+  }
+  .selected-user-info .row .message-value {
+    padding: 10px;
+    width: 280px;
+    height: 34px;
+    line-height: 14px;
+    background-color: #F1F1F1;
+
+    color: #646464;
+    font-size: 14px;
+    font-weight: normal;
+    font-family: "Microsoft YaHei", sans-serif;
+  }
+  .input-group {
+    border: 1px solid #D2D2D2;
+  }
+  .input-group-btn::before {
+    content: '';
+    position: absolute;
+    top: 10px;
+    left: 0;
+    width: 1px;
+    height: 13px;
+    background: #D2D2D2;
+    z-index: 5;
+  }
+  .btn-search {
+    width: 58px;
+    height: 30px;
+    border-radius: 0;
+    outline: none;
+    border: none;
+
+    color: #2190E1;
+  }
+  .btn-search:active,
+  .btn-search:hover,
+  .btn-search:visited,
+  .btn-search:focus {
+    outline: none;
+    background: none;
+    box-shadow: none;
+
+    color: #4A7DE1;
+  }
 </style>
 </style>
 
 
 <style>
 <style>
@@ -230,4 +425,52 @@
   .el-table--striped .el-table__body tr.el-table__row--striped td {
   .el-table--striped .el-table__body tr.el-table__row--striped td {
     background: #F4F4F4;
     background: #F4F4F4;
   }
   }
+  .el-dialog {
+    border-radius: 5px;
+  }
+  .el-dialog__header {
+    padding: 14px 20px;
+    height: 44px;
+    line-height: 16px;
+    border: 1px none #D2D2D2;
+    border-bottom-style: solid;
+  }
+  .el-dialog__header .el-dialog__title {
+    color: #000000;
+    font-size: 16px;
+    font-weight: normal;
+    font-family: "SimHei", sans-serif;
+  }
+  .el-dialog__body {
+    padding: 22px 0 22px 40px;
+  }
+  .el-select .el-input__inner {
+    border-radius: 0;
+    width: 128px;
+    height: 32px;
+  }
+  .search-group .el-input__inner {
+    width: 186px;
+    height: 30px;
+    border-radius: 0;
+    border: none;
+  }
+  .el-dialog__footer {
+    text-align: center;
+  }
+  .el-dialog__footer .el-button {
+    width: 180px;
+    height: 30px;
+    border-radius: 15px;
+    line-height: 14px;
+    padding: 8px 0;
+
+    background: none;
+
+    color: #656565;
+  }
+  .el-dialog__footer .el-button--primary {
+    background-color: #4E8EFC;
+    color: #FFFFFF;
+  }
 </style>
 </style>

+ 1 - 1
sso-manage-console-web/src/components/accounts/users/UserHome.vue

@@ -91,7 +91,7 @@
         <button
         <button
           type="button"
           type="button"
           class="btn btn-default btn-refresh"
           class="btn btn-default btn-refresh"
-          @click="isAddNewUser = true">
+          @click="isAddNewUser = true; newUserInfo = {}">
           新增
           新增
         </button>
         </button>
       </div>
       </div>

+ 8 - 0
sso-manage-console/src/main/java/com/uas/sso/sso/backend/api/UserManageController.java

@@ -59,6 +59,14 @@ public class UserManageController {
         return new ResultBean<>(userBackendService.searchUserByKeyword(spaceUu, key, keyword));
         return new ResultBean<>(userBackendService.searchUserByKeyword(spaceUu, key, keyword));
     }
     }
 
 
+    @RequestMapping(method = RequestMethod.GET, path = "//searchUserFromOthers",
+            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+    public ResultBean<List<User>> searchUserFromOthers(@RequestParam("spaceUU") Long spaceUu,
+            String key, String keyword) {
+
+        return new ResultBean<>(userBackendService.searchUserFromOthers(spaceUu, key, keyword));
+    }
+
     @RequestMapping(method = RequestMethod.PUT, path = "//modifyUserInfo",
     @RequestMapping(method = RequestMethod.PUT, path = "//modifyUserInfo",
             produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
             produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
     public ResultBean<Boolean> modifyUserInfo(@RequestBody UpdateUserInfo userInfo) {
     public ResultBean<Boolean> modifyUserInfo(@RequestBody UpdateUserInfo userInfo) {

+ 10 - 0
sso-manage-console/src/main/java/com/uas/sso/sso/backend/service/UserBackendService.java

@@ -47,6 +47,16 @@ public interface UserBackendService {
      */
      */
     List<User> searchUserByKeyword(Long spaceUu, String key, String keyword);
     List<User> searchUserByKeyword(Long spaceUu, String key, String keyword);
 
 
+    /**
+     * 根据关键字搜索非当前企业的用户信息
+     *
+     * @param spaceUu   企业UU
+     * @param key   搜索字段
+     * @param keyword   搜索关键字
+     * @return  用户列表信息
+     */
+    List<User> searchUserFromOthers(Long spaceUu, String key, String keyword);
+
     /**
     /**
      * 管理员收到客户时,后台修改用户的信息.
      * 管理员收到客户时,后台修改用户的信息.
      *
      *

+ 31 - 0
sso-manage-console/src/main/java/com/uas/sso/sso/backend/service/impl/UserBackendServiceImpl.java

@@ -143,6 +143,37 @@ public class UserBackendServiceImpl implements UserBackendService {
         });
         });
     }
     }
 
 
+    @Override
+    public List<User> searchUserFromOthers(Long spaceUu, String key, String keyword) {
+
+        return userDao.findAll(new Specification<User>() {
+            @Override
+            public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query,
+                    CriteriaBuilder builder) {
+                List<Predicate> predicates = new ArrayList<>();
+
+                if (spaceUu != null) {
+                    Predicate predicate = builder.isNotMember(new Userspace(spaceUu), root.get("userSpaces"));
+                    predicates.add(predicate);
+                }
+
+                if (!StringUtils.isEmpty(key) && !StringUtils.isEmpty(keyword)) {
+                    Predicate predicate = builder.equal(root.get(key), keyword);
+                    predicates.add(predicate);
+                }
+
+                // 移除无效条件表达式
+                predicates.removeAll(Collections.singletonList(null));
+
+                Predicate[] array = new Predicate[predicates.size()];
+                predicates.toArray(array);
+                Predicate predicate = builder.and(array);
+                query.where(predicate);
+                return null;
+            }
+        });
+    }
+
     @Override
     @Override
     public Boolean modifyUserInfo(UpdateUserInfo userInfo) {
     public Boolean modifyUserInfo(UpdateUserInfo userInfo) {