/** @Name : layDate 5.0.9 鏃ユ湡鏃堕棿鎺т欢 @Author: 璐ゅ績 @Site锛歨ttp://www.layui.com/laydate/ @License锛歁IT */ ; !function () { "use strict"; var isLayui = window.layui && layui.define, ready = { getPath: function () { var jsPath = document.currentScript ? document.currentScript.src : function () { var js = document.scripts , last = js.length - 1 , src; for (var i = last; i > 0; i--) { if (js[i].readyState === 'interactive') { src = js[i].src; break; } } return src || js[last].src; }(); return jsPath.substring(0, jsPath.lastIndexOf('/') + 1); }() //鑾峰彇鑺傜偣鐨剆tyle灞炴€у€ , getStyle: function (node, name) { var style = node.currentStyle ? node.currentStyle : window.getComputedStyle(node, null); return style[style.getPropertyValue ? 'getPropertyValue' : 'getAttribute'](name); } //杞藉叆CSS閰嶄欢 , link: function (href, fn, cssname) { //鏈缃矾寰勶紝鍒欎笉涓诲姩鍔犺浇css if (!laydate.path) return; var head = document.getElementsByTagName("head")[0], link = document.createElement('link'); if (typeof fn === 'string') cssname = fn; var app = (cssname || href).replace(/\.|\//g, ''); var id = 'layuicss-' + app, timeout = 0; link.rel = 'stylesheet'; link.href = laydate.path + href; link.id = id; if (!document.getElementById(id)) { head.appendChild(link); } if (typeof fn !== 'function') return; //杞css鏄惁鍔犺浇瀹屾瘯 (function poll() { if (++timeout > 8 * 1000 / 100) { return window.console && console.error('laydate.css: Invalid'); }; parseInt(ready.getStyle(document.getElementById(id), 'width')) === 1989 ? fn() : setTimeout(poll, 100); }()); } } , laydate = { v: '5.0.9' , config: {} //鍏ㄥ眬閰嶇疆椤 , index: (window.laydate && window.laydate.v) ? 100000 : 0 , path: ready.getPath //璁剧疆鍏ㄥ眬椤 , set: function (options) { var that = this; that.config = lay.extend({}, that.config, options); return that; } //涓讳綋CSS绛夊緟浜嬩欢 , ready: function (fn) { var cssname = 'laydate', ver = '' , path = (isLayui ? 'modules/laydate/' : '') + 'laydate.css?v=' + laydate.v + ver; isLayui ? layui.addcss(path, fn, cssname) : ready.link(path, fn, cssname); return this; } } //鎿嶄綔褰撳墠瀹炰緥 , thisDate = function () { var that = this; return { //鎻愮ず妗 hint: function (content) { that.hint.call(that, content); } , config: that.config }; } //瀛楃甯搁噺 , MOD_NAME = 'laydate', ELEM = '.layui-laydate', THIS = 'layui-this', SHOW = 'layui-show', HIDE = 'layui-hide', DISABLED = 'laydate-disabled', TIPS_OUT = '寮€濮嬫棩鏈熻秴鍑轰簡缁撴潫鏃ユ湡
寤鸿閲嶆柊閫夋嫨', LIMIT_YEAR = [100, 200000] , ELEM_STATIC = 'layui-laydate-static', ELEM_LIST = 'layui-laydate-list', ELEM_SELECTED = 'laydate-selected', ELEM_HINT = 'layui-laydate-hint', ELEM_PREV = 'laydate-day-prev', ELEM_NEXT = 'laydate-day-next', ELEM_FOOTER = 'layui-laydate-footer', ELEM_CONFIRM = '.laydate-btns-confirm', ELEM_TIME_TEXT = 'laydate-time-text', ELEM_TIME_BTN = '.laydate-btns-time' //缁勪欢鏋勯€犲櫒 , Class = function (options) { var that = this; that.index = ++laydate.index; that.config = lay.extend({}, that.config, laydate.config, options); laydate.ready(function () { that.init(); }); } //DOM鏌ユ壘 , lay = function (selector) { return new LAY(selector); } //DOM鏋勯€犲櫒 , LAY = function (selector) { var index = 0 , nativeDOM = typeof selector === 'object' ? [selector] : ( this.selector = selector , document.querySelectorAll(selector || null) ); for (; index < nativeDOM.length; index++) { this.push(nativeDOM[index]); } }; /* lay瀵硅薄鎿嶄綔 */ LAY.prototype = []; LAY.prototype.constructor = LAY; //鏅€氬璞℃繁搴︽墿灞 lay.extend = function () { var ai = 1, args = arguments , clone = function (target, obj) { target = target || (obj.constructor === Array ? [] : {}); for (var i in obj) { //濡傛灉鍊间负瀵硅薄锛屽垯杩涘叆閫掑綊锛岀户缁繁搴﹀悎骞 target[i] = (obj[i] && (obj[i].constructor === Object)) ? clone(target[i], obj[i]) : obj[i]; } return target; } args[0] = typeof args[0] === 'object' ? args[0] : {}; for (; ai < args.length; ai++) { if (typeof args[ai] === 'object') { clone(args[0], args[ai]) } } return args[0]; }; //ie鐗堟湰 lay.ie = function () { var agent = navigator.userAgent.toLowerCase(); return (!!window.ActiveXObject || "ActiveXObject" in window) ? ( (agent.match(/msie\s(\d+)/) || [])[1] || '11' //鐢变簬ie11骞舵病鏈塵sie鐨勬爣璇 ) : false; }(); //涓鍐掓场 lay.stope = function (e) { e = e || window.event; e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; }; //瀵硅薄閬嶅巻 lay.each = function (obj, fn) { var key , that = this; if (typeof fn !== 'function') return that; obj = obj || []; if (obj.constructor === Object) { for (key in obj) { if (fn.call(obj[key], key, obj[key])) break; } } else { for (key = 0; key < obj.length; key++) { if (fn.call(obj[key], key, obj[key])) break; } } return that; }; //鏁板瓧鍓嶇疆琛ラ浂 lay.digit = function (num, length, end) { var str = ''; num = String(num); length = length || 2; for (var i = num.length; i < length; i++) { str += '0'; } return num < Math.pow(10, length) ? str + (num | 0) : num; }; //鍒涘缓鍏冪礌 lay.elem = function (elemName, attr) { var elem = document.createElement(elemName); lay.each(attr || {}, function (key, value) { elem.setAttribute(key, value); }); return elem; }; //杩藉姞瀛楃 LAY.addStr = function (str, new_str) { str = str.replace(/\s+/, ' '); new_str = new_str.replace(/\s+/, ' ').split(' '); lay.each(new_str, function (ii, item) { if (!new RegExp('\\b' + item + '\\b').test(str)) { str = str + ' ' + item; } }); return str.replace(/^\s|\s$/, ''); }; //绉婚櫎鍊 LAY.removeStr = function (str, new_str) { str = str.replace(/\s+/, ' '); new_str = new_str.replace(/\s+/, ' ').split(' '); lay.each(new_str, function (ii, item) { var exp = new RegExp('\\b' + item + '\\b') if (exp.test(str)) { str = str.replace(exp, ''); } }); return str.replace(/\s+/, ' ').replace(/^\s|\s$/, ''); }; //鏌ユ壘瀛愬厓绱 LAY.prototype.find = function (selector) { var that = this; var index = 0, arr = [] , isObject = typeof selector === 'object'; this.each(function (i, item) { var nativeDOM = isObject ? [selector] : item.querySelectorAll(selector || null); for (; index < nativeDOM.length; index++) { arr.push(nativeDOM[index]); } that.shift(); }); if (!isObject) { that.selector = (that.selector ? that.selector + ' ' : '') + selector } lay.each(arr, function (i, item) { that.push(item); }); return that; }; //DOM閬嶅巻 LAY.prototype.each = function (fn) { return lay.each.call(this, this, fn); }; //娣诲姞css绫 LAY.prototype.addClass = function (className, type) { return this.each(function (index, item) { item.className = LAY[type ? 'removeStr' : 'addStr'](item.className, className) }); }; //绉婚櫎css绫 LAY.prototype.removeClass = function (className) { return this.addClass(className, true); }; //鏄惁鍖呭惈css绫 LAY.prototype.hasClass = function (className) { var has = false; this.each(function (index, item) { if (new RegExp('\\b' + className + '\\b').test(item.className)) { has = true; } }); return has; }; //娣诲姞鎴栬幏鍙栧睘鎬 LAY.prototype.attr = function (key, value) { var that = this; return value === undefined ? function () { if (that.length > 0) return that[0].getAttribute(key); }() : that.each(function (index, item) { item.setAttribute(key, value); }); }; //绉婚櫎灞炴€ LAY.prototype.removeAttr = function (key) { return this.each(function (index, item) { item.removeAttribute(key); }); }; //璁剧疆HTML鍐呭 LAY.prototype.html = function (html) { return this.each(function (index, item) { item.innerHTML = html; }); }; //璁剧疆鍊 LAY.prototype.val = function (value) { return this.each(function (index, item) { item.value = value; }); }; //杩藉姞鍐呭 LAY.prototype.append = function (elem) { return this.each(function (index, item) { typeof elem === 'object' ? item.appendChild(elem) : item.innerHTML = item.innerHTML + elem; }); }; //绉婚櫎鍐呭 LAY.prototype.remove = function (elem) { return this.each(function (index, item) { elem ? item.removeChild(elem) : item.parentNode.removeChild(item); }); }; //浜嬩欢缁戝畾 LAY.prototype.on = function (eventName, fn) { return this.each(function (index, item) { item.attachEvent ? item.attachEvent('on' + eventName, function (e) { e.target = e.srcElement; fn.call(item, e); }) : item.addEventListener(eventName, fn, false); }); }; //瑙i櫎浜嬩欢 LAY.prototype.off = function (eventName, fn) { return this.each(function (index, item) { item.detachEvent ? item.detachEvent('on' + eventName, fn) : item.removeEventListener(eventName, fn, false); }); }; /* 缁勪欢鎿嶄綔 */ //鏄惁闂板勾 Class.isLeapYear = function (year) { return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; }; //榛樿閰嶇疆 Class.prototype.config = { type: 'date' //鎺т欢绫诲瀷锛屾敮鎸侊細year/month/date/time/datetime , range: false //鏄惁寮€鍚寖鍥撮€夋嫨锛屽嵆鍙屾帶浠 , format: 'yyyy-MM-dd' //榛樿鏃ユ湡鏍煎紡 , value: null //榛樿鏃ユ湡锛屾敮鎸佷紶鍏ew Date()锛屾垨鑰呯鍚坒ormat鍙傛暟璁惧畾鐨勬棩鏈熸牸寮忓瓧绗 , min: '1900-1-1' //鏈夋晥鏈€灏忔棩鏈燂紝骞存湀鏃ュ繀椤荤敤鈥?鈥濆垎鍓诧紝鏃跺垎绉掑繀椤荤敤鈥淂鈥濆垎鍓层€傛敞鎰忥細瀹冨苟涓嶆槸閬靛惊 format 璁惧畾鐨勬牸寮忋€ , max: '2099-12-31' //鏈夋晥鏈€澶ф棩鏈燂紝鍚屼笂 , trigger: 'focus' //鍛煎嚭鎺т欢鐨勪簨浠 , show: false //鏄惁鐩存帴鏄剧ず锛屽鏋滆缃畉rue锛屽垯榛樿鐩存帴鏄剧ず鎺т欢 , showBottom: true //鏄惁鏄剧ず搴曢儴鏍 , btns: ['clear', 'now', 'confirm'] //鍙充笅瑙掓樉绀虹殑鎸夐挳锛屼細鎸夌収鏁扮粍椤哄簭鎺掑垪 , lang: 'cn' //璇█锛屽彧鏀寔cn/en锛屽嵆涓枃鍜岃嫳鏂 , theme: 'default' //涓婚 , position: null //鎺т欢瀹氫綅鏂瑰紡瀹氫綅, 榛樿absolute锛屾敮鎸侊細fixed/absolute/static , calendar: false //鏄惁寮€鍚叕鍘嗛噸瑕佽妭鏃ワ紝浠呮敮鎸佷腑鏂囩増 , mark: {} //鏃ユ湡澶囨敞锛屽閲嶈浜嬩欢鎴栨椿鍔ㄦ爣璁 , zIndex: null //鎺т欢灞傚彔椤哄簭 , done: null //鎺т欢閫夋嫨瀹屾瘯鍚庣殑鍥炶皟锛岀偣鍑绘竻绌?鐜板湪/纭畾涔熷潎浼氳Е鍙 , change: null //鏃ユ湡鏃堕棿鏀瑰彉鍚庣殑鍥炶皟 }; //澶氳瑷€ Class.prototype.lang = function () { var that = this , options = that.config , text = { cn: { weeks: ['鏃?, '涓€', '浜?, '涓?, '鍥?, '浜?, '鍏?] , time: ['鏃?, '鍒?, '绉?] , timeTips: '閫夋嫨鏃堕棿' , startTime: '寮€濮嬫椂闂? , endTime: '缁撴潫鏃堕棿' , dateTips: '杩斿洖鏃ユ湡' , month: ['涓€', '浜?, '涓?, '鍥?, '浜?, '鍏?, '涓?, '鍏?, '涔?, '鍗?, '鍗佷竴', '鍗佷簩'] , tools: { confirm: '纭畾' , clear: '娓呯┖' , now: '鐜板湪' } } , en: { weeks: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] , time: ['Hours', 'Minutes', 'Seconds'] , timeTips: 'Select Time' , startTime: 'Start Time' , endTime: 'End Time' , dateTips: 'Select Date' , month: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] , tools: { confirm: 'Confirm' , clear: 'Clear' , now: 'Now' } } }; return text[options.lang] || text['cn']; }; //鍒濆鍑嗗 Class.prototype.init = function () { var that = this , options = that.config , dateType = 'yyyy|y|MM|M|dd|d|HH|H|mm|m|ss|s' , isStatic = options.position === 'static' , format = { year: 'yyyy' , month: 'yyyy-MM' , date: 'yyyy-MM-dd' , time: 'HH:mm:ss' , datetime: 'yyyy-MM-dd HH:mm:ss' }; options.elem = lay(options.elem); options.eventElem = lay(options.eventElem); if (!options.elem[0]) return; //鏃ユ湡鑼冨洿鍒嗛殧绗 if (options.range === true) options.range = '-'; //鏍规嵁涓嶅悓type锛屽垵濮嬪寲榛樿format if (options.format === format.date) { options.format = format[options.type]; } //灏嗘棩鏈熸牸寮忚浆鍖栨垚鏁扮粍 that.format = options.format.match(new RegExp(dateType + '|.', 'g')) || []; //鐢熸垚姝e垯琛ㄨ揪寮 that.EXP_IF = ''; that.EXP_SPLIT = ''; lay.each(that.format, function (i, item) { var EXP = new RegExp(dateType).test(item) ? '\\d{' + function () { if (new RegExp(dateType).test(that.format[i === 0 ? i + 1 : i - 1] || '')) { if (/^yyyy|y$/.test(item)) return 4; return item.length; } if (/^yyyy$/.test(item)) return '1,4'; if (/^y$/.test(item)) return '1,308'; return '1,2'; }() + '}' : '\\' + item; that.EXP_IF = that.EXP_IF + EXP; that.EXP_SPLIT = that.EXP_SPLIT + '(' + EXP + ')'; }); that.EXP_IF = new RegExp('^' + ( options.range ? that.EXP_IF + '\\s\\' + options.range + '\\s' + that.EXP_IF : that.EXP_IF ) + '$'); that.EXP_SPLIT = new RegExp('^' + that.EXP_SPLIT + '$', ''); //濡傛灉涓嶆槸input|textarea鍏冪礌锛屽垯榛樿閲囩敤click浜嬩欢 if (!that.isInput(options.elem[0])) { if (options.trigger === 'focus') { options.trigger = 'click'; } } //璁剧疆鍞竴KEY if (!options.elem.attr('lay-key')) { options.elem.attr('lay-key', that.index); options.eventElem.attr('lay-key', that.index); } //璁板綍閲嶈鏃ユ湡 options.mark = lay.extend({}, (options.calendar && options.lang === 'cn') ? { '0-1-1': '鍏冩棪' , '0-2-14': '鎯呬汉' , '0-3-8': '濡囧コ' , '0-3-12': '妞嶆爲' , '0-4-1': '鎰氫汉' , '0-5-1': '鍔冲姩' , '0-5-4': '闈掑勾' , '0-6-1': '鍎跨' , '0-9-10': '鏁欏笀' , '0-9-18': '鍥借€? , '0-10-1': '鍥藉簡' , '0-12-25': '鍦h癁' } : {}, options.mark); //鑾峰彇闄愬埗鍐呮棩鏈 lay.each(['min', 'max'], function (i, item) { var ymd = [], hms = []; if (typeof options[item] === 'number') { //濡傛灉涓烘暟瀛 var day = options[item] , time = new Date().getTime() , STAMP = 86400000 //浠h〃涓€澶╃殑鏃堕棿鎴 , thisDate = new Date( day ? ( day < STAMP ? time + day * STAMP : day //濡傛灉鏁板瓧灏忎簬涓€澶╃殑鏃堕棿鎴筹紝鍒欐暟瀛椾负澶╂暟锛屽惁鍒欎负鏃堕棿鎴 ) : time ); ymd = [thisDate.getFullYear(), thisDate.getMonth() + 1, thisDate.getDate()]; day < STAMP || (hms = [thisDate.getHours(), thisDate.getMinutes(), thisDate.getSeconds()]); } else { ymd = (options[item].match(/\d+-\d+-\d+/) || [''])[0].split('-'); hms = (options[item].match(/\d+:\d+:\d+/) || [''])[0].split(':'); } options[item] = { year: ymd[0] | 0 || new Date().getFullYear() , month: ymd[1] ? (ymd[1] | 0) - 1 : new Date().getMonth() , date: ymd[2] | 0 || new Date().getDate() , hours: hms[0] | 0 , minutes: hms[1] | 0 , seconds: hms[2] | 0 }; }); that.elemID = 'layui-laydate' + options.elem.attr('lay-key'); if (options.show || isStatic) that.render(); isStatic || that.events(); //榛樿璧嬪€ if (options.value) { if (options.value.constructor === Date) { that.setValue(that.parse(0, that.systemDate(options.value))); } else { that.setValue(options.value); } } }; //鎺т欢涓讳綋娓叉煋 Class.prototype.render = function () { var that = this , options = that.config , lang = that.lang() , isStatic = options.position === 'static' //涓婚潰鏉 , elem = that.elem = lay.elem('div', { id: that.elemID , 'class': [ 'layui-laydate' , options.range ? ' layui-laydate-range' : '' , isStatic ? (' ' + ELEM_STATIC) : '' , options.theme && options.theme !== 'default' && !/^#/.test(options.theme) ? (' laydate-theme-' + options.theme) : '' ].join('') }) //涓诲尯鍩 , elemMain = that.elemMain = [] , elemHeader = that.elemHeader = [] , elemCont = that.elemCont = [] , elemTable = that.table = [] //搴曢儴鍖哄煙 , divFooter = that.footer = lay.elem('div', { 'class': ELEM_FOOTER }); if (options.zIndex) elem.style.zIndex = options.zIndex; //鍗曞弻鏃ュ巻鍖哄煙 lay.each(new Array(2), function (i) { if (!options.range && i > 0) { return true; } //澶撮儴鍖哄煙 var divHeader = lay.elem('div', { 'class': 'layui-laydate-header' }) //宸﹀彸鍒囨崲 , headerChild = [function () { //涓婁竴骞 var elem = lay.elem('i', { 'class': 'layui-icon laydate-icon laydate-prev-y' }); elem.innerHTML = ''; return elem; }(), function () { //涓婁竴鏈 var elem = lay.elem('i', { 'class': 'layui-icon laydate-icon laydate-prev-m' }); elem.innerHTML = ''; return elem; }(), function () { //骞存湀閫夋嫨 var elem = lay.elem('div', { 'class': 'laydate-set-ym' }), spanY = lay.elem('span'), spanM = lay.elem('span'); elem.appendChild(spanY); elem.appendChild(spanM); return elem; }(), function () { //涓嬩竴鏈 var elem = lay.elem('i', { 'class': 'layui-icon laydate-icon laydate-next-m' }); elem.innerHTML = ''; return elem; }(), function () { //涓嬩竴骞 var elem = lay.elem('i', { 'class': 'layui-icon laydate-icon laydate-next-y' }); elem.innerHTML = ''; return elem; }()] //鏃ュ巻鍐呭鍖哄煙 , divContent = lay.elem('div', { 'class': 'layui-laydate-content' }) , table = lay.elem('table') , thead = lay.elem('thead'), theadTr = lay.elem('tr'); //鐢熸垚骞存湀閫夋嫨 lay.each(headerChild, function (i, item) { divHeader.appendChild(item); }); //鐢熸垚琛ㄦ牸 thead.appendChild(theadTr); lay.each(new Array(6), function (i) { //琛ㄤ綋 var tr = table.insertRow(0); lay.each(new Array(7), function (j) { if (i === 0) { var th = lay.elem('th'); th.innerHTML = lang.weeks[j]; theadTr.appendChild(th); } tr.insertCell(j); }); }); table.insertBefore(thead, table.children[0]); //琛ㄥご divContent.appendChild(table); elemMain[i] = lay.elem('div', { 'class': 'layui-laydate-main laydate-main-list-' + i }); elemMain[i].appendChild(divHeader); elemMain[i].appendChild(divContent); elemHeader.push(headerChild); elemCont.push(divContent); elemTable.push(table); }); //鐢熸垚搴曢儴鏍 lay(divFooter).html(function () { var html = [], btns = []; if (options.type === 'datetime') { html.push('' + lang.timeTips + ''); } lay.each(options.btns, function (i, item) { var title = lang.tools[item] || 'btn'; if (options.range && item === 'now') return; if (isStatic && item === 'clear') title = options.lang === 'cn' ? '閲嶇疆' : 'Reset'; btns.push('' + title + ''); }); html.push(''); return html.join(''); }()); //鎻掑叆鍒颁富鍖哄煙 lay.each(elemMain, function (i, main) { elem.appendChild(main); }); options.showBottom && elem.appendChild(divFooter); //鐢熸垚鑷畾涔変富棰 if (/^#/.test(options.theme)) { var style = lay.elem('style') , styleText = [ '#{{id}} .layui-laydate-header{background-color:{{theme}};}' , '#{{id}} .layui-this{background-color:{{theme}} !important;}' ].join('').replace(/{{id}}/g, that.elemID).replace(/{{theme}}/g, options.theme); if ('styleSheet' in style) { style.setAttribute('type', 'text/css'); style.styleSheet.cssText = styleText; } else { style.innerHTML = styleText; } lay(elem).addClass('laydate-theme-molv'); elem.appendChild(style); } //绉婚櫎涓婁竴涓帶浠 that.remove(Class.thisElemDate); //濡傛灉鏄潤鎬佸畾浣嶏紝鍒欐彃鍏ュ埌鎸囧畾鐨勫鍣ㄤ腑锛屽惁鍒欙紝鎻掑叆鍒癰ody isStatic ? options.elem.append(elem) : ( document.body.appendChild(elem) , that.position() //瀹氫綅 ); that.checkDate().calendar(); //鍒濆鏍¢獙 that.changeEvent(); //鏃ユ湡鍒囨崲 Class.thisElemDate = that.elemID; typeof options.ready === 'function' && options.ready(lay.extend({}, options.dateTime, { month: options.dateTime.month + 1 })); }; //鎺т欢绉婚櫎 Class.prototype.remove = function (prev) { var that = this , options = that.config , elem = lay('#' + (prev || that.elemID)); if (!elem.hasClass(ELEM_STATIC)) { that.checkDate(function () { elem.remove(); }); } return that; }; //瀹氫綅绠楁硶 Class.prototype.position = function () { var that = this , options = that.config , elem = that.bindElem || options.elem[0] , rect = elem.getBoundingClientRect() //缁戝畾鍏冪礌鐨勫潗鏍 , elemWidth = that.elem.offsetWidth //鎺т欢鐨勫搴 , elemHeight = that.elem.offsetHeight //鎺т欢鐨勯珮搴 //婊氬姩鏉¢珮搴 , scrollArea = function (type) { type = type ? 'scrollLeft' : 'scrollTop'; return document.body[type] | document.documentElement[type]; } , winArea = function (type) { return document.documentElement[type ? 'clientWidth' : 'clientHeight'] }, margin = 5, left = rect.left, top = rect.bottom; //濡傛灉鍙充晶瓒呭嚭杈圭晫 if (left + elemWidth + margin > winArea('width')) { left = winArea('width') - elemWidth - margin; } //濡傛灉搴曢儴瓒呭嚭杈圭晫 if (top + elemHeight + margin > winArea()) { top = rect.top > elemHeight //椤堕儴鏄惁鏈夎冻澶熷尯鍩熸樉绀哄畬鍏 ? rect.top - elemHeight : winArea() - elemHeight; top = top - margin * 2; } if (options.position) { that.elem.style.position = options.position; } that.elem.style.left = left + (options.position === 'fixed' ? 0 : scrollArea(1)) + 'px'; that.elem.style.top = top + (options.position === 'fixed' ? 0 : scrollArea()) + 'px'; }; //鎻愮ず Class.prototype.hint = function (content) { var that = this , options = that.config , div = lay.elem('div', { 'class': ELEM_HINT }); div.innerHTML = content || ''; lay(that.elem).find('.' + ELEM_HINT).remove(); that.elem.appendChild(div); clearTimeout(that.hinTimer); that.hinTimer = setTimeout(function () { lay(that.elem).find('.' + ELEM_HINT).remove(); }, 3000); }; //鑾峰彇閫掑/鍑忓悗鐨勫勾鏈 Class.prototype.getAsYM = function (Y, M, type) { type ? M-- : M++; if (M < 0) { M = 11; Y--; } if (M > 11) { M = 0; Y++; } return [Y, M]; }; //绯荤粺娑堟伅 Class.prototype.systemDate = function (newDate) { var thisDate = newDate || new Date(); return { year: thisDate.getFullYear() //骞 , month: thisDate.getMonth() //鏈 , date: thisDate.getDate() //鏃 , hours: newDate ? newDate.getHours() : 0 //鏃 , minutes: newDate ? newDate.getMinutes() : 0 //鍒 , seconds: newDate ? newDate.getSeconds() : 0 //绉 } }; //鏃ユ湡鏍¢獙 Class.prototype.checkDate = function (fn) { var that = this , thisDate = new Date() , options = that.config , dateTime = options.dateTime = options.dateTime || that.systemDate() , thisMaxDate, error , elem = that.bindElem || options.elem[0] , valType = that.isInput(elem) ? 'val' : 'html' , value = that.isInput(elem) ? elem.value : (options.position === 'static' ? '' : elem.innerHTML) //鏍¢獙鏃ユ湡鏈夋晥鏁板瓧 , checkValid = function (dateTime) { if (dateTime.year > LIMIT_YEAR[1]) dateTime.year = LIMIT_YEAR[1], error = true; //涓嶈兘瓒呰繃20涓囧勾 if (dateTime.month > 11) dateTime.month = 11, error = true; if (dateTime.hours > 23) dateTime.hours = 0, error = true; if (dateTime.minutes > 59) dateTime.minutes = 0, dateTime.hours++, error = true; if (dateTime.seconds > 59) dateTime.seconds = 0, dateTime.minutes++, error = true; //璁$畻褰撳墠鏈堢殑鏈€鍚庝竴澶 thisMaxDate = laydate.getEndDate(dateTime.month + 1, dateTime.year); if (dateTime.date > thisMaxDate) dateTime.date = thisMaxDate, error = true; } //鑾峰緱鍒濆鍖栨棩鏈熷€ , initDate = function (dateTime, value, index) { var startEnd = ['startTime', 'endTime']; value = (value.match(that.EXP_SPLIT) || []).slice(1); index = index || 0; if (options.range) { that[startEnd[index]] = that[startEnd[index]] || {}; } lay.each(that.format, function (i, item) { var thisv = parseFloat(value[i]); if (value[i].length < item.length) error = true; if (/yyyy|y/.test(item)) { //骞 if (thisv < LIMIT_YEAR[0]) thisv = LIMIT_YEAR[0], error = true; //骞翠笉鑳戒綆浜?00骞 dateTime.year = thisv; } else if (/MM|M/.test(item)) { //鏈 if (thisv < 1) thisv = 1, error = true; dateTime.month = thisv - 1; } else if (/dd|d/.test(item)) { //鏃 if (thisv < 1) thisv = 1, error = true; dateTime.date = thisv; } else if (/HH|H/.test(item)) { //鏃 if (thisv < 1) thisv = 0, error = true; dateTime.hours = thisv; options.range && (that[startEnd[index]].hours = thisv); } else if (/mm|m/.test(item)) { //鍒 if (thisv < 1) thisv = 0, error = true; dateTime.minutes = thisv; options.range && (that[startEnd[index]].minutes = thisv); } else if (/ss|s/.test(item)) { //绉 if (thisv < 1) thisv = 0, error = true; dateTime.seconds = thisv; options.range && (that[startEnd[index]].seconds = thisv); } }); checkValid(dateTime) }; if (fn === 'limit') return checkValid(dateTime), that; value = value || options.value; if (typeof value === 'string') { value = value.replace(/\s+/g, ' ').replace(/^\s|\s$/g, ''); } //濡傛灉鐐瑰嚮浜嗗紑濮嬶紝鍗曟湭閫夋嫨缁撴潫灏卞叧闂紝鍒欓噸鏂伴€夋嫨寮€濮 if (that.startState && !that.endState) { delete that.startState; that.endState = true; }; if (typeof value === 'string' && value) { if (that.EXP_IF.test(value)) { //鏍¢獙鏃ユ湡鏍煎紡 if (options.range) { value = value.split(' ' + options.range + ' '); that.startDate = that.startDate || that.systemDate(); that.endDate = that.endDate || that.systemDate(); options.dateTime = lay.extend({}, that.startDate); lay.each([that.startDate, that.endDate], function (i, item) { initDate(item, value[i], i); }); } else { initDate(dateTime, value) } } else { that.hint('鏃ユ湡鏍煎紡涓嶅悎娉旤br>蹇呴』閬靛惊涓嬭堪鏍煎紡锛欬br>' + ( options.range ? (options.format + ' ' + options.range + ' ' + options.format) : options.format ) + '
宸蹭负浣犻噸缃?); error = true; } } else if (value && value.constructor === Date) { //濡傛灉鍊间负鏃ユ湡瀵硅薄鏃 options.dateTime = that.systemDate(value); } else { options.dateTime = that.systemDate(); delete that.startState; delete that.endState; delete that.startDate; delete that.endDate; delete that.startTime; delete that.endTime; } checkValid(dateTime); if (error && value) { that.setValue( options.range ? (that.endDate ? that.parse() : '') : that.parse() ); } fn && fn(); return that; }; //鍏巻閲嶈鏃ユ湡涓庤嚜瀹氫箟澶囨敞 Class.prototype.mark = function (td, YMD) { var that = this , mark, options = that.config; lay.each(options.mark, function (key, title) { var keys = key.split('-'); if ((keys[0] == YMD[0] || keys[0] == 0) //姣忓勾鐨勬瘡鏈 && (keys[1] == YMD[1] || keys[1] == 0) //姣忔湀鐨勬瘡鏃 && keys[2] == YMD[2]) { //鐗瑰畾鏃 mark = title || YMD[2]; } }); mark && td.html('' + mark + ''); return that; }; //鏃犳晥鏃ユ湡鑼冨洿鐨勬爣璁 Class.prototype.limit = function (elem, date, index, time) { var that = this , options = that.config, timestrap = {} , dateTime = options[index > 41 ? 'endDate' : 'dateTime'] , isOut, thisDateTime = lay.extend({}, dateTime, date || {}); lay.each({ now: thisDateTime , min: options.min , max: options.max }, function (key, item) { timestrap[key] = that.newDate(lay.extend({ year: item.year , month: item.month , date: item.date }, function () { var hms = {}; lay.each(time, function (i, keys) { hms[keys] = item[keys]; }); return hms; }())).getTime(); //time锛氭槸鍚︽瘮杈冩椂鍒嗙 }); isOut = timestrap.now < timestrap.min || timestrap.now > timestrap.max; elem && elem[isOut ? 'addClass' : 'removeClass'](DISABLED); return isOut; }; //鏃ュ巻琛 Class.prototype.calendar = function (value) { var that = this , options = that.config , dateTime = value || options.dateTime , thisDate = new Date(), startWeek, prevMaxDate, thisMaxDate , lang = that.lang() , isAlone = options.type !== 'date' && options.type !== 'datetime' , index = value ? 1 : 0 , tds = lay(that.table[index]).find('td') , elemYM = lay(that.elemHeader[index][2]).find('span'); if (dateTime.year < LIMIT_YEAR[0]) dateTime.year = LIMIT_YEAR[0], that.hint('鏈€浣庡彧鑳芥敮鎸佸埌鍏厓' + LIMIT_YEAR[0] + '骞?); if (dateTime.year > LIMIT_YEAR[1]) dateTime.year = LIMIT_YEAR[1], that.hint('鏈€楂樺彧鑳芥敮鎸佸埌鍏厓' + LIMIT_YEAR[1] + '骞?); //璁板綍鍒濆鍊 if (!that.firstDate) { that.firstDate = lay.extend({}, dateTime); } //璁$畻褰撳墠鏈堢涓€澶╃殑鏄熸湡 thisDate.setFullYear(dateTime.year, dateTime.month, 1); startWeek = thisDate.getDay(); prevMaxDate = laydate.getEndDate(dateTime.month || 12, dateTime.year); //璁$畻涓婁釜鏈堢殑鏈€鍚庝竴澶 thisMaxDate = laydate.getEndDate(dateTime.month + 1, dateTime.year); //璁$畻褰撳墠鏈堢殑鏈€鍚庝竴澶 //璧嬪€兼棩 lay.each(tds, function (index, item) { var YMD = [dateTime.year, dateTime.month], st = 0; item = lay(item); item.removeAttr('class'); if (index < startWeek) { st = prevMaxDate - startWeek + index; item.addClass('laydate-day-prev'); YMD = that.getAsYM(dateTime.year, dateTime.month, 'sub'); } else if (index >= startWeek && index < thisMaxDate + startWeek) { st = index - startWeek; if (!options.range) { st + 1 === dateTime.date && item.addClass(THIS); } } else { st = index - thisMaxDate - startWeek; item.addClass('laydate-day-next'); YMD = that.getAsYM(dateTime.year, dateTime.month); } YMD[1]++; YMD[2] = st + 1; item.attr('lay-ymd', YMD.join('-')).html(YMD[2]); that.mark(item, YMD).limit(item, { year: YMD[0] , month: YMD[1] - 1 , date: YMD[2] }, index); }); //鍚屾澶撮儴骞存湀 lay(elemYM[0]).attr('lay-ym', dateTime.year + '-' + (dateTime.month + 1)); lay(elemYM[1]).attr('lay-ym', dateTime.year + '-' + (dateTime.month + 1)); if (options.lang === 'cn') { lay(elemYM[0]).attr('lay-type', 'year').html(dateTime.year + '骞?) lay(elemYM[1]).attr('lay-type', 'month').html((dateTime.month + 1) + '鏈?); } else { lay(elemYM[0]).attr('lay-type', 'month').html(lang.month[dateTime.month]); lay(elemYM[1]).attr('lay-type', 'year').html(dateTime.year); } //鍒濆榛樿閫夋嫨鍣 if (isAlone) { if (options.range) { value ? that.endDate = (that.endDate || { year: dateTime.year + (options.type === 'year' ? 1 : 0) , month: dateTime.month + (options.type === 'month' ? 0 : -1) }) : (that.startDate = that.startDate || { year: dateTime.year , month: dateTime.month }); if (value) { that.listYM = [ [that.startDate.year, that.startDate.month + 1] , [that.endDate.year, that.endDate.month + 1] ]; that.list(options.type, 0).list(options.type, 1); //鍚屾鎸夐挳鍙偣鐘舵€ options.type === 'time' ? that.setBtnStatus('鏃堕棿' , lay.extend({}, that.systemDate(), that.startTime) , lay.extend({}, that.systemDate(), that.endTime) ) : that.setBtnStatus(true); } } if (!options.range) { that.listYM = [[dateTime.year, dateTime.month + 1]]; that.list(options.type, 0); } } //璧嬪€煎弻鏃ュ巻 if (options.range && !value) { var EYM = that.getAsYM(dateTime.year, dateTime.month) that.calendar(lay.extend({}, dateTime, { year: EYM[0] , month: EYM[1] })); } //閫氳繃妫€娴嬪綋鍓嶆湁鏁堟棩鏈燂紝鏉ヨ瀹氱‘瀹氭寜閽槸鍚﹀彲鐐 if (!options.range) that.limit(lay(that.footer).find(ELEM_CONFIRM), null, 0, ['hours', 'minutes', 'seconds']); //鏍囪閫夋嫨鑼冨洿 if (options.range && value && !isAlone) that.stampRange(); return that; }; //鐢熸垚骞存湀鏃跺垎绉掑垪琛 Class.prototype.list = function (type, index) { var that = this , options = that.config , dateTime = options.dateTime , lang = that.lang() , isAlone = options.range && options.type !== 'date' && options.type !== 'datetime' //鐙珛鑼冨洿閫夋嫨鍣 , ul = lay.elem('ul', { 'class': ELEM_LIST + ' ' + ({ year: 'laydate-year-list' , month: 'laydate-month-list' , time: 'laydate-time-list' })[type] }) , elemHeader = that.elemHeader[index] , elemYM = lay(elemHeader[2]).find('span') , elemCont = that.elemCont[index || 0] , haveList = lay(elemCont).find('.' + ELEM_LIST)[0] , isCN = options.lang === 'cn' , text = isCN ? '骞? : '' , listYM = that.listYM[index] || {} , hms = ['hours', 'minutes', 'seconds'] , startEnd = ['startTime', 'endTime'][index]; if (listYM[0] < 1) listYM[0] = 1; if (type === 'year') { //骞村垪琛 var yearNum, startY = yearNum = listYM[0] - 7; if (startY < 1) startY = yearNum = 1; lay.each(new Array(15), function (i) { var li = lay.elem('li', { 'lay-ym': yearNum }), ymd = { year: yearNum }; yearNum == listYM[0] && lay(li).addClass(THIS); li.innerHTML = yearNum + text; ul.appendChild(li); if (yearNum < that.firstDate.year) { ymd.month = options.min.month; ymd.date = options.min.date; } else if (yearNum >= that.firstDate.year) { ymd.month = options.max.month; ymd.date = options.max.date; } that.limit(lay(li), ymd, index); yearNum++; }); lay(elemYM[isCN ? 0 : 1]).attr('lay-ym', (yearNum - 8) + '-' + listYM[1]) .html((startY + text) + ' - ' + (yearNum - 1 + text)); } else if (type === 'month') { //鏈堝垪琛 lay.each(new Array(12), function (i) { var li = lay.elem('li', { 'lay-ym': i }), ymd = { year: listYM[0], month: i }; i + 1 == listYM[1] && lay(li).addClass(THIS); li.innerHTML = lang.month[i] + (isCN ? '鏈? : ''); ul.appendChild(li); if (listYM[0] < that.firstDate.year) { ymd.date = options.min.date; } else if (listYM[0] >= that.firstDate.year) { ymd.date = options.max.date; } that.limit(lay(li), ymd, index); }); lay(elemYM[isCN ? 0 : 1]).attr('lay-ym', listYM[0] + '-' + listYM[1]) .html(listYM[0] + text); } else if (type === 'time') { //鏃堕棿鍒楄〃 //妫€娴嬫椂鍒嗙鐘舵€佹槸鍚﹀湪鏈夋晥鏃ユ湡鏃堕棿鑼冨洿鍐 var setTimeStatus = function () { lay(ul).find('ol').each(function (i, ol) { lay(ol).find('li').each(function (ii, li) { that.limit(lay(li), [{ hours: ii }, { hours: that[startEnd].hours , minutes: ii }, { hours: that[startEnd].hours , minutes: that[startEnd].minutes , seconds: ii }][i], index, [['hours'], ['hours', 'minutes'], ['hours', 'minutes', 'seconds']][i]); }); }); if (!options.range) that.limit(lay(that.footer).find(ELEM_CONFIRM), that[startEnd], 0, ['hours', 'minutes', 'seconds']); }; if (options.range) { if (!that[startEnd]) that[startEnd] = { hours: 0 , minutes: 0 , seconds: 0 }; } else { that[startEnd] = dateTime; } lay.each([24, 60, 60], function (i, item) { var li = lay.elem('li'), childUL = ['

' + lang.time[i] + '

    ']; lay.each(new Array(item), function (ii) { childUL.push('' + lay.digit(ii, 2) + ''); }); li.innerHTML = childUL.join('') + '
'; ul.appendChild(li); }); setTimeStatus(); } //鎻掑叆瀹瑰櫒 if (haveList) elemCont.removeChild(haveList); elemCont.appendChild(ul); //骞存湀 if (type === 'year' || type === 'month') { //鏄剧ず鍒囨崲绠ご lay(that.elemMain[index]).addClass('laydate-ym-show'); //閫変腑 lay(ul).find('li').on('click', function () { var ym = lay(this).attr('lay-ym') | 0; if (lay(this).hasClass(DISABLED)) return; if (index === 0) { dateTime[type] = ym; if (isAlone) that.startDate[type] = ym; that.limit(lay(that.footer).find(ELEM_CONFIRM), null, 0); } else { //鑼冨洿閫夋嫨 if (isAlone) { //闈瀌ate/datetime绫诲瀷 that.endDate[type] = ym; } else { //date/datetime绫诲瀷 var YM = type === 'year' ? that.getAsYM(ym, listYM[1] - 1, 'sub') : that.getAsYM(listYM[0], ym, 'sub'); lay.extend(dateTime, { year: YM[0] , month: YM[1] }); } } if (options.type === 'year' || options.type === 'month') { lay(ul).find('.' + THIS).removeClass(THIS); lay(this).addClass(THIS); //濡傛灉涓哄勾鏈堥€夋嫨鍣紝鐐瑰嚮浜嗗勾鍒楄〃锛屽垯鍒囨崲鍒版湀閫夋嫨鍣 if (options.type === 'month' && type === 'year') { that.listYM[index][0] = ym; isAlone && (that[['startDate', 'endDate'][index]].year = ym); that.list('month', index); } } else { that.checkDate('limit').calendar(); that.closeList(); } that.setBtnStatus(); //鍚屾鎸夐挳鍙偣鐘舵€ options.range || that.done(null, 'change'); lay(that.footer).find(ELEM_TIME_BTN).removeClass(DISABLED); }); } else { var span = lay.elem('span', { 'class': ELEM_TIME_TEXT }), scroll = function () { //婊氬姩鏉″畾浣 lay(ul).find('ol').each(function (i) { var ol = this , li = lay(ol).find('li') ol.scrollTop = 30 * (that[startEnd][hms[i]] - 2); if (ol.scrollTop <= 0) { li.each(function (ii, item) { if (!lay(this).hasClass(DISABLED)) { ol.scrollTop = 30 * (ii - 2); return true; } }); } }); }, haveSpan = lay(elemHeader[2]).find('.' + ELEM_TIME_TEXT); scroll() span.innerHTML = options.range ? [lang.startTime, lang.endTime][index] : lang.timeTips lay(that.elemMain[index]).addClass('laydate-time-show'); if (haveSpan[0]) haveSpan.remove(); elemHeader[2].appendChild(span); lay(ul).find('ol').each(function (i) { var ol = this; //閫夋嫨鏃跺垎绉 lay(ol).find('li').on('click', function () { var value = this.innerHTML | 0; if (lay(this).hasClass(DISABLED)) return; if (options.range) { that[startEnd][hms[i]] = value; } else { dateTime[hms[i]] = value; } lay(ol).find('.' + THIS).removeClass(THIS); lay(this).addClass(THIS); setTimeStatus(); scroll(); (that.endDate || options.type === 'time') && that.done(null, 'change'); //鍚屾鎸夐挳鍙偣鐘舵€ that.setBtnStatus(); }); }); } return that; }; //璁板綍鍒楄〃鍒囨崲鍚庣殑骞存湀 Class.prototype.listYM = []; //鍏抽棴鍒楄〃 Class.prototype.closeList = function () { var that = this , options = that.config; lay.each(that.elemCont, function (index, item) { lay(this).find('.' + ELEM_LIST).remove(); lay(that.elemMain[index]).removeClass('laydate-ym-show laydate-time-show'); }); lay(that.elem).find('.' + ELEM_TIME_TEXT).remove(); }; //妫€娴嬬粨鏉熸棩鏈熸槸鍚﹁秴鍑哄紑濮嬫棩鏈 Class.prototype.setBtnStatus = function (tips, start, end) { var that = this , options = that.config , isOut, elemBtn = lay(that.footer).find(ELEM_CONFIRM) , isAlone = options.range && options.type !== 'date' && options.type !== 'time'; if (isAlone) { start = start || that.startDate; end = end || that.endDate; isOut = that.newDate(start).getTime() > that.newDate(end).getTime(); //濡傛灉涓嶅湪鏈夋晥鏃ユ湡鍐咃紝鐩存帴绂佺敤鎸夐挳锛屽惁鍒欐瘮杈冨紑濮嬪拰缁撴潫鏃ユ湡 (that.limit(null, start) || that.limit(null, end)) ? elemBtn.addClass(DISABLED) : elemBtn[isOut ? 'addClass' : 'removeClass'](DISABLED); //鏄惁寮傚父鎻愮ず if (tips && isOut) that.hint( typeof tips === 'string' ? TIPS_OUT.replace(/鏃ユ湡/g, tips) : TIPS_OUT ); } }; //杞箟涓鸿瀹氭牸寮忕殑鏃ユ湡瀛楃 Class.prototype.parse = function (state, date) { var that = this , options = that.config , dateTime = date || (state ? lay.extend({}, that.endDate, that.endTime) : (options.range ? lay.extend({}, that.startDate, that.startTime) : options.dateTime)) , format = that.format.concat(); //杞箟涓鸿瀹氭牸寮 lay.each(format, function (i, item) { if (/yyyy|y/.test(item)) { //骞 format[i] = lay.digit(dateTime.year, item.length); } else if (/MM|M/.test(item)) { //鏈 format[i] = lay.digit(dateTime.month + 1, item.length); } else if (/dd|d/.test(item)) { //鏃 format[i] = lay.digit(dateTime.date, item.length); } else if (/HH|H/.test(item)) { //鏃 format[i] = lay.digit(dateTime.hours, item.length); } else if (/mm|m/.test(item)) { //鍒 format[i] = lay.digit(dateTime.minutes, item.length); } else if (/ss|s/.test(item)) { //绉 format[i] = lay.digit(dateTime.seconds, item.length); } }); //杩斿洖鏃ユ湡鑼冨洿瀛楃 if (options.range && !state) { return format.join('') + ' ' + options.range + ' ' + that.parse(1); } return format.join(''); }; //鍒涘缓鎸囧畾鏃ユ湡鏃堕棿瀵硅薄 Class.prototype.newDate = function (dateTime) { dateTime = dateTime || {}; return new Date( dateTime.year || 1 , dateTime.month || 0 , dateTime.date || 1 , dateTime.hours || 0 , dateTime.minutes || 0 , dateTime.seconds || 0 ); }; //璧嬪€ Class.prototype.setValue = function (value) { var that = this , options = that.config , elem = that.bindElem || options.elem[0] , valType = that.isInput(elem) ? 'val' : 'html' options.position === 'static' || lay(elem)[valType](value || ''); return this; }; //鏍囪鑼冨洿鍐呯殑鏃ユ湡 Class.prototype.stampRange = function () { var that = this , options = that.config , startTime, endTime , tds = lay(that.elem).find('td'); if (options.range && !that.endDate) lay(that.footer).find(ELEM_CONFIRM).addClass(DISABLED); if (!that.endDate) return; startTime = that.newDate({ year: that.startDate.year , month: that.startDate.month , date: that.startDate.date }).getTime(); endTime = that.newDate({ year: that.endDate.year , month: that.endDate.month , date: that.endDate.date }).getTime(); if (startTime > endTime) return that.hint(TIPS_OUT); lay.each(tds, function (i, item) { var ymd = lay(item).attr('lay-ymd').split('-') , thisTime = that.newDate({ year: ymd[0] , month: ymd[1] - 1 , date: ymd[2] }).getTime(); lay(item).removeClass(ELEM_SELECTED + ' ' + THIS); if (thisTime === startTime || thisTime === endTime) { lay(item).addClass( lay(item).hasClass(ELEM_PREV) || lay(item).hasClass(ELEM_NEXT) ? ELEM_SELECTED : THIS ); } if (thisTime > startTime && thisTime < endTime) { lay(item).addClass(ELEM_SELECTED); } }); }; //鎵цdone/change鍥炶皟 Class.prototype.done = function (param, type) { var that = this , options = that.config , start = lay.extend({}, that.startDate ? lay.extend(that.startDate, that.startTime) : options.dateTime) , end = lay.extend({}, lay.extend(that.endDate, that.endTime)) lay.each([start, end], function (i, item) { if (!('month' in item)) return; lay.extend(item, { month: item.month + 1 }); }); param = param || [that.parse(), start, end]; typeof options[type || 'done'] === 'function' && options[type || 'done'].apply(options, param); return that; }; //閫夋嫨鏃ユ湡 Class.prototype.choose = function (td) { var that = this , options = that.config , dateTime = options.dateTime , tds = lay(that.elem).find('td') , YMD = td.attr('lay-ymd').split('-') , setDateTime = function (one) { var thisDate = new Date(); //鍚屾dateTime one && lay.extend(dateTime, YMD); //璁板綍寮€濮嬫棩鏈 if (options.range) { that.startDate ? lay.extend(that.startDate, YMD) : ( that.startDate = lay.extend({}, YMD, that.startTime) ); that.startYMD = YMD; } }; YMD = { year: YMD[0] | 0 , month: (YMD[1] | 0) - 1 , date: YMD[2] | 0 }; if (td.hasClass(DISABLED)) return; //鑼冨洿閫夋嫨 if (options.range) { lay.each(['startTime', 'endTime'], function (i, item) { that[item] = that[item] || { hours: 0 , minutes: 0 , seconds: 0 }; }); if (that.endState) { //閲嶆柊閫夋嫨 setDateTime(); delete that.endState; delete that.endDate; that.startState = true; tds.removeClass(THIS + ' ' + ELEM_SELECTED); td.addClass(THIS); } else if (that.startState) { //閫変腑鎴 td.addClass(THIS); that.endDate ? lay.extend(that.endDate, YMD) : ( that.endDate = lay.extend({}, YMD, that.endTime) ); //鍒ゆ柇鏄惁椤烘椂鎴栭€嗘椂閫夋嫨 if (that.newDate(YMD).getTime() < that.newDate(that.startYMD).getTime()) { var startDate = lay.extend({}, that.endDate, { hours: that.startDate.hours , minutes: that.startDate.minutes , seconds: that.startDate.seconds }); lay.extend(that.endDate, that.startDate, { hours: that.endDate.hours , minutes: that.endDate.minutes , seconds: that.endDate.seconds }); that.startDate = startDate; } options.showBottom || that.done(); that.stampRange(); //鏍囪鑼冨洿鍐呯殑鏃ユ湡 that.endState = true; that.done(null, 'change'); } else { //閫変腑寮€濮 td.addClass(THIS); setDateTime(); that.startState = true; } lay(that.footer).find(ELEM_CONFIRM)[that.endDate ? 'removeClass' : 'addClass'](DISABLED); } else if (options.position === 'static') { //鐩存帴宓屽鐨勯€変腑 setDateTime(true); that.calendar().done().done(null, 'change'); } else if (options.type === 'date') { setDateTime(true); that.setValue(that.parse()).remove().done(); } else if (options.type === 'datetime') { setDateTime(true); that.calendar().done(null, 'change'); } }; //搴曢儴鎸夐挳 Class.prototype.tool = function (btn, type) { var that = this , options = that.config , dateTime = options.dateTime , isStatic = options.position === 'static' , active = { //閫夋嫨鏃堕棿 datetime: function () { if (lay(btn).hasClass(DISABLED)) return; that.list('time', 0); options.range && that.list('time', 1); lay(btn).attr('lay-type', 'date').html(that.lang().dateTips); } //閫夋嫨鏃ユ湡 , date: function () { that.closeList(); lay(btn).attr('lay-type', 'datetime').html(that.lang().timeTips); } //娓呯┖銆侀噸缃 , clear: function () { that.setValue('').remove(); isStatic && ( lay.extend(dateTime, that.firstDate) , that.calendar() ) options.range && ( delete that.startState , delete that.endState , delete that.endDate , delete that.startTime , delete that.endTime ); that.done(['', {}, {}]); } //鐜板湪 , now: function () { var thisDate = new Date(); lay.extend(dateTime, that.systemDate(), { hours: thisDate.getHours() , minutes: thisDate.getMinutes() , seconds: thisDate.getSeconds() }); that.setValue(that.parse()).remove(); isStatic && that.calendar(); that.done(); } //纭畾 , confirm: function () { if (options.range) { if (!that.endDate) return that.hint('璇峰厛閫夋嫨鏃ユ湡鑼冨洿'); if (lay(btn).hasClass(DISABLED)) return that.hint( options.type === 'time' ? TIPS_OUT.replace(/鏃ユ湡/g, '鏃堕棿') : TIPS_OUT ); } else { if (lay(btn).hasClass(DISABLED)) return that.hint('涓嶅湪鏈夋晥鏃ユ湡鎴栨椂闂磋寖鍥村唴'); } that.done(); that.setValue(that.parse()).remove() } }; active[type] && active[type](); }; //缁熶竴鍒囨崲澶勭悊 Class.prototype.change = function (index) { var that = this , options = that.config , dateTime = options.dateTime , isAlone = options.range && (options.type === 'year' || options.type === 'month') , elemCont = that.elemCont[index || 0] , listYM = that.listYM[index] , addSubYeay = function (type) { var startEnd = ['startDate', 'endDate'][index] , isYear = lay(elemCont).find('.laydate-year-list')[0] , isMonth = lay(elemCont).find('.laydate-month-list')[0]; //鍒囨崲骞村垪琛 if (isYear) { listYM[0] = type ? listYM[0] - 15 : listYM[0] + 15; that.list('year', index); } if (isMonth) { //鍒囨崲鏈堥潰鏉夸腑鐨勫勾 type ? listYM[0]-- : listYM[0]++; that.list('month', index); } if (isYear || isMonth) { lay.extend(dateTime, { year: listYM[0] }); if (isAlone) that[startEnd].year = listYM[0]; options.range || that.done(null, 'change'); that.setBtnStatus(); options.range || that.limit(lay(that.footer).find(ELEM_CONFIRM), { year: listYM[0] }); } return isYear || isMonth; }; return { prevYear: function () { if (addSubYeay('sub')) return; dateTime.year--; that.checkDate('limit').calendar(); options.range || that.done(null, 'change'); } , prevMonth: function () { var YM = that.getAsYM(dateTime.year, dateTime.month, 'sub'); lay.extend(dateTime, { year: YM[0] , month: YM[1] }); that.checkDate('limit').calendar(); options.range || that.done(null, 'change'); } , nextMonth: function () { var YM = that.getAsYM(dateTime.year, dateTime.month); lay.extend(dateTime, { year: YM[0] , month: YM[1] }); that.checkDate('limit').calendar(); options.range || that.done(null, 'change'); } , nextYear: function () { if (addSubYeay()) return; dateTime.year++ that.checkDate('limit').calendar(); options.range || that.done(null, 'change'); } }; }; //鏃ユ湡鍒囨崲浜嬩欢 Class.prototype.changeEvent = function () { var that = this , options = that.config; //鏃ユ湡閫夋嫨浜嬩欢 lay(that.elem).on('click', function (e) { lay.stope(e); }); //骞存湀鍒囨崲 lay.each(that.elemHeader, function (i, header) { //涓婁竴骞 lay(header[0]).on('click', function (e) { that.change(i).prevYear(); }); //涓婁竴鏈 lay(header[1]).on('click', function (e) { that.change(i).prevMonth(); }); //閫夋嫨骞存湀 lay(header[2]).find('span').on('click', function (e) { var othis = lay(this) , layYM = othis.attr('lay-ym') , layType = othis.attr('lay-type'); if (!layYM) return; layYM = layYM.split('-'); that.listYM[i] = [layYM[0] | 0, layYM[1] | 0]; that.list(layType, i); lay(that.footer).find(ELEM_TIME_BTN).addClass(DISABLED); }); //涓嬩竴鏈 lay(header[3]).on('click', function (e) { that.change(i).nextMonth(); }); //涓嬩竴骞 lay(header[4]).on('click', function (e) { that.change(i).nextYear(); }); }); //鐐瑰嚮鏃ユ湡 lay.each(that.table, function (i, table) { var tds = lay(table).find('td'); tds.on('click', function () { that.choose(lay(this)); }); }); //鐐瑰嚮搴曢儴鎸夐挳 lay(that.footer).find('span').on('click', function () { var type = lay(this).attr('lay-type'); that.tool(this, type); }); }; //鏄惁杈撳叆妗 Class.prototype.isInput = function (elem) { return /input|textarea/.test(elem.tagName.toLocaleLowerCase()); }; //缁戝畾鐨勫厓绱犱簨浠跺鐞 Class.prototype.events = function () { var that = this , options = that.config //缁戝畾鍛煎嚭鎺т欢浜嬩欢 , showEvent = function (elem, bind) { elem.on(options.trigger, function () { bind && (that.bindElem = this); that.render(); }); }; if (!options.elem[0] || options.elem[0].eventHandler) return; showEvent(options.elem, 'bind'); showEvent(options.eventElem); //缁戝畾鍏抽棴鎺т欢浜嬩欢 lay(document).on('click', function (e) { if (e.target === options.elem[0] || e.target === options.eventElem[0] || e.target === lay(options.closeStop)[0]) { return; } that.remove(); }).on('keydown', function (e) { if (e.keyCode === 13) { if (lay('#' + that.elemID)[0] && that.elemID === Class.thisElem) { e.preventDefault(); lay(that.footer).find(ELEM_CONFIRM)[0].click(); } } }); //鑷€傚簲瀹氫綅 lay(window).on('resize', function () { if (!that.elem || !lay(ELEM)[0]) { return false; } that.position(); }); options.elem[0].eventHandler = true; }; //鏍稿績鎺ュ彛 laydate.render = function (options) { var inst = new Class(options); return thisDate.call(inst); }; //寰楀埌鏌愭湀鐨勬渶鍚庝竴澶 laydate.getEndDate = function (month, year) { var thisDate = new Date(); //璁剧疆鏃ユ湡涓轰笅涓湀鐨勭涓€澶 thisDate.setFullYear( year || thisDate.getFullYear() , month || (thisDate.getMonth() + 1) , 1); //鍑忓幓涓€澶╋紝寰楀埌褰撳墠鏈堟渶鍚庝竴澶 return new Date(thisDate.getTime() - 1000 * 60 * 60 * 24).getDate(); }; //鏆撮湶lay window.lay = window.lay || lay; //鍔犺浇鏂瑰紡 isLayui ? ( laydate.ready() , layui.define(function (exports) { //layui鍔犺浇 laydate.path = layui.cache.dir; exports(MOD_NAME, laydate); }) ) : ( (typeof define === 'function' && define.amd) ? define(function () { //requirejs鍔犺浇 return laydate; }) : function () { //鏅€歴cript鏍囩鍔犺浇 laydate.ready(); window.laydate = laydate }() ); }();