"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
请选择日期
{{tips}}
',$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&&at.mY)return!0;if(e){if(a===t.Y){if(t.M&&et.mM)return!0;e==t.mM&&(n+="+")}}return n}function disabledDay(a,e){var t=vm.calendar.minDay,n=vm.calendar.maxDay;return"-"===e?t>a:"+"===e?n&&a>n:"-+"===e?t>a||n&&a>n:e}function isSelected(a){var e=vm.calendar.year>>0,t=vm.calendar.month>>0;return!(lastDate.year!==e||lastDate.month!==t||lastDate.day!==a)}function changeStyle(a){vm.calendar.list.forEach(function(e){e.selected=e.day!=a?!1:!0})}function updateTime(){var a=vm.calendar,e=a.year,t=a.month,n=a.day,l=a.hour,r=a.minute,s=a.second,d=e+"-"+t+"-"+n;vm.showTime&&(d+=" "+l+":"+r+":"+s),lastDate={year:e>>0,month:t>>0,day:n>>0},vm.dateVal=av.filters.date(d,vm.format)}var lastDate={year:vm.calendar.year>>0,month:vm.calendar.month>>0,day:vm.calendar.day>>0},timer;getCalendar(),vm.$turn=function(a,e){var t=vm.calendar.year>>0,n=vm.calendar.month>>0;return 1===a?t+=e:(n+=e,1>n&&(n=12,t--),n>12&&(n=1,t++)),isLimited(t,n)===!0?void(vm.tips="日期超出限制"):(vm.calendar.year=t,void(vm.calendar.month=numberFormat(n,2)))},vm.$getDate=function(a,e){a||(vm.calendar.day=e,changeStyle(e),updateTime(),vm.showCalendar=!1)},vm.$focus=function(){vm.showCalendar=!0},vm.$now=function(){var a=av.filters.date(null,"Y")>>0,e=av.filters.date(null,"m")>>0,t=av.filters.date(null,"d")>>0,n=isLimited(a,e),l=disabledDay(t,n);return l?void(vm.tips="今天超出了限制日期"):(vm.calendar.year=a,vm.calendar.month=e,vm.calendar.day=t,vm.calendar.hour=av.filters.date(null,"H"),vm.calendar.minute=av.filters.date(null,"i"),vm.calendar.second=av.filters.date(null,"s"),changeStyle(t),updateTime(),void(vm.showCalendar=!1))},vm.$watch("calendar.year",function(){getCalendar()}),vm.$watch("calendar.month",function(){getCalendar()}),vm.$watch("calendar.hour",function(a){vm.calendar.hour=a,updateTime()}),vm.$watch("calendar.minute",function(a){vm.calendar.minute=a,updateTime()}),vm.$watch("calendar.second",function(a){vm.calendar.second=a,updateTime()}),vm.$watch("showCalendar",function(v){!v&&vm.duplex&&(eval("parentVm."+vm.duplex+' = "'+vm.dateVal+'"'),vm.callback&&vm.callback(vm.dateVal))}),vm.$watch("tips",function(a){a&&(clearTimeout(timer),timer=setTimeout(function(){vm.tips=""},1500))}),document.addEventListener("click",function(){vm.showCalendar=!1})},showTime:!1,showCalendar:!1,disabled:!1,exclass:"",tips:"",duplex:"",format:"",dateVal:"",radius:0,border:1,btns:{prevYear:"<<",nextYear:">>",prevMonth:"<",nextMonth:">"},$focus:av.noop,$turn:av.noop,$getDate:av.noop,$now:av.noop,$cancelBubble:function(a){a.stopPropagation&&a.stopPropagation()||(a.cancelBubble=!0)},callback:null}),av});