(function () {
    //数据   status 0 未检测  1 正常 2 异常 
    var page = {
        isScroll: false,
        init: function ($page, param) {
            //console.log(param) 传过来的参数 在param上
            //测温时间段
            $page.find('#MeasureTime').lrpickerex({
                code: 'MeasureTime',
                type: 'dataItem',
                change: function (value, text, datalist, $self) {
                    loadData($page, param);
                }
            }).lrpickerSet(0);
            //状态
            $page.find('#Status').lrpickerex({
                code: 'TemperatureMeasure',
                type: 'dataItem'
            }).lrpickerSet(1);
            //初始化
            setTimeout(function () {
                loadData($page, param);
            }, 1000);

            //选择学生
            $page.find('.timeTableList').on('tap',
                'li',
                function () {
                    var that = $(this);
                    var jsons = JSON.parse(that.attr('student'));
                    that.addClass('active');
                    $('.timeTableAlertZ').css('display', 'block');;
                    $('.timeTableAlert').find('.timeTableAlertTop').attr('student', that.attr('student')).end()
                        .find('.timeTableAlertT').html(jsons.PersonBeingMeasuredName).end()
                        .find('.timeTableAlertTxt').html('学号: ' + jsons.PersonBeingMeasured).end()
                        .addClass('active');
                    //未检测时默认为"正常"
                    if (jsons.Status !== "0") {
                        $page.find('#Status').lrpickerSet(jsons.Status);
                    }
                    $page.find('#Temperature').val(jsons.Temperature);
                    $page.find('#ProcessingResult').val(jsons.ProcessingResult);
                    $page.find('#Remark').val(jsons.Remark);
                });
            $page.find('.timeTableAlertZ').on('tap', function () {
                timeTableAlertFn()
            });
            function timeTableAlertFn() {
                $('.timeTableAlertZ').css('display', 'none');
                $('.timeTableList li.active').removeClass('active');
                $('.timeTableAlert').removeClass('active');
            }

            //确定
            $page.find(".timeTableBtn").on('tap',
                function () {
                    // 获取表单数据
                    if (!$page.find('.lr-form-container').lrformValid()) {
                        return false;
                    }
                    var data = JSON.parse($(this).siblings('.timeTableAlertTop').attr('student'));
                    data.Status = $page.find('#Status').lrpickerGet();
                    data.Temperature = $page.find('#Temperature').val();
                    data.ProcessingResult = $page.find('#ProcessingResult').val();
                    data.Remark = $page.find('#Remark').val();
                    data.MeasureTime = $page.find('#MeasureTime').lrpickerGet();
                    learun.layer.confirm('是否确认提交测温？',
                        function (_index) {
                            if (_index === '1') {
                                learun.layer.loading(true, '正在提交');
                                learun.httppost(
                                    config.webapi + '/Learun/EducationalAdministration/Thermography/save',
                                    {
                                        keyValue: data.ID,
                                        strEntity: JSON.stringify(data)
                                    },
                                    (data) => {
                                        learun.layer.loading(false);
                                        if (data) {
                                            learun.layer.toast("提交成功");
                                            timeTableAlertFn();
                                            loadData($page, param);
                                        }
                                    });
                            }
                        });
                });

        }
    };

    function loadData($page, param) {
        var _postParam = {
            queryJson: JSON.stringify({
                MeasurerID: learun.storage.get('userinfo').baseinfo.account,
                MeasureTime: $page.find('#MeasureTime').lrpickerGet()
            }
            )
        };
        learun.httpget(config.webapi + "/Learun/EducationalAdministration/Thermography/listOfStudent", _postParam, (data) => {
            if (data) {
                studentCheckData(data, param);
            }
        });
    }
    function studentCheckData(weekData2, param) {
        var studCheckList = $('.timeTableList');
        var html = '';
        var className = '';
        if (weekData2.length == 0) {
            html = '<li>暂时没有信息</li>'
        } else {
            className = weekData2[0].ClassName;
            $.each(weekData2, function (j, k) {
                var statusName = !k.Status ? 'sStatue1' : k.Status == "0" ? 'sStatue1' : k.Status == "1" ? 'sStatue2' : 'sStatue3';
                html += '<li student=' + JSON.stringify(k) + ' class="' + statusName + '"><div>' +
                    k.PersonBeingMeasuredName + '<span class="iconfont icon-check"></span>' +
                    '</div></li>';
            });
        }
        studCheckList.html(html);
        var htmls = '<i class="iconfont icon-addressbook1"></i>测温人：' + learun.storage.get('userinfo').baseinfo.realName + ' &nbsp;&nbsp; <i class="iconfont icon-locationfill"></i>班级：' + className;
        $('#shouldArrive').html(htmls);
    }
    return page;
})();