(function () {
    var weekChina = ["一", "二", "三", "四", "五", "六", "日"];
    var begin = '';
    var end = '';
    var multipleData = null;
    var page = {
        grid: null,
        init: function ($page) {
            begin = '';
            end = '';
            multipleData = null;
            page.grid = $page.find('#lr_EducationalAdministrationOpenLessonPlanOfElectiveStudent_list').lrpagination({
                lclass: page.lclass,
                rows: 10,                            // 每页行数 
                getData: function (param, callback) {// 获取数据 param 分页参数,callback 异步回调 
                    param.multipleData = multipleData;
                    page.loadData(param, callback, $page);
                },
                renderData: function (_index, _item, _$item) {// 渲染数据模板 
                    return page.rowRender(_index, _item, _$item, $page);
                },
                click: function (item, $item, $et) {// 列表行点击事件 
                    if ($et.hasClass('lr-btn-danger')) {
                        page.btnClick(item, $item, $page);
                    }
                    else {
                        page.rowClick(item, $item, $page);
                    }
                },
                btns: page.rowBtns
            });
        },
        lclass: 'lr-list',
        loadData: function (param, callback, $page) {// 列表加载后台数据 
            var _postParam = {
                pagination: {
                    rows: param.rows,
                    page: param.page,
                    sidx: 'LessonNo',
                    sord: 'asc'
                },
                queryJson: '{}'
            };
            //if (param.multipleData) {
            //    _postParam.queryJson = JSON.stringify(multipleData);
            //}
            if (true) {
                _postParam.queryJson = JSON.stringify({ StuNo: JSON.parse(localStorage.userinfo).baseinfo.account, StuMajorNo: JSON.parse(localStorage.userinfo).baseinfo.majorno });
            }
            learun.httpget(config.webapi + 'learun/EducationalAdministration/OpenLessonPlanOfElectiveStudent/pagelist', _postParam, (data) => {
                $page.find('.lr-badge').text('0');  
                if (data) {
                    $page.find('.lr-badge').text(data.records);
                    callback(data.rows, parseInt(data.records));
                }
                else {
                    callback([], 0);
                }
            });
        },
        rowRender: function (_index, _item, _$item, $page) {// 渲染列表行数据 
            _$item.addClass('lr-list-item lr-list-item-multi');
            _$item.append($('<p class="lr-ellipsis"><span>学年：</span></p>').dataFormatter({ value: _item.AcademicYearNo }));
            _$item.append($('<p class="lr-ellipsis"><span>学期：</span></p>').dataFormatter({ value: _item.Semester }));
            _$item.append($('<p class="lr-ellipsis"><span>课程名称：</span></p>').dataFormatter({
                value: _item.LessonNo,
                type: 'dataSource',
                code: 'LessonInfo',
                keyId: 'lessonno',
                text: 'lessonname'
            }));
            var ls = "";
            if (_item.LessonSection.indexOf(',') == -1)
                ls = "星期" + weekChina[_item.LessonSection.slice(0, 1) - 1] + "第" + _item.LessonSection.slice(1) + "节";
            else
                ls = "星期" + weekChina[_item.LessonSection.slice(0, 1) - 1] + "第" + _item.LessonSection.slice(1, 2) + "、" + _item.LessonSection.slice(4) + "节";
            _$item.append($('<p class="lr-ellipsis"><span>上课节次：</span></p>').dataFormatter({ value: ls }));
            _$item.append($('<p class="lr-ellipsis"><span>上课时间：</span></p>').dataFormatter({ value: _item.LessonTime }));
            _$item.append($('<p class="lr-ellipsis"><span>学分：</span></p>').dataFormatter({ value: _item.StudyScore }));
            _$item.append($('<p class="lr-ellipsis"><span>教师姓名：</span></p>').dataFormatter({ 
                value: _item.EmpNo,
                type: 'dataSource',
                code: 'EmpInfo',
                keyId: 'empno',
                text: 'empname' }));
            _$item.append($('<p class="lr-ellipsis"><span>教室名称：</span></p>').dataFormatter({
                value: _item.ClassRoomNo,
                type: 'dataSource',
                code: 'ClassRoomInfo',
                keyId: 'classroomno',
                text: 'classroomname'
            }));
            _$item.append($('<p class="lr-ellipsis"><span>人数上限：</span></p>').dataFormatter({ value: _item.StuNumMax }));
            _$item.append($('<p class="lr-ellipsis"><span>已报名人数：</span></p>').dataFormatter({ value: _item.StuNumOfApply }));
            var signstatustxt = "";
            if (_item.Status == 1) {
                signstatustxt = '<span class="circle bgcyellow">审核中</span>';
            } else if (_item.Status == 2) {
                signstatustxt = '<span class="circle bgcblue1">报名成功</span>';
            } else if (_item.Status == 3) {
                signstatustxt = '<span class="circle bgcpink">报名失败</span>';
            } else {
                signstatustxt = '<span class="circle bgccyan">未报名</span>';
            }
            _$item.append(signstatustxt);
            return '';
        },
        rowClick: function (item, $item, $page) {// 列表行点击触发方法 
            learun.nav.go({ path: 'EducationalAdministration/OpenLessonPlanOfElectiveStudent/form', title: '查看详情', type: 'right', param: { keyValue: item.Id } });
        },
        btnClick: function (item, $item, $page) {// 左滑按钮点击事件 
            learun.layer.confirm('确定要取消报名吗？', function (_index) {
                if (_index === '1') {
                    var _postData = {}
                    _postData.keyValue = item.Id;
                    _postData.StuNo = JSON.parse(localStorage.userinfo).baseinfo.account;
                    learun.layer.loading(true, '正在取消报名...');
                    learun.httppost(config.webapi + 'learun/EducationalAdministration/OpenLessonPlanOfElectiveStudent/Cancel', _postData, (data, info) => {
                        if (data) {// 成功 
                            learun.layer.toast(info);
                            page.grid.reload();
                        }
                        learun.layer.loading(false);
                    });
                }
            }, '数字化校园提示', ['取消', '确定']);
        },
        rowBtns: ['<a class="lr-btn-danger">取消报名</a>'] // 列表行左滑按钮 
    };
    return page;
})(); 