<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<%@ include file="/WEB-INF/jspf/comm.jspf" %>
<%@ include file="/WEB-INF/jspf/ztreeCommom.jsp" %>
<%@ include file="/WEB-INF/jspf/confirmJsp.jspf" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<html>
<head>
    <meta charset="utf-8" />
    <title>预览pdfIframe页面</title>
    <meta http-equiv=X-UA-Compatible IE=EmulateIE7>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <%--<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv=X-UA-Compatible IE=EmulateIE7>--%>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="${path}/static/js/html5shiv.min.js"></script>
    <script type="text/javascript" src="${path}/static/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="${path}/static/js/respond.min.js"></script>
    <![endif]-->
    <script>
        var path = "${path}";
    </script>
    <style type="text/css">
        body{
            width:100%;
            height:98%;
            margin:0;
            padding:0;
            background-color: #fff;
            overflow: hidden;
        !important;
        }

        #loadBtn{
            margin-left:20px;
            height:30px;
            width:89%;
        !important;
        }

         #colDiv{
             height:70%;
             overflow:hidden;
         !important;
         }

         .ztree{
             height:100%;
             margin-left:0px;
             overflow:auto;
             overflow:auto;
         !important;
         }

        .content-left{
            height:100%;
            width:16%;
            float:left;
            border-right: 1px #ccc solid;
            overflow:hidden;
        !important;
        }

        .content-right{
            height:100%;
            width:83%;
            float:right;

            overflow: hidden;
        }



        .loading {
            width: 148px;
            height: 56px;
            position: absolute;
            top: 28px;
            right: 16px;
            line-height: 56px;
            color: red;
            padding-left: 60px;
            font-size: 7px;
            background: #000;
            opacity: 0.7;
            -moz-border-radius: 20px;
            -webkit-border-radius: 20px;
            border-radius: 20px;
            filter: progid:DXImageTransform.Microsoft.Alpha(opacity=70);
            display: none;
        }

        #iframe1{
            height: 100%;
            width:100%;
        !important;
        }

        /*
         *页头div
         */
        .headDiv{
            height:43px;
            background-color: #1D9ED7;
            text-align: center;
        }

        /*
        *页头标题div
        */
        .headSpanDiv{
            padding:10px 15px;
            color: #FFF;
        }

       /*
        * 页头标题
        */
        .headspan{
            font-size: 1.5em;
            font-weight: bold;
        }

        .searchDiv{
            width:100%;
            height:13%;
            border: 1px solid #e5e5e5;
         }

        .labelDiv{
            padding-top: 2%;
            padding-right: 0;
            text-align: right;
        }

        .rowDiv{
            padding-top:0.5%;
        }

        .inputDiv{
            padding:0!important;
            margin-left: -3%!important;
        }

        h4{
            color: #fff;
            font-size: 1.0em;
            font-weight: bold;
        }

        hr{
            margin:0!important;
        }

        .treeBtn1 {
            margin-left:20px;
            margin-top: 10px;
            margin-right: 10px;
            width: 41%;
        }

        .treeBtn {
            margin-top: 10px;
            margin-left: 10px;
            margin-right: 10px;
            width: 41%;
        }

        #searchDiv{
            margin-left: 0px;
            margin-top: 5px;
        !important;
        }

        #key {
            margin-left: 10px;
            margin-bottom: 0px;
            width: 70%;
            !important;
        }

        #searchBtn {
            width: 20%;
            !important;
        }
    </style>
</head>
<body onkeydown="disabledPrint()">
        <!--主键-->
        <input type="hidden" id="patientId" value="${patientId}">
        <!--记账号-->
        <input type="hidden" id="accountNumber" value="${accountNumber}">
        <input type="hidden" id="assortIds" value="${assortIds}">
        <input type="hidden" id="visitId" value="${visitId}">
        <!--业务识别码1:护理按需采集预览-->
        <input type="hidden" id="typeFlag" value="1">
