项目随笔:判断月份先后

有三个数据录入:服务起始月,补缴开始月,补缴结束月
要求:补缴结束月必须是服务起始月前一月,补缴开始月必须先于或等于补缴结束月且不超过补缴支持月数

JS代码:


function selectSocialSecurityRepay() {
        var startMonth = $('#startMonth').textbox('getValue'); // 社保服务起始月(startMonth区别于下面的strMonth)

        if (!$.trim(startMonth)) {
            $.messager.alert('提示信息', '请录入社保服务起始月!', 'info');
        } else {
            if(${socialSecurityRepayMonth==0}){
                $.messager.alert('提示信息', '不支持补缴!', 'info');
            }else {
                var beginMonth = $('#beginMonth').textbox('getValue'); // 补缴起始月
                var endMonth = $('#endMonth').textbox('getValue'); // 补缴结束月
                if (!$.trim(beginMonth)||!$.trim(endMonth)) {
                    $.messager.alert('提示信息', '请录入补缴起始结束月!', 'info');
                }else {

                    var arr = startMonth.split("-");
                    var startYear = parseInt(arr[0]);// 社保服务起始年
                    var strMonth = parseInt(arr[1]);// 社保服务起始月 (strMonth区别于上面的startMonth)

                    var arr2 = beginMonth.split("-");
                    var beginYear = parseInt(arr2[0]);// 补缴起始年
                    var bgMonth = parseInt(arr2[1]);// 补缴起始月(bgMonth区别于beginMonth)

                    var arr3 = endMonth.split("-");
                    var endYear = parseInt(arr3[0]);//补缴结束年
                    var edMonth = parseInt(arr3[1]);//补缴结束月(edMonth区别于endMonth)

                    var socialSecurityRepayMonth = ${socialSecurityRepayMonth};//补缴支持月数

                    //1.判断补缴结束月是否是社保服务起始月前一月
                    if (strMonth==1) {
                        //社保服务起始月一月
                        if (edMonth==12&&startYear>endYear) {
                            var result = startYear-endYear;
                            if (result == 1) {
                                //2.判断补缴起始月是否小于等于补缴结束月
                                if (beginYear<=endYear){
                                    if (beginYear==endYear) {
                                        if (bgMonth<=edMonth){
                                            //3.判断支持补缴几个月
                                            var resultMonth2 = edMonth-bgMonth;
                                            if (socialSecurityRepayMonth>resultMonth2){
                                                //todo 4.
                                                //处理补缴月份(补缴开始结束为同一年)
                                                var repayMonth =beginMonth;
                                                if (resultMonth2!=0){
                                                    for (var i=0;i<resultMonth2;i++)
                                                    {
                                                        var month = bgMonth + i + 1;
                                                        repayMonth+=","+beginYear+"-"+month;
                                                    }
                                                }
                                                var url = '${ctx}/user/employeeSocialSecurityRepay/select/${employeeId}/' + startMonth +'/'+repayMonth+'/'+beginMonth+'/'+endMonth;

                                                $('<div></div>').window({
                                                    id: 'selectSocialSecurityRepayWindow',
                                                    title: '查看社保',
                                                    width: document.documentElement.clientWidth - 100,
                                                    height: document.documentElement.clientHeight - 100,
                                                    minimizable: false,
                                                    maximizable: false,
                                                    collapsible: false,
                                                    content: '<iframe src="' + url + '" width="100%" height="100%" scrolling="no" frameborder="no"></iframe>',
                                                    modal: true,
                                                    onClose: function () {
                                                        $('#dg').datagrid('reload');
                                                        $(this).window('destroy');
                                                    }
                                                });

                                            }else {
                                                $.messager.alert('提示信息', '仅支持补缴'+socialSecurityRepayMonth+'个月!', 'info');
                                            }
                                        }else {
                                            $.messager.alert('提示信息', '补缴起始月必须先于或等于补缴结束月!', 'info');
                                        }
                                    }else {
                                        //3.判断支持补缴几个月
                                        var resultYear2 = endYear-beginYear;
                                        //目前最多支持补缴月数不会超过1年,所以resultYear2==1即可
                                        if (resultYear2==1){
                                            var resultMonth2 = 12-bgMonth+edMonth;
                                            if (socialSecurityRepayMonth>resultMonth2){
                                                //todo 4.
                                                //处理补缴月份(补缴开始结束不是同一年)
                                                var repayMonth =beginMonth;
                                                for (var i=0;i<resultMonth2;i++)
                                                {
                                                    var month = bgMonth + i + 1;
                                                    if (month<=12){
                                                        repayMonth+=","+beginYear+"-"+month;
                                                    }else {
                                                        var month2 = month-12;
                                                        repayMonth+=","+endYear+"-"+month2;
                                                    }
                                                }

                                                var url = '${ctx}/user/employeeSocialSecurityRepay/select/${employeeId}/' + startMonth +'/'+repayMonth+'/'+beginMonth+'/'+endMonth;

                                                $('<div></div>').window({
                                                    id: 'selectSocialSecurityRepayWindow',
                                                    title: '查看社保',
                                                    width: document.documentElement.clientWidth - 100,
                                                    height: document.documentElement.clientHeight - 100,
                                                    minimizable: false,
                                                    maximizable: false,
                                                    collapsible: false,
                                                    content: '<iframe src="' + url + '" width="100%" height="100%" scrolling="no" frameborder="no"></iframe>',
                                                    modal: true,
                                                    onClose: function () {
                                                        $('#dg').datagrid('reload');
                                                        $(this).window('destroy');
                                                    }
                                                });

                                            }else {
                                                $.messager.alert('提示信息', '仅支持补缴'+socialSecurityRepayMonth+'个月!', 'info');
                                            }
                                        }else {
                                            $.messager.alert('提示信息', '仅支持补缴'+socialSecurityRepayMonth+'个月!', 'info');
                                        }
                                    }
                                }else {
                                    $.messager.alert('提示信息', '补缴起始月必须先于或等于补缴结束月!', 'info');
                                }
                            }else {
                                $.messager.alert('提示信息', '补缴结束月必须为社保服务起始月前一月!', 'info');
                            }
                        }else {
                            $.messager.alert('提示信息', '补缴结束月必须为社保服务起始月前一月!', 'info');
                        }
                    }else {
                        if (startYear==endYear&&strMonth>edMonth) {
                            var resultMonth = strMonth-edMonth;
                            if (resultMonth == 1) {
                                //2.判断补缴起始月是否小于等于补缴结束月
                                if (beginYear<=endYear){
                                    if (beginYear==endYear) {
                                        if (bgMonth<=edMonth){
                                            //3.判断支持补缴几个月
                                            var resultMonth2 = edMonth-bgMonth;
                                            if (socialSecurityRepayMonth>resultMonth2){
                                                //todo 4.
                                                //处理补缴月份(补缴开始结束为同一年)
                                                var repayMonth =beginMonth;
                                                if (resultMonth2!=0){
                                                    for (var i=0;i<resultMonth2;i++)
                                                    {
                                                        var month = bgMonth + i + 1;
                                                        repayMonth+=","+beginYear+"-"+month;
                                                    }
                                                }
                                                var url = '${ctx}/user/employeeSocialSecurityRepay/select/${employeeId}/' + startMonth +'/'+repayMonth+'/'+beginMonth+'/'+endMonth;

                                                $('<div></div>').window({
                                                    id: 'selectSocialSecurityRepayWindow',
                                                    title: '查看社保',
                                                    width: document.documentElement.clientWidth - 100,
                                                    height: document.documentElement.clientHeight - 100,
                                                    minimizable: false,
                                                    maximizable: false,
                                                    collapsible: false,
                                                    content: '<iframe src="' + url + '" width="100%" height="100%" scrolling="no" frameborder="no"></iframe>',
                                                    modal: true,
                                                    onClose: function () {
                                                        $('#dg').datagrid('reload');
                                                        $(this).window('destroy');
                                                    }
                                                });

                                            }else {
                                                $.messager.alert('提示信息', '仅支持补缴'+socialSecurityRepayMonth+'个月!', 'info');
                                            }
                                        }else {
                                            $.messager.alert('提示信息', '补缴起始月必须先于或等于补缴结束月!', 'info');
                                        }
                                    }else {
                                        //3.判断支持补缴几个月
                                        var resultYear2 = endYear-beginYear;
                                        if (resultYear2==1){
                                            var resultMonth2 = 12-bgMonth+edMonth;
                                            if (socialSecurityRepayMonth>resultMonth2){
                                                //todo 4.
                                                //处理补缴月份(补缴开始结束不是同一年)
                                                var repayMonth =beginMonth;
                                                for (var i=0;i<resultMonth2;i++)
                                                {
                                                    var month = bgMonth + i + 1;
                                                    if (month<=12){
                                                        repayMonth+=","+beginYear+"-"+month;
                                                    }else {
                                                        var month2 = month-12;
                                                        repayMonth+=","+endYear+"-"+month2;
                                                    }
                                                }

                                                var url = '${ctx}/user/employeeSocialSecurityRepay/select/${employeeId}/' + startMonth +'/'+repayMonth+'/'+beginMonth+'/'+endMonth;

                                                $('<div></div>').window({
                                                    id: 'selectSocialSecurityRepayWindow',
                                                    title: '查看社保',
                                                    width: document.documentElement.clientWidth - 100,
                                                    height: document.documentElement.clientHeight - 100,
                                                    minimizable: false,
                                                    maximizable: false,
                                                    collapsible: false,
                                                    content: '<iframe src="' + url + '" width="100%" height="100%" scrolling="no" frameborder="no"></iframe>',
                                                    modal: true,
                                                    onClose: function () {
                                                        $('#dg').datagrid('reload');
                                                        $(this).window('destroy');
                                                    }
                                                });

                                            }else {
                                                $.messager.alert('提示信息', '仅支持补缴'+socialSecurityRepayMonth+'个月!', 'info');
                                            }
                                        }else {
                                            $.messager.alert('提示信息', '仅支持补缴'+socialSecurityRepayMonth+'个月!', 'info');
                                        }
                                    }
                                }else {
                                    $.messager.alert('提示信息', '补缴起始月必须先于或等于补缴结束月!', 'info');
                                }
                            }else {
                                $.messager.alert('提示信息', '补缴结束月必须为社保服务起始月前一月!', 'info');
                            }
                        }else {
                            $.messager.alert('提示信息', '补缴结束月必须为社保服务起始月前一月!', 'info');
                        }
                    }
                }
            }
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值