<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<%@include file="/wdk/theme/je/module/public/common.jsp"%>
		<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->

	  	<title>组织机构管理(平台管理员)</title>
	  	
	  	<script type="text/javascript"> 
		//初始化加载左侧的树
		$(function(){
			loadOrgTree();
			
			//注册用户添加成功的监听(新增修改页面关闭后刷新左边树)
	  		$.addListener("uum_org_edit","reloadLeftTree");
			
		});
		
		/**
		 * 下拉框
		 */
		function Combo_box(id, moduleCode){
			$.combobox({
				id:id
				,url:'wdk?action=wdk.pub&method=call_service&ajaxparam='+new Date().getTime()
				,queryParams:{
			        _SRVNAME:'service.wdk.pub'
			        ,_SRVMETHOD:'wql_queryCombobox'
			        ,_DATA:$.json2str({
		       			modulecode:moduleCode
		       			,jparam:{
		       				condition:''
		       			}
			        })
			   		,_RSFIELD:'result'
				}
			});
		}
		
		//加载组织树
		function loadOrgTree(){
			debugger;
			//组织参数
			var dataJson = {
				op_acc: $.getSessionUser().account_id
				,parent_uuid: '-1'
				,level: '0'
				,include_self: '1'
				,result_fields:'org_uuid,org_code,org_name,parent_uuid'
				,order_expr:' display_order '
		    };
			var queryMethod= "queryOrgListByParentID"; //方法名
			
			//组织请求数据集
			var dataParam = {
		        _SRVNAME: 'service.usr.org',
		        _SRVMETHOD: queryMethod,
		        _DATA: $.json2str(dataJson),
		        _RSFIELD: 'resultset',//TODO:待确认
		        _RSTYPE: 'tree',
		        _RSPARAM: $.json2str({
		   			idField: 'org_uuid'
		   			,textField: 'org_name'
		   			,parentField: 'parent_uuid'
					,asyn:'0'							//是否是异步 0:同步;1:异步
		   		   	,asyn_dataField:'parent_uuid'		//如果是异步,则从url中取出的参数替换_DATA参数的名
		   		})
		    };
			
		    //加载树    
		    $.tree({
		        id: 'listtree',
		        checkbox: false,
		        expandall: false,
		        cascadeCheck: false,
		        asyn: true,
		        url: 'wdk?action=wdk.pub&method=call_service&ajaxparam='+new Date().getTime(),
		        queryParams:dataParam,
		        onClick:function(event,treeid,node){
		        	//刷新数据
		        	refreshRightPanel(node);
		        }
		    });
		}
		
		
		//新增同级
		function opt_addSameOrg(){
			var arr = $.tree_getAllNode('listtree');
			var org_uuid = $("#org_uuid").val();
		    if(org_uuid==""){
		    	var len =0;
		    	if(arr){
		    		len =arr.length;
		    	}
		    	if(len>0){  //如果没有组织 可以新增顶级同级
		    		alert('没有选择组织,不能新增!');
		          	return;
		    	}else{
		          	$("#parent_uuid").val("-1");
		    	}
		    }else{
		    	if(arr){
		    		for(var i=0;i<arr.length;i++){
		    			//所选节点是根节点
		    			if(org_uuid == arr[i].id && (_sessionuser.account_id != '00000000000000000000000000000000')){
		    				alert('当前账号不能新建顶级组织!');
				          	return;
		    			}
		    		}
		    	}
		    }
			$.openInTab({
		  		id:$.getUUID(),
		  		title:'组织管理-新增组织',
		  		height:600,
		      	width:1250,
		     	url:'platform/uum/uum_org_edit.jsp',
		      	queryParams:{
		        	actionflag:'addSame'
		        	,parent_uuidname:$("#parent_uuidname").val()
		       		,parent_uuid:$("#parent_uuid").val()
		      	}
			});
		}
		
		
		
		//新增子级
		function opt_addSonOrg(){
			var org_uuid = $("#org_uuid").val();
		    if(org_uuid==""){
		      	alert('没有选择组织,不能新增!');
		      	return;
		    }
			$.openInTab({
		  		id:$.getUUID(),
		  		title:'组织管理-新增子级',
		  		height:600,
		      	width:1250,
		     	url:'platform/uum/uum_org_edit.jsp',
		      	queryParams:{
		        	actionflag:'addSon'
		       		,parent_uuidname:$("#org_name").val()
		      		,parent_uuid:$("#org_uuid").val()
		      	}
			});
		}
		
		//修改组织
		function opt_updateOrg(){
			var org_uuid = $("#org_uuid").val();
			if(org_uuid==""){
		      	alert('没有选择组织,不能修改!');
		      	return;
		    }
			$.openInTab({
		  		id:$.getUUID(),
		  		title:'组织管理-修改组织',
		      	height:600,
		      	width:1250,
		     	url:'platform/uum/uum_org_edit.jsp',
		      	queryParams:{
		        	actionflag:'update'
		      		,selected_id:$("#org_uuid").val()
		      	}
			});
		}
		
		
		//新增修改机构后,属性左边机构树
		function reloadLeftTree(retParam){
			if(retParam){
				if(retParam.actionflag=="addSame"){
					//获取当前id
	              	var node = $.tree_getNodeById("listtree", $("#org_uuid").val());     
	           		//刷树
	         	   	$.tree_addNodes("listtree", node.getParentNode(), -1, retParam, false); 
				}else if(retParam.actionflag=="addSon"){
					//获取当前id
	              	var node = $.tree_getNodeById("listtree", $("#org_uuid").val());     
	           		//刷树
	         	   	$.tree_addNodes("listtree", node, -1, retParam, false); 
				}else if(retParam.actionflag=="update"){
					//获取当前id
	             	var node = $.tree_getNodeById("listtree",$("#org_uuid").val());            
	           		//刷新数据
	         		refreshRightPanel(node); 
	         		//返回机构名称
	        	   	node.text = retParam.text; 
	           		//刷树
	            	$.tree_updateNode("listtree",node);
				}
			}
		}
		
		//点击了左侧的树之后,刷新右侧的页面数据
		function refreshRightPanel(node){
			if(node==null){
				return;
			}
			//打开旋转 
			$.wait_open();
			//组织参数
			var dataParam = {
				_SRVNAME:'service.uum.org'
		 	  	,_SRVMETHOD:'queryByID'
		 		,_DATA:$.json2str({
					op_account_uuid:$.getSessionUser().account_id
					,org_uuid:node.id
				})
		  	};
			
			//加载数据
			$.cuajax({
				url:'wdk?action=wdk.pub&method=call_service&ajaxparam='+new Date().getTime()
				,method:"post"
				,timeout:WDK_Timeout
				,data:dataParam  
				,async:false         //这里需要同步,后续还要设置值 false:同步 ;true:异步
				,success:function(result) {
					//关闭旋转 
					$.wait_close();
			  		var jres = $.str2json(result);
			  		//加载成功
			  		if(jres.code=="1"){
			  			//回填数据
			      		$.setFieldValue(jres.org_info, "#view_form");
			  		}else{
			  			alert(jres.desc);
			  		}
		  		
				},
				error:function(result){
		  			$.wait_close();
		  			alert('网络错误!result='+result);
				}
		  	});
		}
		
		//删除组织
		function opt_deleteOrg(){	
			var org_uuid = $("#org_uuid").val();
		    if(org_uuid==""){
		      	alert('请点击需要删除的记录');
		      	return;
		    }
		    
		    confirmDialog('是否确认删除!',function(){
		    	//打开旋转 
				$.wait_open();
				
			  	//组织参数
				var dataParam = {
					_SRVNAME:'service.usr.org'
			   	  	,_SRVMETHOD:'delete'
			   		,_DATA:$.json2str({
						op_account_uuid:$.getSessionUser().account_id
						,org_uuid:$("#org_uuid").val()
					})
			    };
			  	
			  	//加载数据
				$.cuajax({
					url:'wdk?action=wdk.pub&method=call_service&ajaxparam='+new Date().getTime()
			 		,method:"post"
			  		,timeout:WDK_Timeout
			  		,data:dataParam  	
			  		,success:function(result) {
			  			//关闭旋转 
			  			$.wait_close();
			    		var jres = $.str2json(result);
			    		alert(jres.desc);
			    		if(jres.code=="1"){  //操作成功
				    		//加载数据
				    		var arr =[];
				            arr[1] = $("#org_uuid").val();
				            $.tree_remove("listtree",arr);
				            //清空数据
				            $.setFieldNullValue("#view_form");
			    		}
			  		},
			  		error:function(result){
			    		$.wait_close();
			    		alert('网络错误!result='+result);
			  		}
			    });
		    },function(){});
		}
		
		</script>
		
	</head>
	
	<body class="easyui-layout" data-options="fit:true" style="background:#fff;">
		<div data-options="region:'north',border:false,collapsed:false" class="page-title" style="height:45px;line-height:35px;">
			<div class="page-title-text"></div>
			<div class="edit-page-toolbar" style="line-height:30px;">
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa fa-plus'" onclick="opt_addSameOrg()">新增同级</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa fa-plus'" onclick="opt_addSonOrg()">新增子级</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa fa-edit'" onclick="opt_updateOrg()">修改</a>
	    		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa fa-remove'" onclick="opt_deleteOrg()">删除</a>
			</div>
		</div>
		<div data-options="region:'center',border:false,collapsed:false" >	
			<div class="easyui-layout" data-options="fit:true">
				<div data-options="region:'west',border:true,collapsed:false" style="width:220px;" >
					<div class="tree_title" style="width:95%;font-weight: bold;margin:15px 0 0 8px;font-size:14px;">组织机构</div>
		  	  		<div id="listtree"></div>
				</div>
				<div data-options="region:'center',border:true,collapsed:false" style="border-left:0;">
					<div class="edit-container" style="width:985px;">	
					<form id="view_form" >
						<input type="hidden" id="org_uuid" name="org_uuid"/>
						<input type="hidden" id="parent_uuid" name="parent_uuid"/>
						
						<div class="form-title" >
							<span class="form-title-text">基本信息</span>
						</div>
						
						<div class="row">
							<div class="formgroup" style="width:450px;">
								<label>上级组织</label>
								<div>
									<input type="text" class="easyui-validatebox" id="parent_uuidname" name="parent_uuidname" value="" readonly="readonly"/>
								</div>
							</div>
							<div class="formgroup" style="width:450px;">
								<label>系统编码</label>
								<div>
									<input type="text" class="easyui-validatebox" id="path_code" name="path_code" value="" readonly="readonly"/>
								</div>
							</div>					
						</div>
						
						<div class="row">
							<div class="formgroup" style="width:450px;">
								<label>组织编码</label>
								<div>
									<input type="text" class="easyui-validatebox" id="org_code" name="org_code" value="" readonly="readonly"/>
								</div>
							</div>
							<div class="formgroup" style="width:450px;">
								<label>助记码</label>
								<div>
									<input type="text" class="easyui-validatebox" id="mark_code" name="mark_code" value="" readonly="readonly"/>
								</div>
							</div>					
						</div>
						
						<div class="row">
							<div class="formgroup" style="width:450px;">
								<label>组织名称</label>
								<div>
									<input type="text" class="easyui-validatebox" id="org_name" name="org_name" value="" readonly="readonly"/>
								</div>
							</div>
							<div class="formgroup" style="width:450px;">
								<label>主数据标准名称</label>
								<div>
									<input type="text" class="easyui-validatebox" id="simple_name" name="simple_name" value="" readonly="readonly"/>
								</div>
							</div>					
						</div>
						
						<div class="row">
							<div class="formgroup" style="width:450px;">
								<label>英文名称</label>
								<div>
									<input type="text" class="easyui-validatebox" id="english_name" name="english_name" value="" readonly="readonly"/>
								</div>
							</div>
							<div class="formgroup" style="width:450px;">
								<label>排序序号</label>
								<div>
									<input type="text" class="easyui-validatebox" id="display_order" name="display_order" value="" readonly="readonly"/>
								</div>
							</div>					
						</div>
						
						<div class="row">
							<div class="formgroup" style="width:450px;">
								<label>组织类型</label>
								<div>
									<input type="text" class="easyui-validatebox" id="org_type_scodename" name="org_type_scodename" value="" readonly="readonly"/>
								</div>
							</div>
							<div class="formgroup" style="width:450px;">
								<label>组织级别</label>
								<div>
									<input type="text" class="easyui-validatebox" id="org_level_scodename" name="org_level_scodename" value="" readonly="readonly"/>
								</div>
							</div>					
						</div>
						
						<div class="row">	
							<div class="formgroup" style="width:450px;">
								<label>虚拟组织</label>
								<div>
									<input type="checkbox" id="is_virtual_org"  name="is_virtual_org" disabled/> 
								</div>
							</div>
							<div class="formgroup" style="width:450px;">
								<label>是否封存</label>
								<div>
									<input type="checkbox" id="is_seal_up"  name="is_seal_up" disabled/> 
								</div>
							</div>
						</div>
						<div class="row" style="height:50px;">
							<div class="formgroup col-12">
								<label>描述</label>
								<div>
									<textarea class="easyui-validatebox"  id="remark" name="remark" disabled="disabled" rows="2" readonly="readonly" style="resize:none;"></textarea>
								</div>
							</div>
						</div>
						<div class="form-title" style="margin-top:10px;">
							<span class="form-title-text">行政信息</span>
						</div>
						
						<div class="row">
							<div class="formgroup" style="width:450px;">
								<label>行政区划</label>
								<div>
									<input type="text" class="easyui-validatebox" id="area_uuidname" name="area_uuidname" value="" readonly="readonly"/>
								</div>
							</div>
							<div class="formgroup" style="width:450px;">
								<label>法人单位</label>
								<div>
									<input type="checkbox" id="is_ppl_org"  name="is_ppl_org" disabled/> 
								</div>
							</div>
						</div>
						
						<div class="row">
							<div class="formgroup" style="width:450px;">
								<label>法人代表</label>
								<div>
									<input type="text" class="easyui-validatebox" id="principle" name="principle" value="" readonly="readonly"/>
								</div>
							</div>
							<div class="formgroup" style="width:450px;">
								<label>电话</label>
								<div>
									<input type="text" class="easyui-validatebox" id="tel_no" name="tel_no" value="" data-options="validType:'isTel',tipPosition:'bottom'" readonly="readonly"/>
								</div>
							</div>					
						</div>
						
						<div class="row">
							<div class="formgroup" style="width:450px;">
								<label>传真</label>
								<div>
									<input type="text" class="easyui-validatebox" id="fax" name="fax" value="" readonly="readonly"/>
								</div>
							</div>
							<div class="formgroup" style="width:450px;">
								<label>邮编</label>
								<div>
									<input type="text" class="easyui-validatebox" id="zip_code" name="zip_code" value="" readonly="readonly"/>
								</div>
							</div>					
						</div>
						
						<div class="row" style="height:50px;">
							<div class="formgroup col-12">
								<label>地址</label>
								<div>
									<textarea class="easyui-validatebox"  id="address" name="address" disabled="disabled" rows="2" readonly="readonly" style="resize:none;"></textarea>
								</div>
							</div>
						</div>
					</form>	
					</div>
				</div>
			</div>			
		</div>		
	</body>
	
	


</html>