<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>私塾家</title>
<script th:include="sys/common/metaCSS" th:remove="tag"></script> 
<script th:include="sys/common/metaJS" th:remove="tag"></script> 
<script src="sys/js/My97DatePicker/WdatePicker.js" th:src="@{/static/sys/js/My97DatePicker/WdatePicker.js}"></script>

<link href="sys/css/bootstrap.css" th:href="@{/static/sys/css/bootstrap.css}" rel="stylesheet"/>
<link href="sys/css/zTree/zTreeStyle.css" th:href="@{/static/sys/css/zTree/zTreeStyle.css}" rel="stylesheet"/>
<script src="js/jquery-2.2.4.min.js" th:src="@{/static/js/jquery-2.2.4.min.js}"></script>
<script src="sys/js/zTree/jquery.ztree.all-3.5.min.js" th:src="@{/static/sys/js/zTree/jquery.ztree.all-3.5.min.js}"></script>

</head>
<style>
	.tablelink{margin-right:10px;}
	.stylecss{
	      color: red;
	}
	.select_width{
	     width: 220px;
	}
	.date_width{
	     width: 150px;
	}
	
	.tablelist th,td{
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}
	
	span{margin:0;padding:0;display: inline-block;}
    	@media (min-width: 1200px){
			.row-fluid [class*="span"] {
			    margin-left: 0px;
			}
		}
	
	
</style>
<body>
<div class="place">
	<span>位置：</span>
	<ul class="placeul">
		<li><a href="#">商户管理</a></li>
		<li><a href="#">所有商户</a></li>
	</ul>
</div>

<div class="rightinfo container-fluid" style="padding-left: 10px;">
	<div class="row-fluid">
		<div id="divTree" class="span2" >
			<ul id="columnsTree" class="ztree" style="min-height:540px; overflow: auto;"></ul>
			
<!-- 			<div class="span2" id="closeTree" style="background-color: #ccc;width: 15px;height: 100%;padding-top: 300px;color: red;cursor: pointer;  "> -->
<!-- 				<span> -->
<!-- 					&lt;&gt; -->
<!-- 				</span> -->
<!-- 			</div> -->
		</div>
		
		<div class="span10" >
			<iframe id="listIframe" scrolling="auto" frameborder="0" style="width:104%;height:100%;"></iframe>
		</div>
	</div>
</div>

</body>


<script type="text/javascript">
function addTab(url) {
	$("#listIframe").attr("src",url);
	startInit("listIframe", 560);
}

function refreshList(){
	$("#listIframe").attr("src", $("#listIframe").attr("src"));
}

var setting = {
	async : {
		enable : true,
		autoParam : [ "id" ],
		url : "[[${sysUrl}]]/sys/fx/merchantTree",
		dataFilter : filter
	},
	data : {
		key : {
			name : "name"
		},
		simpleData : {
			enable : true,
			pIdKey : "pId"
		}
	},
	callback : {
		onClick : clickNode,
		onAsyncSuccess : renderIcon
	}
};

function filter(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;
}

function clickNode(event, treeId, treeNode, clickFlag) {
	var url = "[[${sysUrl}]]/sys/fx/merchantAllList.html?LIKE_orgCode=" + treeNode.id;
	addTab(url);
	event.preventDefault();
}

function renderIcon(event, treeId, treeNode, msg){
	var ztree = $.fn.zTree.getZTreeObj(treeId);
	var nodes = null;
	if(treeNode){
		nodes = treeNode.children;
	}
	if(nodes){
		for(var i = 0; i < nodes.length; i++){
			nodes[i].icon="[[${imgUrl}]]/resources/images/menu_1.png";
			ztree.updateNode(nodes[i]);
		}
	}
	zTreeOnAsyncSuccess(event, treeId, treeNode, msg, ztree);
}

var firstAsyncSuccessFlag = 0;
function zTreeOnAsyncSuccess(event, treeId, treeNode, msg, zTree) {
	if (firstAsyncSuccessFlag == 0) {  
	      try {  
	             //调用默认展开第一个结点  
	             var selectedNode = zTree.getSelectedNodes();  
	             var nodes = zTree.getNodes();  
	             zTree.expandNode(nodes[0], true);
	             
	             var childNodes = zTree.transformToArray(nodes[0]);  
                 zTree.selectNode(childNodes[0]);  
	          	 
	             clickNode(event, treeId, treeNode, true);
	             firstAsyncSuccessFlag = 1;
	       } catch (err) {  
	          
	       }  
	   }  
}

