//@ sourceURL=request.js
//默认是查询基础号表字典，当选择源数据的时候改为false
var baseList = false;
//默认是显示一个表格，当点击生产新号表时，改为true
var showTwoTable = false;
//保存临时生成的新号表数据
var tempData = null;
$(function () {
    daterangepickerWithIdAndCallBack('sourceRange', initSourceList);
    daterangepickerWithIdAndCallBack('newRange', initSourceList);
    // initDaterangepickerWithId('sourceRange');
    // initDaterangepickerWithId('newRange');
    initSourceList();
    //  initFeeTable();
    //重置查询参数
    $('#btn_clean').click(function () {
        cleanParams();
    });

    // $("#btn_query").click(function (t) {
    //     initSourceList();
    // });

    $(".selectpicker").selectpicker({
        dropuAuto: false
    });
    $("#btn_creat").click(function (t) {
        showTwoTable = true;
        initSourceList();
        $("#btn_creat").removeClass('in').addClass('hide');
        $("#btn_cancel").removeClass('hide').addClass('in');
        $("#tb_table_1").css("display", "block");
        $("#tb_table_2").css("display", "block");
    });
    $("#btn_cancel").click(function (t) {
        showTwoTable = false;
        //取消后置空
        tempData = null;
        initSourceList();
        $("#btn_cancel").removeClass('in').addClass('hide');
        $("#btn_creat").removeClass('hide').addClass('in');
        $("#tb_table_1").css("display", "none");
        $("#tb_table_2").css("display", "none");
    });

    $("#btn_add").click(function (t) {
        $("#editModal").modal();
        $("#classTitle").text("新增");
        clearInput();
    });

    $("#btn_save").click(function (t) {
        if (showTwoTable) {
            //保存临时生成的新号表数据
            saveRequest();
        }
    });

    $("#saveEdit").click(function (t) {
        if (showTwoTable) {
            //保存临时生成的新号表数据
            saveTempRequest();
        } else {
            //单独添加一个排班，直接保存
            saveRequest();
        }
    });


    initMzWorkTime();
    initDeptSelect();
    initDoctorSelect();
    initChargeType();

    $("#editDay").change(function (e) {
        var editDay = $("#editDay").val();
        if (editDay.length == 8 && editDay.indexOf("-") <= 0) {
            if (editDay.substring(4, 6) > 12) {
                new PNotify({
                    title: '错误提示',
                    text: '号表日期错误,月份不能大于12',
                    type: 'error',
                    hide: true,
                    styling: 'bootstrap3'
                });
                $("#editDay").val(null);
                return;
            }
            if (editDay.substring(6) > 31) {
                new PNotify({
                    title: '错误提示',
                    text: '号表日期错误,天数不能大于31',
                    type: 'error',
                    hide: true,
                    styling: 'bootstrap3'
                });
                $("#editDay").val(null);
                return;
            }
            editDay = editDay.substring(0, 4) + "-" + editDay.substring(4, 6) + "-" + editDay.substring(6);
            $("#editDay").val(editDay);
        }
        var dateFormat = /^(\d{4})-(\d{2})-(\d{2})$/;
        if (!dateFormat.test(editDay)) {
            new PNotify({
                title: '错误提示',
                text: '号表日期错误',
                type: 'error',
                hide: true,
                styling: 'bootstrap3'
            });
        }
        var arr = editDay.split("-");
        if (!checkDate(arr[0], arr[1], arr[2])) {
            new PNotify({
                title: '错误提示',
                text: '表表日期错误',
                type: 'error',
                hide: true,
                styling: 'bootstrap3'
            });
        }
    });

});

/**
 * 清空输入框
 */
function clearInput() {
    $("#requestId").val(null);
    $("#editDay").val(null);
    $('#ampm').selectpicker('val', null);
    $('#ampm').selectpicker('refresh');
    $('#deptNo').selectpicker('val', null);
    $('#deptNo').selectpicker('refresh');
    $('#doctorParam').selectpicker('val', null);
    $('#doctorParam').selectpicker('refresh');
    $('#chargeType').selectpicker('val', null);
    $('#chargeType').selectpicker('refresh');
    $("#checkFee").val(null);
    $("#totalNum").val(null);
}


/**
 * 号表类型切换事件
 * @param object
 */
