<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<html>
<head>
    <title>病案封存</title>
    <meta charset="utf-8">
    <!-- 解决部分兼容性问题，如果安装了GCF，则使用GCF来渲染页面，如果未安装GCF，则使用最高版本的IE内核进行渲染。 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <!-- 页面按原比例显示 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <%@include file="../../jspf/comm.jspf" %>
</head>
<style>
    .modal-header2 {
        text-align: center !important;
        vertical-align: middle !important;
        background-color: #3c8dbc !important;
        color: #fff;
        font-size: 16px;
        font-weight: bold;
        padding: 5px 5px 5px 5px !important;
    }

    /*.modal-header {*/
    /*padding: 5px 5px 5px 5px !important;*/
    /*}*/
    .modal-footer {
        padding: 5px;
    }

    .divCss {
        margin-top: 5px;
    }

    .divCss2 {
        margin-top: 5px;
        margin-left: 20px;
    }

    .divCss8 {
        margin-top: 5px;
        margin-right: 20px;
    }

    /* dataTables表头居中 */
    .table > thead:first-child > tr:first-child > th {
        text-align: center !important;
    }

    .enterCss2 {
        height: 160px;
        width: 500px;
    }

    #deptDiv {
        height: 18px;
        margin-top: -7px;
    }

    .toolbarCss {
        margin-right: 20px;
        margin-bottom: 0px;
    !important;
    }

    .fixed-table-toolbar .bs-bars .pull-right{
        height: 20px;
    !important;
    }

    /*选中行颜色*/
    .fixed-table-container tbody .selected td {
        background-color: #9acfea;
    }
</style>
<body>
<div style="margin-left:30px;margin-right:10px;height:auto">

    <!--搜索-->
    <form style="margin-top:20px;">
        <div class="form-inline">
            <div class="form-group divCss8">
                <label for="inpNo">住院号:</label>
                <input type="text" class="input-sm form-control" id="inpNo" placeholder="请输入住院号">
            </div>
            <div class="form-group divCss8">
                <label for="visitId">住院次数:</label>
                <input type="number" class="input-sm form-control" id="visitId" placeholder="请输入次数">
            </div>
            <div class="form-group divCss8">
                <label for="name">姓名:</label>
                <input type="text" class="input-sm form-control" id="name" placeholder="请输入姓名">
            </div>

            <div class="form-group divCss8">
                <label for="archivestate">归档状态 :</label>
                <select class="input-sm form-control" id="archivestate">
                    <option value="">全部</option>
                    <option value="已归档">已归档</option>
                    <option value="已封存">已封存</option>


                </select>
            </div>
            <div class="form-group " id="deptDiv">
                <label>出院科室 :</label>
                <%--<select class="input-sm form-control" id="deptName">--%>
                <%--<option value="">全部</option>--%>
                <%--&lt;%&ndash;<option value="在院">在院</option>&ndash;%&gt;--%>
                <%--&lt;%&ndash;<option value="未归档">未归档</option>&ndash;%&gt;--%>
                <%--&lt;%&ndash;<option value="归档中">归档中</option>&ndash;%&gt;--%>
                <%--&lt;%&ndash;<option value="初审">初审</option>&ndash;%&gt;--%>
                <%--&lt;%&ndash;<option value="已认证">已认证</option>&ndash;%&gt;--%>
                <%--&lt;%&ndash;<option value="已归档">已归档</option>&ndash;%&gt;--%>
                <%--</select>--%>
                <select class="selectpicker bla bla bli" multiple data-live-search="true" name="deptName"
                        data-actions-box="true" data-deselect-all-text="取消全选" data-select-all-text="全选" data-none-results-text="没找到相应记录{0}" id="deptName" title="请输入科室">
                    <option value="">全部</option>
                </select>
            </div>
            <%--            <div class="form-group divCss">--%>
            <%--                <label for="state">召回状态 :</label>--%>
            <%--                <select class="input-sm form-control" id="state">--%>
            <%--                    <option value="">全部</option>--%>
            <%--                    <option value="已召回">已召回</option>--%>
            <%--                    <option value="未召回">未召回</option>--%>
            <%--                </select>--%>
            <%--            </div>--%>
            <button type="button" class="btn btn-primary btn-sm divCss" id="searchBtn">查询</button>
            <button type="button" class="btn btn-info btn-sm divCss" id="excelBtn">条件导出</button>
        </div>
    </form>
    <!--数据表格-->
    <table id="table" class="table text-nowrap table-striped"></table>
    <div id="toolbar" class="btn-group pull-right toolbarCss" >
        <div class="columns columns-right btn-group pull-right" style="margin-top:0px;">
            <div class="btn-group btn-info">
                <select id="sel_exportoption" class="form-control">                
                    <option value="">导出当前页面数据</option>
                                   
                    <option value="all">导出全部数据</option>
                                 
                    <option value="selected">导出选中数据</option>
                </select>
            </div>
            <button class=" btn btn-success btn-sm" style="height: 34px" type="button" id="refreshBtn" name="refresh"
                    aria-label="Refresh"
                    title="Refresh">
                <i class="glyphicon glyphicon-refresh icon-refresh"></i>
            </button>
        </div>
    </div>