<div id="loading" class="loading">正在采集,请稍等</div>
<!--文件路径-->
<input type="hidden" id="filePath">
<input type="hidden" id="detailIds">
<div class="row">
    <div class="headDiv">
         <div class="headSpanDiv">
              <span class="headspan">
                    病案浏览
              </span>
         </div>
    </div>
    <!--病案详情-->
    <div class="searchDiv">
        <input type="hidden" id="admissId" value="${commom.admissId}">
        <div class="row rowDiv">
            <div class="col-sm-3 inputDiv">
                <div class="form-group">
                     <label  class="col-sm-5 control-label labelDiv">主管医生：</label>
                     <div class="col-sm-7">
                          <input type="text" readonly class="form-control input input-sm input" id="doctorInCharge">
                     </div>
                </div>
            </div>
            <div class="col-sm-3 inputDiv">
                <div class="form-group">
                     <label  class="col-sm-5 control-label labelDiv">姓名：</label>
                     <div class="col-sm-7">
                          <input type="text" readonly class="form-control input-sm input" id="name">
                     </div>
                </div>
            </div>
            <div class="col-sm-3 inputDiv">
                 <div class="form-group">
                      <label  class="col-sm-5 control-label labelDiv">住院号：</label>
                      <div class="col-sm-7">
                          <input type="text" readonly class="form-control input-sm input" id="inpatientNo">
                      </div>
                 </div>
            </div>
            <div class="col-sm-3 inputDiv">
                 <div class="form-group">
                      <label  class="col-sm-5 control-label labelDiv">住院次数：</label>
                      <div class="col-sm-7">
                          <input type="text" readonly class="form-control input-sm input" id="admissTimes">
                      </div>
                 </div>
            </div>
        </div>
        <div class="row rowDiv">
            <div class="col-sm-3 inputDiv">
                 <div class="form-group">
                      <label  class="col-sm-5 control-label labelDiv">出院科室：</label>
                      <div class="col-sm-7">
                            <input type="text" readonly class="form-control input-sm input" id="disDeptName">
                      </div>
                 </div>
            </div>
            <div class="col-sm-3 inputDiv">
                 <div class="form-group">
                      <label  class="col-sm-5 control-label labelDiv">出院日期：</label>
                      <div class="col-sm-7">
                            <input type="text" readonly class="form-control input-sm input" id="disDate">
                      </div>
                 </div>
            </div>
        </div>
    </div>
</div>
<div class="content-left">
    <div class="row" style="margin-top: 5px">
        <%--<div class="col-md-4">
        </div>
        <div class="col-md-4" style="padding:0 2px">--%>
          <button id="loadBtn" type="button" class="btn btn-xs btn-primary" onclick="onloadPdf()">加载PDF</button>
        <%--</div>
        <div class="col-md-4" style="padding:0 2px;" >
            <button type="button" class="btn btn-xs btn-primary" style="display: none" onclick="flashPdf()" id="freshBtnDiv">刷新</button>
            <button type="button" class="btn btn-xs btn-danger" style="display: none" id="delBtnDiv">删除</button>
        </div>--%>
    </div>
    <div class="row form-inline" id="searchDiv">
        <input type="text" id="key" value="" class="input-sm empty" placeholder="标题"/>
        <button type="button" class="btn btn-primary btn-sm" id="searchBtn">查询</button>
    </div>
    <div class="row">
    <button type="button" class="btn  btn-success btn-sm treeBtn1" onclick="expandAll();">全部展开</button>
    <button type="button" class="btn  btn-success btn-sm treeBtn" onclick="collapseAll();">全部收缩</button>
    </div>

    <div >
        <div id="colDiv">

                <ul id="ztree" class="ztree"></ul>

        </div>
    </div>
</div>
<div class="content-right">
    <iframe src="" id="iframe1" frameborder="0" scrolling="yes"></iframe>