function sourceChange(object) {
    $("#source_group").find("button").each(function (index, element) {
        if ($(element).hasClass("btn-primary")) {
            $(element).removeClass("btn-primary").addClass("btn-default");
        }
    });
    $(object).removeClass("btn-default").addClass("btn-primary");
    var sourceGroup = getIndex("source_group");
    if (sourceGroup == 0) {
        baseList = true;
    } else {
        baseList = false;
    }
    initSourceList();
}


/**
 * 获取按钮组选择的下标
 * @param id
 * @returns {number}
 */
function getIndex(id) {
    var index = 0;
    var item = $("#" + id).find("button");
    for (var i = 0; i <= item.length; i++) {
        if ($(item[i]).hasClass("btn-primary")) {
            index = i;
            break;
        }
    }
    return index;
}

/**
 * 查询源号表信息
 */
function initSourceList() {
    $('#tb_table_2').bootstrapTable("destroy");
    var tableId = 'tb_table';
    var destroyTableId = 'tb_table_1';
    if (showTwoTable) {
        tableId = 'tb_table_1';
        destroyTableId = 'tb_table';
    }
    $('#' + destroyTableId).bootstrapTable("destroy");
    $('#' + tableId).bootstrapTable("destroy");
    $('#' + tableId).bootstrapTable({
        url: '/thmz/getRequestByTimes',         //请求后台的URL（*）
        method: 'post',                      //请求方式（*）
        toolbar: '#toolbar',                //工具按钮用哪个容器
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否显示分页（*）
        sortable: true,                     //是否启用排序
        sortOrder: "asc",                   //排序方式
        queryParams: queryParams,           //传递参数（*）
        sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
        pageNumber: 1,                       //初始化加载第一页，默认第一页
        pageSize: 15,                       //每页的记录行数（*）
        pageList: [10, 15, 25, 50, 100],        //可供选择的每页的行数（*）
        search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
        strictSearch: true,
        showColumns: false,                  //是否显示所有的列
        showRefresh: false,                  //是否显示刷新按钮
        minimumCountColumns: 2,             //最少允许的列数
        clickToSelect: true,                //是否启用点击选中行
        uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
        showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
        cardView: false,                    //是否显示详细视图
        detailView: false,
        //rowStyle:rowStyle,//通过自定义函数设置行样式
        ajaxOptions: {
            headers: {
                'Accept': 'application/json',
                'Authorization': 'Bearer ' + localStorage.getItem("token")
            }
        },
        columns: [
            {
                title: '操作',
                field: 'op',
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    var str = '<button type="button" class="btn btn-primary  btn-sm" onclick="updateRequest(' + row.id + ')">编辑</button>';
                    str += '<button type="button" class="btn btn-danger  btn-sm" onclick="deleteRequest(' + row.id + ')">删除</button>';
                    return [str].join('');
                }
            },
            {
                field: 'requestDay',
                title: '日期',
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return format(value, "yyyy-MM-dd");
                }
            }, {
                field: 'ampm',
                title: '号段',
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    var text = '上午';
                    if (value == 'p') {
                        text = '下午';
                    } else if (value == 'd') {
                        text = '全天';
                    }else if (value == 'n') {
                        text = '中午';
                    }else if (value == 'e') {
                        text = '晚班';
                    }else if (value == 'l') {
                        text = '夜班';
                    }
                    return text;
                }
            }, {
                field: 'unitName',
                title: '科室',
                align: "center",
                valign: 'middle'
            }, {
                field: 'doctorName',
                title: '医生',
                align: "center",
                valign: 'middle'
            }, {
                field: 'chargeTypeName',
                title: '号别',
                align: "center",
                valign: 'middle'
            }, {
                field: 'checkFee',
                title: '检查费',
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return value.toFixed(2);
                }
            }, {
                field: 'totalNum',
                title: '总号数',
                align: "center",
                valign: 'middle'
            }, {
                field: 'leftNum',
                title: '剩余号数',
                align: "center",
                valign: 'middle'
            }, {
                field: 'bespeakNo',
                title: '当前号数',
                align: "center",
                valign: 'middle'
            }
        ],
        onLoadSuccess: function () {
            if (baseList) {
                $('#' + tableId).bootstrapTable('hideColumn', 'op');//隐藏上述操作列
            }
        },
        responseHandler: function (res) {
            if (res == '401' || res == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            var ress = eval(res);
            if (ress.code == -1) {
                if (ress.message != null && ress.message != '') {
                    new PNotify({
                        title: '错误提示',
                        text: ress.message,
                        type: 'error',
                        hide: true,
                        styling: 'bootstrap3'
                    });
                }
                return {
                    "total": 0,//总页数
                    "rows": {}   //数据
                };
            }
            return {
                "total": ress.data.length,//总页数
                "rows": ress.data   //数据
            };
        },
    });
    initNewList();
}