</div>

<%--确认框--确认/取消封存--%>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content ">
            <div class="modal-header2">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="exampleModalLabel">封存信息修改</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group ">
                        <input type="hidden" id="id" name="id" value=""/><label hidden id="danganhao"></label>
                        <span style="vertical-align:top;">取消封存概述：</span><textarea rows="6" style="width:100%;"
                                                                                  maxlength="255"
                                                                                  id="recallReason2"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">返回</button>
                <button type="button" class="btn btn-primary btn-sm" id="stateBtn">确认</button>
            </div>
        </div>
    </div>
</div>

<%--确认框--确认/取消封存--%>
<div class="modal fade" id="exampleModal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content ">
            <div class="modal-header2">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="exampleModalLabel1">封存信息修改</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group ">
                        <input type="hidden" id="id1" name="id" value=""/><label hidden id="danganhao1"></label>
                        <span style="vertical-align:top;">确认封存概述：</span><textarea rows="6" style="width:100%;"
                                                                                  maxlength="255"
                                                                                  id="recallReason"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">返回</button>
                <button type="button" class="btn btn-primary btn-sm" id="stateBtn1">确认</button>
            </div>
        </div>
    </div>
</div>


</body>
<script>
    var tipLoad = 1;

    $(function () {
        //日期控件
        $(".input-daterange").datepicker({
            format: "yyyy-mm-dd",
            language: "zh-CN"
        });

        var url = window.location.href;
        var index = url.substring(url.lastIndexOf('?') + 1).replace("num=", "");
        if (index != null && index != "" && index.indexOf("excel") != -1) {
            $("#excelBtn").show();
            $("#toolbar").show();
        } else {
            $("#excelBtn").hide();
            $(".columns-right").hide();
        }


        // var deptAdmissionTo = url.substring(url.lastIndexOf('&') + 1).replace("depts=", "");
        // var deptArr = deptAdmissionTo.split(',');
        // //var n = (deptAdmissionTo.split(',')).length ;
        // if (deptAdmissionTo == null || deptAdmissionTo == '' || deptArr.length > 1) {
        //     $('#deptDiv').show();
        // } else {
        //     $('#deptDiv').hide();
        // }

        function getDept() {
            //获取科室列表
            $.ajax({
                url: "${path}/inHosp/getDept",
                type: "POST",
                data: {effective: 1, typecode: "dept_code"},
                success: function (result) {
                    if (result != null) {
                        for (var i = 0; i < result.length; i++) {
                            $("#deptName").append("<option value=" + result[i].code + ">" + result[i].name + "</option>");
                        }
                    }
                    $('#deptName').selectpicker('refresh');
                    // for (var i = 0; i < result.length; i++) {
                    //     if (deptArr.length != 1 && deptArr[0] != "") {
                    //         var bol = deptArr.indexOf(result[i].code);
                    //         if (bol != -1) {
                    //             $("#deptName").append("<option value=" + result[i].code + ">" + result[i].name + "</option>");
                    //         }
                    //     } else {
                    //         $("#deptName").append("<option value=" + result[i].code + ">" + result[i].name + "</option>");
                    //     }
                    // }
                }
            });
        }

        getDept();
    });


    //处理导出内容,这个方法可以自定义某一行、某一列、甚至某个单元格的内容,也就是将其值设置为自己想要的内容
    function DoOnCellHtmlData(cell, row, col, data) {
        if (row == 0) {
            return data;
        }

        //由于备注列超过6个字的话,通过span标签处理只显示前面6个字,如果直接导出的话会导致内容不完整,因此要将携带完整内容的span标签中title属性的值替换
        if (col == 4 || col == 11 || col == 7) {
            var spanObj = $(data);//将带 <span title="val"></span> 标签的字符串转换为jQuery对象
            var title = spanObj.attr("title");//读取<span title="val"></span>中title属性的值
            //var span = cell[0].firstElementChild;//读取cell数组中的第一个值下的第一个元素
            if (typeof (title) != 'undefined') {
                return title;
            }
        }

        return data;
    }

    function initTable() {
        if (tipLoad == 1) {
            $("#table").bootstrapTable({ // 对应table标签的id
                //method: 'POST',
                url: "${path}/storage/StorageList", // 获取表格数据的url
                contentType: "application/x-www-form-urlencoded",//一种编码。好像在post请求的时候需要用到。这里用的get请求，注释掉这句话也能拿到数据
                //dataField: "data",//这是返回的json数组的key.默认是"rows".这里只有前后端约定好就行
                cache: false, // 设置为 false 禁用 AJAX 数据缓存， 默认为true
                striped: true,  //表格显示条纹，默认为false
                pagination: true, // 在表格底部显示分页组件，默认false
                paginationShowPageGo: true,
                pageList: [10, 20, 50, 100], // 如果设置了分页，设置可供选择的页面数据条数。设置为All 则显示所有记录。
                smartDisplay: false,
                pageSize: 2, // 页面数据条数
                pageNumber: 1, // 初始化加载第一页，默认第一页
                sidePagination: 'server', // 设置为服务器端分页     客户端：client
                search: false,
                showColumns: true,
                // sortable: true,
                // sortOrder: "asc",
                toolbar: '#toolbar',//指定工具栏
                searchOnEnterKey: true, //设置为 true时，按回车触发搜索方法，否则自动触发搜索方法
                undefinedText: '---', //当数据为 undefined 时显示的字符
                singleSelect: false,//设置True 将禁止多选
                clickToSelect: true,//设置true 将在点击行时，自动选择rediobox 和 checkbox
                //height: 560,     //定义表格的高度。
                searchTimeOut: 500,// 默认500  设置搜索超时时间。
                toolbarAlign: 'right',// 指定 toolbar 水平方向的位置。'left' 或 'right'
                paginationDetailHAlign: 'left',//指定 分页详细信息 在水平方向的位置。'left' 或 'right'。
                showHeader: true,//是否显示列头。
                trimOnSearch: true,//设置为 true 将自动去掉搜索字符的前后空格。
                //是否显示导出按钮
                showExport: true,
                //导出表格方式（默认basic：只导出当前页的表格数据；all：导出所有数据；selected：导出选中的数据）
                exportDataType: "basic",
                //导出文件类型
                exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
                exportOptions: {
                    fileName: document.title
                },

                queryParams: function (params) {
                    var currPageSize = this.pageSize;
                    if (currPageSize == 2) {
                        currPageSize = 10;
                    }

                    var limit = null;
                    var offset = params.offset;
                    //判断是否导出全部all
                    if ($("#sel_exportoption").val() == "all") {
                        offset = 0;
                        limit = this.totalRows;
                        this.pageSize = limit;
                    } else {
                        limit = currPageSize;
                        this.pageSize = currPageSize;
                    }

                    //var url = window.location.href;
                    //var deptName = '';
                     //var deptName = url.substring(url.lastIndexOf('&') + 1).replace("depts=", "");


                    // var len = ($("#deptName").val()).length;
                    // if (len > 0) {
                    //     var deptNameT = $("#deptName").val();
                    //     if (deptNameT.indexOf("") == -1) {
                    //         deptName = $("#deptName").val().toString();
                    //     }
                    // }
                    // var url = window.location.href;
                    // var deptName = url.substring(url.lastIndexOf('&') + 1).replace("depts=", "");
                   /* var len = value.length;
                    if (len > 0) {
                        if (value.indexOf("") == -1) {
                            deptName = value.toString();
                        }
                    }*/

                    var deptNameA = $("#deptName").val().toString();
                    if (deptNameA.indexOf("") != -1 && deptNameA.length<=0) {
                        deptNameA = "";
                    }

                    var temp = {
                        limit: limit,     //页面大小
                        offset: offset,   //页码
                        order: params.order,      //排位命令（desc，asc）
                        idNo: $("#idNo").val(),
                        inpNo: "" + $("#inpNo").val(),
                        visitId: "" + $("#visitId").val(),
                        name: "" + $("#name").val(),
                        archivestate: "" + $("#archivestate").val(),
                        // state:"" + $("#state").val(),
                        deptName: deptNameA
                    };
                    return temp;
                },
                sortName: 'id', // 要排序的字段
                sortOrder: 'desc', // 排序规则
                columns: [{
                    title: '全选',
                    field: 'select',   //复选框
                    checkbox: true,
                    width: 25,
                    align: 'center',
                    valign: 'middle',

                },
                    {
                        title: '序号',
                        field: 'id',
                        align: 'center',
                        valign: 'middle',
                        //sortable: true,
                        visible: false,
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {
                        title: '病案清单id',
                        field: 'archiveDetailId',
                        align: 'left',
                        valign: 'middle',
                        visible: false
                    },
                    {
                        title: '住院号',
                        field: 'inpNo',
                        align: 'center',
                        valign: 'middle',
                    },
                    {
                        title: '住院次数',
                        field: 'visitId',
                        align: 'center',
                        valign: 'middle',
                    },
                    {
                        title: '姓名',
                        field: 'name',
                        align: 'center',
                        valign: 'middle',
                    },
                    {
                        title: '性别',
                        field: 'sex',
                        align: 'center',
                        valign: 'middle',
                    },
                    {
                        title: '身份证号',
                        field: 'idNo',
                        align: 'left',
                        valign: 'middle',
                        visible: false
                    },
                    {
                        title: '入院科室',
                        field: 'deptAdmissionTo',
                        align: 'center',
                        valign: 'middle',
                    },
                    {
                        title: '入院日期',
                        field: 'admissionDateTime',
                        align: 'center',
                    },
                    {
                        title: '出院科室',
                        field: 'deptName',
                        align: 'center',
                        valign: 'middle',
                    },
                    {
                        title: '出院日期',
                        field: 'dischargeDateTime',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return value.substring(0, 10);
                        }
                        // formatter: function (value, row, index) {
                        //     return value
                        // }
                    },
                    /*{
                        title: '上次封存状态',
                        field: 'state',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            //在院  未归档  归档中  初审 已归档 已认证
                            var a = '';
                            if (value == "已封存") {
                                a = '<span style="color:red"><i class="fa fa-check-circle-o" aria-hidden="true"></i>'+ value +'</span>';
                            } else {
                                a = '<span style="color:#ccc;"><i class="fa fa-times-circle-o" aria-hidden="true"></i>'+ value +'</span>';
                            }
                            return a;
                        }
                    },*/
                    {
                        title: '归档状态',
                        field: 'archivestate',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            //在院  未归档  归档中  初审 已归档 已认证
                            //在院  未归档  归档中  初审 已归档 已认证 复审退回
                            var a = '';
                            if (value == "已封存") {
                                a = '<span style="color:#00CC00;"><i class="fa fa-times-circle-o" aria-hidden="true"></i>' + value + '</span>';
                            } else if (value == "已归档") {
                                a = '<span style="color:#030378"><i class="fa fa-check-circle-o" aria-hidden="true"></i>' + value + '</span>';
                            }
                            return a;
                        }
                    },
                    {
                        title: "操作",
                        align: 'left',
                        valign: 'middle',
                        width: 80, // 定义列的宽度，单位为像素px
                        formatter: function (value, row, index) {
                            var url = window.location.href;
                            var index = url.substring(url.lastIndexOf('?') + 1).replace("num=", "");
                            if (index != null && index != "" && index.indexOf("recall") != -1) {
                                if (row.archivestate == "已封存" || row.archivestate == "已归档") {
                                    if (row.archivestate == "已封存") {
                                        return '<button class="btn btn-success btn-sm" onclick="recallFun(\'' + row.id + '\',\'' + row.archiveDetailId + '\')">取消封存 </button>';
                                        //return '<button class="btn btn-warning btn-sm"  onclick="recallFun(\'' + row.id + '\',\'' + row.archiveDetailId + '\')">已封存 </button>' + '<button class="btn btn-danger btn-sm" onclick="logFun(\'' + row.id + '\',\'' + row.archiveDetailId + '\',\'' + row.recallReason + '\')">日志</button>';
                                    } else {
                                        return '<button class="btn btn-warning btn-sm" onclick="recallFun1(\'' + row.id + '\',\'' + row.archiveDetailId + '\')">封存 </button>';
                                    }
                                } else {
                                    return '';
                                }
                            }

                        },
                        cellStyle: function (value, row, index) {
                            return {classes: 'success'}

                        }
                    }
                ],
                onLoadSuccess: function (result) {  //加载成功时执行
                    //console.info("加载成功");
                    tipLoad = 0;
                },
                onLoadError: function () {  //加载失败时执行
                    //console.info("加载数据失败");
                    tipLoad = 0;
                }

            });
        }
    }

    function recallFun(id, archiveDetailId) {
        $('#exampleModal').modal({
            backdrop: 'static',//backdrop 为 static 时，点击模态对话框的外部区域不会将其关闭。
            keyboard: false,//keyboard 为 false 时，按下 Esc 键不会关闭 Modal。
            show: true//弹出对话框
        });
        $("#recallReason2").val("");
        $("#danganhao").html(archiveDetailId);
    }

    function recallFun1(id, archiveDetailId) {
        $('#exampleModal1').modal({
            backdrop: 'static',//backdrop 为 static 时，点击模态对话框的外部区域不会将其关闭。
            keyboard: false,//keyboard 为 false 时，按下 Esc 键不会关闭 Modal。
            show: true//弹出对话框
        });
        $("#recallReason").val("");
        $("#danganhao1").html(archiveDetailId);
    }


    //查询
    $('#searchBtn').click(function () {
        if (tipLoad == 0) {
            $("#table").bootstrapTable("refreshOptions", {pageNumber: 1});
        } else {
            toastr.warning("正在查询，请稍等...");
        }
    });

    //获取table的高度
    function getHeight() {
        return $(window).height() - 100;
    }

    initTable();

    //2.初始化select的change事件
    $("#sel_exportoption").change(function () {
        $('#table').bootstrapTable('refreshOptions', {
            exportDataType: $(this).val()
        });
    });
    $("#refreshBtn").click(function () {
        //刷新
        $('#table').bootstrapTable('refresh');
    });

    //导出excel功能
    $("#excelBtn").click(function () {
        var inpNo = "" + $("#inpNo").val();
        var visitId = "" + $("#visitId").val();
        var name = "" + $("#name").val();
        var idNo = "" + $("#idNo").val();
        var state = "" + $("#state").val();
        var archivestate = "" + $("#archivestate").val();
        var deptNameA = $("#deptName").val().toString();
        if (deptNameA.indexOf("") != -1 && deptNameA.length<=0) {
            deptNameA = "";
        }
        window.location.href = "${path}/medicalRecall/exportExcel?inpNo=" + inpNo + "&visitId=" + visitId +
            "&name=" + name + "&state=" + state + "&idNo=" + idNo + "&archivestate=" + archivestate + "&deptName=" + deptNameA;
    });

    $("#stateBtn").click(function () {
        $('#exampleModal').modal('hide');  //手动关闭
        var archiveDetailId = $("#danganhao").html();
        var visitId = $("#visitId").html();
        var id = archiveDetailId;
        var ArchiveState = $("#archivestate").html();
        var recallReason = $("#recallReason2").val();
        $.ajax({
            url: "${path}/storage/updateState",
            type: "POST",
            data: {"ArchiveState": "已归档", "archiveDetailId": archiveDetailId, recallReason: recallReason},
            success: function (result) {
                //刷新
                $('#table').bootstrapTable('refresh');
                if (result > 0) {
                    toastr.success("取消封存成功!");
                } else {
                    toastr.error("取消封存失败!");
                }
            }, error: function () {
                //刷新
                toastr.error("封存异常111!!")
            }
        });
    });


    $("#stateBtn1").click(function () {
        $('#exampleModal1').modal('hide');  //手动关闭
        var archiveDetailId = $("#danganhao1").html();
        var visitId = $("#visitId").html();
        var id = archiveDetailId;
        var ArchiveState = $("#archivestate").html();
        var recallReason = $("#recallReason").val();
        $.ajax({
            url: "${path}/storage/updateState",
            type: "POST",
            data: {"ArchiveState": "已封存", "archiveDetailId": archiveDetailId, recallReason: recallReason},
            success: function (result) {
                //刷新
                $('#table').bootstrapTable('refresh');
                if (result > 0) {
                    toastr.success("确认封存成功!");
                } else {
                    toastr.error("确认封存失败!");
                }
            }, error: function () {
                //刷新
                toastr.error("封存异常111!!")
            }
        });
    });

</script>

</html>