teamBusinessEdit.js 10.7 KB
Newer Older
doc_wei's avatar
doc_wei 已提交
1

doc_wei's avatar
doc_wei 已提交
2 3
var userList = new Array();

doc_wei's avatar
doc_wei 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16
layui.config({
	base: basePath, 
	version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'jquery', 'winui', 'textool', 'tableTreeDj', 'form'], function (exports) {
	winui.renderColor();
	var index = parent.layer.getFrameIndex(window.name);
	var $ = layui.$,
		textool = layui.textool,
		tableTree = layui.tableTreeDj,
		form = layui.form;
	var objectKey = GetUrlParam("objectKey");
17 18
	var objectId = GetUrlParam("objectId");
	var objectType = GetUrlParam("objectType");
doc_wei's avatar
doc_wei 已提交
19 20 21 22 23 24 25 26

	var treeTableData = [];
	// 已经选中的权限对应关系
	var checkTrueList = [];

	showGrid({
		id: "showForm",
		url: reqBasePath + "queryTeamBusiness",
27
		params: {objectId: objectId},
doc_wei's avatar
doc_wei 已提交
28 29 30 31 32 33
		pagination: false,
		method: "GET",
		template: $("#showTemplate").html(),
		ajaxSendLoadBefore: function(hdb, json) {},
		ajaxSendAfter: function (json) {
			loadTreeTable();
doc_wei's avatar
doc_wei 已提交
34 35 36 37 38
			userList.push(json.bean.chargeUserMation);
			$.each(userList, function(i, item) {
				$("#chargeUser").val(item.name);
			});

doc_wei's avatar
doc_wei 已提交
39
			// 解析成员信息
40 41
			if (!isNull(json.bean.teamRoleList)) {
				$.each(json.bean.teamRoleList, function (i, item) {
doc_wei's avatar
doc_wei 已提交
42
					treeTableData.push({
43 44 45 46 47 48 49 50 51 52 53 54 55
						id: item.roleId,
						pId: '0',
						name: item.name
					});
					$.each(item.teamRoleUserList, function (j, bean) {
						treeTableData.push({
							id: bean.userId,
							pId: item.roleId,
							name: bean.userMation.name,
							departmentName: bean.userMation.departmentName,
							phone: bean.userMation.phone,
							email: bean.userMation.email
						});
doc_wei's avatar
doc_wei 已提交
56 57
					});
				});
58
			}
doc_wei's avatar
doc_wei 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

			// 解析权限信息
			$.each(json.bean.teamObjectPermissionList, function (i, item) {
				var authGroupKey = item.permissionKey;
				var authKey = item.permissionValue;
				var checkParams = getInPoingArr(treeTableData, "id", item.ownerId);
				if (checkParams != null) {
					var roleId = checkParams.pId == '0' ? checkParams.id : checkParams.pId;
					var userId = checkParams.pId == '0' ? '' : checkParams.id;
					var id = authGroupKey + '_' + authKey + '_' + roleId + '_' + userId;
					checkTrueList.push(id);
				}
			});

			reloadTreeTable();

			textool.init({eleId: 'remark', maxlength: 200});
			matchingLanguage();
			form.render();
			form.on('submit(formEditBean)', function (data) {
				if (winui.verifyForm(data.elem)) {
					var teamRoleList = getTeamRoleList();
					if (teamRoleList.length == 0) {
						winui.window.msg('团队成员不能为空', {icon: 2, time: 2000});
						return false;
					}
					var teamObjectPermissionList = getTeamObjectPermissionList();
					var params = {
						id: json.bean.id,
88 89 90
						objectId: objectId,
						objectKey: objectKey,
						teamTemplateId: json.bean.teamTemplateId,
doc_wei's avatar
doc_wei 已提交
91
						teamRoleList: JSON.stringify(teamRoleList),
doc_wei's avatar
doc_wei 已提交
92
						chargeUser: userList[0].id,
doc_wei's avatar
doc_wei 已提交
93 94 95
						teamObjectPermissionList: JSON.stringify(teamObjectPermissionList)
					};
					AjaxPostUtil.request({url: reqBasePath + "updateTeamBusiness", params: params, type: 'json', method: "POST", callback: function (json) {
96 97
						location.href = "../../tpl/teamBusiness/teamBusinessDetails.html?objectId=" + objectId + "&objectKey=" + objectKey
							+ "&objectType=" + objectType;
doc_wei's avatar
doc_wei 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
					}});
				}
				return false;
			});
		}
	});

	function loadTreeTable() {
		tableTree.render({
			id: 'messageTable',
			elem: '#messageTable',
			data: [],
			// 该参数不能删除,分页参数无效,目前只能通过设置10000来保证当前页最大的数据量
			limit: 10000,
			cols: [[
				{ field: 'name', title: '名称', width: 160 },
				{ field: 'departmentName', title: '部门', width: 120 },
				{ field: 'phone', title: '联系方式', width: 140 },
				{ field: 'email', title: '邮箱', width: 200 },
				{ title: systemLanguage["com.skyeye.operation"][languageType], fixed: 'right', align: 'center', width: 150, toolbar: '#tableBar' }
			]],
			done: function(json) {
				matchingLanguage();
			}
		}, {
			keyId: 'id',
			keyPid: 'pId',
			title: 'name',
			defaultShow: true,
		});

		tableTree.getTable().on('tool(messageTable)', function (obj) {
			var data = obj.data;
			var layEvent = obj.event;
			if (layEvent === 'removeRole') {
				// 移除角色和该角色下的用户
doc_wei's avatar
doc_wei 已提交
134
				var tmp = [];
doc_wei's avatar
doc_wei 已提交
135
				$.each(treeTableData, function(index, item) {
doc_wei's avatar
doc_wei 已提交
136 137
					if (item.id != data.id && item.pId != data.id) {
						tmp.push(item);
doc_wei's avatar
doc_wei 已提交
138 139
					}
				});
doc_wei's avatar
doc_wei 已提交
140 141
				treeTableData = [].concat(tmp);

doc_wei's avatar
doc_wei 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
				restCheckbox();
				reloadTreeTable();
			} else if (layEvent === 'addUser') { // 添加成员
				var roleId = data.id;
				systemCommonUtil.userReturnList = [];
				systemCommonUtil.chooseOrNotMy = "1"; // 人员列表中是否包含自己--1.包含;其他参数不包含
				systemCommonUtil.chooseOrNotEmail = "2"; // 人员列表中是否必须绑定邮箱--1.必须;其他参数没必要
				systemCommonUtil.checkType = "1"; // 人员选择类型,1.多选;其他。单选
				systemCommonUtil.openSysUserStaffChoosePage(function (userReturnList) {
					var userList = [].concat(userReturnList);
					$.each(userList, function (i, item) {
						// 一个用户在一个团队中只能属于一个角色
						var checkParams = getInPoingArr(treeTableData, "id", item.id);
						if (checkParams == null) {
							item['pId'] = roleId;
							treeTableData.push(item);
						}
					});
					restCheckbox();
					reloadTreeTable();
				});
			} else if (layEvent === 'removeUser') { // 移除成员
				var roleId = data.pId;
				var userId = data.id;
				$.each(treeTableData, function(index, item) {
					if (!isNull(item) && item.pId == roleId && item.id == userId) {
						treeTableData.splice(index, 1);
					}
				});
				restCheckbox();
				reloadTreeTable();
			}
		});
	}

	// 刷新成员树表格
	function reloadTreeTable() {
		var data = $.extend(true, [], treeTableData);
		tableTree.reload("messageTable", {data: data});
		loadAuthList();
	}

	loadAuthList();
	form.on('select(objectType)', function(data) {
		checkTrueList = [];
		loadAuthList();
	});

	function getTeamRoleList() {
		var teamRoleList = [];
		$.each(treeTableData, function (i, item) {
			var teamRole = {};
			if (item.pId == '0') {
				// 角色
				teamRole['roleId'] = item.id;
				// 查询这个角色下的用户
				var roleUserList = [];
				$.each(treeTableData, function (j, bean) {
					if (bean.pId == item.id) {
						roleUserList.push({
							userId: bean.id
						});
					}
				});
				teamRole['teamRoleUserList'] = roleUserList;
				teamRoleList.push(teamRole);
			}
		});
		return teamRoleList;
	}

	function getTeamObjectPermissionList() {
		var checkRow = $("#authList input[type='checkbox']:checked");
		var teamObjectPermissionList = [];
		$.each(checkRow, function (i, item) {
			var id = $(item).attr('id');
			var str = id.split('_');
			var authGroupKey = str[0];
			var authKey = str[1];
			var roleId = str[2];
			var userId = str[3];
			teamObjectPermissionList.push({
				permissionKey: authGroupKey,
				permissionValue: authKey,
				ownerId: isNull(userId) ? roleId : userId,
				ownerKey: isNull(userId) ? sysServiceMation["dictData"]["key"] : sysServiceMation["userInfo"]["key"],
				fromType: 1
			});
		});
		return teamObjectPermissionList;
	}

	function loadAuthList() {
		// 加载该受用类型的团队可以设置哪些权限
		var colsList = teamObjectPermissionUtil.getAuthCols(objectType);
		$('#authList').html(getDataUseHandlebars($('#authTableTemplate').html(), {list: colsList}));
		$.each(colsList, function (i, item) {
			var data = $.extend(true, [], treeTableData);
			// 给数据设置权限组的key,
			$.each(data, function (j, bean) {
				bean.authGroupKey = item.id;
			});
			loadAuthTreeTable(item.id, item.cols, data);
		});

		$.each(checkTrueList, function (i, id) {
			$(`input[id='${id}']`).prop("checked", true);
		});
		form.render('checkbox');

		form.on('checkbox(checkClick)', function(obj) {
			var id = $(this).attr('id');
			var str = id.split('_');
			var authGroupKey = str[0];
			var authKey = str[1];
			var roleId = str[2];
			var userId = str[3];
			var name = authGroupKey + '_' + authKey + '_' + roleId;
			var _table = $(`div[lay-id='${authGroupKey}']`);
			if (isNull(userId)) {
				// 如果用户id为空,代表点击的是角色的选择box,需要把name是这个的都选中
				if (obj.elem.checked) {
					_table.find(`input[name='${name}']`).prop("checked", true);
				} else {
					_table.find(`input[name='${name}']`).prop("checked", false);
				}
			} else {
				if (obj.elem.checked) {
					if (_table.find(`input[name='${name}']:checked`).length
						== _table.find(`input[name='${name}']`).length - 1) {
						$(`input[id='${name}_']`).prop("checked", true);
					}
				} else {
					$(`input[id='${name}_']`).prop("checked", false);
				}
			}

			restCheckbox();
			form.render('checkbox');
		});
	}

	function restCheckbox() {
		// 将所有选中的重新放入 checkTrueList 中,防止出现操作成员信息时无法回显
		var checkRow = $("#authList input[type='checkbox']:checked");
		checkTrueList = [];
		$.each(checkRow, function (i, item) {
			checkTrueList.push($(item).attr('id'));
		});
	}

	function loadAuthTreeTable(id, cols, data) {
		tableTree.render({
			id: id,
			elem: '#' + id,
			data: data,
			// 该参数不能删除,分页参数无效,目前只能通过设置10000来保证当前页最大的数据量
			limit: 10000,
			cols: [cols],
		}, {
			keyId: 'id',
			keyPid: 'pId',
			title: 'name',
			defaultShow: true,
		});
	}

	$("body").on("click", "#addRole", function() {
		_openNewWindows({
			url: "../../tpl/sysDictData/sysDictDataSelectChoose.html?sysDictType=teamRole",
			title: '选择角色',
			pageId: "sysDictDataSelectChoose",
			area: ['50vw', '50vh'],
			callBack: function (refreshCode, turnData) {
				var checkParams = getInPoingArr(treeTableData, "id", turnData.id);
				if (checkParams == null) {
					turnData["pId"] = '0';
					turnData["lay_is_open"] = true;
					treeTableData.push(turnData);
					reloadTreeTable();
				} else {
					winui.window.msg("角色重复", {icon: 2, time: 2000});
				}
			}});
	});

doc_wei's avatar
doc_wei 已提交
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
	// 团队经理选择
	$("body").on("click", "#chargeUserSelPeople", function (e) {
		systemCommonUtil.userReturnList = [].concat(userList);
		systemCommonUtil.chooseOrNotMy = "1"; // 人员列表中是否包含自己--1.包含;其他参数不包含
		systemCommonUtil.chooseOrNotEmail = "2"; // 人员列表中是否必须绑定邮箱--1.必须;其他参数没必要
		systemCommonUtil.checkType = "2"; // 人员选择类型,1.多选;其他。单选
		systemCommonUtil.openSysUserStaffChoosePage(function (userReturnList) {
			// 重置数据
			userList = [].concat(userReturnList);
			// 添加选择
			$.each(userList, function(i, item) {
				$("#chargeUser").val(item.name);
			});
		});
	});

doc_wei's avatar
doc_wei 已提交
344
	$("body").on("click", "#cancle", function() {
345 346
		location.href = "../../tpl/teamBusiness/teamBusinessDetails.html?objectId=" + objectId + "&objectKey=" + objectKey
			+ "&objectType=" + objectType;
doc_wei's avatar
doc_wei 已提交
347 348
	});
});