<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('发送质控消息')" />
    <th:block th:include="mrqc/include :: select2-min-css"/>
    <link rel="stylesheet" th:href="@{/mrqc/css/select2-bootstrap.css}"/>
</head>
<style>
</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sdisStruct-add">
        <div class="form-group col-xs-12 col-sm-6 col-md-6 col-lg-12">
            <label class="col-xs-2 col-sm-7 col-md-7 col-lg-2 control-label" style="padding-top: 8px">目标:</label>
            <div class="col-xs-10 col-sm-5 col-md-5 col-lg-10">
                <input type="hidden" class="form-control" name="mainDoctor" id="mainDoctor" th:value="${doctorName}"/>
                <select id="mainDoctorSel" class="form-control select2-multiple" multiple th:value="${doctorName}">
                </select>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<th:block th:include="mrqc/include :: select2-js"/>
<th:block th:include="mrqc/include :: bootstrap-suggest-min-js"/>

<script th:inline="javascript">
    var prefixApi = ctx + "api";
    var prefixKqyy = ctx + "kqyyApi";
    var allDoctor = JSON.parse('[[${allDoctor}]]');
    var doctorName = [[${doctorName}]];
    var recordId = [[${recordId}]];
    var loginName = [[${loginName}]];
    var mainDoctors = [[${mainDoctors}]];

</script>
<script th:inline="javascript">
	// select2 开启 tags 输入中文显示不全的BUG，不动源码的修复方式、参考https://blog.csdn.net/jx520/article/details/84936454
	$(document).on('keyup', '.select2-selection--multiple .select2-search__field', function(event){
	    var $this = $(this);
	    $this.css('width', '20em');// 写个大点的值就行了。不用计算。
	});

    $(function() {
        initDoctor(allDoctor);
    });

    function initDoctor(doctors) {

        $("#mainDoctorSel").html("");
        var html = "";
        // if(mainDoctors != null){
        // 	for (var i=0;i< mainDoctors.split(",").length;i++){
        //     	var mainDoctor = mainDoctors.split(",")[i];
        //         html += "<option value='" + mainDoctor + "' selected>" + mainDoctor + "</option>"
        //
        //     }
        // }

        for (var key in doctors) {
            //多选框默认选中主治医师
            /*if(loginName != null && loginName == key){
                html += "<option value='" + mainDoctors + "' selected>" + mainDoctors + "</option>"
                continue;
            }*/
            html += "<option value='" + key + "'>" + doctors[key] + "</option>"
        }

        $("#mainDoctorSel").html(html);
    }

    function submitHandler() {
        debugger
        var args = new Map();
        var doctors = new Array();
        if(doctorName != null){
           args["sender"] = doctorName;
        }else{
            $("#mainDoctorSel option:selected").each(function () {
                if ($(this).val() != null && $(this).val() != '')
                    doctors.push($(this).val())
            });
            args["sender"] = doctors.join(',');
        }
        args["recordIds"] = recordId;
        $.post(prefixKqyy + '/sendMsgToIIH', args, function (result) {
            var index = parent.layer.getFrameIndex(window.name);
            $.post(prefixApi + '/remindMQ', args, function (resultQ) {
                parent.layer.close(index);
                parent.layer.msg(result.msg);
            });
        });

    }
</script>
</body>
</html>
