<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<html>
<head>
    <title>PDF详情</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" %>
    <%@ include file="../../jspf/ztreeCommom.jsp" %>
    <%@include file="../../jspf/floatWin.jspf" %>
    <script type="text/javascript"
            src="${path}/static/bootstrap-3.3.7/plugins/bootstrap-multiselect-master/dist/js/bootstrap-multiselect.js"></script>
    <link rel="stylesheet"
          href="${path}/static/bootstrap-3.3.7/plugins/bootstrap-multiselect-master/dist/css/bootstrap-multiselect.css"
          type="text/css"/>
    <style type="text/css">
        .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;
        }

        .divCss2 {
            color: black;
            margin-top: 5px;
            margin-left: 2px;
        }

        .divCss5 {
            color: black;
            margin-top: 0px;
            margin-left: 1px;

        }

        .fixed-table-container {
            border-top: 1px solid #ddd;
            border-left: 0px solid #ddd;
            border-right: 0px solid #ddd;
        !important;
        }

        .divCss7 {
            margin-top: 5px;
            margin-left: 0px;
            color: blue;
        }

        .divCss4 {
            border-top: 1px solid #e5e5e5;
            border-bottom: 1px solid #e5e5e5;
            width: 97.5%;
            margin-top: 10px;
            margin-bottom: 5px;
        }

        label, span, textarea, input {
            color: black;
            font-weight: normal;
        }

        body {
            background-color: #fff;
            overflow: hidden;
        }

        #mb {
            display: none;
            height: 120%;
            width: 100%;
            /*position: fixed;*/
            position: absolute;
            z-index: 1200;
            /*height: 1380px;*/
            background: #FFF;
            top: 0;
            left: 0;
            opacity: 0.6;
        }


        #arrow {
            color: #fff;
            background: #000;
            width: 20px;
            height: 90px;
            line-height: 90px;
            font-size: 12px;
            font-family: "宋体";
            text-align: center;
            font-weight: bold;
            float: left;
        }

        .panel {
            width: 98%;
        }

        /*选中行颜色*/
        .fixed-table-container tbody .selected td {
            background-color: #9acfea;
        }

        #table{
            /*table-layout:fixed;*/
            scroll:auto;
        }

        table tr {
            color: #000
        }

        .table th {
            text-align: center;
        }

        td {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        #verifyModal .modal-content {
            margin-left: 30%;
            margin-top: 20%;
            width: 100%;
        }

        #WZModal .modal-content {
            margin-left: 30%;
            margin-top: 0%;
            width: calc(150%);
        }

        #returnModal .modal-content {
            margin-left: 15%;
            margin-top: 20%;
            width: 120%;
        }

        #firstModal .modal-content {
            margin-left: 10%;
            margin-top: 20%;
            width: 100%;
        }

        #lastModal .modal-content {
            margin-left: -30%;
            margin-top: 20%;
            width: calc(150%);
        }

        #lastBackModal .modal-content {
            margin-left: -30%;
            margin-top: 20%;
            width: calc(150%);
        }

        #assortNameQX {
            width: 200px
        }

        .bs-searchbox {
            width: 190px;
        }

        .bs-searchbox input.form-control {
            height: 25px;
        }
    </style>
</head>
<body>
<div id="mb"></div>
<div class="row form-inline">
    <div style="width: 70%;float:left;" id="pdfDiv">
        <iframe id="pdf_page" name="pdf_page" style="width:100%;height:100%;"></iframe>
    </div>
    <div id="arrow">&gt;</div>

    <div style="width: 28%;height:100%;float:right;overflow-y:scroll;overflow-x: hidden;" id="infoDiv">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">缺陷信息</h3>
            </div>

            <div class="panel-body">
                <form class="form-horizontal" id="form">
                    <div class="row divCss2 ">
                        <span style="vertical-align:center;float: left">退回：</span>

                        <div id="flagDiv" style="float: left;margin-left:5px" hidden>
                            <select style="width:100px;" class="selectpicker bla bla bli" multiple name="flag" id="flag"
                                    title="请输入角色">
                                <option value="1" selected>医生</option>
                                <option value="2">护士</option>
                            </select>
                        </div>
                        <input class="form-control" style="margin-left: 3px;" id="roleVal" readonly hidden/>
                    </div>
                    <div class="row divCss2">
                        <%-- <span  class="divCss7">缺陷信息：</span>--%>
                        <div id="typFlagDiv">
                            <div class="row">
                                <div class="col-xs-2">选项：</div>
                                <div class="col-xs-8" id="mulDiv" style="margin-left: -30px;">
                                </div>
                            </div>
                            <%-- <div class="divCss4" id="faultTypeDiv2">
                             </div>--%>
                        </div>
                        <div class="row divCss2">
                            <span style="vertical-align:top;">内容：</span>
                            <textarea id="content" rows="6" style="width:80%;"></textarea>
                        </div>
                        <div class="row divCss2">
                            <div class="col-sm-6" style="text-align: center;">
                                <button type="button" class="btn btn-primary btn-sm" id="saveBtn">保存</button>
                            </div>
                            <div class="col-sm-6">
                                <button type="button" class="btn btn-default btn-sm" id="clearBtn">清空</button>
                            </div>
                        </div>
                </form>
            </div>
        </div>
    </div>
    <%--<div class="divCss4" id="faultTypeDiv3"></div>--%>
    <div class="row divCss2 panel panel-primary ">
        <div class="row" style="margin-right: 5px;margin-bottom: 5px;">
            <div class="columns columns-right btn-group pull-right">
                <button type="button" class="btn btn-warning btn-sm" id="addBtn" hidden>添加</button>
                <button type="button" class="btn btn-danger btn-sm" id="delBtn" hidden>删除</button>
                <button type="button" class="btn btn-primary btn-sm" id="dealBtn" hidden>处理</button>
                <button type="button" class="btn btn-success btn-sm" id="dealCancelBtn" hidden>取消处理</button>
            </div>
        </div>
        <div class="form-inline " style="margin-bottom: -15px;font-size: 14px;">
            <div class="form-group ">
                <label>类型:</label>
                <input type="text" class="input-sm form-control" id="assortNameQX" placeholder="请输入缺陷类型">
            </div>
            <div class="form-group divCss2" style="margin-left: 10px">
                <label>处理否:</label>
                <select class="input-sm form-control" id="dealFlagQX">
                    <option value="">全部</option>
                    <option value="1">已处理</option>
                    <option value="0">未处理</option>
                </select>
            </div>
            <button type="button" class="btn btn-primary btn-sm divCss" id="searchBtnQX">查询</button>
        </div>
        <!--数据表格-->
        <table id="table" class="table text-nowrap table-striped" style="table-layout:fixed"></table>
        <%--<div id="toolbar" class="btn-group pull-left" style="text-align: left">

        </div>--%>
    </div>
    <div class="row divCss2">
        <button type="button" class="btn btn-primary btn-large" id="backBtn">主任退回</button>
        <button type="button" class="btn btn-success btn-large" id="firstBtn">初审</button>
    </div>