/**
 * 构建列表查询参数
 * @param params
 * @returns {{mzChargeDetail: {patientId: string | number | string[] | undefined | jQuery, warnDept: string | number | string[] | undefined | jQuery, doctorCode: string | number | string[] | undefined | jQuery, name: string | number | string[] | undefined | jQuery, payMark: number}, beginTime: Date, endTime: Date, pageSize: *, pageIndex: number}}
 */
function queryParams(params) {
    if (baseList) {
        var temp = {
            beginDate: "2012-02-13 00:00:00",
            endDate: "2012-02-19 23:59:59",
            unitCode: $("#unitCode").val(),
            ampm: $("#ampmParams").val()
        };
        return temp;
    }
    var rePortRangeArr = getSourceRangeArr();
    var temp = {
        beginDate: rePortRangeArr[0],
        endDate: rePortRangeArr[1],
        unitCode: $("#unitCode").val(),
        ampm: $("#ampmParams").val()
    };
    return temp;
};


/**
 * 生成新号表数据
 */
function initNewList() {
    if (!showTwoTable) {
        return;
    }
    initNewListCommon('/thmz/getNewRequestByTimes', newListQueryParams);
}


/**
 * 生成新号表的通用方法
 * @param url
 * @param newParams
 */
function initNewListCommon(url, newParams) {
    $('#tb_table_2').bootstrapTable("destroy");
    $('#tb_table_2').bootstrapTable({
        url: url,                            //请求后台的URL（*）
        method: 'post',                      //请求方式（*）
        toolbar: '#toolbar',                //工具按钮用哪个容器
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否显示分页（*）
        sortable: true,                     //是否启用排序
        sortOrder: "asc",                   //排序方式
        queryParams: newParams,           //传递参数（*）
        sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
        pageNumber: 1,                       //初始化加载第一页，默认第一页
        pageSize: 15,                       //每页的记录行数（*）
        pageList: [10, 15, 25, 50, 100],        //可供选择的每页的行数（*）
        search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
        strictSearch: true,
        showColumns: false,                  //是否显示所有的列
        showRefresh: false,                  //是否显示刷新按钮
        minimumCountColumns: 2,             //最少允许的列数
        clickToSelect: true,                //是否启用点击选中行
        uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
        showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
        cardView: false,                    //是否显示详细视图
        detailView: false,
        //rowStyle:rowStyle,//通过自定义函数设置行样式
        ajaxOptions: {
            headers: {
                'Accept': 'application/json',
                'Authorization': 'Bearer ' + localStorage.getItem("token")
            }
        },
        columns: [
            {
                title: '操作',
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    var str = '<button type="button" class="btn btn-primary  btn-sm" onclick="updateRequestByIndex(' + index + ')">编辑</button>';
                    str+= '<button type="button" class="btn btn-danger  btn-sm" onclick="deleteRequestByIndex(' + index + ')">删除</button>';
                    return [str].join('');
                }
            },
            {
                field: 'requestDay',
                title: '日期',
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return format(value, "yyyy-MM-dd");
                }
            }, {
                field: 'ampm',
                title: '号段',
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    var text = '上午';
                    if (value == 'p') {
                        text = '下午';
                    } else if (value == 'd') {
                        text = '全天';
                    }
                    return text;
                }
            }, {
                field: 'unitName',
                title: '科室',
                align: "center",
                valign: 'middle'
            }, {
                field: 'doctorName',
                title: '医生',
                align: "center",
                valign: 'middle'
            }, {
                field: 'chargeTypeName',
                title: '号别',
                align: "center",
                valign: 'middle'
            }, {
                field: 'checkFee',
                title: '检查费',
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return value.toFixed(2);
                }
            }, {
                field: 'totalNum',
                title: '总号数',
                align: "center",
                valign: 'middle'
            }, {
                field: 'leftNum',
                title: '剩余号数',
                align: "center",
                valign: 'middle'
            }, {
                field: 'bespeakNo',
                title: '当前号数',
                align: "center",
                valign: 'middle'
            }
        ],
        responseHandler: function (res) {
            if (res == '401' || res == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            var ress = eval(res);
            if (ress.code == -1) {
                if (ress.message != null && ress.message != '') {
                    new PNotify({
                        title: '错误提示',
                        text: ress.message,
                        type: 'error',
                        hide: true,
                        styling: 'bootstrap3'
                    });
                }
                // return {
                //     "total": 0,//总页数
                //     "rows": {}   //数据
                // };
            }
            //临时保存新号表数据
            tempData = ress.data;
            return {
                "total": ress.data.length,//总页数
                "rows": ress.data   //数据
            };
        },
    });
}


