更新人员选择工具

This commit is contained in:
wenc000 2020-10-26 10:55:50 +08:00
parent 25185405c3
commit d460eb504f
5 changed files with 420 additions and 197 deletions

View File

@ -182,5 +182,13 @@ public interface IApiConsts {
* 获取所在部门用户列表通过职位ID列表
*/
String LIST_USER_DEPARTMENT_RESOURCE_BY_POSITION_IDS = "%s/resource/user/listuserdepartmentresourcebypositionids";
/**
* 组织部门人员分页列表
*/
String LIST_SELECT_DEPARTMENT_USER = "%s/resource/user/listselectdepartmentuser/%s";
/**
* 通过id列表获取用户ID
*/
String LIST_PAGE_SELECT_DEPARTMENT_USER = "%s/resource/user/listpageselectdepartmentuser/%s";
}

View File

@ -11,13 +11,16 @@ import com.cm.common.exception.SearchException;
import com.cm.common.exception.UpdateException;
import com.cm.common.plugin.oauth.service.user.IUserService;
import com.cm.common.plugin.pojo.bos.UserResourceBO;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultList;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -87,18 +90,6 @@ public class UserController extends AbstractController {
return userService.listPositionUsers(params);
}
@ApiOperation(value = "通过用户ID获取用户列表", notes = "通过用户ID获取用户列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "userIds", value = "用不ID列表", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listuserbyids/{userIds}")
public JSONArray listUserByIds(@PathVariable("userIds") String userIds) throws AccessTokenException, SearchException {
Map<String, Object> params = getParams();
params.put("userIds", userIds);
return userService.listUserByIds(params);
}
@ApiOperation(value = "全部用户列表", notes = "全部用户列表接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listallusers")
@ -189,4 +180,47 @@ public class UserController extends AbstractController {
return userService.listPageUserSimple(params);
}
@ApiOperation(value = "组织部门人员列表", notes = "组织部门人员列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listselectdepartmentuser/{departmentId}")
public JSONArray listSelectDepartmentUser(@PathVariable("departmentId") String departmentId) throws SearchException {
return userService.listSelectDepartmentUser(departmentId);
}
@ApiOperation(value = "组织部门人员分页列表", notes = "组织部门人员分页列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpageselectdepartmentuser/{departmentId}")
public JSONObject listPageSelectDepartmentUser(@PathVariable("departmentId") String departmentId, ListPage page) throws SearchException {
Map<String, Object> params = requestParams();
page.setParams(params);
return userService.listPageSelectDepartmentUserByDepartmentId(departmentId, page);
}
@ApiOperation(value = "通过ID列表获取用户列表", notes = "通过ID列表获取用户列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "userIds", value = "用户ID列表用下划线分隔1_2_3", paramType = "body")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("listuserbyids")
public JSONArray listUserByIds(@RequestBody Map<String, Object> params) throws SearchException, ParamsException {
if (params.get("selectedUserIds") == null || StringUtils.isBlank(params.get("selectedUserIds").toString())) {
throw new ParamsException("用户列表不能为空");
}
params.put("userIds", params.get("selectedUserIds"));
params.remove("selectedUserIds");
return userService.listUserByIds(params);
}
}

View File

@ -6,6 +6,7 @@ import com.cm.common.exception.AccessTokenException;
import com.cm.common.exception.SearchException;
import com.cm.common.plugin.pojo.bos.UserResourceBO;
import com.cm.common.plugin.pojo.bos.user.UserDepartmentResourceBO;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultList;
import org.aspectj.lang.annotation.DeclareError;
@ -68,17 +69,6 @@ public interface IUserService {
@Deprecated
JSONArray listPositionUsers(Map<String, Object> params) throws AccessTokenException, SearchException;
/**
* 通过id列表获取用户ID
*
* @param params
* @return
* @throws AccessTokenException
* @throws SearchException
*/
@Deprecated
JSONArray listUserByIds(Map<String, Object> params) throws AccessTokenException, SearchException;
/**
* 全部用户
*
@ -331,4 +321,32 @@ public interface IUserService {
*/
List<UserDepartmentResourceBO> listUserDepartmentResourceByPositionIds(List<String> positionIds) throws SearchException;
/**
* 获取选择的部门用户插件用
*
* @param params
* @return
* @throws SearchException
*/
JSONArray listSelectDepartmentUser(String departmentId) throws AccessTokenException, SearchException;
/**
* 组织部门人员分页列表插件用
*
* @param departmentId
* @param page
* @return
* @throws SearchException
*/
JSONObject listPageSelectDepartmentUserByDepartmentId(String departmentId, ListPage page) throws AccessTokenException, SearchException;
/**
* 通过id列表获取用户ID插件用
*
* @param params
* @return
* @throws AccessTokenException
* @throws SearchException
*/
JSONArray listUserByIds(Map<String, Object> params) throws AccessTokenException, SearchException;
}

