(function () {
    //数据   status 1 正常  2 早退 3 旷课 4 病假 5 迟到 6 事假 
    var page = {
        isScroll: false,
        init: function ($page, param) {
            //console.log(param) 传过来的参数 在param上
            //初始化
            console.log(param);
            loadData(param);
            $('.tSec3Time').html('<span>' + param.LessonDate + '</span>第' + param.LessonTime.substring(1) + '节');
            $('.tSec4T').html('<div>' +
                param.LessonName +
                '</div> <div>' +
                param.ClassroomName +
                ' ' +
                '</div>')


            $page.find('.timeTableList').on('tap',
                'li',
                function () {
                    var that = $(this)
                    if (that.hasClass('active')) {
                        that.removeClass('active')
                    } else {
                        that.addClass('active')
                    }
                });

            //选择考勤状态
            $page.find('#status').lrpickerex({
                placeholder: '选择考勤状态',
                type: 'dataItem',
                code: 'ktkqlx'
            });
            $page.find(".timeTableBtn").on('tap',
                function () {

                    var status = $("#status").lrpickerGet();
                    console.log(status);
                    var rowData = new Array();
                    var num = 0;

                    $(".timeTableList li").each(function () {
                        if ($(this).hasClass("active")) {
                            rowData.push(JSON.parse($(this).attr("student")));
                            num++;
                        }
                    })
                    var jsonObj = JSON.parse(JSON.stringify(rowData));
                    console.log(JSON.stringify(jsonObj));
                    if (num > 0) {
                        if (status) {
                            learun.layer.confirm('是否确认提交考勤？',
                                function (num) {
                                    learun.layer.loading(true, '正在提交');
                                    learun.httppost(
                                        config.webapi + '/Learun/EducationalAdministration/StuAttendanceLeave/apply',
                                        {
                                            kqType: status,
                                            lessonTime: param.LessonTime,
                                            lessonDate: param.LessonDate,
                                            classRoomNo: param.ClassRoomNo,
                                            dataJson: JSON.stringify(rowData)
                                        },
                                        (data) => {
                                            learun.layer.loading(false);
                                            if (data) { // 删除数据成功 
                                                loadData(param);
                                            }
                                        });

                                })
                        } else {
                            learun.layer.toast("请选择考勤状态");
                        }
                    } else {
                        learun.layer.toast("没有选中任何项");
                    }





                });

        }
    };

    function loadData(param) {
        var _postParam = {
            pagination: {
                rows: "1000",
                page: "1",
                sidx: 'ClassNo',
                sord: 'DESC'
            },
            queryJson: JSON.stringify({
                year: param.AcademicYear,
                semester: param.Semester,
                empno: param.EmpNo,
                lessonNo: param.LessonNo,
                teachClassNo: param.TeachClassNo,
                lessonTime: param.LessonTime,
                LessonSortNo: param.LessonSortNo,
            }
            )
        };
        learun.httpget(config.webapi + "/teachattendance/students", _postParam, (data) => {
            console.log(data);
            studentCheckData(data, param)
        })
    }
    function studentCheckData(weekData2, param) {
        var studCheckList = $('.timeTableList');
        var html = '';
        if (weekData2.rows.length == 0) {
            html = '<li>暂时没有信息</li>'
        } else {
            $.each(weekData2.rows, function (j, k) {
                var statusName = !k.Sort ? '' : k.Sort == "准时" ? 'sStatue1' : k.Sort == "早退" ? 'sStatue2' : k.Sort == "旷课" ? 'sStatue3' : k.Sort == "病假" ? 'sStatue4' : k.Sort == "迟到" ? 'sStatue5' : 'sStatue6';
                html += '<li student=' + JSON.stringify(k) + ' class="' + statusName + '">' +
                    '<span class="iconfont icon-check"></span>' + k.StuName +
                    '</li>';

                $('#shouldArrive span').text(weekData2.records);

            })
        }

        studCheckList.html(html)
    }
    return page;
})();