<%@page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<div id="InfoDialog" style="overflow:auto;height:90%">
	<ul id="mappingUser_tree" class="ztree"></ul>
</div>

<div style= "position: absolute; bottom: 21px;width: 100%;">
<table width="90%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td align="right">
			<a href="#" class="easyui-linkbutton" id="save" data-options="iconCls:'icon-ok'" onclick="javascript:saveData()">保存</a>
			<a href="#" class="easyui-linkbutton" id="back" data-options="iconCls:'icon-back'" onclick="javascript:closeBox()">返 回</a>
		</td>
	</tr>
</table>
</div>
<SCRIPT type="text/javascript">
$(function() {
	loadTree();
});
	//展现左边机构树
	function loadTree(){
		
	//展现左边机构树
	 $.sendPost ('jwAppsMappingData_listMappingUserTree', {FIELD_tableName:'B_V_UFP_MAPPER_USERTREE'}, function(data){
		resetQueryData();
		var setting1 = {
		view: {
			  showLine: true,
			  selectedMulti: false
		},
		check: {
			enable: true,
			chkStyle: "checkbox",
			chkboxType: { "Y": "ps", "N": "s" }
		},
		data: {
		  key: {
		    title:"NAME",
		    name:"NAME"
		  },
		  simpleData: {
		    enable: true,
		    idKey: "UUID",
		    pIdKey: "PARENT_ID",
		    rootPId: ""
			  }
			}
		};
		var zTree = $.fn.zTree.init($("#mappingUser_tree"), setting1, data.rowSet);
		var treeNode = zTree.getNodeByParam("UUID","A", null);
		zTree.expandNode(treeNode,null,null,null,null);
	 }, function(data){
		alert("失败");
	 }, "json");
	}
	
	function saveData() {
		var params={}
		var treeObj = $.fn.zTree.getZTreeObj("mappingUser_tree");
		var nodes = treeObj.getCheckedNodes(true);
		var userSysNames="";
		var deptId="";
		for (i = 1; i < nodes.length; i++)
		{
			//人员
			if(nodes[i].TYPE==1){
				var node=nodes[i].getParentNode();
				if(node!=null)
					//结构：  username+appid,username+appid,
					if(userSysNames.indexOf(node.UUID)!=-1)
					{
						$.messager.alert('提示',"同一个应用中，一个统一用户账号只能绑定一个账号！");
						return;
					}
					userSysNames=userSysNames+nodes[i].UUID+"+"+node.UUID+",";
			}
		}
		if(userSysNames.length>0){
			userSysNames = userSysNames.substring(0,userSysNames.length - 1);
			params.FIELD_USER_ID='${is_row.USER_ID}';
			params.uuids=userSysNames;
			//新建
			$.sendPost ('jwAppsMappingAct_insertMappingUser', params, function(v_result){
				$.messager.alert('提示',v_result.VALUE);
				$('#list').datagrid('reload');
			}, function(data){
				alert("失败");
			}, "json");
			
			
		}
		else{
			$.messager.alert('提示',"未选择绑定的用户");
			return;
		}
	}
</SCRIPT>