/**
 * 构建列表查询参数
 * @param params
 * @returns {{mzChargeDetail: {patientId: string | number | string[] | undefined | jQuery, warnDept: string | number | string[] | undefined | jQuery, doctorCode: string | number | string[] | undefined | jQuery, name: string | number | string[] | undefined | jQuery, payMark: number}, beginTime: Date, endTime: Date, pageSize: *, pageIndex: number}}
 */
function newListQueryParams(params) {
    var newRangeArr = getNewRangeArr();
    if (baseList) {
        var temp = {
            beginDate: "2012-02-13 00:00:00",
            endDate: "2012-02-19 23:59:59",
            newBeginDate: newRangeArr[0],
            newEndDate: newRangeArr[1],
        };
        return temp;
    }
    var rePortRangeArr = getSourceRangeArr();
    var temp = {
        beginDate: rePortRangeArr[0],
        endDate: rePortRangeArr[1],
        newBeginDate: newRangeArr[0],
        newEndDate: newRangeArr[1],
    };
    return temp;
};


/**
 * 设置病人id
 */
function setPatientId() {
    var patientId_or_cardNo = $("#patientId_or_cardNo").val();
    $.ajax({
        type: "GET",
        url: '/thmz/getByIcCardNo?icCardNo=' + patientId_or_cardNo,
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
        success: function (res) {
            if (res == '401' || res == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            if (res.code == 0) {
                if (res.data != null) {
                    $("#patientId").val(res.data.patientId);
                } else {
                    $("#patientId").val(patientId_or_cardNo);
                }
            }
        }
    });
}


/**
 * 获取源号表时间选择器的时间数组
 * @returns {string[]}
 */
function getSourceRangeArr() {
    var rePortRange = $('#sourceRange span').html();
    var rePortRangeArr = rePortRange.split(" - ");
    rePortRangeArr[0] = rePortRangeArr[0] + " 00:00:00"
    rePortRangeArr[1] = rePortRangeArr[1] + " 23:59:59"
    return rePortRangeArr;
}


/**
 * 获取新号表时间选择器的时间数组
 * @returns {string[]}
 */
function getNewRangeArr() {
    var rePortRange = $('#newRange span').html();
    var rePortRangeArr = rePortRange.split(" - ");
    rePortRangeArr[0] = rePortRangeArr[0] + " 00:00:00"
    rePortRangeArr[1] = rePortRangeArr[1] + " 23:59:59"
    return rePortRangeArr;
}


/**
 * 清空查询条件
 */
function cleanParams() {
    $('#sourceRange span').html(moment().format('YYYY-MM-DD') + ' - ' + moment().format('YYYY-MM-DD'));
    $('#newRange span').html(moment().format('YYYY-MM-DD') + ' - ' + moment().format('YYYY-MM-DD'));
    $('#ampmParams').selectpicker('val', null);
    $('#ampmParams').selectpicker('refresh');
    $('#unitCode').selectpicker('val', null);
    $('#unitCode').selectpicker('refresh');
    initSourceList();
}


/**
 * 保存临时生成的新号表数据
 */
function saveTempRequest() {
    var index = $("#requestId").val();
    var realParams = JSON.parse('{"mzyRequests":""}');
    var tempJson = JSON.parse('{"requestDay":"","ampm":"","unitCode":"","doctorCode":"","chargeType":"","totalNum":"","leftNum":"","bespeakNo":"1","checkFee":""}');
    tempJson.requestDay = $("#editDay").val();
    tempJson.ampm = $("#ampm").val();
    tempJson.unitCode = $("#deptNo").val();
    tempJson.doctorCode = $("#doctorParam").val();
    tempJson.chargeType = $("#chargeType").val();
    tempJson.totalNum = $("#totalNum").val();
    tempJson.leftNum = $("#totalNum").val();
    tempJson.checkFee = $("#checkFee").val();
    if (index == null || index == "") {
        tempData[tempData.length] = tempJson;
    } else {
        tempData[index] = tempJson;
    }
    realParams.mzyRequests = tempData;
    $("#editModal").modal("hide");
    initNewListCommon("/thmz/formatRequest", realParams);

}


/**
 * 保存号表数据
 */
function saveRequest() {
    var data = null;
    if (showTwoTable) {
        var realParams = JSON.parse('{"mzyRequests":[]}');
        for (var i = 0; i < tempData.length; i++) {
            var thisData = tempData[i];
            var tempJson = JSON.parse('{"requestDay":"","ampm":"","unitCode":"","doctorCode":"","chargeType":"","totalNum":"","leftNum":"","bespeakNo":"1","checkFee":""}');
            tempJson.requestDay = thisData.requestDay;
            tempJson.ampm = thisData.ampm;
            tempJson.unitCode = thisData.unitCode;
            tempJson.doctorCode = thisData.doctorCode;
            tempJson.chargeType = thisData.chargeType;
            tempJson.totalNum = thisData.totalNum;
            tempJson.leftNum = thisData.leftNum;
            tempJson.checkFee = thisData.checkFee;
            realParams.mzyRequests[i] = tempJson;
        }
        data = JSON.stringify(realParams);
    } else {
        data = JSON.stringify({
            mzyRequests: [{
                id: $("#requestId").val(),
                requestDay: $("#editDay").val(),
                ampm: $("#ampm").val(),
                unitCode: $("#deptNo").val(),
                doctorCode: $("#doctorParam").val(),
                chargeType: $("#chargeType").val(),
                totalNum: $("#totalNum").val(),
                leftNum: $("#totalNum").val(),
                bespeakNo: 1,
                checkFee: $("#checkFee").val()
            }]
        });
    }
    $.ajax({
        type: "POST",
        url: '/thmz/saveRequest',
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
        data: data,
        success: function (res) {
            if (res == '401' || res == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            if (res.code == 0) {
                $("#editModal").modal("hide");
                clearInput();
                if(showTwoTable){
                    initSourceList();
                }else {
                    $('#tb_table').bootstrapTable('refresh');
                }
                successMesage(res);
                if (showTwoTable) {
                    $('#sourceRange span').html($('#newRange span').html());
                    $("#btn_cancel").click();
                }
            } else {
                errorMesage(res);
            }
        }
    });
}


/**
 * 初始门诊时间区间下拉选
 */
function initMzWorkTime() {
    $.ajax({
        type: "GET",
        url: '/thmz/getMzWorkTime',
        dataType: "json",
        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
        success: function (res) {
            if (res == '401' || res == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            var html = '';
            $.each(res.data, function (commentIndex, comment) {
                html += '<option value="' + comment.code + '">' + comment.name + '</option>';
            });
            $('#ampm').empty();   //清空resText里面的所有内容
            $('#ampm').html(html);
            $('#ampm').selectpicker('refresh');

            $('#ampmParams').empty();   //清空resText里面的所有内容
            $('#ampmParams').html(html);
            $('#ampmParams').selectpicker('refresh');
        }
    });
}


/**
 * 科室列表
 */
function initDeptSelect() {
    //科室列表
    $.ajax({
        type: "GET",
        url: '/thmz/allMzGhUnitCode',
        dataType: "json",
        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
        success: function (data) {
            if (data == '401' || data == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            var html = '';
            $.each(data.data, function (commentIndex, comment) {
                html += '<option value="' + comment.code + '">' + comment.name + '(' + comment.pyCode + ')</option>';
            });
            $('#deptNo').empty();
            $('#deptNo').html(html);
            $('#deptNo').selectpicker('refresh');

            $('#unitCode').empty();
            $('#unitCode').html(html);
            $('#unitCode').selectpicker('refresh');
        }
    });
}


/**
 * 挂号列表中的医生列表初始化
 */
function initDoctorSelect() {
    //医生列表
    $.ajax({
        type: "GET",
        //url: '/thmz/listEmployeeByDepts?depts=' + $('#deptNo').val(),
        url: '/thmz/listEmployeeByDepts?depts=null',
        dataType: "json",
        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
        success: function (res) {
            if (res == '401' || res == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            var html = '<option value=""></option>';
            $.each(res.data, function (commentIndex, comment) {
                html += '<option value="' + comment.employeeCode + '">' + comment.employeeName + ' (' + comment.deptName + ') </option>';
            });
            $('#doctorParam').empty();
            $('#doctorParam').html(html);
            $('#doctorParam').selectpicker('destroy').selectpicker('refresh');
        }
    });
}


/**
 * 初始门诊号别下拉选
 */
function initChargeType() {
    $.ajax({
        type: "GET",
        url: '/thmz/getAllMzChargeType',
        dataType: "json",
        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
        success: function (res) {
            if (res == '401' || res == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            var html = '<option value=""></option>';
            $.each(res.data, function (commentIndex, comment) {
                html += '<option value="' + comment.code + '">' + comment.name + '</option>';
            });
            $('#chargeType').empty();   //清空resText里面的所有内容
            $('#chargeType').html(html);
            $('#chargeType').selectpicker('refresh');
        }
    });
}


/**
 * 修改号表信息
 * @param id
 */
function updateRequest(id) {
    $("#requestId").val(id);
    $.ajax({
        type: "GET",
        url: '/thmz/getRequestById?id=' + id,
        dataType: "json",
        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
        success: function (res) {
            if (res == '401' || res == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            if (res.code == 0) {
                $("#classTitle").text("修改");
                $("#editDay").val(format(res.data.requestDay, "yyyy-MM-dd"));
                $('#ampm').selectpicker('val', res.data.ampm);
                $('#ampm').selectpicker('refresh');
                $('#deptNo').selectpicker('val', res.data.unitCode);
                $('#deptNo').selectpicker('refresh');
                //initDoctorSelect();
                $('#doctorParam').selectpicker('val', res.data.doctorCode);
                $('#doctorParam').selectpicker('refresh');
                $('#chargeType').selectpicker('val', res.data.chargeType);
                $('#chargeType').selectpicker('refresh');
                $("#totalNum").val(res.data.totalNum);
                $("#totalNum").val(res.data.leftNum);
                $("#checkFee").val(res.data.checkFee);
                $("#editModal").modal();
            }
        }
    });
}


/**
 * 删除号表信息
 * @param id
 */
function deleteRequest(id) {
    if (!confirm("确认要删除当前操作的号表信息吗？")) {
        return;
    }
    $.ajax({
        type: "GET",
        url: '/thmz/deleteRequestById?id=' + id,
        dataType: "json",
        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
        success: function (res) {
            if (res == '401' || res == 401) {
                window.location.href = '/thmz/login/view'
                return;
            }
            if (res.code == 0) {
                successMesage(res);
                var tableId = 'tb_table';
                if (showTwoTable) {
                    tableId = 'tb_table_1';
                }
                $('#' + tableId).bootstrapTable("refresh");
            }else {
                errorMesage(res);
            }
        }
    });
}


/**
 * 临时新号表修改
 * @param index
 */
function updateRequestByIndex(index) {
    $("#requestId").val(index);
    var data = tempData[index];
    $("#classTitle").text("修改");
    $("#editDay").val(format(data.requestDay, "yyyy-MM-dd"));
    $('#ampm').selectpicker('val', data.ampm);
    $('#ampm').selectpicker('refresh');
    $('#deptNo').selectpicker('val', data.unitCode);
    $('#deptNo').selectpicker('refresh');
    $('#doctorParam').selectpicker('val', data.doctorCode);
    $('#doctorParam').selectpicker('refresh');
    $('#chargeType').selectpicker('val', data.chargeType);
    $('#chargeType').selectpicker('refresh');
    $("#totalNum").val(data.totalNum);
    $("#totalNum").val(data.leftNum);
    $("#checkFee").val(data.checkFee);
    $("#editModal").modal();
}




/**
 * 临时新号表删除
 * @param index
 */
function deleteRequestByIndex(index) {
    if (!confirm("确认要删除当前操作的号表信息吗？")) {
        return;
    }
    tempData.splice(index, 1);
    var realParams = JSON.parse('{"mzyRequests":""}');
    realParams.mzyRequests = tempData;
    initNewListCommon("/thmz/formatRequest", realParams);
}