</div>
<%--<script type="text/javascript" src="${path}/static/js/showRecord/showRecord.js"></script>--%>
<%--<script type="text/javascript" src="${path}/static/js/showRecord/showRecordIframe.js?time=2021-02-07"></script>--%>
<%--<script type="text/javascript" src="${path}/static/js/showRecord/showRecordIframeCommom.js"></script>--%>
</body>
    <script>
        //屏蔽鼠标右键
        document.oncontextmenu = function(e) {
                var e = e || window.event;
                e.returnValue = false;
                return false;
        }
        //禁止快捷键打印
        function disabledPrint(){
                if(event.keyCode==80 && event.ctrlKey){
                        event.keyCode=0;
                        event.returnValue=false;
                }
                if (event.ctrlKey && event.keyCode == 83) {
                        event.preventDefault();
                        event.returnValue = false;
                        return false;
                }
        }

    //展开
    function expandAll() {
        var treeObj = $.fn.zTree.getZTreeObj("ztree");
        treeObj.expandAll(true);
    }

    //收缩
    function collapseAll() {
        var treeObj = $.fn.zTree.getZTreeObj("ztree");
        treeObj.expandAll(false);
    }

        //初始化函数
        $(function(){

                function focusKey(e) {
                        if (key.hasClass("empty")) {
                                key.removeClass("empty");
                        }
                }

                function blurKey(e) {
                        if (key.get(0).value === "") {
                                key.addClass("empty");
                        }
                }

                /**
                * 遍历树节点，将
                * 1.自身不满足搜索条件
                *     且
                * 2.其子节点不包含有满足条件的节点
                * 的节点加入到filterResult中
                *
                * @param node 查询的节点
                * @param inputStr 搜索条件
                * @param filterResult 过滤的结果集
                * @return 该节点是否满足条件
                */
                function filterNodes(node, inputStr, filterResult) {
                        if (node != null) {
                                //自身是否符合搜索条件
                                var selfMatch = node.name.indexOf(inputStr) > -1;
                                //子节点是否有满足的条件的节点
                                var childMatch = false;
                                var children = node.children;
                                if (children != undefined) {
                                        for (index in children) {
                                                childMatch = filterNodes(children[index], inputStr, filterResult) || childMatch;
                                        }
                                }
                                //自身不满足搜索条件 且其子节点不包含有满足条件的节点
                                if (!selfMatch && !childMatch) {
                                        filterResult.push(node);
                                }
                                return selfMatch || childMatch;
                        } else {
                                return true;
                        }
                }

                function searchNode() {
                        var zTree = $.fn.zTree.getZTreeObj("ztree");
                        var value = $("#key").val();
                        if (value == "") {
                                //显示隐藏的节点
                                var nodes = zTree.getNodesByParam("isHidden", true);
                                zTree.showNodes(nodes);
                        } else {
                                //显示隐藏的节点
                                nodes = zTree.getNodesByParam("isHidden", true);
                                zTree.showNodes(nodes);

                                var root = zTree.getNodeByParam("level", "0");

                                var hiddenNodes = new Array();


                                filterNodes(root, value, hiddenNodes);
                                zTree.hideNodes(hiddenNodes);
                        }
                        zTree.expandAll(true);
                }


                function updateNodes(highlight) {
                        var zTree = $.fn.zTree.getZTreeObj("ztree");
                        for (var i = 0, l = nodeList.length; i < l; i++) {
                                zTree.showNode(nodeList[i]);
                        }
                }

                // function getFontCss(treeId, treeNode) {
                //     return (!!treeNode.highlight) ? {color: "#A60000", "font-weight": "bold"} : {
                //         color: "#333",
                //         "font-weight": "normal"
                //     };
                // }
                $(document).keydown(function (event) {
                        if (event.keyCode == 13) {
                                searchNode();
                        }
                });

                $("#searchBtn").click(function () {
                        searchNode();
                });

                //加载iframe
                //$("#iframe").prop("src",path+"/font/showRecordIframe?patientId="+$("#patientId").val())+"&assortIds="+assortIds;

                //树操作
                var menu = {
                        setting: {
                                view:{
                                        fontCss : {"font-family": "微软雅黑","color":"blue"}
                                },
                                data:{
                                        key:{
                                                name:"name"
                                        },
                                        simpleData: {
                                                chkStyle: "checkbox",
                                                enable: true,
                                                idKey: "id",
                                                pIdKey: "parentId"
                                        }
                                },
                                check:{
                                        enable:true
                                },
                                callback: { //回调函数
                                        onCheck: onCheck,
                                        onClick:onClick
                                }
                        },
                        loadMenuTree:function(){
                                var url = '';
                                var params = '';
                                //获取业务识别编码
                                url = path+"/font/getRecordTypeTree";
                                params = {patientId:$("#patientId").val(),assortIds:$("#assortIds").val()};
                                $.ajax({
                                        type: "post",
                                        url: url,
                                        data: params,
                                        dataType:"json",
                                        async:false,
                                        success:function(data){
                                        $.fn.zTree.init($("#ztree"), menu.setting, data);
                                        zTree = $.fn.zTree.getZTreeObj("ztree");
                                        var nodes = zTree.getNodes();
                                        zTree.expandNode(nodes[0], true, false, true);
                                        var detailIds = '';
                                        for (var i = 0; i < data.length; i++) {
                                            if(data[i].selfId != null  && data[i].checked == 'true'){
                                                if(i != data.length - 1){
                                                        detailIds += "'"+data[i].selfId+"',";
                                                }else{
                                                        detailIds += "'"+data[i].selfId+"'";
                                                }
                                            }
                                        }
                                        if(detailIds.substring(detailIds.length-1,detailIds.length) == ","){
                                                detailIds = detailIds.substring(0,detailIds.length-1);
                                        }
                                        if(detailIds == ''){
                                                toastr.warning('该患者该时间段未上传报告!');
                                        }
                                                $("#detailIds").val(detailIds);
                                        }
                                });
                                //加载pdf
                                onloadPdf();
                        }
                };

                //加载树
                $().ready(function(data){
                menu.loadMenuTree();
                // //判断是否是护理按需采集，是显示刷新按钮
                // var typeFlag = parent.$("#typeFlag").val();
                // if(typeFlag == 1){
                // 	$("#freshBtnDiv").show();
                // }else if(typeFlag == 2){
                // 	var delPower = parent.$("#delPower").val();
                // 	if(delPower == 1){
                // 		$("#delBtnDiv").show();
                // 	}
                // }
                });

                //获取获取树选中节点，赋值隐藏域并加载pdf
                function onPdfLoadByselected() {
                        var treeObj = $.fn.zTree.getZTreeObj("ztree");
                        nodes = treeObj.getCheckedNodes(true);
                        var detailIds = '';
                        for (var i = 0; i < nodes.length; i++) {
                                if (nodes[i].level == 2) {
                                        if (i != (nodes.length - 1)) {
                                                detailIds += "'" + nodes[i].selfId + "',";
                                        } else {
                                                detailIds += "'" + nodes[i].selfId + "'";
                                        }
                                }
                        }
                        $("#detailIds").val(detailIds);

                        //加载pdf
                        onloadPdf();
                }

                //树选中事件
                function onCheck(e, treeId, treeNode) {
                     onPdfLoadByselected();
                };
                //树点击事件
                function onClick(e, treeId, treeNode) {
                    //点击后选中
                    zTree.checkNode(treeNode,!treeNode.checked, true);
                    onPdfLoadByselected();
                };

                //加载pdfan按钮功能
                function onloadPdf(){
                        var url = '';
                        var params = '';
                        //获取业务识别编码
                        var detailIds = $("#detailIds").val();
                        //console.log(detailIds);
                        if(detailIds != '') {
                                url = path + "/font/getPdfToPdf";
                                params = {detailIds: detailIds};
                                $.ajax({
                                        type: 'post',
                                        url: url,
                                        data: params,
                                        success: function (data) {
                                                if (data.code == 100) {
                                                        var pdfUrl = path + "/static/pdfjs/web/viewer.html?file=" + path + "/font/showPdf";
                                                        $("#iframe1").attr("src", pdfUrl);
                                                        $("#iframe1").css("height", $("body")[0].offsetHeight)
                                                } else {
                                                        toastr.error(data.msg);
                                                }
                                        }
                                });
                        }else{
                        toastr.warning("请至少勾选一个");
                        }
                        /*$("#iframe1").attr("src",path+"/static/pdfjs/web/viewer.html?file="+path+"/font/getPdfToPdf/"+patientId+"/"+detailIds);*/

                }

                //加载病案信息
                function loadRecord(){
                    $.ajax({
                        type:'get',
                        url:path+'/font/getRecord',
                        data:{masterId:$("#patientId").val()},
                        async:false,
                        dataType:'json',
                        success:function (data) {
                                if(null != data && data != ''){
                                        $("#doctorInCharge").val(data.doctorInCharge);
                                        $("#inpatientNo").val(data.inpNo);
                                        $("#name").val(data.name);
                                        $("#admissTimes").val(data.visitId);
                                        $("#disDate").val(data.dischargeDateTime);
                                        $("#disDeptName").val(data.deptName);
                                        $("#archivestate").val(data.archivestate);
                                }
                        }
                     });
                }

                //加载病案信息
                loadRecord();
        });


    </script>
</html>
