1 line
6.4 KiB
JavaScript
1 line
6.4 KiB
JavaScript
|
"use strict";define(["avalon","css!./doui.datepicker.min"],function(av){function getThisYearMonth(){var a=new Date;return[a.getFullYear(),a.getMonth()+1]}function getNumsOfYearMonth(a,e){return new Date(a,e,0).getDate()}function getDayByYearMonth(a,e,t){return t=t||1,new Date(a,e-1,t).getDay()}function numberFormat(a,e){if(a+="",a.length===e)return a;for(;a.length<e;)a="0"+a;return a}var parentVm=null;return av.component("do:datepicker",{$replace:!0,$template:'<div class="do-ui-datepicker do-fn-noselect"><input class="date-input" type="text" ms-duplex="dateVal" ms-on-focus="$focus" ms-click="$cancelBubble" ms-attr-disabled="disabled" ms-css-border-width="border" ms-css-border-radius="radius"><div class="calendar" ms-if="showCalendar" ms-click="$cancelBubble"><div class="calendar-hd">请选择日期</div><div class="calendar-contrl"><a href="javascript:;" ms-click="$turn(1, -1)" class="prev-year">{{btns.prevYear}}</a><a href="javascript:;" ms-click="$turn(0, -1)" class="prev-month">{{btns.prevMonth}}</a><a href="javascript:;" ms-click="$turn(0, 1)" class="next-month">{{btns.nextMonth}}</a><a href="javascript:;" ms-click="$turn(1, 1)" class="next-year">{{btns.nextYear}}</a><span class="date-display">{{calendar.year + \'-\' + calendar.month}}</span></div><ul class="calendar-table"><li class="tr tr-hd"><span class="td">日</span><span class="td">一</span><span class="td">二</span><span class="td">三</span><span class="td">四</span><span class="td">五</span><span class="td">六</span></li><li class="tr list do-fn-cl"><span class="td" ms-class="weeken:el.weeken" ms-class-1="{{el.disable ? \'disabled\' : \'do-st-hand\'}}" ms-class-2="selected:el.selected" ms-repeat="calendar.list" ms-click="$getDate(el.disable, el.day)">{{el.day}}</span></li></ul><div class="time-contrl" ms-if="showTime"><label class="hours"><input type="text" ms-duplex-time="calendar.hour" data-format="hour"></label><label class="minutes"><input type="text" ms-duplex-time="calendar.minute" data-format="minute"></label><label class="seconds"><input type="text" ms-duplex-time="calendar.second" data-format="second"></label><a href="javascript:;" class="now" ms-click="$now">现在</a></div><span class="calendar-tips" ms-if="tips">{{tips}}</span></div></div>',$construct:function(a,e,t){var n=av.mix(e,t),l=n.duplex.slice(0,n.duplex.indexOf("."));parentVm=av.vmodels[l],n.duplex=n.duplex.slice(n.duplex.indexOf(".")+1);var r=new Function("v","return v."+n.duplex)(parentVm);return n.showTime||n.format||(n.format="Y-m-d"),void 0===r&&(n.minDate?(r=n.minDate,n.format):a.maxDate&&(r=n.maxDate,n.format)),a.dateVal=r&&av.filters.date(r,n.format),a.calendar={list:[],year:av.filters.date(a.dateVal,"Y"),month:av.filters.date(a.dateVal,"m"),day:av.filters.date(a.dateVal,"d")||0,hour:av.filters.date(a.dateVal,"H")||0,minute:av.filters.date(a.dateVal,"i")||0,second:av.filters.date(a.dateVal,"s")||0,minYear:n.minDate&&av.filters.date(n.minDate,"Y")>>0,minMonth:n.minDate&&av.filters.date(n.minDate,"m")>>0,minDay:n.minDate&&av.filters.date(n.minDate,"d")>>0||1,maxYear:n.maxDate&&av.filters.date(n.maxDate,"Y")>>0,maxMonth:n.maxDate&&av.filters.date(n.maxDate,"m")>>0,maxDay:n.maxDate&&av.filters.date(n.maxDate,"d")>>0},delete n.minDate,delete n.maxDate,av.mix(a,n)},$init:function(vm,ele){function getCalendar(){var a=vm.calendar.year>>0,e=vm.calendar.month>>0,t=getNumsOfYearMonth(a,e),n=-getDayByYearMonth(a,e)+1,l=isLimited(a,e);vm.calendar.list.clear();for(var r=n;t>=r;r++){var s={weeken:!1,day:"",selected:!1,disable:!0};if(r>0){var d=getDayByYearMonth(a,e,r);s={weeken:0==d||6==d,day:r,selected:isSelected(r),disable:disabledDay(r,l)}}vm.calendar.list.push(s)}}function isLimited(a,e){var t={Y:vm.calendar.minYear,M:vm.calendar.minMonth,mY:vm.calendar.maxYear,mM:vm.calendar.maxMonth},n="";if(!t.Y&&!t.mY||!t.M&&!t.mM)return!1;if(!a)return!1;if(t.Y&&a<t.Y||t.mY&&a>t.mY)return!0;if(e){if(a===t.Y){if(t.M&&e<t.M)return!0;e==t.M&&(n+="-")}if(a===t.mY){if(t.mM&&e>t.mM)return!0;e==t.mM&&(n+="+")}}return n}function disabledDay(a,e){var t=vm.calendar.minDay,n=vm.calendar.maxDay;return"-"===e?
|