</div>


<%--审核弹窗--%>
<div class="modal fade" id="verifyModal" 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">初审信息</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group ">
                        <input id="archiveId" hidden/>
                        <span style="vertical-align:top;">初审内容：</span>
                        <textarea rows="6" style="width:80%;" id="verifyText"></textarea>
                    </div>
                    <div class="form-group ">
                        <span style="vertical-align:top;">护士备注：</span>
                        <textarea id="nuresText2" rows="6" style="width:80%;" disabled></textarea>
                    </div>
                    <div class="form-group ">
                        <span style="vertical-align:top;">医生备注：</span>
                        <textarea id="doctorText2" rows="6" style="width:80%;" disabled></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="verifyBtn">通过</button>
            </div>
        </div>
    </div>
</div>

<%--审核弹窗--%>
<div class="modal fade" id="WZModal" tabindex="-5" 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">是否强制提交</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group ">
                        <div style="color:black" id="WzRsult"></div>
                    </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="wzSaveBtn">通过</button>
            </div>
        </div>
    </div>
</div>


<%--退回弹窗--%>
<div class="modal fade" id="returnModal" 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">退回信息</h4>
            </div>
            <div class="modal-body divCss2">
                <!--通过审批且未过期的patientId集合-->
                <form class="form-horizontal" id="form2">
                    <div class="row">
                        <%--<div class="row divCss3 ">退回信息</div>--%>
                        <div class="row divCss2">
                            <div class="row divCss2" hidden>
                                <span style="vertical-align:center;">病案评分：</span>
                                <input id="score" type="number" class="input-sm "/> 分
                            </div>
                            <div class="row divCss2">
                                <span style="vertical-align:top;">退回内容：</span>
                                <textarea id="backContent" rows="6" style="width:80%;"></textarea>
                            </div>
                            <div class="row divCss2">
                                <span style="vertical-align:top;">护士备注：</span>
                                <textarea id="nuresText" rows="6" style="width:80%;" disabled></textarea>
                            </div>
                            <div class="row divCss2">
                                <span style="vertical-align:top;">医生备注：</span>
                                <textarea id="doctorText" rows="6" style="width:80%;" disabled></textarea>
                            </div>
                        </div>
                    </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="returnBtn">确认</button>
            </div>
        </div>
    </div>
</div>


<%--终审弹窗--%>
<div class="modal fade" id="lastModal" 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">终审信息</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group ">
                        <span style="vertical-align:top;">内容：</span>
                        <textarea rows="9" style="width:90%;" id="lastText"></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="lastSaveBtn">通过</button>
            </div>
        </div>
    </div>
</div>


<%--病案室退回弹窗--%>
<div class="modal fade" id="lastBackModal" 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">退回信息</h4>
            </div>
            <div class="modal-body divCss2">
                <!--通过审批且未过期的patientId集合-->
                <form class="form-horizontal" id="form6">
                    <div class="row">
                        <%--<div class="row divCss3 ">退回信息</div>--%>
                        <div class="row divCss2">
                            <div class="row divCss2">
                                <span style="vertical-align:center;">病案评分：</span>
                                <input id="scoreLast" type="number" class="input-sm "/> 分
                            </div>
                            <div class="row divCss2">
                                <span style="vertical-align:top;">内容：</span>
                                <textarea id="backContentLast" rows="9" style="width:85%;"></textarea>
                            </div>
                        </div>
                    </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 divCss2" id="lastBackBtn">确认</button>
            </div>
        </div>
    </div>
</div>