View File

@ -13,6 +13,7 @@ import com.cm.common.plugin.oauth.token.ClientTokenManager;
import com.cm.common.plugin.pojo.bos.UserResourceBO;
import com.cm.common.plugin.pojo.bos.user.UserDepartmentResourceBO;
import com.cm.common.plugin.utils.RestTemplateUtil;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultList;
import org.apache.commons.lang3.StringUtils;
@ -71,13 +72,6 @@ public class UserServiceImpl extends AbstractService implements IUserService {
return JSONArray.parseArray(result);
}
@Override
public JSONArray listUserByIds(Map<String, Object> params) throws AccessTokenException, SearchException {
String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_USER_BY_ID, apiPathProperties.getUserCenter()), params);
searchResourceResult(result, "获取人员列表失败");
return JSONArray.parseArray(result);
}
@Override
public JSONArray listAllUsers(Map<String, Object> params) throws AccessTokenException, SearchException {
String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_ALL_USER, apiPathProperties.getUserCenter()), params);
@ -380,4 +374,29 @@ public class UserServiceImpl extends AbstractService implements IUserService {
searchResourceResult(result, "获取人员信息失败");
return JSONArray.parseArray(result, UserDepartmentResourceBO.class);
}
@Override
public JSONArray listSelectDepartmentUser(String departmentId) throws SearchException {
Map<String, Object> params = getHashMap(2);
params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken());
String result = restTemplateUtil.doGetFormNormal(String.format(IApiConsts.LIST_SELECT_DEPARTMENT_USER, apiPathProperties.getUserCenter(), departmentId), params);
searchResourceResult(result, "获取组织部门人员列表失败");
return JSONArray.parseArray(result);
}
@Override
public JSONObject listPageSelectDepartmentUserByDepartmentId(String departmentId, ListPage page) throws SearchException {
page.getParams().put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken());
String result = restTemplateUtil.doGetFormNormal(String.format(IApiConsts.LIST_PAGE_SELECT_DEPARTMENT_USER, apiPathProperties.getUserCenter(), departmentId), page.getParams());
searchResourceResult(result, "获取组织部门人员分页列表失败");
return JSONObject.parseObject(result);
}
@Override
public JSONArray listUserByIds(Map<String, Object> params) throws AccessTokenException, SearchException {
params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken());
String result = restTemplateUtil.doPostFormNormal(String.format(IApiConsts.LIST_USER_BY_ID, apiPathProperties.getUserCenter()), params);
searchResourceResult(result, "获取人员列表失败");
return JSONArray.parseArray(result);
}
}

View File

