(function(o){"use strict";"function"==typeof define&&define.amd?define(["jquery"],o):o(jQuery)})(function(o){var t,i=[31,29,31,30,31,30,31,31,30,31,30,31],e=[31,28,31,30,31,30,31,31,30,31,30,31],n=new Date,p=n.getFullYear(),l=n.getMonth(),a=n.getDate(),u=n.getHours(),v=n.getMinutes(),s=null,r={type:"date",background:"#494a4a"},c=!1;o.extend(o.fn,{datetime:function(d){return this.each(function(){function h(){var t=o('
< >
    选择时间关闭今天
    ');o("body").append(t),c=!0}function m(o,t){var i=new Date(t,o,1);return i.getDay()}function f(o,t){var n=t%4,p=t%100,l=t%400;return 0==n&&0!=p||0==l?i[o]:e[o]}function g(){var t="",i=f(l,p);a>i&&(a=i),console.log(a);for(var e,n=m(l,p),u=0;u";for(u=1;u<=i;u++)e=u==a?"class = 'curDay'":"",t+="
  • "+u+"
  • ";o("#dayDat").html(t)}function y(){for(var t="",i="",e=0;e<24;e++)e<10&&(e="0"+e),t+=e==u?"
  • "+e+"
  • ":"
  • "+e+"
  • ";for(e=0;e<60;e++)e<10&&(e="0"+e),i+=e==v?"
  • "+e+"
  • ":"
  • "+e+"
  • ";o("#selHour ol").html(t),o("#selMinute ol").html(i)}function T(){o(".dateTimeWrap").show();var i=t.type;if("date"!=i){y(),o(".datePart").hide().siblings(".timePart").show();var e=o("#selHour .cur");o("#selHour ol").scrollTop(e.offset().top-o("#selHour ol").offset().top+o("#selHour ol").scrollTop()-e.outerHeight());var n=o("#selMinute .cur");o("#selMinute ol").scrollTop(n.offset().top-o("#selMinute ol").offset().top+o("#selMinute ol").scrollTop()-n.outerHeight())}"time"!=i&&(g(),o(".datePart").show().siblings(".timePart").hide(),o("#yearSelect").val(p),o("#monthSelect").val(l)),"datetime"==i?o(".selTime").show():o(".selTime").hide()}function M(){var o=t.type,i=t.value,e=!0;return i&&i.length>0&&("datetime"==o&&(5!=i.length||i[0]>2050||i[0]<1920||i[1]>12||i[1]<1||i[2]>31||i[2]<1||i[3]>23||i[3]<1||i[4]>59||i[4]<1)&&(e=!1),"date"==o&&(3!=i.length||i[0]>2050||i[0]<1920||i[1]>12||i[1]<1||i[2]>31||i[2]<1)&&(e=!1),"time"==o&&(2!=i.length||i[0]>23||i[0]<1||i[1]>59||i[1]<1)&&(e=!1)),e}function P(){var i,e,n=t.type;(i="date"==n?p+"-"+(parseInt(l)+1)+"-"+a:"time"==n?u+":"+v:p+"-"+(parseInt(l)+1)+"-"+a+" "+u+":"+v,s.val(i),o(".dateTimeWrap").hide(),t.success&&"function"==typeof t.success)&&(e="date"==n?[p,parseInt(l)+1,parseInt(a)]:"time"==n?[u,v]:[p,parseInt(l)+1,parseInt(a),u,v],t.success(e))}var S=o(this);t=o.extend(!0,{},r,d),c||h(),o("#selcurday,#close,#dayDat,.changeMonth span,.selTime").unbind("click"),o("#yearSelect,#monthSelect").unbind("change"),o("#yearSelect,#monthSelect").change(function(){l=o("#monthSelect").val(),p=o("#yearSelect").val(),g()}),o(".changeMonth span").click(function(){"pre"==this.id?(l-=1,-1==l&&(l=11,p-=1)):(l+=1,12==l&&(l=0,p+=1)),g(),o("#yearSelect").val(p),o("#monthSelect").val(l)}),o("#selcurday").click(function(){var i=new Date;p=i.getFullYear(),l=i.getMonth(),a=i.getDate(),g(),o("#yearSelect").val(p),o("#monthSelect").val(l),"datetime"!=t.type?P():o(".datePart").hide().siblings(".timePart").show()}),o("#close").click(function(){o(".dateTimeWrap").hide()}),o("#dayDat").on("click","li",function(){a=o(this).html(),"datetime"!=t.type?P():o(".datePart").hide().siblings(".timePart").show()}),o(".selTime").click(function(){"选择时间"==o(this).html()?o(".datePart").hide().siblings(".timePart").show():o(".datePart").show().siblings(".timePart").hide()}),o(".timePart ol,.timeFooter #ensure,.timeFooter #curTime").unbind("click"),o(".timePart ol").on("click","li",function(){o(this).addClass("cur").siblings("li").removeClass("cur");var t=o(this).parent();t.animate({scrollTop:o(this).offset().top-t.offset().top+t.scrollTop()-o(this).outerHeight()},100)}),o(".timeFooter #ensure").click(function(){u=o("#selHour ol .cur").html(),v=o("#selMinute ol .cur").html(),P(),o(".dateTimeWrap").hide()}),o(".timeFooter #curTime").click(function(){u=n.getHours(),v=n.getMinutes(),parseInt(u)<10&&(u="0"+u),parseInt(v)<10&&(v="0"+v),y(u,v),P()}),S.click(function(){if(t=o.extend(!0,{},r,d),!M())return alert("参数错误"),!1;var i=this.value;if(i){i=i.replace(/-/g,"/");var e=new Date(i)}"date"==t.type?this.value?(l=e.getMonth(),p=e.getFullYear(),a=e.getDate()):(l=t.value[1]-1,p=t.value[0],a=t.value[2]):"time"==t.type?this.value?(u=this.value.split(":")[0],v=this.value.split(":")[1]):(v=t.value[1],u=t.value[0]):this.value?(l=e.getMonth(),p=e.getFullYear(),a=e.getDate(),u=e.getHours(),v=e.getMinutes()):(l=t.value[1]-1,p=t.value[0],a=t.value[2],v=t.value[4],u=t.value[3]),s=o(this),T();var n=S.offset().left,c=S.offset().top+S.outerHeight()+4;o(".dateTimeWrap").css({background:t.background,top:c,left:n})})}),this}})});