<%@ 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" %>
    <style type="text/css">

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


        #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: #3c8dbc;
        }

        table tr {
            color: #000
        }

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

        #WZModal .modal-content {
            margin-left: 50%;
            margin-top: 35%;
            width: 100%;
        }

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

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

        #lastModal .modal-content {
            margin-left: 50%;
            margin-top: 35%;
            width: 100%;
        }

        #lastBackModal .modal-content {
            margin-left: 50%;
            margin-top: 35%;
            width: 120%;
        }



    </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 style="vertical-align:center;">退回：</span>
                        <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>
                        <input type id="roleVal" readonly hidden/>
                    </div>
                    <div class="row divCss2">
                        <span  class="divCss7">选项：</span>
                        <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 class="row divCss2 panel panel-primary">
            <!--数据表格-->
            <table id="table" class="table text-nowrap table-striped"></table>
            <div id="toolbar" class="btn-group pull-right" style="margin-right: 20px;">
                <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 class=" btn btn-success" style="height: 34px" type="button" id="refreshBtn" name="refresh"--%>
                    <%--aria-label="Refresh"--%>
                    <%--title="Refresh">--%>
                    <%--<i class="glyphicon glyphicon-refresh icon-refresh"></i>--%>
                    <%--</button>--%>
                </div>
            </div>
        </div>
        <div class="row divCss2">
            <button type="button" class="btn btn-primary btn-large" id="backBtn" hidden>主任退回</button>
            <button type="button" class="btn btn-success btn-large" id="firstBtn" hidden>初审</button>
            <button type="button" class="btn btn-primary btn-large" id="back2Btn" hidden>病案室退回</button>
            <button type="button" class="btn btn-success btn-large" id="lastBtn" hidden>终审</button>
        </div>
    </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-header">
                <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-header">
                <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-header">
                <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-header">
                <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="6" style="width:85%;" 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-header">
                <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="6" style="width:80%;"></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");
    //1主任还是2病案室
    //var roleVal=2;
    var roleVal = GetQueryString("roleVal");
    //自动生成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 () {
        function getFaultType() {
            $("#faultTypeDiv2").empty();
            //获取科室列表
            $.ajax({
                url: "${path}/lastVerify/getFaultType",
                type: "POST",
                data: {effective: 1},
                success: function (result) {
                    if (result != null) {
                        var html = '';
                        for (var i = 0; i < result.length; i++) {
                            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 +  '</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 + "(" + result[i].price + ")" + '</label></div>';
                            }


                        }
                        $("#faultTypeDiv2").append(html);
                        //查看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文件不存在或破损!");
                       }
                        // rowDiv.append(col1);
                        //根据病案号查找退回信息
                        //$("#faultTypeDiv").append(html);
                    }
                }
            });
        }

        getFaultType();


        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;
        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(),
                        backFlag:roleVal,
                        archiveDetailId: archiveDetailId
                    };
                    return temp;
                },
                singleSelect: true,//设置True 将禁止多选
                clickToSelect: true,//设置true 将在点击行时，自动选择rediobox 和 checkbox
                toolbar: '#toolbar',//指定工具栏
                toolbarAlign: 'right',// 指定 toolbar 水平方向的位置。'left' 或 'right'
                //height:'300',
                height: $(window).height() / 2,//自定义高度
                columns: [{
                    title: '全选',
                    field: 'select',   //复选框
                    checkbox: true,
                    width: 15,
                    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
                }, {
                    title: '退回',
                    field: 'backFlag',
                    align: 'center',
                    width: 100,
                    formatter: function (value, row, index) {

                        if (row.archivestate == "提交" || row.archivestate == "复审退回") {
                            //roleVal=1;
                            $("#backBtn").show();
                            $("#firstBtn").show();
                        }else {
                            $("#backBtn").hide();
                            $("#firstBtn").hide();
                            $("#lastBtn").hide();
                            $("#back2Btn").hide();
                            if (row.archivestate == "提交") {
                                $("#addBtn").show();
                                $("#delBtn").show();
                            }

                        }
                        if(row.archivestate == "初审") {
                            //roleVal=2;
                            $("#firstBtn").hide();
                            $("#backBtn").hide();
                            $("#addBtn").hide();
                            $("#delBtn").hide();
                            $("#back2Btn").show();
                            $("#lastBtn").show();
                        }else{
                            $("#back2Btn").hide();
                            $("#lastBtn").hide();
                        }
                        if(row.archivestate == "主任退回"){
                            $("#firstBtn").hide();
                            $("#backBtn").hide();
                            $("#back2Btn").hide();
                            $("#lastBtn").hide();

                            $("#roleVal").show();
                            $("#saveBtn").hide();
                            $("#delBtn").hide();
                            $("#addBtn").hide();
                            $("#clearBtn").hide();
                            $('.bootstrap-select').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 {
                                $('.selectpicker').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);
                        }

                        if (row.id > selectNodeId) {
                            selectNodeId = row.id;
                        }
                        if (stateA == null) {
                            stateA = row.archivestate;
                            if (roleVal == 1) {
                                if (row.archivestate == "提交" || row.archivestate == "复审退回") {
                                    $("#backBtn").show();
                                    $("#firstBtn").show();
                                } else {
                                    $("#backBtn").hide();
                                    $("#firstBtn").hide();
                                }
                                $("#lastBtn").hide();
                                $("#back2Btn").hide();


                            } else if (roleVal == 2) {
                                $("#back2Btn").show();
                                $("#lastBtn").show();
                                $("#firstBtn").hide();
                                $("#backBtn").hide();
                                //if (row.archivestate == "初审") {

                                //} else {
                                    //$("#back2Btn").hide();
                                   // $("#lastBtn").hide();
                               // }

                            }
                        }

                        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: 'content',
                    title: '内容',
                    width: 250
                }],
                onClickRow: function (row) {
                    editId = row.id;
                    btnFlag = 2;
                    $("#content").val(row.content);
                    if(row.assortId==definedId){
                        $("#defined").val(row.price);
                    }else{
                        $("#defined").val(0);
                    }

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

                        $("#roleVal").show();
                        $("#saveBtn").hide();
                        $("#delBtn").hide();
                        $("#addBtn").hide();
                        $("#clearBtn").hide();
                        $('.bootstrap-select').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 {
                            $('.selectpicker').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{
                    // $("#flag").val(row.backFlag);
                    if(roleVal==1){
                        if(row.backFlag==5 || row.backFlag==6){
                            $("#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();
                            $("#addBtn").hide();
                            $("#clearBtn").hide();
                            $('.bootstrap-select').hide();



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



                            $('.bootstrap-select').show();
                            $('.selectpicker').selectpicker('val', row.backFlag);
                            $('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;
                                }
                            });
                        }
                    }else if(roleVal == 2) {
                        if (row.backFlag == 1 || row.backFlag == 2) {
                            $("#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();
                            $("#addBtn").hide();
                            $("#clearBtn").hide();

                            $('.bootstrap-select').hide();
                            var val = "";
                            if (row.backFlag == 1) {
                                val = "科主任退回医生";
                            } else if (row.backFlag == 2) {
                                val = "科主任退回护士";
                            } else {
                                $('.selectpicker').selectpicker('val', row.backFlag);
                            }
                            $("#roleVal").val(val);
                        } else {
                            $("#roleVal").hide();
                            $("#saveBtn").show();
                            $("#delBtn").show();
                            $("#addBtn").show();
                            $("#clearBtn").show();

                            $('.bootstrap-select').show();
                            var backVal = row.backFlag;
                            if (backVal == 5) {
                                backVal = 1;
                            } else if (backVal == 6) {
                                backVal = 2;
                            }
                            //console.log(backVal+"================"+ row.backFlag);
                            if (backVal != null) {
                                $('.selectpicker').selectpicker('val', backVal);
                            }
                            $('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;
                                }
                            });
                        }
                    }

                    }
                    //selectNode=row.id;

                },
                //如果想双击获取row，把onlClickRow改为onDbClickRow，如下
                onDblClickRow: function (row) {
                    // if (template.defaults.imports.hasPermission('/payment_manager/payment_detail')) {
                    //     EditBook(row.id);
                    // }
                },onRefresh: function (result) {

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

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

                },
                onLoadError: function () {  //加载失败时执行
                    //$('#table').bootstrapTable("checkBy", {field: 'id', values: [selectNodeId]});
                }
            });
        }
        initTable();
        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);
                                }
                            }
                        }
                    }
                }
            });
        }

        //初审
        $("#firstBtn").click(function () {
            getStaffFun(archiveDetailId,2);
            $('#verifyModal').modal({
                backdrop: 'static',//backdrop 为 static 时，点击模态对话框的外部区域不会将其关闭。
                keyboard: false,//keyboard 为 false 时，按下 Esc 键不会关闭 Modal。
                show: true//弹出对话框
            });
            $("#verifyText").val("");
        });


        $("#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 {
                        $("#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("强制提交失败!");
                    }
                }
            });
        });


        //主任退回
        $("#backBtn").click(function () {
            //清空标签的内容
            $('#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//弹出对话框
            });

        });

        //主任退回确认
        $("#returnBtn").on('click', function () {
            if ($("#backContent").val().length > 1000) {
                toastr.warning("退回内容长度不超过1000!");
                return;
            }// else if (!validateNum($("#score").val())) {
            //     toastr.warning("评分范围0-100!");
            //     return;
            // }
            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');  //手动关闭
                        window.close();
                        toastr.success("退回成功!");
                        //刷新
                        $('#table').bootstrapTable('refresh');
                    } else {
                        toastr.error("退回失败!");
                    }
                }
            });


        });


        //终审
        $("#lastBtn").click(function () {
            $("#lastText").val("");
            $('#lastModal').modal({
                backdrop: 'static',//backdrop 为 static 时，点击模态对话框的外部区域不会将其关闭。
                keyboard: false,//keyboard 为 false 时，按下 Esc 键不会关闭 Modal。
                show: true//弹出对话框
            });
        });

        $("#lastSaveBtn").click(function () {
            //审核信息保存
            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');
                        window.close();
                    } else {
                        toastr.error("终审操作失败!");
                    }

                }
            });
        });

        //终审退回
        $("#back2Btn").click(function () {
            //分值只读
            $.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//弹出对话框
            });

        });


        //病案室退回
        $("#lastBackBtn").on('click', function () {
            if ($("#backContentLast").val().length > 1000) {
                toastr.warning("退回内容长度不超过1000!");
                return;
            }// } else if (!validateNum($("#scoreLast").val())) {
            //     toastr.warning("评分范围0-100!");
            //     return;
            // }
            var data = {};
            data.archiveDetailId = archiveDetailId;
            //退回信息
            data.score = $("#scoreLast").val();
            data.backContent = $("#backContentLast").val();
            data.state = "复审退回";
            data.backFlag = 4;
            //根据病案号保存缺陷信息
            $.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 {
                        toastr.error("退回失败!");
                    }
                }
            });
        });




        $("#addBtn").click(function () {
            editId=null;
            //1添加和2编辑
            btnFlag=1;
            //默认选中医生
            $('.selectpicker').selectpicker('val', 1);
            $("#content").val("");
            $("#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='checkbox']").prop('checked', false);

        });

        $("#clearBtn").click(function () {
            //默认选中医生
            $('.selectpicker').selectpicker('val', 1);
            $("#content").val("");
            $('input[name="Fruit"]').each(function () {//遍历每一个名字为interest的复选框，其中选中的执行函数
                $(this)[0].checked=false;
            });
			$("#typeFlag").prop("disabled", false);
			$("#typeFlag").selectpicker('val',"");
            $("#typeFlag").selectpicker('refresh');
        });

        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 () {
            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));
                }
            });
            if($("#flag").val().length <= 0){
                toastr.warning("退回角色至少选一个!");
                return;
            }else if(arr.length<=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();
            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');


                }
            });

        });

        $("#delBtn").click(function () {
            if (editId == null) {
                toastr.warning("选中1条记录!");
                return;
            }
            //删除记录
            $.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');
                }
            });
        });
    });

</script>
</html>
