(function () {
    var today = fmtDate();
    //工资条数据
    var wagesData = "";
    var page = {
        isScroll: false,
        init: function ($page) {
            loadData();
            wagesSec1I = $page.find('.wagesSec1 i');
            wagesSec1Span = $page.find('.wagesSec1 span');
            wagesSec1 = $page.find('.wagesSec1');
            wagesSec1Span.text(today.y + ' 年 ' + today.m + ' 月').attr('year', today.y).attr('mouth', today.m);
            wagesSec1.find('.wagesSec1Txt').text(today.y + ' 年 ' + today.m + ' 月实发工资');

            var num1 = 0;
            $.each(wagesData, function (i, item) {
                if (item.year == today.y && item.month == today.m) {
                    num1++;
                    wagesAjax(item);
                }
            });
            if (num1 == 0) {
                $('.wagesSec1T').text('￥0');
                $('.wagesSec2').html("无记录");
            }


            wagesSec1I.on('tap', function () {
                var ind = wagesSec1I.index($(this));
                var year = parseInt(wagesSec1Span.attr('year'));
                var mouth = parseInt(wagesSec1Span.attr('mouth'));
                var y = 0, m = 0
                if (ind == 0) {
                    if (mouth == 1) { y = year - 1, m = 12 } else { y = year, m = mouth - 1 };
                } else {
                    if (mouth == 12) { y = year + 1, m = 1 } else { y = year, m = mouth + 1 };
                }
                wagesSec1Span.text(y + ' 年 ' + m + ' 月').attr('year', y).attr('mouth', m);
                wagesSec1.find('.wagesSec1Txt').text(y + ' 年 ' + m + ' 月实发工资');
                console.log(y + "/" + m);
                if (wagesData.length > 0) {

                    var num = 0;
                    $.each(wagesData, function (i, item) {
                        if (item.year == y && item.month == m) {
                            num++;
                            wagesAjax(item);
                        }
                    });
                    if (num == 0) {
                        $('.wagesSec1T').text('￥0');
                        $('.wagesSec2').html("无记录");
                    }
                }
            })
        },
    };
    function loadData() {
        learun.httpgetnosy(config.webapi + 'Learun/EducationalAdministration/SalarySheet/list', "", (data) => {
            if (data) {
                console.log(data);
                wagesData = data;
            }
        });
    }
    function wagesAjax(item) {
        console.log(item);
        $('.wagesSec1T').text('￥' + item.Fsalary)
        var html = '<div class="wagesSec2T">应发金额 <span></span></div>' +
            '<ul class="wagesSec2List">' +
            '<li>基本工资<span>￥' + item.BaseSalary + '</span></li>' +
            '<li>职位补贴<span>￥' + item.JobSubsidies + '</span></li>' +
            '<li>绩效工资<span>￥' + item.PerformanceBonus + '</span></li>' +
            '<li>手机费<span>￥' + item.MobilePhoneFee + '</span></li>' +
            '<li>交通费<span>￥' + item.TransportationFee + '</span></li>' +
            '<li>全勤奖<span>￥' + item.AttendanceBonus + '</span></li>' +
            '<li>应发金额<span>￥' + item.SSalary + '</span></li>' +
            '</ul>' +
            '<div class="wagesSec2T">扣款金额 <span></span></div>' +
            '<ul class="wagesSec2List">' +
            '<li>养老金保险<span>￥' + item.PensionInsurance + '</span></li>' +
            '<li>个人所得税<span>￥' + item.PersonalIncomeTax + '</span></li>' +
            '<li>事假<span>￥' + item.PersonalLeave + '</span></li>' +
            '<li>迟到<span>￥' + item.Late + '</span></li>' +
            '<li>病假<span>￥' + item.Sick + '</span></li>' +
            '<li>个人所得税<span>￥' + item.PersonalIncomeTax + '</span></li>' +
            '</ul>';
        $('.wagesSec2').html(html);
    }
    //获取年月日
    function fmtDate(obj) {
        var date = new Date();
        var y = 1900 + date.getYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        return { y: y, m: m, d: d }
    }

    return page;
})();