<%@ 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;
        }


        .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;
        }


        #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%;
        }

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

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

        table tr {
            color: #000
        }

        #firstModal .modal-content {
            margin-left: 50%;
            margin-top: 35%;
            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%);
        }

        #verinfyQZModal .modal-content {
            margin-left: 20%;
            margin-top:20%;
            width: 450px;
            color: black;
        }

        #assortNameQX {
            width: 200px
        }

        .bs-searchbox{
            width:190px;
        }
        .bs-searchbox input.form-control{
            height: 25px;
        }

        .multiselect-search{
            width:200px; !important;
        }

    </style>
</head>
<body>
<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 >退回：</span>
                        <select style="width:100px;" class="selectpicker bla bla bli" multiple name="flag" id="flag"
                                title="请输入角色">
                            <option value="5" selected>医生</option>
                            <option value="6">护士</option>
                        </select>
                        <input class="form-control" type id="roleVal" readonly />
                    </div>
                    <div class="row divCss2">
                        <%--<span  class="divCss7">缺陷信息：</span>--%>
                        <div id="typFlagDiv" class="divCss2">
                            <div class="row">
                                <div class="col-xs-2" >选项：</div>
                                <div class="col-xs-8" id="mulDiv" style="margin-left: -30px;">
                                    <%--<select  id="typeFlag" multiple="multiple" title="请输入选项" name="typeFlag" >--%>
                                        <%--<optgroup label="广东省">--%>
                                        <%--<option value="1">广州市</option>--%>
                                        <%--<option value="2">深圳市</option>--%>
                                        <%--<option value="3">珠海市</option>--%>
                                        <%--</optgroup>--%>
                                        <%--<option value="">请输入选项</option>--%>
                                    <%--</select>--%>
                                </div>
                            <%--<span style="vertical-align:center;">选项：</span>--%>
                            <%--<select class="selectpicker bla bla bli" multiple name="typeFlag" data-live-search="true"--%>
                                    <%--aria-expanded="false"--%>
                                    <%--id="typeFlag" title="请输入选项">--%>
                                <%--<option value="">请输入选项</option>--%>
                            <%--</select>--%>

                            </div>


                        </div>
                        <div class="divCss2" 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 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">添加</button>
                <button type="button" class="btn btn-danger btn-sm" id="delBtn">删除</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 "></table>
            <%--<div id="toolbar" class="btn-group pull-right" style="margin-right: 20px;">

            </div>--%>
        </div>
        <div class="row divCss2">
            <button type="button" class="btn btn-primary btn-large" id="back2Btn" >病案室退回</button>
            <button type="button" class="btn btn-success btn-large" id="lastBtn" >终审</button>
        </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" hidden>
                                <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 class="row divCss2">
                                <span  style="vertical-align:bottom; display:inline-block;">请选择电子病历可修改部分：</span>
                                <div class="row form-inline" style="vertical-align:top; display:inline-block;">
                                    <div class="checkbox" >
                                        <label >
                                            <input type="checkbox" name="box" style="vertical-align:text-top;" value="1">仅病案首页</label>
                                    </div>
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" name="box" value="2">医生文书</label>
                                    </div>
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" value="3">护士文书</label>
                                    </div>
                            </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="lastBackBtn">确认</button>
            </div>
        </div>
    </div>
</div>