// 增删改节点之后，刷新局部
function refreshNode(id, pid, name, op) {
	var ztree = $.fn.zTree.getZTreeObj("columnsTree");
	var pNode = ztree.getNodeByParam("id", pid, null);
	// 添加一级节点
	if (pNode == null) {
		ztree.refresh();
	}
	// 父节点是叶子节点，只能是新增
	if (!pNode.isParent) {
		pNode.isParent = true;
		ztree.reAsyncChildNodes(pNode, "refresh");
	}
	// 父节点未展开，直接返回
	if (!pNode.open)
		return;
	// 新增节点，重新展开父节点
	if (id == "") {
		pNode.open = false;
		ztree.reAsyncChildNodes(pNode, "refresh");
		return;
	}
	// 删除
	var treeNode = ztree.getNodeByParam("id", id, null);
	if (op == "delete") {
		ztree.removeNode(treeNode);
	} else {
		// 修改
		treeNode.name = name;
		ztree.updateNode(treeNode);
	}
}

$(document).ready(function() {
	$.fn.zTree.init($("#columnsTree"), setting);
});

var browserVersion = window.navigator.userAgent.toUpperCase();
var isOpera = false;
var isFireFox = false;
var isChrome = false;
var isSafari = false;
var isIE = false;
var iframeTime;
function reinitIframe(iframeId, minHeight) {
    try {
    	if (typeof(reValue) == "undefined") {
    		browserVersion = window.navigator.userAgent.toUpperCase();
    	}
        var iframe = document.getElementById(iframeId);
        var bHeight = 0;
        if (isChrome == false && isSafari == false)
            bHeight = iframe.contentWindow.document.body.scrollHeight;

        var dHeight = 0;
        if (isFireFox == true)
            dHeight = iframe.contentWindow.document.documentElement.offsetHeight + 2;
        else if (isIE == false && isOpera == false)
            dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
        else
            bHeight += 3;
        var height = Math.max(bHeight, dHeight);
        if (height < minHeight) height = minHeight;
        iframe.style.height = height + "px";
    } catch (ex) { }
}
function startInit(iframeId, minHeight) {
	if (typeof(reValue) == "undefined") {
		browserVersion = window.navigator.userAgent.toUpperCase();
	}
    isOpera = browserVersion.indexOf("OPERA") > -1 ? true : false;
    isFireFox = browserVersion.indexOf("FIREFOX") > -1 ? true : false;
    isChrome = browserVersion.indexOf("CHROME") > -1 ? true : false;
    isSafari = browserVersion.indexOf("SAFARI") > -1 ? true : false;
    if (!!window.ActiveXObject || "ActiveXObject" in window)
        isIE = true;
    reinitIframe(iframeId, minHeight);
    if (iframeTime != null)
        clearInterval(iframeTime)
    iframeTime = window.setInterval("reinitIframe('" + iframeId + "'," + minHeight + ")", 100);
}
</script>

<script type="text/javascript">


$(function () {
	
	$("#reduce_num").click(function (){
		if($("#add_service_num").val()<=1){
			parent.layer.msg("塾币不能小于1。",{icon:11});
			return;
		}
		$("#add_service_num").val(parseInt($("#add_service_num").val())-1);
	});
	
	$("#add_num").click(function (){
		$("#add_service_num").val(parseInt($("#add_service_num").val())+1);
	});

})


function save(){
	var type= $("#service_type").val();
	var num=$("#add_service_num").val();
	var merchantId=$("#merchant_id").val();
	
	var url="[[${sysUrl}]]/sys/fx/merchant/update/"+merchantId;
	var params ={
        'type' : type,
        'num':num
    };
	$.post(url,params,function(data){
		if(data.meta.success){
			parent.layer.msg("设置成功",{icon:1});
			parent.location.reload();
			parent.layer.close(parent.layer.getFrameIndex(window.name));
		}else{
			parent.layer.msg(data.meta.message,{icon:11});
		}
	});
}


function joinServiceAdd(type){
	var title='';
	if(type==1){
		title="添加机构塾币";
	}else if(type==3){
		title="添加平台塾币";
	}else{
		title="添加机构端口";
	}
	$("#add_service_num").val(1)
	 $.ajax({
		  url: "[[${sysUrl}]]/sys/fx/getMerchant/"+$("#merchant_id").val(),
	      type: 'POST',
	      data: {},
	      processData: false,
	      contentType: false, 
	      beforeSend: function () {
	      },
	      success: function (responseStr) {
	    	  if(responseStr.meta.success){
	    		  $("#service_type").val(type);
	    		  layer.open({
	    			    type: 1,
	    			    title: title,
	    			    closeBtn: 1, //不显示关闭按钮
	    			    shift: 0.8,
	    			    offset: '150px',
	    			    area: ['40%', '40%'],
	    			    content: $("#joinServiceAdd")
	    			});
	    		  
	    	  }else{
	    		  parent.layer.msg(responseStr.meta.message,{icon:11});
	    	  }
	      }
	      ,
	      error : function (responseStr) {
	    	  parent.layer.msg("查询失败,请刷新后重试！",{icon:11});
	      }
	  });
	

}


