Easyui datagrid 开始时间不能大于结束时间

  <th><span>检查时间:</span></th>
                 <td>
                        <input class="easyui-datetimebox" name="condition.bb" id="bb"
                               data-options="editable:false" style="width:155px" value="@stime"><input class="easyui-datetimebox" name="condition.ee" id="ee"
                               data-options="editable:false" style="width:155px" value="@etime">
                    </td>
    $(function () {
         formatDateTimeBox('bb', 'ee', true);//初始化日期格式
         formatDateTimeBox('ee', 'bb', false);
    });
    function formatDateTimeBox(sId, eId, flag) {
        $("#search_form_cm #" + sId).datetimebox({
            formatter: function (date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                var h = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                var s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                sTime = y + "-" + (m < 10 ? ("0" + m) : m) + "-" + (d < 10 ? ("0" + d) : d) + " " + h + ":" + minute + ":" + s;
                sTime = sTime.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", "");
                eTime = $("#search_form_cm #" + eId).datetimebox("getValue").replaceAll("-", "").replaceAll(" ", "").replaceAll(":", "");

                if (flag == true) {
                    if (parseInt(sTime) > parseInt(eTime)) {
                        $.messager.alert("提示", "开始时间不能大于结束时间!");
                        return "";
                    } else {
                        return y + "-" + (m < 10 ? ("0" + m) : m) + "-" + (d < 10 ? ("0" + d) : d) + " " + h + ":" + minute + ":" + s;
                    }
                } else {
                    if (parseInt(sTime) < parseInt(eTime)) {
                        $.messager.alert("提示", "开始时间不能大于结束时间!");
                        return "";
                    } else {
                        return y + "-" + (m < 10 ? ("0" + m) : m) + "-" + (d < 10 ? ("0" + d) : d) + " " + h + ":" + minute + ":" + s;
                    }
                }
            },
            onSelect: function (date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                var h = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                var s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                if (sId == 'ee') {
                    var canyuEndDate = y + "-" + (m < 10 ? ("0" + m) : m) + "-" + (d < 10 ? ("0" + d) : d);
                    //后去endDate
                    var endDate = $("#search_form_cm #bb").datebox("getValue");
                    //endDate = endDate.substr(0, 10);
                    // if (dateNumber(canyuEndDate) >= dateNumber(endDate) && dateNumber(endDate) != 0) {
                    var canyuEndDateNum = dateNumber(canyuEndDate);
                    var endDateStr = getNextDate(endDate, 0);
                    var endDateNum = dateNumber(endDateStr);
                    if (dateNumber(endDate) != 0 && (canyuEndDateNum != endDateNum)) {
                        //$.messager.alert("提示", "两数相等");
                        $("#search_form_cm #ee").datebox("setValue", "")
                        return true;
                    }
                }

                return y + "-" + (m < 10 ? ("0" + m) : m) + "-" + (d < 10 ? ("0" + d) : d) + " " + h + ":" + minute + ":" + s;
            }
        });
    }
    //日期转换
    function dateNumber(param) {
        param = param.replace(/-/g, '');
        param = Number(param);
        return param;
    }

    // date 代表指定的日期,格式:2018-09-27
    // day 传-1表始前一天,传1表始后一天
    // JS获取指定日期的前一天,后一天
    function getNextDate(date, day) {
        var dd = new Date(date);
        dd.setDate(dd.getDate() + day);
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
        var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
        return y + "-" + m + "-" + d;
    };

 

posted @ 2021-12-08 10:08  Valoris  阅读(121)  评论(0编辑  收藏  举报