@ -1,193 +1,337 @@
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<base th:href="${#request.getContextPath() + '/'} ">
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11,chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" type="text/css" href="assets/fonts/font-awesome/css/font-awesome.css"/>
<link rel="stylesheet" type="text/css" href="assets/js/vendor/bootstrap/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="assets/js/easyui/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="assets/js/easyui/themes/icon.css"/>
<link rel="stylesheet" type="text/css" href="assets/js/vendor/zTree3/css/metroStyle/metroStyle.css"/>
<link rel="stylesheet" type="text/css" href="assets/css/minimal.css"/>
<link rel="stylesheet" type="text/css" href="assets/css/system.css">
</head>
<body>
<div id="app" class="easyui-layout easyui-layout-dialog dept-selector">
<div class="selector-title" data-options="region:'north'">
<div id="selectUsers" class="selector-title-wrapper"></div>
</div>
<div class="selector-tree" data-options="region:'west',split:false,collapsible:false,border:true">
<div class="selector-tree-wrapper">
<ul id="leftTree" class="ztree"></ul>
<head>
<base th:href="${#request.getContextPath() + '/'}">
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
<link rel="stylesheet" type="text/css" href="assets/js/vendor/zTree3/css/metroStyle/metroStyle.css"/>
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
<style>
.user-search {width: 188px !important; display: inline;}
.user-selected {border-left: 2px solid #009688 !important;}
</style>
</head>
<body>
<div class="layui-fluid layui-anim layui-anim-fadein" style="padding: 0;">
<div class="layui-card">
<div class="layui-card-body" style="padding: 0px;">
<div class="layui-row">
<div class="layui-col-xs12">
<div id="selectUsers" class="layui-btn-container selector-title-wrapper"></div>
</div>
</div>
<div class="selector-body" data-options="region:'center',border:true">
<div class="selector-body-wrapper">
<div class="selector-body-search">
<input type="text" class="form-control" id="name" placeholder="检索用户名" oninput="searchUser()"/>
<div class="layui-row">
<div class="layui-col-xs5">
<div class="selector-tree-wrapper">
<ul id="leftTree" class="ztree"></ul>
</div>
</div>
<div class="layui-col-xs7">
<div class="selector-body-wrapper">
<div class="selector-body-search">
<input type="text" id="searchUser" class="layui-input user-search" placeholder="快捷检索当前列表"/>
<div class="layui-btn-group">
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-click-select-all-user>全选</button>
<button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-click-clear-all-user>清空</button>
</div>
</div>
<div id="users" class="selector-body-content list-group">
<div id="userWrapper"></div>
</div>
</div>
<div id="users" class="selector-body-content list-group"></div>
</div>
</div>
<div class="edit-button-footer2">
<div class="col-sm-offset-4 col-sm-8">
<button type="button" class="btn btn-primary" onclick="confirmBox()">确认</button>
<!--
<button type="button" class="btn btn-default" onclick="closeBox()">关闭</button>
-->
<div class="layui-form-item layui-layout-admin">
<div class="layui-input-block">
<div class="layui-footer" style="left: 0;">
<button type="button" class="layui-btn confirm">确认</button>
<button type="button" class="layui-btn layui-btn-primary close">关闭</button>
</div>
</div>
</div>
</div>
<input type="hidden" id="selectedUserIds"/>
<script type="text/javascript" src="assets/js/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="assets/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="assets/js/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="assets/js/vendor/zTree3/js/jquery.ztree.all.js"></script>
<script type="text/javascript" src="assets/js/common.js"></script>
<script type="text/javascript">
var hrefParams = top.restAjax.params(window.location.href);
$('#selectedUserIds').val(hrefParams.selectedUserIds);
// 是否单选
var single = hrefParams.single;
var selectDepartmentUserArray = [];
function closeBox() {
top.DialogBox.closeBox();
}
function confirmBox() {
top.DialogBox.dialogData.selectedDepartmentUsers = selectDepartmentUserArray;
closeBox();
}
// 人员是否已经选择
function isUserSelected(userId) {
var isSelected = false;
for(var i = 0, item; item = selectDepartmentUserArray[i++];) {
if(item.userId == userId) {
isSelected = true;
break;
</div>
</div>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script>
layui.config({
base: 'assets/layuiadmin/'
}).extend({
index: 'lib/index'
}).use(['index', 'flow', 'ztree', 'common'], function() {
var $ = layui.$;
var $win = $(window);
var common = layui.common;
var flow = layui.flow;
var selectedUserIds = top.dialog.dialogData.selectedUserIds;
var selectDepartmentUserOldArray = [];
var selectDepartmentUserArray = [];
var selectedParentId = 0;
var searchTimeout;
top.dialog.dialogData.selectedDepartmentUsers = [];
function closeBox() {
top.dialog.closeBox();
}
function initFrame() {
var height = $win.height() - 160;
$('.selector-tree-wrapper').css({
height: height +'px',
border: '1px dotted silver'
});
$('.selector-body-wrapper').css({
height: (height - 10) +'px',
border: '1px dotted silver'
});
$('.selector-body-content').css({
height: ($('.selector-body-wrapper').height() - 30) +'px'
});
}
// 初始化树
function initThree() {
var setting = {
async: {
enable: true,
autoLoad: false,
type: 'get',
url: top.restAjax.path('api/department/listztreedepartment', []),
autoParam:['id'],
otherParam:{},
dataFilter: function(treeId, parentNode, childNodes) {
if (!childNodes) return null;
for (var i=0, l=childNodes.length; i<l; i++) {
childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
}
return childNodes;
}
},
callback: {
onClick: function(event, treeId, treeNode) {
parentId = treeNode.id;
$('#searchUser').val('');
initUsers(treeNode.id);
return false;
}
},
view: {
fontCss: {'color': 'black'}
}
return isSelected;
};
var zTree = $.fn.zTree.init($('#leftTree'), setting);
zTree.addNodes(null, {id: '0', pId: '-1', name: '未划分人员', url: 'javascript:void(0);', isParent: 'true'});
common.refreshTree('leftTree');
}
// 添加人员dom
function addUserDom(data) {
var userDom = '';
for(var i = 0, item; item = data[i++];) {
var avatarDom;
if(null == item.userAvatar || '' == item.userAvatar) {
avatarDom = '<img class="user-avatar" src="assets/images/profile-photo.jpg"/> '
} else {
avatarDom = '<img class="user-avatar" src="route/file/downloadfile/false/'+ item.userAvatar +'"/> ';
}
userDom += '<a id="user_'+ item.userId +'" href="javascript:void(0);" class="users list-group-item '+ (isUserSelected(item.userId) ? 'user-selected' : '') +'" lay-click-user data-userid="'+ item.userId +'" data-username="'+ item.userName +'">'+ avatarDom + item.userName +' ['+ item.userUsername +']</a>';
}
// 删除已经选择的人员
function removeSelectedUser(userId) {
for(var i = 0, item; item = selectDepartmentUserArray[i]; i++) {
if(item.userId == userId) {
selectDepartmentUserArray.splice(i, 1);
$('#selected_user_'+ userId).remove();
$('#userWrapper').append(userDom);
}
function addSearchUserDom(data) {
if(data.length < 1) {
return;
}
var users = $('.users');
for(var i = 0; i < data.length; i++) {
var user = data[i];
for(var j = 0, userItem; userItem = users[j++];) {
if(user.userId === userItem.dataset.userid) {
data.splice(i, 1);
i--;
break;
}
}
}
// 清空已经选择的人员
function clearSelectedUser() {
selectDepartmentUserArray.splice(0, selectDepartmentUserArray.length);
$('.selected_user').remove();
}
// 添加人员
function addSelectedUser(userId, userName, userUsername) {
selectDepartmentUserArray.push({
userId: userId,
userName: userName,
userUsername: userUsername
});
$('#selectUsers').append('<a id="selected_user_'+ userId +'" href="javascript:;" class="btn btn-success btn-xs selected_user">'+ userName +' <i class="fa fa-close" onclick="removeSelectedUser(\''+ userId +'\')"></i></a>');
}
// 选择人员
function selectUser(userId, userName, userUsername) {
// 如果是单选
if(single == 'true') {
clearSelectedUser();
addSelectedUser(userId, userName, userUsername);
return;
}
if(!isUserSelected(userId)) {
addSelectedUser(userId, userName, userUsername);
var userDom = '';
for(var i = 0, item; item = data[i++];) {
var avatarDom;
if(null == item.userAvatar || '' == item.userAvatar) {
avatarDom = '<img class="user-avatar" src="assets/images/profile-photo.jpg"/> '
} else {
avatarDom = '<img class="user-avatar" src="route/file/downloadfile/false/'+ item.userAvatar +'"/> ';
}
userDom += '<a id="user_'+ item.userId +'" href="javascript:void(0);" class="users search-users list-group-item '+ (isUserSelected(item.userId) ? 'user-selected' : '') +'" lay-click-user data-userid="'+ item.userId +'" data-username="'+ item.userName +'">'+ avatarDom + item.userName +' ['+ item.userUsername +']</a>';
}
// 筛选人员
function searchUser() {
$('.users').hide().filter(":contains('" + $('#name').val() + "')").show();
}
// 初始化人员列表
function initUsers(parentId) {
var loadLayerIndex;
top.restAjax.get(top.restAjax.path('api/user/listdepartmentusers/{parentId}', [parentId]), {}, null, function(code, data) {
$('#users').empty();
var userDom = '';
for(var i = 0, item; item = data[i++];) {
var avatarDom;
if(null == item.userAvatar || '' == item.userAvatar) {
avatarDom = '<img class="user-avatar" src="assets/images/profile-photo.jpg"/> '
} else {
avatarDom = '<img class="user-avatar" src="route/file/downloadfile/false/'+ item.userAvatar +'"/> ';
}
userDom += '<a id="user_'+ item.userId +'" href="javascript:;" class="users list-group-item" onclick="selectUser(\''+ item.userId +'\', \''+ item.userName +'\', \''+ item.userUsername +'\')">'+ avatarDom + item.userName +' ['+ item.userUsername +']</a>';
}
$('#users').append(userDom);
}, function(code, data) {
top.DialogBox.msg(data.msg);
}, function() {
loadLayerIndex = top.DialogBox.msg(TextMessage.loading, {icon: 16, time: 0, shade: 0.3});
}, function() {
top.DialogBox.close(loadLayerIndex);
});
}
// 初始化树
function initThree() {
var setting = {
async: {
enable: true,
autoLoad: false,
type: 'get',
url: top.restAjax.path('api/department/listdepartments', []),
autoParam:['id'],
otherParam:{},
dataFilter: function(treeId, parentNode, childNodes) {
if (!childNodes) return null;
for (var i=0, l=childNodes.length; i<l; i++) {
childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
}
return childNodes;
}
},
callback: {
onClick: function(event, treeId, treeNode) {
initUsers(treeNode.id);
return false;
}
},
view: {
fontCss: {'color': 'black'}
}
};
var zTree = $.fn.zTree.init($("#leftTree"), setting);
zTree.addNodes(null, {id: '0', pId: '-1', name: '未划分人员', url: 'javascript:;', isParent: 'true'})
}
// 初始化选择的人员
function initSelectedUsers() {
if($('#selectedUserIds').val() != '') {
top.restAjax.get(top.restAjax.path('api/user/listuserbyids/{selectedUserIds}', [$('#selectedUserIds').val()]), {}, null, function(code, data) {
for(var i = 0, item; item = data[i++]; ) {
selectUser(item.userId, item.userName, item.userUsername);
}
$('#userWrapper').append(userDom);
}
// 初始化懒加载
function initUserFlowLoad() {
flow.load({
elem: '#users',
scrollElem: '#users',
isAuto: false,
done: function(page, next) {
var loadLayerIndex;
top.restAjax.get(top.restAjax.path('api/user/listpageselectdepartmentuser/{parentId}', [selectedParentId]), {
page: page,
rows: 20
}, null, function(code, data) {
next(addUserDom(data.rows), page < (parseInt(data.total / 20) + 1));
}, function(code, data) {
top.DialogBox.msg(data.msg);
top.dialog.msg(data.msg);
}, function() {
loadLayerIndex = top.DialogBox.msg(TextMessage.loading, {icon: 16, time: 0, shade: 0.3});
loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
}, function() {
top.DialogBox.close(loadLayerIndex);
top.dialog.close(loadLayerIndex);
});
}
}
$(function() {
$('#app').fadeTo(1000, 1);
initThree();
initUsers(0);
initSelectedUsers();
top.DialogBox.dialogData.selectedDepartmentUsers = null;
});
</script>
</body>
}
function listSearchUser(searchUser) {
if(!searchUser) {
return;
}
var loadLayerIndex;
top.restAjax.get(top.restAjax.path('api/user/listselectdepartmentuser/{parentId}', [selectedParentId]), {
keywords: searchUser
}, null, function(code, data) {
addSearchUserDom(data);
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {
loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
}, function() {
top.dialog.close(loadLayerIndex);
});
}
// 初始化人员列表
function initUsers(parentId) {
selectedParentId = parentId;
$('#userWrapper').empty();
$('.layui-flow-more').remove();
initUserFlowLoad();
}
// 初始化选择的人员
function initSelectedUsers(callback) {
if(typeof(selectedUserIds) != 'undefined' && selectedUserIds != null && selectedUserIds != '') {
var loadLayerIndex;
top.restAjax.post(top.restAjax.path('api/user/listuserbyids', []), {
selectedUserIds: selectedUserIds
}, null, function(code, data) {
for(var i = 0, item; item = data[i++]; ) {
selectUser(item.userId, item.userName);
selectDepartmentUserOldArray.push({
userId: item.userId,
userName: item.userName
});
}
callback();
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {
loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
}, function() {
top.dialog.close(loadLayerIndex);
});
} else {
callback();
}
}
initFrame();
initThree();
initSelectedUsers(function() {
initUsers(0);
});
$('#searchUser').on('keyup', function() {
var value = $(this).val();
if(value) {
$('.layui-flow-more').hide();
} else {
$('.layui-flow-more').show();
}
$('.users').hide().filter(":contains('" + value + "')").show();
$('.search-users').remove();
if(searchTimeout) {
clearTimeout(searchTimeout);
}
searchTimeout = setTimeout(function() {
listSearchUser(value);
}, 1000);
});
// 人员是否已经选择
function isUserSelected(userId) {
var isSelected = false;
for(var i = 0, item; item = selectDepartmentUserArray[i]; i++) {
if(item.userId == userId) {
isSelected = true;
break;
}
}
return isSelected;
}
// 删除已经选择的人员
function removeSelectedUser(userId) {
for(var i = 0, item; item = selectDepartmentUserArray[i]; i++) {
if(item.userId == userId) {
selectDepartmentUserArray.splice(i, 1);
var selectedUserDom = $('#selected_user_'+ userId);
selectedUserDom.focus();
selectedUserDom.remove();
$('#user_'+ userId).removeClass('user-selected');
break;
}
}
}
// 选择人员
function selectUser(userId, userName, isOnlySelect) {
if(!isUserSelected(userId)) {
$('#user_'+ userId).addClass('user-selected');
selectDepartmentUserArray.push({
userId: userId,
userName: userName
});
$('#selectUsers').append('<a id="selected_user_'+ userId +'" href="javascript:void(0);" class="layui-btn layui-btn-xs">'+ userName +' <i class="fa fa-close" lay-click-removeuser data-userid="'+ userId +'"></i></a>');
$('#selected_user_'+ userId).focus();
} else {
if(!isOnlySelect) {
removeSelectedUser(userId);
}
}
}
$(document.body).on('click', '*[lay-click-user]', null, function() {
var data = this.dataset;
selectUser(data.userid, data.username);
});
$(document.body).on('click', '*[lay-click-removeuser]', null, function() {
var data = this.dataset;
removeSelectedUser(data.userid);
});
$(document.body).on('click', '*[lay-click-select-all-user]', null, function() {
$('#userWrapper').children().each(function() {
var data = this.dataset;
selectUser(data.userid, data.username, true);
});
});
$(document.body).on('click', '*[lay-click-clear-all-user]', null, function() {
$('#userWrapper').children().each(function() {
var data = this.dataset;
removeSelectedUser(data.userid);
});
});
$('.close').on('click', function() {
// 关闭按钮返回之前的数据
top.dialog.dialogData.selectedDepartmentUsers = selectDepartmentUserOldArray;
top.dialog.dialogData.selectedUserIds = null;
closeBox();
});
$('.confirm').on('click', function() {
top.dialog.dialogData.selectedDepartmentUsers = selectDepartmentUserArray;
top.dialog.dialogData.selectedUserIds = null;
closeBox();
});
});
</script>
</body>
</html>