diff --git a/src/modules/laydate.js b/src/modules/laydate.js index d6cc4067..41aaf390 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -1802,7 +1802,6 @@ // 重新选择或者第一次选择 index = 0; that.endState = false; - that.endDate = {}; } else { index = 1; that.endState = true; @@ -1860,18 +1859,22 @@ if (that.endState && that.autoCalendarModel.auto) { isChange = that.autoCalendarModel(); } - if ((isChange || that.rangeLinked && that.endState) && that.newDate(that.startDate) > that.newDate(that.endDate)) { + // 判断是否反选 + var needSwapDate = (isChange || that.rangeLinked && that.endState) && that.newDate(that.startDate) > that.newDate(that.endDate); + if (needSwapDate){ var isSameDate = that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month && that.startDate.date === that.endDate.date; - // 判断是否反选 - var startDate = that.startDate; - that.startDate = lay.extend({}, that.endDate, isSameDate ? {} : that.startTime); + var startDate; + // 如果是同一天并且出现了反选证明是时分秒出现开始时间大于结束时间的现象 + if(isSameDate){ + startDate = that.startTime; + that.startTime = that.endTime; + that.endTime = startDate; + } + // 当出现反向选择时(即“后点击”的日期比“先点击”的日期小),重新提取区间 + startDate = that.startDate; + that.startDate = lay.extend({}, that.endDate, that.startTime); options.dateTime = lay.extend({}, that.startDate); - that.endDate = lay.extend({}, startDate, isSameDate ? {} : that.endTime); - isSameDate && ( // 如果是同一天并且出现了反选证明是时分秒出现开始时间大于结束时间的现象 - startDate = that.startTime, - that.startTime = that.endTime, - that.endTime = startDate - ) + that.endDate = lay.extend({}, startDate, that.endTime); } isChange && (options.dateTime = lay.extend({}, that.startDate)); }