<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>案例库管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/webpage/include/treeview.jsp" %>
	<style type="text/css">
		.ztree {overflow:auto;margin:0;_margin-top:10px;padding:10px 0 0 10px;}
	</style>
	<script type="text/javascript">
        function refresh(){//刷新
            window.location="${ctx}/workexample/workExample/form?exampleId="+$("#exampleId").val();
        }
        function changeExample(id,name,parentId) {
            var exampleId = $("#exampleId").val();
            $.ajax({
                type:'post',
                url:'${ctx}/workexample/workExampleIndices/saveExample',
                data:{
                    "ids":id,"exampleId":exampleId
                },
                success:function(data){
                    refreshTree(exampleId);
                }
            })

			//alert("id:"+id+",name:"+name+",parentId:"+parentId)
        }
        function sleep(numberMillis) {
            var now = new Date();
            var exitTime = now.getTime() + numberMillis;
            while (true) {
                now = new Date();
                if (now.getTime() > exitTime)
                    return;
            }
        }
        function addExampleInfo() {
            parent.layer.msg("请先暂存工程概况数据!", {icon: 5});
        }
        function doSubmita(obj) {
           if($('#userContent')[0].contentWindow.doSubmit(obj)){
               //sleep(500);
               return true;
		   }else {
               return false;
		   }
        }

        function sleep(numberMillis) {
            var now = new Date();
            var exitTime = now.getTime() + numberMillis;
            while (true) {
                now = new Date();
                if (now.getTime() > exitTime)
                    return;
            }
        }

	</script>
	<style>
		body{
			background-color:transparent;
			filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#26FFFFFF, endColorstr=#26FFFFFF);
			color:#ffffff;
			background-color:rgba(255,255,255,0);
			height:100%;
		}
	</style>
</head>
<body>
<div class="wrapper wrapper-content full-width" id="divId">
	<sys:message content="${message}"/>
	<div id="content" class="pr full-height full-width">
		<div id="left"  class="contentShadow fl contents">
			<div class="ztreeContainer">
				<c:choose>
					<c:when test="${sign == 'view' or sign == 'audit'}">

					</c:when>
					<c:otherwise>
						<div class="layui-item nav-btns">
							<input id="exampleId" name="exampleId" type="hidden" value="${workExample.id}"/>
									<div id="id1" style="display:none">
										<sys:treeselectExample id="exampleInfo" name="" value="" labelName="" labelValue="" title="指标项目" url="/workexample/workExampleIndices/treeDataExampleInfo" checked="true" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
									</div>
									<div id="id2" style="display:none">
									<button style="font-size:14px;" type="button" onclick="addExampleInfo()" class="nav-btn nav-btn-add"><i class="fa fa-plus"></i>&nbsp;新增
									</button>
									</div>


						</div>
					</c:otherwise>
				</c:choose>

				<div id="ztree" class="ztree leftBox-content"></div>
			</div>
		</div>
		<div id="right"  class="fl contents">
			<div class="layui-row contentShadow full-height tran-bg">
				<c:choose>
					<c:when test="${sign == 'view'}">
						<iframe id="userContent" name="userContent" src="${ctx}/workexample/workExample/view?id=${workExample.id}" width="100%" height="100%" frameborder="0"></iframe>
					</c:when>
					<c:when test="${sign == 'audit'}">
						<iframe id="userContent" name="userContent" src="${ctx}/workexample/workExample/audit?id=${workExample.id}" width="100%" height="100%" frameborder="0"></iframe>
					</c:when>
					<c:when test="${sign == 'modify'}">
						<iframe id="userContent" name="userContent" src="${ctx}/workexample/workExample/modify?id=${workExample.id}" width="100%" height="100%" frameborder="0"></iframe>
					</c:when>
					<c:otherwise>
						<iframe id="userContent" name="userContent" src="${ctx}/workexample/workExample/forms?id=${workExample.id}" width="100%" height="100%" frameborder="0"></iframe>
					</c:otherwise>
				</c:choose>
			</div>
		</div>
	</div>
</div>
	<script type="text/javascript">
        function addDiyDom(treeId, treeNode) {
            var spaceWidth = 15;
            var switchObj = $("#" + treeNode.tId + "_switch"),
                icoObj = $("#" + treeNode.tId + "_ico");
            switchObj.remove();
            icoObj.before(switchObj);

            if (treeNode.level > 0) {
                var spaceStr = "<span style='display: inline-block;width:" + (spaceWidth * treeNode.level)+ "px'></span>";
                switchObj.before(spaceStr);
            }
        }

        var setting = {data:{simpleData:{enable:true,idKey:"id",pIdKey:"pId",rootPId:'0'}},
            callback:{onClick:function(event, treeId, treeNode){
                var id = treeNode.id == '0' ? '' :treeNode.id;
                var _type = treeNode.type;
                $('#userContent')[0].contentWindow.changeInfo(id,treeNode.pIds,_type);

                //$('#userContent').attr("src","${ctx}/workexample/workExample/view?id="+id+"&parentIds="+treeNode.pIds);
            }
            }
            ,view:{
                showLine: false,
                showIcon: false,
                addDiyDom: addDiyDom
            }
        };

        function refreshTree(exampleId){
           	if(exampleId == undefined){
                exampleId = '${workExample.id}';
			}
            if(exampleId!=null && exampleId!=''&& exampleId != undefined){
				$("#id1").show();
                $("#id2").hide();
			}else{
                $("#id1").hide();
                $("#id2").show();
			}
            console.log(exampleId+"---------------exampleId");
            $.getJSON("${ctx}/workexample/workExampleIndices/treeDataExample?workExampleId="+exampleId,function(data){
                $.fn.zTree.init($("#ztree"), setting, data).expandAll(true);
            });
        }
        refreshTree();

        // var width = $('#divId').width();
        // var leftWidth = width*0.1; // 左侧窗口大小
        // var htmlObj = $("html"), mainObj = $("#main");
        // var frameObj = $("#left, #openClose, #right, #right iframe");
        // function wSize(){
        //     var strs = getWindowSize().toString().split(",");
        //     htmlObj.css({"overflow-x":"hidden", "overflow-y":"hidden"});
        //     mainObj.css("width","auto");
        //     frameObj.height(strs[0] - 120);
        //    /* var leftWidth = ($("#left").width() < 0 ? 0 : $("#left").width());
        //     $("#right").width($("#content").width()- leftWidth - $("#openClose").width() -60);
        //     $(".ztree").width(leftWidth - 10).height(frameObj.height() - 46);*/
        //     $("#content").width(width);
        //     $("#left").width(width*0.12);
        //     $("#ztree").width(width*0.12);
        //     $("#ztree").height('86%');
        //     $("#right").width(width*0.82);
        //     $("#officeContent").width(width*0.82);
        // }
	</script>
	<%--<script src="${ctxStatic}/common/wsize.min.js" type="text/javascript"></script>--%>
</body>
</html>