</body>
<script>

    //1、添加或者是2、编辑
    var btnFlag = 1;
    //编辑id
    var editId;
    //保存table選中的記錄
    var selectNodeId = 0;
    //病案号
    //var archiveDetailId="1333ad3c4d6448c89372835dbad3c364";
    var archiveDetailId = GetQueryString("archiveDetailId");
    //页面标题title
    document.title = decodeURIComponent(GetQueryString("titleName")) ;
    //1主任还是2病案室
    var roleVal = 1;
    //自动生成PDF的路径
    //var pdfPath = "C:/Users/Administrator/Desktop/测试/ttt.pdf";
    var pdfPath = GetQueryString("pdfPath");
    //自定义id
    var definedId;
    //判断归档状态
    var stateA = null;


    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
        var context = "";
        if (r != null)
            context = r[2];
        reg = null;
        r = null;
        return context == null || context == "" || context == "undefined" ? "" : context;
    }


    $(function () {
        $("#mb").css("display", "block");
        var oMoveBox = $("#arrow"), infoDiv = $("#infoDiv"), maxL = 0;
        oMoveBox.click(function () {
            if (maxL > 0) {
                maxL = 0;
                $("#pdfDiv").css("width", '70%');
                $("#arrow").html(">");
                $("#infoDiv").show();
            } else {
                maxL = 1;
                $("#pdfDiv").css("width", '97%');
                $("#arrow").html("<");
                $("#infoDiv").hide();
            }
        });

        var max = 0;
        var selectId = 0;
        var scollPostionVal = null;
        function initTable() {
            $('#table').bootstrapTable({
                url: "${path}/fault/getFaultList", // 获取表格数据的url
                queryParams: function (params) {
                    var temp = {
                        ///limit: limit,     //页面大小
                        // offset: offset,   //页码
                        //order: params.order,      //排位命令（desc，asc）
                        //id: $("#id").val(),
                        backContent: $("#assortNameQX").val(),
                        dealFlag: $("#dealFlagQX").val(),
                        backFlag: roleVal,
                        archiveDetailId: archiveDetailId
                    };
                    return temp;
                },
                singleSelect: true,//设置True 将禁止多选
                clickToSelect: true,//设置true 将在点击行时，自动选择rediobox 和 checkbox
                toolbar: '#toolbar',//指定工具栏
                toolbarAlign: 'right',// 指定 toolbar 水平方向的位置。'left' 或 'right'
                //height:'300',
                width: '100%',
                height: $(window).height() / 2,//自定义高度
                columns: [{
                    title: '全选',
                    field: 'select',   //复选框
                    checkbox: true,
                    width: 30,
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'archive_detail_id',
                    title: 'id',
                    visible: false
                }, {
                    field: 'assortId',
                    title: '缺陷类型',
                    width: 150,
                    visible: false,
                    formatter: function (value, row, index) {

                        return value
                    }
                }, {
                    field: 'assortName',
                    title: '缺陷类型',
                    width: 150
                }, {
                    field: 'price',
                    title: '类型分',
                    width: 80,
                    visible: false,
                    formatter: function (value, row, index) {
                        var result = '<span style="color:blue;"><i class="fa fa-times-circle-o" aria-hidden="true"></i>' + value + '分</span>';
                        return result
                    }
                }, {
                    title: '退回',
                    field: 'backFlag',
                    align: 'center',
                    width: 100,
                    formatter: function (value, row, index) {
                        if (btnFlag == 3) {
                            selectNodeId = row.id;
                            btnFlag = 0;
                        }
                        if (row.id > selectNodeId) {
                            selectNodeId = row.id;
                        }
                        if (btnFlag == 4) {
                            selectNodeId = editId;
                        }

                        if (row.archivestate == "主任退回" || row.archivestate == "初审") {
                            // console.log("==================================");
                            $("#firstBtn").hide();
                            $("#backBtn").hide();
                            $("#addBtn").hide();
                            $("#delBtn").hide();
                            $("#back2Btn").hide();
                            $("#lastBtn").hide();
                            $("#dealBtn").hide();
                            $("#dealCancelBtn").hide();

                            $("#roleVal").show();
                            $("#saveBtn").hide();
                            $("#clearBtn").hide();
                            $('#flagDiv').hide();
                            var val = "";
                            if (row.backFlag == 1) {
                                val = "科主任退回医生";
                            } else if (row.backFlag == 2) {
                                val = "科主任退回护士";
                            } else if (row.backFlag == 5) {
                                val = "病案室退回医生";
                            } else if (row.backFlag == 6) {
                                val = "病案室退回护士";
                            } else {
                                $('#flag').selectpicker('val', row.backFlag);
                            }


                            $("#roleVal").val(val);
                            $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                //chk_value.push($(this).val());//将选中的值添加到数组chk_value中
                                if ($(this).val() == row.assortId) {
                                    $(this)[0].checked = true;
                                } else {
                                    $(this)[0].checked = false;
                                }
                                $(this)[0].disabled = "true";

                            });

                            $("#content").attr("disabled", true);

                        } else {
                            //console.log("==================================");
                            $("#addBtn").show();
                        }

                        var result = "";
                        if (value == 1) {
                            result = '<span style="color:green;"><i class="fa fa-times-circle-o" aria-hidden="true"></i>科主任退回医生</span>';
                        } else if (value == 2) {
                            result = '<span style="color:red;"><i class="fa fa-times-circle-o" aria-hidden="true"></i>科主任退回护士</span>';
                        } else if (value == 5) {
                            result = '<span style="color:orange;"><i class="fa fa-times-circle-o" aria-hidden="true"></i>病案室退回医生</span>';
                        } else if (value == 6) {
                            result = '<span style="color:dodgerblue;"><i class="fa fa-times-circle-o" aria-hidden="true"></i>病案室退回护士</span>';
                        }
                        return result
                    }
                }, {
                    field: 'dealFlag',
                    title: '处理否',
                    align: 'center',
                    width: 80,
                    formatter: function (value, row, index) {
                        var result = "";
                        if (value == "1") {
                            result = '<span style="color:green;"><i class="fa fa-times-circle-o" aria-hidden="true"></i>已处理</span>';
                        } else {
                            result = '<span style="color:blue;"><i class="fa fa-times-circle-o" aria-hidden="true"></i>未处理</span>';
                        }
                        return result
                    }
                }, {
                    field: 'dealPerson',
                    title: '处理人',
                    width: 80

                }, {
                    field: 'dealTime',
                    title: '处理时间',
                    width: 80

                }, {
                    field: 'content',
                    title: '内容',
                    width: 200
                }],
                onClickRow: function (row) {
                    editId = row.id;
                    btnFlag = 2;
                    if (row != null) {
                        $("#content").val(row.content);
                        if (row.assortId == definedId) {
                            $("#defined").val(row.price);
                        } else {
                            $("#defined").val(0);
                        }

                        if (row.dealFlag == "0") {
                            $("#dealBtn").show();
                            $("#dealCancelBtn").hide();
                        } else {
                            $("#dealBtn").hide();
                            $("#dealCancelBtn").show();
                        }

                        // $("#typeFlag").selectpicker('val', row.assortId);
                        // $("#typeFlag").prop("disabled", true);
                        // $("#typeFlag").selectpicker('refresh');
                        $("#typeFlag").multiselect('clearSelection', true);
                        $('#typeFlag').multiselect('select', [row.assortId]);
                        //$("#typeFlag").multiselect('disable');


                        if (row.archivestate == "主任退回" || row.archivestate == "初审") {
                            $("#firstBtn").hide();
                            $("#backBtn").hide();
                            $("#addBtn").hide();
                            $("#delBtn").hide();
                            $("#saveBtn").hide();
                            $("#clearBtn").hide();
                            $("#dealBtn").hide();
                            $("#dealCancelBtn").hide();
                            $('#flagDiv').hide();
                            $("#roleVal").show();

                            var val = "";
                            if (row.backFlag == 1) {
                                val = "科主任退回医生";
                            } else if (row.backFlag == 2) {
                                val = "科主任退回护士";
                            } else if (row.backFlag == 5) {
                                val = "病案室退回医生";
                            } else if (row.backFlag == 6) {
                                val = "病案室退回护士";
                            } else {
                                $('#flag').selectpicker('val', row.backFlag);
                            }

                            $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                //chk_value.push($(this).val());//将选中的值添加到数组chk_value中
                                if ($(this).val() == row.assortId) {
                                    $(this)[0].checked = true;

                                } else {
                                    $(this)[0].checked = false;

                                }
                                $(this)[0].disabled = "true";
                            });

                            $("#content").attr("disabled", true);

                        } else {
                            $("#addBtn").show();
                            $("#saveBtn").show();
                            $("#clearBtn").show();
                            if (row.backFlag == 5 || row.backFlag == 6) {
                                $("#typeFlag").multiselect('disable');

                                //$("#typeFlag").selectpicker('val', row.assortId);
                                //$("#typeFlag").prop("disabled", true);
                                // $("#typeFlag").selectpicker('refresh');

                                $("#content").attr("disabled", true);
                                //$('.selectpicker').attr("disabled", true);
                                $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                    //chk_value.push($(this).val());//将选中的值添加到数组chk_value中
                                    if ($(this).val() == row.assortId) {
                                        $(this)[0].checked = true;
                                    } else {
                                        $(this)[0].checked = false;
                                    }
                                    $(this)[0].disabled = "true";
                                });

                                $("#roleVal").show();
                                $("#saveBtn").hide();
                                $("#delBtn").hide();
                                $("#clearBtn").hide();
                                $('#flagDiv').hide();

                                var val = "";
                                if (row.backFlag == 1) {
                                    val = "科主任退回医生";
                                } else if (row.backFlag == 2) {
                                    val = "科主任退回护士";
                                } else if (row.backFlag == 5) {
                                    val = "病案室退回医生";
                                } else if (row.backFlag == 6) {
                                    val = "病案室退回护士";
                                } else {
                                    $('#flag').selectpicker('val', row.backFlag);
                                }
                                $("#roleVal").val(val);
                            } else {
                                $("#roleVal").hide();
                                $("#delBtn").show();
                                $('#flagDiv').show();
                                $('#flag').selectpicker('val', row.backFlag);
                                $('input[name="Fruit"]').removeAttr("disabled");
                                $("#content").removeAttr("disabled");
                                //$("#typeFlag").selectpicker('val', row.assortId);
                                //$("#typeFlag").prop("disabled", true);
                                //$("#typeFlag").selectpicker('refresh');
                                $("#typeFlag").multiselect('enable');

                                $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                    //chk_value.push($(this).val());//将选中的值添加到数组chk_value中
                                    if ($(this).val() == row.assortId) {
                                        $(this)[0].checked = true;
                                    } else {
                                        $(this)[0].checked = false;
                                    }
                                });
                            }

                        }
                    }
                    //selectNode=row.id;

                }, onUncheck: function (rowsAfter, rowsBefore) {
                    //console.log("====取消选中");
                    editId = null;
                    scollPostionVal = null;
                }, onCheck:function(row){
                    editId = row.id;
                    if(editId!=null) {
                        scollPostionVal = $('#table').bootstrapTable('getScrollPosition');
                    }
                },
                //如果想双击获取row，把onlClickRow改为onDbClickRow，如下
                onDblClickRow: function (row) {
                    // if (template.defaults.imports.hasPermission('/payment_manager/payment_detail')) {
                    //     EditBook(row.id);
                    // }
                }, onRefresh: function (result) {

                }, onLoadSuccess: function (result) {  //加载成功时执行
                    // if (editId != null) {
                    //     //对刷新表格的数据选中之前选的id行
                    //     $('#table').bootstrapTable("checkBy", {field: 'id', values: [editId]});
                    // }else{
                    //     //console.log("===="+ selectNodeId);
                    //     //选中第一行
                    //     $('#table').bootstrapTable("checkBy", {field: 'id', values: [selectNodeId]});
                    // }

                    if(scollPostionVal!=null) {
                        $("#table").bootstrapTable('scrollTo', scollPostionVal);
                    }else{
                        scollPostionVal=$(window).height() / 2;//自定义高度
                        $("#table").bootstrapTable('scrollTo', scollPostionVal);
                    }
                    if (selectNodeId != 0) {
                        // $("#typeFlag").selectpicker('val', selectNodeId).trigger("change");

                        $('#table').bootstrapTable("checkBy", {field: 'id', values: [selectNodeId]});

                    }
                    //获取表格选中行
                    var row = $('#table').bootstrapTable('getSelections')[0];

                    if (row != null) {
                        if (row.id != null && row.id != "") {
                            selectId = row.assortId;
                            $("#typeFlag").multiselect('clearSelection', true);
                            $('#typeFlag').multiselect('select', [row.assortId]);
                            btnFlag = 2;
                            $("#content").val(row.content);
                            $('#flag').selectpicker('val', row.backFlag);


                            $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                if ($(this).val() == row.assortId) {
                                    $(this)[0].checked = true;
                                } else {
                                    $(this)[0].checked = false;
                                    // $("#typeFlag").selectpicker('val', row.assortId);
                                    // $("#typeFlag").prop("disabled", true);
                                    // $("#typeFlag").selectpicker('refresh');


                                }
                            });


                            if (row.backFlag == 5 || row.backFlag == 6) {
                                $("#typeFlag").multiselect('disable');
                                $("#content").attr("disabled", true);
                                $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                    //chk_value.push($(this).val());//将选中的值添加到数组chk_value中
                                    if ($(this).val() == row.assortId) {
                                        $(this)[0].checked = true;
                                    } else {
                                        $(this)[0].checked = false;
                                    }
                                    $(this)[0].disabled = "true";
                                });

                                $("#roleVal").show();
                                $("#saveBtn").hide();
                                $("#delBtn").hide();
                                $("#clearBtn").hide();

                                $('#flagDiv').hide();
                                var val = "";
                                if (row.backFlag == 1) {
                                    val = "科主任退回医生";
                                } else if (row.backFlag == 2) {
                                    val = "科主任退回护士";
                                } else if (row.backFlag == 5) {
                                    val = "病案室退回医生";
                                } else if (row.backFlag == 6) {
                                    val = "病案室退回护士";
                                } else {
                                    $('#flag').selectpicker('val', row.backFlag);
                                }
                                $("#roleVal").val(val);
                            } else {
                                $("#roleVal").hide();
                                $("#saveBtn").show();
                                $("#delBtn").show();
                                $("#addBtn").show();
                                $("#clearBtn").show();

                                $('#flagDiv').show();
                                var backVal = row.backFlag;

                                if (backVal != null) {
                                    $('#flag').selectpicker('val', backVal);
                                }
                                // $("#typeFlag").selectpicker('val', row.assortId);
                                // $("#typeFlag").prop("disabled", true);
                                // $("#typeFlag").selectpicker('refresh');

                                $('input[name="Fruit"]').removeAttr("disabled");
                                $("#content").removeAttr("disabled");
                                $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                    //chk_value.push($(this).val());//将选中的值添加到数组chk_value中
                                    if ($(this).val() == row.assortId) {
                                        $(this)[0].checked = true;
                                    } else {
                                        $(this)[0].checked = false;
                                    }
                                });
                            }
                        }

                        if (row.archivestate == "主任退回" || row.archivestate == "初审") {
                            $("#firstBtn").hide();
                            $("#backBtn").hide();
                            $("#addBtn").hide();
                            $("#delBtn").hide();
                            $("#back2Btn").hide();
                            $("#lastBtn").hide();
                            $("#dealBtn").hide();
                            $("#dealCancelBtn").hide();

                            $("#roleVal").show();
                            $("#saveBtn").hide();
                            $("#clearBtn").hide();
                            $('#flagDiv').hide();
                            var val = "";
                            if (row.backFlag == 1) {
                                val = "科主任退回医生";
                            } else if (row.backFlag == 2) {
                                val = "科主任退回护士";
                            } else if (row.backFlag == 5) {
                                val = "病案室退回医生";
                            } else if (row.backFlag == 6) {
                                val = "病案室退回护士";
                            } else {
                                $('#flag').selectpicker('val', row.backFlag);
                            }
                            $("#roleVal").val(val);

                            $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                //chk_value.push($(this).val());//将选中的值添加到数组chk_value中
                                if ($(this).val() == row.assortId) {
                                    $(this)[0].checked = true;
                                } else {
                                    $(this)[0].checked = false;
                                }
                                $(this)[0].disabled = "true";
                            });

                            $("#content").attr("disabled", true);

                        } else {
                            if (row.dealFlag == "0") {
                                $("#dealBtn").show();
                                $("#dealCancelBtn").hide();
                            } else {
                                $("#dealBtn").hide();
                                $("#dealCancelBtn").show();
                            }
                            $("#addBtn").show();
                        }

                    } else {
                        if (archiveDetailId != null && archiveDetailId != "") {
                            $.ajax({
                                url: "${path}/beHosp/getMaster",
                                type: "POST",
                                data: {"id": archiveDetailId},
                                success: function (result) {
                                    if (result != null) {
                                        if (result.id != null) {
                                            if (result.cmtDoctor == '0' || result.cmtNurse == '0') {

                                                $("#firstBtn").hide();
                                                $("#backBtn").hide();
                                                $("#addBtn").hide();
                                                $("#delBtn").hide();
                                                $("#back2Btn").hide();
                                                $("#lastBtn").hide();
                                                $("#dealBtn").hide();
                                                $("#dealCancelBtn").hide();

                                                $("#roleVal").show();
                                                $("#saveBtn").hide();
                                                $("#clearBtn").hide();
                                                $('#flagDiv').hide();

                                            }
                                        } else {
                                            toastr.warning("病案号不存在!");
                                        }
                                    } else {
                                        toastr.warning("病案不存在!");
                                    }
                                }, error: function () {
                                    toastr.error("操作失败!");
                                }
                            });
                        } else {
                            toastr.warning("病案号不存在!");
                        }
                    }
                },
                onLoadError: function () {  //加载失败时执行
                    //$('#table').bootstrapTable("checkBy", {field: 'id', values: [selectNodeId]});
                }
            });
        }

        function getFaultType() {

            $("#faultTypeDiv2").empty();
            priceAllArr = null;
            //获取科室列表
            $.ajax({
                url: "${path}/lastVerify/getFaultType",
                type: "POST",
                data: {effective: 1},
                success: function (result) {
                    if (result != null) {
                        var htmlVal = "";
                        var typeArr = [];
                        for (var k = 0; k < result.length; k++) {
                            if (result[k].typeName.indexOf(")") != -1) {
                                var parentVal = (result[k].typeName).split(")");
                                if (typeArr.indexOf(parentVal[0] + ")") == -1) {
                                    typeArr.push(parentVal[0] + ")");
                                }
                            }
                        }

                        var htmls = '<select  id="typeFlag" multiple="multiple" title="请输入选项" name="typeFlag" >';
                        if (typeArr != []) {
                            //console.log(typeArr);
                            for (var x = 0; x < typeArr.length; x++) {
                                var pVal = typeArr[x];
                                //console.log(pVal);
                                if (pVal != null && pVal != '') {
                                    htmlVal = '<optgroup label="' + pVal.substr(1, pVal.length - 2) + '" class="group-' + x + '">';
                                    //$("#typeFlag").append('<optgroup label="'+pVal.substr(1,pVal.length-1)+'" class="group-'+x+'">');
                                    for (var y = 0; y < result.length; y++) {
                                        // var text = (result[y].typeName).split(")");
                                        var str = result[y].typeName;
                                        var pos = str.indexOf(")");
                                        //console.log(result[y].typeName.substr(pos+1,str.length));

                                        if (result[y].typeName.indexOf(pVal) != -1) {
                                            htmlVal += '<option value="' + result[y].id + '">' + result[y].typeName.substr(pos + 1, str.length) + '</option>';
                                            //$("#typeFlag").append('<option value="'+result[y].id+'">'+text[1]+'</option>');
                                        }
                                    }
                                    htmlVal += '</optgroup>';
                                    // $("#typeFlag").append('</optgroup>');
                                    //$("#typeFlag").append(htmlVal);htmls
                                    htmls += htmlVal;
                                }
                            }

                        }
                        // console.log($("#typeFlag").html());
                        $("#mulDiv").append(htmls);
                        $('#typeFlag').multiselect({
                            nonSelectedText: '--请选择--',
                            enableCollapsibleOptGroups: true,
                            collapseOptGroupsByDefault: true,
                            enableFiltering: true,
                            includeSelectAllOption: true,
                            buttonWidth: 300,  //选择框的大小
                        });

                        var html = '';
                        for (var i = 0; i < result.length; i++) {
                            //multSelect
                            priceAllArr = result;
                            if (result[i].typeFlag == 'defined') {
                                definedId = result[i].id;
                                //html += '<div class="row" style="width:600px"><label class="col-xs-6"><input name="Fruit" type="checkbox" value="' + result[i].id + '">' + result[i].typeName + "(<input type='text' style='width:50px;' id='defined' value='0'/>)" + '</label></div>';
                                html += '<div class="row" style="width:600px"><label class="col-xs-6"><input name="Fruit" type="checkbox" value="' + result[i].id + '">' + result[i].typeName + '</label></div>'
                            } else {
                                //html += '<div class="row" style="width:600px"><label class="col-xs-6"><input name="Fruit" type="checkbox" value="' + result[i].id + '">' + result[i].typeName + "(" + result[i].price + ")" + '</label></div>'
                                //$("#typeFlag").append("<option value=" + result[i].id + ">" + result[i].typeName+"("+result[i].price+"分)" + "</option>");
                                // $("#typeFlag").append("<option value=" + result[i].id + ">" + result[i].typeName + "</option>");
                            }
                        }

                        $("#faultTypeDiv2").append(html);
                        //  $("#typeFlag").selectpicker('refresh'); //
                        //查看PDF
                        if (pdfPath != "") {
                            $('#pdf_page').attr('src', "${path}/static/pdfjs/web/viewer.html?file=" + encodeURIComponent("${path}/inHosp/pdfStreamHandeler?url=" + pdfPath));
                            //病案号 45e9b098f9da49ffba1843bfc6930cb8
                        } else {
                            toastr.warning("勾选的PDF文件不存在或破损!");
                        }
                        initTable();
                        // rowDiv.append(col1);
                        //根据病案号查找退回信息
                        //$("#faultTypeDiv").append(html);
                    }
                }
            });
            if (selectId != 0) {
                $('#typeFlag').multiselect('select', [selectId]);
            }
        }

        getFaultType();

        $("#searchBtnQX").click(function () {
            $('#table').bootstrapTable('refresh');
        });

        //初审
        $("#firstBtn").click(function () {
            if (archiveDetailId != null && archiveDetailId != "") {
                $.ajax({
                    url: "${path}/beHosp/getMaster",
                    type: "POST",
                    data: {"id": archiveDetailId},
                    success: function (result) {
                        if (result != null) {
                            if (result.archivestate != null) {
                                if (result.archivestate == '复审退回' || result.archivestate == '提交') {
                                    getStaffFun(archiveDetailId, 2);
                                    $('#verifyModal').modal({
                                        backdrop: 'static',//backdrop 为 static 时，点击模态对话框的外部区域不会将其关闭。
                                        keyboard: false,//keyboard 为 false 时，按下 Esc 键不会关闭 Modal。
                                        show: true//弹出对话框
                                    });
                                    $("#verifyText").val("");
                                } else {
                                    toastr.warning("科主任已经退回!");
                                    //刷新
                                    $('#table').bootstrapTable('refresh');
                                }

                            } else {
                                toastr.warning("病案号不存在!");
                            }
                        } else {
                            toastr.warning("病案不存在!");
                        }
                    }, error: function () {
                        toastr.error("操作失败!");
                    }
                });
            } else {
                toastr.warning("病案号不存在!");
            }
        });


        $("#verifyBtn").on('click', function () {
            //审核信息保存
            var firstTrial = $("#verifyText").val();
            if (firstTrial.length > 255) {
                toastr.warning("长度不超过255!");
                return;
            }
            var state = "初审";
            //归档状态改为初审还是有就是初审内容保存
            $("#WzRsult").empty();
            $.ajax({
                url: "${path}/beHosp/updateStateByArchivId",
                type: "POST",
                data: {archiveDetailId: archiveDetailId, firstTrial: firstTrial, state: state},
                success: function (result) {
                    $("#verifyModal").modal('hide');
                    if (result == "完整") {
                        $("#table").bootstrapTable("refresh");
                        toastr.success("初审操作成功!");
                    } else if(result == "提交失败,存在缺陷未处理!"){
                        toastr.warning(result);
                    }else {
                        $("#WzRsult").html(result);
                        $('#WZModal').modal({
                            backdrop: 'static',//backdrop 为 static 时，点击模态对话框的外部区域不会将其关闭。
                            keyboard: false,//keyboard 为 false 时，按下 Esc 键不会关闭 Modal。
                            show: true//弹出对话框
                        });
                        //$("#table").bootstrapTable("refresh");
                        // toastr.error(result);
                    }
                }
            });
        });

        $("#wzSaveBtn").on('click', function () {
            var firstTrial = $("#verifyText").val();
            var content = $("#WzRsult").html();
            if (firstTrial.length > 255) {
                toastr.warning("长度不超过255!");
                return;
            }

            //console.log(archiveDetailId+"==="+ firstTrial+"==="+ content);
            //完整性强制提交  forceWZ
            $.ajax({
                url: "${path}/beHosp/forceWZ",
                type: "POST",
                data: {archiveDetailId: archiveDetailId, firstTrial: firstTrial, content: content},
                success: function (result) {
                    $("#WZModal").modal('hide');
                    if (result == "1") {
                        $("#WZModal").modal('hide');
                        $("#table").bootstrapTable("refresh");
                        toastr.success("强制提交成功!");
                    } else {
                        $("#WZModal").modal('hide');
                        $("#table").bootstrapTable("refresh");
                        toastr.error("强制提交失败!");
                    }
                }
            });
        });

        function getStaffFun(masterId, flag) {
            $.ajax({
                url: "${path}/staffRemark/staffRemarkList",
                type: "POST",
                data: {masterId: masterId, effective: 1},
                success: function (result) {
                    if (result != null) {
                        for (var i = 0; i < result.length; i++) {
                            if (result[i].typeFlag == 1) {
                                //1护士
                                if (flag == 1) {
                                    $("#nuresText").val(result[i].content);
                                } else if (flag == 2) {
                                    $("#nuresText2").val(result[i].content);
                                }
                            } else if (result[i].typeFlag == 0) {
                                //0医生
                                if (flag == 1) {
                                    $("#doctorText").val(result[i].content);
                                } else if (flag == 2) {
                                    $("#doctorText2").val(result[i].content);
                                }
                            }
                        }
                    }
                }
            });
        }

        //主任退回
        $("#backBtn").click(function () {
            if (archiveDetailId != null && archiveDetailId != "") {
                $.ajax({
                    url: "${path}/beHosp/getMaster",
                    type: "POST",
                    data: {"id": archiveDetailId},
                    success: function (result) {
                        if (result != null) {
                            if (result.archivestate != null) {
                                if (result.archivestate == '复审退回' || result.archivestate == '提交') {
                                    //清空标签的内容
                                    $('#backContent').val("");
                                    //分值只读
                                    $.ajax({
                                        url: "${path}/fault/getTotal",
                                        type: "POST",
                                        data: {backFlag: 1, archiveDetailId: archiveDetailId},
                                        success: function (result) {
                                            if (result != null && result != "") {
                                                $("#score").val(result.price);
                                                $("#score").attr("readonly", true);
                                            } else {
                                                $("#score").val(0);
                                            }
                                        }
                                    });
                                    getStaffFun(archiveDetailId, 1);
                                    $('#returnModal').modal({
                                        backdrop: 'static',//backdrop 为 static 时，点击模态对话框的外部区域不会将其关闭。
                                        keyboard: false,//keyboard 为 false 时，按下 Esc 键不会关闭 Modal。
                                        show: true//弹出对话框
                                    });
                                } else {
                                    toastr.warning("科主任已经退回!");
                                    //刷新
                                    $('#table').bootstrapTable('refresh');
                                }

                            } else {
                                toastr.warning("病案号不存在!");
                            }
                        } else {
                            toastr.warning("病案不存在!");
                        }
                    }, error: function () {
                        toastr.error("操作失败!");
                    }
                });
            } else {
                toastr.warning("病案号不存在!");
            }
        });

        //主任退回确认
        $("#returnBtn").on('click', function () {
            if ($("#backContent").val().length > 1000) {
                toastr.warning("退回内容长度不超过1000!");
                return;
            }// else if (!validateNum($("#score").val())) {
            //     toastr.warning("评分范围0-100!");
            //     return;
            // }
            if (archiveDetailId != null && archiveDetailId != "") {
                var data = {};
                data.archiveDetailId = archiveDetailId;
                //退回信息
                data.score = $("#score").val();
                data.backContent = $("#backContent").val();
                data.state = "主任退回";
                data.backFlag = 3;
                //根据病案号保存缺陷信息
                $.ajax({
                    url: "${path}/lastVerify/updateDetailByArchivId",
                    type: "POST",
                    data: data,
                    success: function (result) {
                        if (result == 1) {
                            //关闭modal
                            $('#returnModal').modal('hide');  //手动关闭
                            //$('#firstModal').modal('hide');  //手动关闭
                            toastr.success("退回成功!");
                            //刷新
                            $('#table').bootstrapTable('refresh');
                        } else if (result == 2) {
                            toastr.warning("请先登记未处理缺陷!");
                            $('#returnModal').modal('hide');  //手动关闭
                        } else {
                            toastr.error("退回失败!");
                        }
                    }
                });
            } else {
                toastr.warning("病案号不存在!");
            }
        });


        $("#addBtn").click(function () {
            $(".multiselect-clear-filter").click();
            $(".checkbox").parent().parent('li').addClass("multiselect-collapsible-hidden");
            $(".checkbox").parent().parent('li').css("display", "none");
            if (archiveDetailId != null && archiveDetailId != "") {
                $.ajax({
                    url: "${path}/beHosp/getMaster",
                    type: "POST",
                    data: {"id": archiveDetailId},
                    success: function (result) {
                        if (result != null) {
                            if (result.id != null) {
                                if (result.archivestate == '复审退回' || result.archivestate == '提交') {
                                    editId = null;
                                    //1添加和2编辑
                                    btnFlag = 1;
                                    //默认选中医生
                                    $("#saveBtn").show();
                                    $("#clearBtn").show();
                                    $("#content").removeAttr("disabled");
                                    $("#content").val("");
                                    $('#flagDiv').show();
                                    $('#flag').selectpicker('val', 1);
                                    // $("#typeFlag").prop("disabled", false);
                                    // $('#typeFlag').selectpicker('val', "");
                                    // $("#typeFlag").selectpicker('refresh');
                                    $("#typeFlag").multiselect('enable');
                                    $("#typeFlag").multiselect('clearSelection', true);
                                    $("#typeFlag").multiselect('refresh');
                                    $("#roleVal").hide();
                                    $("#defined").val(0);
                                    $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                        $(this)[0].checked = false;
                                    });
                                    $("#table").bootstrapTable("checkBy", {field: 'id', values: 0});
                                    $("tr").removeClass("selected");
                                    //$('input[type = "checkbox"]').check=false;
                                    $('input[name="Fruit"]').removeAttr("disabled");

                                } else {
                                    toastr.warning("科主任已经退回或审核!");
                                    //刷新
                                    $('#table').bootstrapTable('refresh');
                                }

                            } else {
                                toastr.warning("病案号不存在!");
                            }
                        } else {
                            toastr.warning("病案不存在!");
                        }
                    }, error: function () {
                        toastr.error("操作失败!");
                    }
                });
            } else {
                toastr.warning("病案号不存在!");
            }

        });

        $("#clearBtn").click(function () {
            //默认选中医生
            $(".multiselect-clear-filter").click();
            $('#flag').selectpicker('val', 1);
            $("#content").val("");
            $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                $(this)[0].checked = false;
            });
            // $("#typeFlag").selectpicker('val',"");
            // $("#typeFlag").prop("disabled", false);
            // $("#typeFlag").selectpicker('refresh');
            $("#typeFlag").multiselect('clearSelection', true);
            $("#typeFlag").multiselect('enable');
            $(".checkbox").parent().parent('li').addClass("multiselect-collapsible-hidden");
            $(".checkbox").parent().parent('li').css("display", "none");

        });

        function validateNum(value) {
            var testReg = /^(((\d|[1-9]\d)(\.\d{1,2})?)|100|100.0|100.00)$/;
            if (testReg.test(value) != true) {
                toastr.warning("评分范围0-100,保留两位小数!");
                return false;
            } else {
                return true;
            }
        }

        $("#saveBtn").click(function () {
            $(".multiselect-clear-filter").click();
            $(".checkbox").parent().parent('li').addClass("multiselect-collapsible-hidden");
            $(".checkbox").parent().parent('li').css("display", "none");
            if (archiveDetailId != null && archiveDetailId != "") {
                $.ajax({
                    url: "${path}/beHosp/getMaster",
                    type: "POST",
                    data: {"id": archiveDetailId},
                    success: function (result) {
                        if (result != null) {
                            if (result.id != null) {
                                if (result.archivestate == '提交' || result.archivestate == '复审退回') {
                                    // if (!validateNum($("#defined").val())) {
                                    //     toastr.warning("评分范围0-100!");
                                    //     return;
                                    // }
                                    var arr = [];
                                    var arrText = [];
                                    $('input[name="Fruit"]:checked').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                                        arr.push($(this).val());//将选中的值添加到数组arr中
                                        if ($(this).val() == definedId) {
                                            //自定义值
                                            var defVal = $("#defined").val();
                                            if (defVal != "" && defVal != null) {
                                                arrText.push(defVal);
                                            } else {
                                                arrText.push(0);
                                            }
                                        } else {
                                            //获取分值
                                            var str = $(this).parent().parent().text().trim();
                                            var begin = str.indexOf('(') + 1;
                                            var last = str.indexOf(')');
                                            arrText.push(str.substring(begin, last));
                                        }
                                    });

                                    var ss = $("#typeFlag").val();
                                    if (ss != null) {
                                        for (var k = 0; k < ss.length; k++) {
                                            if (ss[k] != null && ss[k] != "") {
                                                arr.push(ss[k]);
                                                //分值
                                                arrText.push(0);
                                            }
                                        }
                                    }

                                    if ($("#flag").val().length <= 0) {
                                        toastr.warning("退回角色至少选一个!");
                                        return;
                                    } else if (arr.length <= 0) {
                                        toastr.warning("缺陷选项至少选一个!");
                                        return;
                                    } else if (arr.length == 1) {
                                        if (arr[0] == "") {
                                            toastr.warning("缺陷选项至少选一个!");
                                            return;
                                        }

                                    }


                                    //保存记录到缺陷记录表
                                    var data = {};
                                    data.id = editId;
                                    data.archiveDetailId = archiveDetailId;
                                    data.backFlag = $("#flag").val().toString();


                                    data.content = $("#content").val();
                                    data.assortId = arr.toString();
                                    data.backContent = arrText.toString() + "";
                                    //data.recallReason= btnFlag;


                                    //判断是添加还是删除recallReason ：1添加，2编辑
                                    $.ajax({
                                        url: "${path}/fault/addFaultList",
                                        type: "POST",
                                        data: data,
                                        success: function (result) {
                                            if (result.indexOf("成功") != -1) {
                                                toastr.success(result);
                                            } else {
                                                toastr.error(result);
                                            }
                                            //刷新
                                            $('#table').bootstrapTable('refresh');


                                        }
                                    });
                                } else {
                                    toastr.warning("科主任已经退回或审核!");
                                    //刷新
                                    $('#table').bootstrapTable('refresh');
                                }

                            } else {
                                toastr.warning("病案号不存在!");
                            }
                        } else {
                            toastr.warning("病案不存在!");
                        }
                    }, error: function () {
                        toastr.error("操作失败!");
                    }
                });
            } else {
                toastr.warning("病案号不存在!");
            }
        });

        $("#delBtn").click(function () {
            if (editId == null) {
                toastr.warning("选中1条记录!");
                return;
            }
            if (archiveDetailId != null && archiveDetailId != "") {
                $.ajax({
                    url: "${path}/beHosp/getMaster",
                    type: "POST",
                    data: {"id": archiveDetailId},
                    success: function (result) {
                        if (result != null) {
                            if (result.id != null) {
                                if (result.archivestate == '提交' || result.archivestate == '复审退回') {
                                    //删除记录
                                    $.ajax({
                                        url: "${path}/fault/delFault",
                                        type: "POST",
                                        data: {id: editId},
                                        success: function (result) {
                                            if (result.indexOf("成功") != -1) {
                                                toastr.success(result);
                                            } else {
                                                toastr.error(result);
                                            }
                                            //刷新
                                            $('#table').bootstrapTable('refresh');
                                        }
                                    });
                                } else {
                                    toastr.warning("科主任已经退回或审核!");
                                    //刷新
                                    $('#table').bootstrapTable('refresh');
                                }

                            } else {
                                toastr.warning("病案号不存在!");
                            }
                        } else {
                            toastr.warning("病案不存在!");
                        }
                    }, error: function () {
                        toastr.error("操作失败!");
                    }
                });
            } else {
                toastr.warning("病案号不存在!");
            }

        });
        $("#dealBtn").click(function () {
            if (editId == null) {
                toastr.warning("选中1条记录!");
                return;
            }
            //1添加和2编辑、3删除、4处理
            btnFlag = 4;
            if (archiveDetailId != null && archiveDetailId != "") {
                $.ajax({
                    url: "${path}/beHosp/getMaster",
                    type: "POST",
                    data: {"id": archiveDetailId},
                    success: function (result) {
                        if (result != null) {
                            if (result.id != null) {
                                if (result.archivestate == '提交' || result.archivestate == '复审退回') {
                                    //处理记录，登录处理人信息

                                    $.ajax({
                                        url: "${path}/fault/dealFault",
                                        type: "POST",
                                        data: {id: editId},
                                        success: function (result) {
                                            if (result.indexOf("成功") != -1) {
                                                toastr.success(result);
                                            } else if (result.indexOf("失败") != -1) {
                                                toastr.error(result);
                                            } else {
                                                toastr.warning(result);
                                            }
                                            //刷新
                                            $('#table').bootstrapTable('refresh');
                                        }
                                    });
                                } else {
                                    toastr.warning("处理失败!");
                                }

                            } else {
                                toastr.warning("病案号不存在!");
                            }
                        } else {
                            toastr.warning("病案不存在!");
                        }
                    }, error: function () {
                        toastr.error("操作失败!");
                    }
                });
            } else {
                toastr.warning("病案号不存在!");
            }
        });


        $("#dealCancelBtn").click(function () {
            if (editId == null) {
                toastr.warning("选中1条记录!");
                return;
            }
            //1添加和2编辑、3删除、4处理
            btnFlag = 4;
            if (archiveDetailId != null && archiveDetailId != "") {
                $.ajax({
                    url: "${path}/beHosp/getMaster",
                    type: "POST",
                    data: {"id": archiveDetailId},
                    success: function (result) {
                        if (result != null) {
                            if (result.id != null) {
                                if (result.archivestate == '提交' || result.archivestate == '复审退回') {
                                    //处理记录，登录处理人信息

                                    $.ajax({
                                        url: "${path}/fault/dealFault",
                                        type: "POST",
                                        data: {id: editId},
                                        success: function (result) {
                                            if (result.indexOf("成功") != -1) {
                                                toastr.success(result);
                                            } else if (result.indexOf("失败") != -1) {
                                                toastr.error(result);
                                            } else {
                                                toastr.warning(result);
                                            }
                                            //刷新
                                            $('#table').bootstrapTable('refresh');
                                        }
                                    });
                                } else {
                                    toastr.warning("处理失败!");
                                    //刷新
                                    //$('#table').bootstrapTable('refresh');
                                }

                            } else {
                                toastr.warning("病案号不存在!");
                            }
                        } else {
                            toastr.warning("病案不存在!");
                        }
                    }, error: function () {
                        toastr.error("操作失败!");
                    }
                });
            } else {
                toastr.warning("病案号不存在!");
            }
        });
        $("#mb").css("display", "none");
    });

</script>
</html>
