<!DOCTYPE html>
<html>

<head>
	<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, maximum-scale=1">
	<link charset="utf-8" rel="stylesheet" href="/static/css/layui.css?v=1.0.0">
	<link rel="stylesheet" href="/static/css/temp.css" media="all">
	<script src="/static/js/jquery-1.8.2.min.js?v=1.0.0"></script>
	<script src="/static/js/layui.js?v=1.0.0"></script>
	<script src="/static/js/common.js?v=1.0.0"></script>
	<script src="/static/js/api.config.js"></script>
	<script src="/static/js/util.js?v=1.0.0"></script>
	<script src="/static/js/customform.js?v=1.0.0"></script>
	<script src="/static/js/url.js?v=1.0.0"></script>
	<script src="/static/js/lay/lay-config.js?v=1.0.0"></script>
	<script src="/static/js/jquery.nestable.js"></script>
</head>
<style>
	.border-info {

		border: 1px solid #e1e4e3;
	}
</style>

<body class="bg-info">

	<div class="layui-card  border-info">

		<div class="layui-card-header layui-card-header-bb-2"
			style="height: 70px;line-height: 20px; padding-left: 0;padding-right: 8px;">
			<div style="float: left;line-height: 70px; padding-left: 20px;font-size: 15px;font-weight: bold;">

				工号角色配置
			</div>

			<div style="border-left: 2px solid #e1e4e3;float: right;margin: 5px;">

				<div class="card-btn" style="margin-left: 10px;" onclick="save()">
					<div class="card-btn-img img-save"></div>
					<div class="card-btn-desc">
						保存
					</div>
				</div>

			</div>


		</div>
		<div class="layui-card-body">

			<div class="layui-row">

				<div class="layui-col-sm4 " style="padding-right: 15px;">

					<div class="layui-card border-info">

						<div class="layui-card-header " style="font-weight: bold;">

							可选角色
							<!-- <div style="float: right;">
									<i class="layui-icon layui-icon-addition" style="font-size: 30px; color: #1E9FFF;"></i>
								</div> -->
						</div>
						<div class="layui-card-body" style="padding: 10px;">

							<div class="dd" id="chnlChain1" style="overflow-y: auto;">

							</div>
						</div>

					</div>
				</div>
				<div class="layui-col-sm4 " style="">
					<div class="layui-card border-info">

						<div class="layui-card-header" style="font-weight: bold;">

							已选角色
						</div>
						<div class="layui-card-body" style="padding: 10px;">
							<div class="dd" id="chnlChain2" style="overflow-y: auto;"></div>
						</div>
					</div>
				</div>

			</div>

		</div>

	</div>

	<input type="hidden" name="loginNo" />
	<input type="hidden" name="loginName" />
</body>

<script>
	$(function () {

		var url = ctx + "/sysmgr/sys/settings/sysLoginFuncs/queryInit";

		var param = util.getUrlParam();

		$("input[name=loginNo]").val(param.loginNo);

		$("input[name=loginName]").val(param.loginName);

		util.ajaxJson("页面加载中，请稍后...", url, {
			"loginNo": param.loginNo
		}, function (data) {

			if (data.result != "0") {

				util.showDialog("页面加载失败!", 0);

				console.log(data);

				return;
			}


			var authEnum = [];

			$.each(data.body.authList, function (i, item) {

				authEnum.push({
					"key": item.optCode,
					"value": item.optName
				});
			});


			$('#chnlChain1').nestable({
				group: 1,
				maxDepth: 1,
				rmSourceItem: false,
				itemKey: "roleCode",
				itemName: 'roleName',
				data: data.body.roleList
			});

			$('#chnlChain2').nestable({
				group: 1,
				maxDepth: 1,
				dragFlag: true, //是否允许拖拽
				addItemCloseBtn: true, //是否添加删除按钮
				addItemQuickBtn: true,
				quickKey: 'authTar',
				quickDesc: 'authTarDesc',
				quickTitle: '赋权',
				quickEnum: authEnum,
				itemKey: "roleCode",
				itemName: 'roleName',
				data: data.body.checkRoleList
			});
		});
	});




	function save() {

		var sourceArr = $('#chnlChain1').nestable('getItemData');

		var arr = $('#chnlChain2').nestable('getItemData');

		for (var i = 0; i < arr.length; i++) {

			arr[i].loginNo = $("input[name=loginNo]").val();
			arr[i].loginName = $("input[name=loginName]").val();
		}

		// if (sourceArr.length == 0) {

		// 	arr = [];
		// }

		var url = ctx + "/sysmgr/sys/settings/sysLoginFuncs/updateRole";


		util.ajaxJson("保存中，请稍后···", url, {
			"loginNo": $("input[name=loginNo]").val(),
			"checkRoleList": arr
		}, function (data) {



			if (data.result != "0") {

				util.error("保存失败!");

			} else {

				util.success("保存成功!");


			}



		});
	}



	$(".dd").height($(window).height() - 200);
</script>

</html>