function joinServiceEdit(id){
	  $.ajax({
		  url: "[[${sysUrl}]]/sys/fx/getMerchant/"+id,
	      type: 'POST',
	      data: {},
	      processData: false,
	      contentType: false, 
	      beforeSend: function () {
	      },
	      success: function (responseStr) {
	    	  if(responseStr.meta.success){
	    		  
	    		  $("#merchant_id").val(id);
	    		  $("#lib_service_num").html(responseStr.data.merchant.libService);
	    		  $("#platform_service_num").html(responseStr.data.merchant.platformService);
	    		  $("#port_num").html(responseStr.data.merchant.portNum);
	    		  
	    		  layer.open({
    			    type: 1,
    			    title: '管理塾币',
    			    closeBtn: 1, //不显示关闭按钮
    			    shift: 0.8,
    			    offset: '150px',
    			    area: ['40%', '40%'],
    			    content: $("#joinServiceEdit")
	    		 });
	    		  
	    	  }else{
	    		  parent.layer.msg(responseStr.meta.message,{icon:11});
	    	  }
	      }
	      ,
	      error : function (responseStr) {
	    	  parent.layer.msg("查询失败,请刷新后重试！",{icon:11});
	      }
	  });
}
</script>

<script type="text/javascript">

		function merchantallot(type){
			var id=$("#merchant_id").val();
			var title="";
			if(type==1){
				title="分配机构塾币";
			}else{
				title="分配平台塾币";
			}
			layer.open({
			    type: 2,
			    title: title,
			    closeBtn: 1, //不显示关闭按钮
			    shift: 0.8,
			    offset: '150px',
			    area: ['40%', '40%'],
			    content: '[[${sysUrl}]]/sys/fx/merchantAllot.html?id='+id+'&type='+type
			});
		}


		function savemerchant(id){
			var title="开通商户";
			if(id!=null && id!='' && id!=undefined){
				title="修改商户";
			}
			layer.open({
			    type: 2,
			    title: title,
			    closeBtn: 1, //不显示关闭按钮
			    shift: 0.8,
			    offset: '10px',
			    area: ['50%', '90%'],
			    content: '[[${sysUrl}]]/sys/fx/merchantAdd.html?id='+id
			});
		}


		function updatemerchant(id,status){  
			
			if(status==4){
				parent.layer.confirm("确定操作删除？", {
					icon: 4, btn: ['确定','关闭'],offset: '100px' //按钮
				}, function(){
					$.ajax({
						url : "[[${sysUrl}]]/sys/fx/updateMerchant",
						type : "post",
						data : {id:id,status:status},
						dataType : "json",
						success : function(data) {
							if(data.meta.success){
								parent.layer.msg("操作成功",{icon:1});
						    	setTimeout(function(){
						    		location.reload();
								},1000);
							}else{
								alert("操作异常，请刷新后重试...")
							}
						}
					});
				});
			}else{
				
				$.ajax({
					url : "[[${sysUrl}]]/sys/fx/updateMerchant",
					type : "post",
					data : {id:id,status:status},
					dataType : "json",
					success : function(data) {
						if(data.meta.success){
							parent.layer.msg("操作成功",{icon:1});
					    	setTimeout(function(){
					    		location.reload();
							},1000);
						}else{
							alert("操作异常，请刷新后重试...")
						}
					}
				});
			}
		}
	
	
</script>

<script type="text/javascript">
$("#button").on('click',function(){
	document.getElementById("seachform").action = "[[${sysUrl}]]/sys/fx/exportMerchant";
	$("#seachform").submit();
	document.getElementById("seachform").action = "[[${sysUrl}]]/sys/fx/merchantAllList.html";
});

$("#closeTree").on('click',function(){
	var display =$('#divTree').css('display');
	if(display == 'none'){
		$("#divTree").show();
		$(".span10").css("width","82.90598290598291%");
	}else{
		$("#divTree").hide();
		$(".span10").css("width","95%");
	}
	
});


</script>




</html>