<%--没签收是否强制提交弹窗--%>
<div class="modal fade" id="verinfyQZModal" 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>
                </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="verinfyQZBtn">通过</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");
    var type = GetQueryString("type");
    if(type==1){
        $("#saveBtn").hide();
        $("#clearBtn").hide();
        $("#addBtn").hide();
        $("#delBtn").hide();
        $("#back2Btn").hide();
        $("#lastBtn").hide();
        $("#flag").attr("disabled", "disabled");
        //$("#typeFlag").attr("disabled", "disabled");
        $("#content").attr('readonly','true');
    }
    //1主任还是2病案室
    var roleVal = 2;
    //自动生成PDF的路径
    //var pdfPath = "C:/Users/Administrator/Desktop/测试/ttt.pdf";
    var pdfPath = GetQueryString("pdfPath");
    var isSignVal = GetQueryString("isSignVal");
    var isscanedVal = GetQueryString("isscanedVal");
    document.title = decodeURIComponent(GetQueryString("titleName")) ;
    //自定义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 () {


        var priceAllArr;
        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() {
            $("#roleVal").hide();
            $('#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: '缺陷类型ID',
                    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
                    }
                }, {
                    field: 'minusPoint',
                    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 == "已归档" || row.archivestate == "已认证") {
                            $("#firstBtn").hide();
                            $("#backBtn").hide();
                            $("#addBtn").hide();
                            $("#delBtn").hide();
                            $("#back2Btn").hide();
                            $("#lastBtn").hide();
                            $("#dealBtn").hide();
                            $("#dealCancelBtn").hide();

                            $("#roleVal").show();
                            $("#saveBtn").hide();
                            $("#clearBtn").hide();
                            //$('.bootstrap-select').hide();
                            $('#flag').selectpicker('hide').trigger("change");
                            //$("#typeFlag").prop("disabled", true);
                            $("#typeFlag").multiselect('disable');
                           // $("#typeFlag").selectpicker('refresh');
                            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);

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

                            $('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("=====================");
                            $("#firstBtn").show();
                            $("#backBtn").show();
                            $("#addBtn").show();
                            $("#delBtn").show();
                            $("#back2Btn").show();
                            $("#lastBtn").show();
                            $("#dealBtn").show();
                            $("#dealCancelBtn").show();

                            $("#roleVal").show();
                            $("#saveBtn").show();
                            $("#clearBtn").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: 250
                }],
                onClickRow: function (row) {
                    if (row.archivestate == "复审退回" || row.archivestate == "已归档" || row.archivestate == "已认证") {
                        $("#firstBtn").hide();
                        $("#backBtn").hide();
                        $("#back2Btn").hide();
                        $("#lastBtn").hide();
                        $("#dealBtn").hide();
                        $("#dealCancelBtn").hide();

                        $("#roleVal").show();
                        $("#saveBtn").hide();
                        $("#delBtn").hide();
                        $("#addBtn").hide();
                        $("#clearBtn").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);

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

                        $('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();
                        }
                        btnFlag = 2;
                        $("#content").val(row.content);
                        if (row.assortId == definedId) {
                            $("#defined").val(row.price);
                        } else {
                            $("#defined").val(0);
                        }


                        if (row.backFlag == 1 || row.backFlag == 2) {
                            $("#content").attr("disabled", true);
                            //$('#flag').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();

                            //$('.bootstrap-select').hide();
                            $("#typeFlag").multiselect('hide');
                            $("#typeFlag").multiselect('disable');
                            // $('#flag').selectpicker('hide').trigger("change");
                            // $("#typeFlag").prop("disabled", true);
                            // $("#typeFlag").selectpicker('refresh');
                            var val = "";
                            if (row.backFlag == 1) {
                                val = "科主任退回医生";
                            } else if (row.backFlag == 2) {
                                val = "科主任退回护士";
                            } else {
                                $('#flag').selectpicker('val', row.backFlag);
                            }
                            //$("#typeFlag").selectpicker('val', row.assortId).trigger("change");
                            $("#typeFlag").multiselect('clearSelection',true);
                            $('#typeFlag').multiselect('select', [row.assortId]);
                            $("#roleVal").val(val);
                        } else {
                            $("#roleVal").hide();
                            $("#saveBtn").show();
                            $("#delBtn").show();
                            $("#addBtn").show();
                            $("#clearBtn").show();

                            //$('.bootstrap-select').show();
                            $('#flag').selectpicker('show').trigger("change");
                            $("#typeFlag").multiselect('enable');
                            // $("#typeFlag").prop("disabled", false);
                            // $("#typeFlag").selectpicker('refresh');
                            var backVal = row.backFlag;

                            if (backVal != null) {
                                $('#flag').selectpicker('val', backVal);
                            }

                            //$("#typeFlag").selectpicker('val', row.assortId).trigger("change");
                            $("#typeFlag").multiselect('clearSelection',true);
                            $('#typeFlag').multiselect('select', [row.assortId]);

                            $('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;
                                }
                            });
                        }
                    }

                }, 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) {
                       // console.log(row);
                        selectId=row.assortId;
                        $("#typeFlag").multiselect('clearSelection',true);
                        $('#typeFlag').multiselect('select', [selectId]);

                        if(row.id!=null && row.id!="") {
                            if (row.dealFlag == "0") {
                                $("#dealBtn").show();
                                $("#dealCancelBtn").hide();
                            } else {
                                $("#dealBtn").hide();
                                $("#dealCancelBtn").show();
                            }
                            editId = row.id;
                            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;
                                }
                            });
                        }

                        if (row.backFlag == 1 || row.backFlag == 2) {
                            $("#content").attr("disabled", true);
                            //$('#flag').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();

                            //$('.bootstrap-select').hide();
                            $('#flag').selectpicker('hide').trigger("change");
                            $("#typeFlag").multiselect('disable');
                            // $("#typeFlag").prop("disabled", true);
                            // $("#typeFlag").selectpicker('refresh');
                            var val = "";
                            if (row.backFlag == 1) {
                                val = "科主任退回医生";
                            } else if (row.backFlag == 2) {
                                val = "科主任退回护士";
                            } else {
                                $('#flag').selectpicker('val', row.backFlag);
                            }
                            //$("#typeFlag").selectpicker('val', row.assortId).trigger("change");
                            $("#roleVal").val(val);
                        } else {
                            $("#roleVal").hide();
                            $("#saveBtn").show();
                            $("#delBtn").show();
                            $("#addBtn").show();
                            $("#clearBtn").show();

                            //$('.bootstrap-select').show();
                            $('#flag').selectpicker('show').trigger("change");
                            // $("#typeFlag").prop("disabled", false);
                            // $("#typeFlag").selectpicker('refresh');
                            $("#typeFlag").multiselect('enable');
                            var backVal = row.backFlag;

                            if (backVal != null) {
                                $('#flag').selectpicker('val', backVal);
                            }
                           // $("#typeFlag").selectpicker('val', row.assortId).trigger("change");

                            $('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;
                                }
                            });
                        }
                    }


                },
                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);
                        var type = GetQueryString("type");
                        if (type == 1) {
                            $("#typeFlag").attr("disabled", "disabled");
                        }
                        $('#typeFlag').multiselect({
                            nonSelectedText : '--请选择--',
                            enableCollapsibleOptGroups: true,
                            collapseOptGroupsByDefault: true,
                            enableFiltering: true,
                            includeSelectAllOption: true,
                            buttonWidth:300,  //选择框的大小
                        });
                        //console.log("=================================================================================================");

                        // $('#typeFlag').multiselect({
                        //     enableClickableOptGroups: true,
                        //     enableCollapsibleOptGroups: true,
                        //     collapseOptGroupsByDefault: true,
                        //     enableFiltering: true,
                        //     includeSelectAllOption: true
                        //
                        //     // nonSelectedText: '请选择',
                        //     // numberDisplayed: 10,
                        //     // enableFiltering: true,
                        //      //allSelectedText:'全部'
                        // });

                        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").selectpicker('val', selectNodeId).trigger("change");
                // $("#typeFlag").multiselect('clearSelection',true);
                $('#typeFlag').multiselect('select', [selectId]);
                //console.log(selectId+"===================================================="+selectId);
                //  $('#table').bootstrapTable("checkBy", {field: 'id', values: [selectNodeId]});
            }

        }
        getFaultType();

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

        function verinfyFun(){
            var firstTrial = $("#lastText").val();
            if (firstTrial.length > 255) {
                toastr.warning("内容长度不超过255!");
                return;
            }
            var state = "已归档";
            //归档状态改为初审还是有就是初审内容保存
            $.ajax({
                url: "${path}/lastVerify/updateStateByArchivId",
                type: "POST",
                data: {archiveDetailId: archiveDetailId, firstTrial: firstTrial, state: state},
                success: function (result) {
                    //if (result == 1) {
                    $("#lastModal").modal('hide');
                    toastr.success("终审操作成功!");
                    //刷新
                    $('#table').bootstrapTable('refresh');
                    //location.reload();

                    //} else {
                    //toastr.error("终审操作成功!");
                    //}

                }
            });

            //修改master表score字段 保存总分数
            $.ajax({
                url: "${path}/lastVerify/updateScore",
                type: "POST",
                data: {id:archiveDetailId,score:$("#scoreLast").val()},
                success: function (result) {
                }
            });
        }
        //终审
        $("#lastBtn").click(function () {
            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 == '初审') {
                                    $("#lastText").val("");
                                    $('#lastModal').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("病案号不存在!");
            }

        });

        $("#verinfyQZBtn").on('click', function () {
            //有纸质且未签收，强制提交
            verinfyFun();
            $("#verinfyQZModal").modal('hide');
        });

        $("#lastSaveBtn").click(function () {
            //审核信息保存
            var isscaned=isscanedVal;
            var isSign=""+isSignVal;
            if(((isscaned=="1") && (isSign=="1"))||(isscaned=="0")){
                //无纸质 或 有纸质且已签收
                verinfyFun();
            }else{
                //弹窗是否强制提交
                $('#verinfyQZModal').modal({
                    backdrop: 'static',//backdrop 为 static 时，点击模态对话框的外部区域不会将其关闭。
                    keyboard: false,//keyboard 为 false 时，按下 Esc 键不会关闭 Modal。
                    show: true//弹出对话框
                });
            }
        });

        //终审退回
        $("#back2Btn").click(function () {
            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 == '初审') {
                                    //分值只读
                                    $.ajax({
                                        url: "${path}/fault/getTotal",
                                        type: "POST",
                                        data: {backFlag: roleVal, archiveDetailId: archiveDetailId},
                                        success: function (result) {
                                            if (result != null && result != "") {
                                                $("#scoreLast").val(result.price);
                                                $("#scoreLast").attr("readonly", true);
                                            } else {
                                                $("#scoreLast").val(0);
                                            }
                                        }
                                    });
                                    $("#backContentLast").val("");
                                    $('#lastBackModal').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("病案号不存在!");
            }


        });


        //病案室退回
        $("#lastBackBtn").on('click', function () {
            if ($("#backContentLast").val().length > 1000) {
                toastr.warning("退回内容长度不超过1000!");
                return;
            }// } else if (!validateNum($("#scoreLast").val())) {
            //     toastr.warning("评分范围0-100!");
            //     return;
            // }
            if (archiveDetailId != null && archiveDetailId != "") {
                var data = {};
                data.archiveDetailId = archiveDetailId;
                //退回信息
                data.score = $("#scoreLast").val();
                data.backContent = $("#backContentLast").val();
                data.state = "复审退回";
                data.backFlag = 4;
                // data.checkID = [];//定义一个空数组
                // $("input[name='box']:checked").each(function(i){//把所有被选中的复选框的值存入数组
                //     data.checkID[i] =$(this).val();
                //     console.log(data.checkID);
                // })
              //  debugger
                //根据病案号保存缺陷信息
                $.ajax({
                    url: "${path}/lastVerify/updateDetailByArchivId",
                    type: "POST",
                    data: data,
                    success: function (result) {
                        if (result == 1) {
                            //关闭modal
                           $('#lastBackModal').modal('hide');  //手动关闭
                            //$('#firstModal').modal('hide');  //手动关闭
                            toastr.success("退回成功!");
                            //刷新
                            $('#table').bootstrapTable('refresh');
                        }else if (result == 2) {
                            toastr.warning("请先登记未处理缺陷!");
                            $('#lastBackModal').modal('hide');  //手动关闭
                        } else {
                            toastr.error("退回失败!");
                        }
                    }
                });

                //修改master表score字段 保存总分数
                $.ajax({
                    url: "${path}/lastVerify/updateScore",
                    type: "POST",
                    data: {id:archiveDetailId,score:$("#scoreLast").val()},
                    success: function (result) {
                    }
                });

                /*var data2 = {};
                data2.archiveDetailId = archiveDetailId;
                //调平台质控接口
                $.ajax({
                    url: "${path}/lastVerify/emrShowBackReason",
                    type: "POST",
                    data: data2,
                    success: function (result) {
                        if (result.indexOf("true")!=-1) {
                            console.log("调平台质控接口成功!");
                        }else {
                            console.log("调平台质控接口失败!");
                        }
                    }
                });*/
            } 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 == '初审') {
                                    editId = null;
                                    //1添加和2编辑、3删除、4处理
                                    btnFlag = 1;
                                    //默认选中医生
                                    $("#clearBtn").show();
                                    $("#saveBtn").show();
                                    //$('.bootstrap-select').show();
                                    $('#flag').selectpicker('show').trigger("change");
                                    // $("#typeFlag").prop("disabled", false);
                                    // $("#typeFlag").selectpicker('refresh');
                                    $("#typeFlag").multiselect('enable');
                                    $("#typeFlag").multiselect('clearSelection',true);
                                   // $("#typeFlag").multiselect('updateButtonText');
                                   // $('#typeFlag').multiselect('updateButtonText');
                                    //$("#typeFlag option").attr("selected",false);
                                    //$("#typeFlag input[type='checkbox']").each(function(){this.checked=false;});
                                    // refresh
                                    //$("li").removeClass("active");

                                    $("#roleVal").hide();

                                    // $("#typeFlag").selectpicker('deselectAll');
                                    // $("#typeFlag").selectpicker("val", "");

                                    $('#flag').selectpicker('val', 5);

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

                                } 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('select', [""]);
            $("#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 == '初审') {
                                    // 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;
                                    if (roleVal == 2) {
                                        //病案室
                                        data.backFlag = $("#flag").val().toString().replace(1, 5).replace(2, 6);
                                    } else {
                                        data.backFlag = $("#flag").val().toString();
                                    }

                                    //医生、护士
                                    data.content = $("#content").val();
                                    //类id
                                    data.assortId = arr.toString();
                                    //价格
                                    data.backContent = arrText.toString()+"";

                                    //data.recallReason= btnFlag;
                                    console.log(data);
                                    //判断是添加还是删除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 == '初审') {
                                    btnFlag = 3;
                                    //删除记录
                                    $.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 == '初审') {
                                    //处理记录，登录处理人信息

                                    $.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("病案号不存在!");
            }
        });


        $("#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 == '初审' ) {
                                    //处理记录，登录处理人信息

                                    $.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("病案号不存在!");
            }
        });
    });

</script>
</html>
