123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- Namespace.register("U.MD.UI.calendar");
- /**
- * 日历控件调用API函数
- * @param el 对象元素
- * @param parentnode 添加到的父元素
- * @param datetimeboolean 【boolean】是否显示选择时分秒功能
- */
- U.MD.UI.Calendar = U.MD.UI.calendar = function (el, parentnode, datetimeboolean) {
- if (!el)
- return
- if(typeof datetimeboolean == 'boolean' && datetimeboolean == false){
- U.MD.UI.calendar.datetimeformat = datetimeboolean
- }else{
- U.MD.UI.calendar.datetimeformat = true;
- }
- U.MD.UI.calendar.create(el, parentnode);
- }
- U.MD.UI.calendar.NOW = new Date(); /*获取当天时间*/
- U.MD.UI.calendar.CURRENTYEAR = U.MD.UI.calendar.NOW.getFullYear(); /*今年*/
- U.MD.UI.calendar.CURRENTMONTH = U.MD.UI.calendar.NOW.getMonth(); /*今月*/
- U.MD.UI.calendar.CURRENTDAY = U.MD.UI.calendar.NOW.getDate(); /*今日*/
- U.MD.UI.calendar.year = U.MD.UI.calendar.CURRENTYEAR; /*可变年*/
- U.MD.UI.calendar.month = U.MD.UI.calendar.CURRENTMONTH; /*可变月*/
- U.MD.UI.calendar.day = U.MD.UI.calendar.CURRENTDAY; /*可变日*/
- U.MD.UI.calendar.hour = '00'; /*时*/
- U.MD.UI.calendar.minute = '00'; /*分*/
- U.MD.UI.calendar.second = '00'; /*秒*/
- U.MD.UI.calendar.datetimeformat = true; /*是否以时分秒时间格式输出*/
- U.MD.UI.calendar.fouseinp = null; /*当前聚焦的input*/
- U.MD.UI.calendar.board = null; /*最外层div*/
- U.MD.UI.calendar.tit = null; /*日期标题*/
- U.MD.UI.calendar.mark = 1; /*标记量*/
- U.MD.UI.calendar.template = [ /*html模板块*/
- /*功能*/
- '<div class="U_MD_UI_calendar_features">' +
- '<div class="U_MD_UI_calendar_closeBtn" id="U_MD_UI_calendar_closeBtn">关闭</div>' +
- '<div class="U_MD_UI_calendar_features_a">' +
- '<div class="U_MD_UI_calendar_prev U_MD_UI_calendar_btn" id="prevDate"></div>' +
- '<div class="U_MD_UI_calendar_tit" id="calendar_tit"></div>' +
- '<input type="text" id="calendar_tit_btn" style="display: none;">' +
- '<div class="U_MD_UI_calendar_next U_MD_UI_calendar_btn" id="nextDate"></div>' +
- '</div>' +
- '<i></i>' +
- '</div>',
- /*星期*/
- '<div id="calendar_day">' +
- '<ul class="U_MD_UI_calendar_week">' +
- '<li>日</li>' +
- '<li>一</li>' +
- '<li>二</li>' +
- '<li>三</li>' +
- '<li>四</li>' +
- '<li>五</li>' +
- '<li>六</li>' +
- '</ul>' +
- '<ul class="U_MD_UI_calendar_c" id="calendar_week_c"></ul>' +
- '</div>',
- /*选择月*/
- '<div class="U_MD_UI_calendar_month" id="calendar_month" style="display: none">' +
- '<ul class="U_MD_UI_calendar_month_c">' +
- '<li><span>1月</span></li>' +
- '<li><span>2月</span></li>' +
- '<li><span>3月</span></li>' +
- '<li><span>4月</span></li>' +
- '<li><span>5月</span></li>' +
- '<li><span>6月</span></li>' +
- '<li><span>7月</span></li>' +
- '<li><span>8月</span></li>' +
- '<li><span>9月</span></li>' +
- '<li><span>10月</span></li>' +
- '<li><span>11月</span></li>' +
- '<li><span>12月</span></li>' +
- '</ul>' +
- '</div>',
- /*选择年*/
- '<div id="calendar_year" class="U_MD_UI_calendar_month" style="display: none">' +
- '<ul class="U_MD_UI_calendar_month_c">' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '<li></li>' +
- '</ul>' +
- '</div>',
- /*选择时间*/
- '<span id="U_MD_UI_calendar_timeText" class="U_MD_UI_calendar_timeText">选择时间</span>' +
- '<div class="U_MD_UI_calendar_timeBox">' +
- '<div id="U_MD_UI_calendar_clearText" class="U_MD_UI_calendar_timeBtn">清空</div>' +
- '<div id="U_MD_UI_calendar_nowTime" class="U_MD_UI_calendar_timeBtn">现在</div>' +
- '<div id="U_MD_UI_calendar_okBtn" class="U_MD_UI_calendar_timeBtn">确定</div>' +
- '</div>',
- /*选择时间内容*/
- '<div id="calendar_timeChoose" class="U_MD_UI_calendar_timeChoose" style="display: none">' +
- '</div>'
- ];
- /**
- * 创建日历的壳
- * @param els 对象元素
- * @param els 父元素
- */
- U.MD.UI.calendar.create = function (els, parentnode) {
- if (els == U.MD.UI.calendar.fouseinp && U.MD.UI.calendar.board.style.display == 'block')
- return
- if (parentnode && U.MD.UI.calendar.board) {
- U.MD.UI.calendar.board.parentNode.removeChild(U.MD.UI.calendar.board);
- U.MD.UI.calendar.board = null;
- }
- var _top = document.documentElement.scrollTop || document.body.scrollTop,
- _left = document.documentElement.scrollLeft || document.body.scrollLeft;
- var _offsetHtml = [Math.abs(els.getBoundingClientRect().left) + _left, Math.abs(els.getBoundingClientRect().top) + _top]; /*获取元素相对于html文档的距离*/
- U.MD.UI.calendar.fouseinp = els; /*当前聚焦的input*/
- if (!U.MD.UI.calendar.board) { /*判断是否有创建日历内容*/
- U.MD.UI.calendar.showBoard(els, _offsetHtml, parentnode); /*创建日历内容*/
- } else {
- U.MD.UI.calendar.resetData(_offsetHtml);
- }
- U.MD.UI.calendar.showDay(); /*日期显示*/
- }
- /**
- * 时分秒模板控制
- * @param that 对象元素
- * @param text 改变的文字
- */
- U.MD.UI.calendar.toggleChooseText = function (that) {
- var _child = U.selectEl('.U_MD_UI_calendar_c_a')[0].children, //模板元素
- _len = _child.length; //长度
- if (that.innerText == '返回日期') { //点击的字
- U.MD.UI.calendar.changeDisplay(_lastTemplate, _child[_len - 1]); //切换模板
- that.innerText = "选择时间"; //改变文字
- U.selectEl(that).removeClass("U_MD_UI_calendar_timeTextClick"); //删除选中class
- return; //调出函数
- }
- for (var i = 0; i < _len - 1; i++) { //循环模板
- _child[i].style.display != 'none' && (_child[i].style.display = 'none', _lastTemplate = _child[i]); //隐藏
- }
- _child[_len - 1].style.display = 'block'; //显示选择时分秒模板
- that.innerText = "返回日期"; //改变文字
- U.selectEl(that).addClass("U_MD_UI_calendar_timeTextClick"); //添加class
- }
- /**
- * 数据重置
- * @param offsethtml 偏移量
- */
- U.MD.UI.calendar.resetData = function (offsethtml) {
-
- U.MD.UI.calendar.board.style.display = 'block'; /*让日历显示*/
- U.MD.UI.calendar.mark = 1;
- U.selectEl('#calendar_day')[0].style.display = 'block';
- U.selectEl('#calendar_month')[0].style.display = 'none';
- U.selectEl('#calendar_year')[0].style.display = 'none';
- U.MD.UI.calendar.board.style.left = offsethtml[0] + 'px'; /*改变日历显示的x轴*/
- U.MD.UI.calendar.board.style.top = offsethtml[1] + U.MD.UI.calendar.fouseinp.clientHeight + 10 + 'px'; /*改变日历显示的y轴*/
- U.MD.UI.calendar.year = U.MD.UI.calendar.CURRENTYEAR;
- U.MD.UI.calendar.month = U.MD.UI.calendar.CURRENTMONTH;
- U.MD.UI.calendar.ChooseDefault(true);
- }
- /**
- * 创建时间选择模块
- * @param addel 添加父元素
- */
- U.MD.UI.calendar.createChooseTime = function (addel) {
- var _dataObj = [["时", "分", "秒"], [24, 60, 60], ["hour", "minute", "second"]],
- _lastTemplate;
- var _ct = $$('div', { id: 'calendar_time', className: 'U_MD_UI_calendar_time', innerHTML: U.MD.UI.calendar.template[4] }, U.MD.UI.calendar.board);
- for (var i = 0; i < _dataObj[0].length; i++) {
- var _row = $$('div', { className: "U_MD_UI_calendar_timeRow" }, addel);
- $$('span', { className: "U_MD_UI_calendar_timeRowText", innerText: _dataObj[0][i] }, _row);
- var _rowCon = $$('div', { className: "U_MD_UI_calendar_timeRowCon" }, _row),
- _ul = $$('ul', { className: "U_MD_UI_calendar_timeRowUl", name: _dataObj[2][i] }, _rowCon);
- for (var j = 0; j < _dataObj[1][i]; j++) {
- var _text = j.toString().length == 1 ? '0' + j : j;
- $$('li', { innerText: _text, onclick: function () {
- var _parentUl = this.parentNode,
- _activeLi = _parentUl.querySelector('.U_MD_UI_calendar_timeRowActive');
- U.selectEl(_activeLi).removeClass('U_MD_UI_calendar_timeRowActive');
- U.selectEl(this).addClass('U_MD_UI_calendar_timeRowActive');
- switch (_parentUl.name) {
- case 'hour': U.MD.UI.calendar.hour = this.innerText; break;
- case 'minute': U.MD.UI.calendar.minute = this.innerText; break;
- case 'second': U.MD.UI.calendar.second = this.innerText; break;
- }
- }
- }, _ul);
- }
- }
- if (!U.MD.UI.calendar.datetimeformat) {
- _ct.style.display = 'none';
- }
- U.selectEl('#U_MD_UI_calendar_timeText')[0].onclick = function () { //绑定进入选择时分秒的模块时间
- U.MD.UI.calendar.toggleChooseText(this)
- }
- U.selectEl('#U_MD_UI_calendar_clearText')[0].onclick = function () { //绑定清空事件
- U.MD.UI.calendar.fouseinp.value ? U.MD.UI.calendar.fouseinp.value = '' : U.MD.UI.calendar.fouseinp.innerText = '';
- U.MD.UI.calendar.ChooseDefault(true);
- U.MD.UI.calendar.board.style.display = 'none';
- }
- U.selectEl('#U_MD_UI_calendar_nowTime')[0].onclick = function () { //绑定输出今天事件
- U.MD.UI.calendar.outPutDate(true);
- }
- U.selectEl('#U_MD_UI_calendar_okBtn')[0].onclick = function () { //绑定确定事件
- U.MD.UI.calendar.outPutDate(false);
- }
- }
- /**
- * 创建日历
- * @param input 当前聚焦的input
- * @param offsetHtml 元素相对于html文档的距离
- */
- U.MD.UI.calendar.showBoard = function (input, offsetHtml, parentnode) {
- var _template = U.MD.UI.calendar.template, /*转局部变量*/
- _parentNode = parentnode || document.body,
- _templateHTML = _template[1] + _template[2] + _template[3] + _template[5];
- if (!parentnode) {
- U.MD.UI.calendar.board = $$('div', { "className": "U_MD_UI_calendar_bigboard", style: { left: offsetHtml[0] + "px", top: offsetHtml[1] + input.clientHeight + 10 + "px"} }, _parentNode); /*创建日历元素*/
- } else {
- U.MD.UI.calendar.board = $$('div', { "className": "U_MD_UI_calendar_bigboard" }, parentnode);
- }
- U.MD.UI.calendar.board.innerHTML = _template[0]; /*给上html模板的第一个*/
- _dayC = $$('div', { "className": 'U_MD_UI_calendar_c_a', innerHTML: _templateHTML }, U.MD.UI.calendar.board); /*创建剩下的内容,把html模板内容丢进去*/
- U.MD.UI.calendar.tit = U.selectEl('#calendar_tit')[0]; /*获取日历标题*/
- _mc = U.selectEl('#calendar_month > ul > li'); /*获取选择月模块的li*/
- _titInp = U.selectEl('#calendar_tit_btn')[0]; /*获取日历标题的input*/
- _timer = null; /*定义一个定时器*/
- U.MD.UI.calendar.createChooseTime($('#calendar_timeChoose')[0]);
- U.MD.UI.calendar.tit.onclick = function () { /*给日历标题绑定点击事件*/
- clearTimeout(_timer); /*清除定时器*/
- if (U.MD.UI.calendar.mark == 1) { /*标记数是1*/
- U.MD.UI.calendar.tit.innerText = U.MD.UI.calendar.year; /*日历标题赋值可变月*/
- U.MD.UI.calendar.changeDisplay($('#calendar_month')[0], U.selectEl('#calendar_day')[0]); /*选择月显示,选择天隐藏*/
- U.MD.UI.calendar.mark = 2; /*标记数赋值2,以表示当前停留在选择月模块*/
- U.MD.UI.calendar.ChooseDefault();
- } else if (U.MD.UI.calendar.mark == 2) { /*标记数是2*/
- _timer = setTimeout(function () { /*赋值一个定时器*/
- U.MD.UI.calendar.changeDisplay($('#calendar_year')[0], U.selectEl('#calendar_month')[0]); /*选择年显示,选择月隐藏*/
- U.MD.UI.calendar.dateTenYear(); /*调用显示10年内容函数*/
- U.MD.UI.calendar.mark = 3; /*标记数复制3,以表示档期那停球在选择年模块*/
- U.MD.UI.calendar.ChooseDefault();
- }, 250); /*0.25秒后执行*/
- }
- }
- U.MD.UI.calendar.tit.ondblclick = function () { /*给日历标题绑定双击事件*/
- clearTimeout(_timer); /*清除定时器,防止进入单击事件*/
- if (U.MD.UI.calendar.mark === 2) { /*标记数是2*/
- _obj = U.MD.UI.calendar.changeDisplay(_titInp, this, 'inline-block'); /*日历标题文本框显示,日历标题隐藏*/
- _obj[0].value = this.innerText; /*把日历title赋值给编辑input*/
- _obj[0].focus(); /*编辑input给上聚焦*/
- }
- }
- _titInp.onkeydown = function (e) { /*给日历标题文本框一个键盘事件*/
- switch (e.keyCode) {
- case 13: /*编辑input 回车来更改内容*/
- var _arr2 = U.MD.UI.calendar.changeDisplay(U.MD.UI.calendar.tit, this, 'inline-block'); /*显示日历title, 隐藏编辑input*/
- _arr2[0].innerText = U.MD.UI.calendar.year = !isNaN(parseInt(this.value)) ? parseInt(this.value) : U.MD.UI.calendar.CURRENTYEAR; /*把编辑input的内容赋值给日历title*/
- break;
- }
- };
- _titInp.onblur = function () { /*给日历标题文本框一个失去焦点*/
- var _arr3 = U.MD.UI.calendar.changeDisplay(U.MD.UI.calendar.tit, this, 'inline-block'); /*同上*/
- _arr3[0].innerText = U.MD.UI.calendar.year = !isNaN(parseInt(this.value)) ? parseInt(this.value) : U.MD.UI.calendar.CURRENTYEAR;
- }
- U.selectEl('#prevDate')[0].onclick = function () { /*给向左的小三角绑定点击事件*/
- if (U.MD.UI.calendar.mark == 1) { _lessNum = -1 } /*标记数是1,-1月*/
- else if (U.MD.UI.calendar.mark == 2) { _lessNum = -12 } /*标记数是2,-12月*/
- else if (U.MD.UI.calendar.mark == 3) { _lessNum = -120 }; /*标记数是3, -120月*/
- U.MD.UI.calendar.fullDate(_lessNum, false);
- };
- U.selectEl('#nextDate')[0].onclick = function () { /*给向右的小三角绑定点击事件*/
- if (U.MD.UI.calendar.mark == 1) { _addNum = 1 } /*标记数是1,+1月*/
- else if (U.MD.UI.calendar.mark == 2) { _addNum = 12 } /*标记数是1,+12月*/
- else if (U.MD.UI.calendar.mark == 3) { _addNum = 120 }; /*标记数是1,+120月*/
- U.MD.UI.calendar.fullDate(_addNum, true);
- };
- for (var i = 0; i < _mc.length; i++) { /*给选择月的模块li循环*/
- _mc[i].onclick = function () { /*给每个绑定一个点击事件*/
- U.MD.UI.calendar.changeDisplay($('#calendar_day')[0], U.selectEl('#calendar_month')[0]); /*选择天显示,选择月隐藏*/
- U.MD.UI.calendar.month = parseInt(this.innerText) - 1; /*赋值选的月*/
- U.MD.UI.calendar.showDay(); /*刷新数据*/
- U.MD.UI.calendar.mark = 1; /*标记量赋值1*/
- }
- }
- U.selectEl('#U_MD_UI_calendar_closeBtn')[0].onclick = function () { /*给关闭按钮绑定一个事件*/
- U.UF.EV.stopBubble();
- U.MD.UI.calendar.board.style.display = 'none'; /*让日历空间隐藏*/
- }
- }
- /**
- * 创建或更新选择天模块的内容
- */
- U.MD.UI.calendar.showDay = function () { /*显示日期*/
- _monthFristDay = new Date(U.MD.UI.calendar.year, U.MD.UI.calendar.month, 1).getDay(); /*当月第一天的星期*/
- _lastMonthDay = new Date(U.MD.UI.calendar.year, U.MD.UI.calendar.month, 0).getDate(); /*上个月的最后一天*/
- _fullDay = new Date(U.MD.UI.calendar.year, U.MD.UI.calendar.month + 1, 0).getDate(); /*当月总天数*/
- _totalDay = (_t = _monthFristDay + _fullDay) % 7 === 0 ? _t : _t + (7 - _t % 7); /*当月总共需要显示天数*/
- _dayC = U.selectEl('#calendar_week_c')[0];
- _dayC.innerHTML = '';
- for (var _i = 0; _i < _totalDay; _i++) {
- _li = $$('li', {}, _dayC);
- if (_i < _monthFristDay) { /*如果小于当月第一天的星期,这里显示的是上月最后几天的号显示*/
- $$('span', { "className": 'U_MD_UI_calendar_unavailable', innerText: (_lastMonthDay - _monthFristDay + _i + 1) }, _li);
- } else if (_i < (_fullDay + _monthFristDay)) { /*如果小于(当月总天数 + 当月第一天的星期)*/
- var _d = _i - _monthFristDay + 1, _week = new Date(U.MD.UI.calendar.year, U.MD.UI.calendar.month, _d).getDay(), _today = U.MD.UI.calendar.NOW.getDate() === _d && (U.MD.UI.calendar.CURRENTMONTH === U.MD.UI.calendar.month && U.MD.UI.calendar.CURRENTYEAR === U.MD.UI.calendar.year);
- _dayV = _d;
- if (_week === 6 || _week === 0) { /*如果是周末字体显示为红色,否则给黑色*/
- _today ? $$('span', { "className": 'U_MD_UI_calendar_day U_MD_UI_calendar_today U_MD_UI_calendar_weekend', innerText: _d, "onclick": function () { U.MD.UI.calendar.day = this.innerText; U.MD.UI.calendar.outPutDate() } }, _li) : $$('span', { "className": 'U_MD_UI_calendar_day U_MD_UI_calendar_weekend', innerText: _d, "onclick": function () { U.MD.UI.calendar.day = this.innerText; U.MD.UI.calendar.outPutDate() } }, _li);
- } else if (_today) { /*如果是今天,打重点*/
- $$('span', { "className": 'U_MD_UI_calendar_day U_MD_UI_calendar_today', innerText: _d, "onclick": function () { U.MD.UI.calendar.day = this.innerText; U.MD.UI.calendar.outPutDate() } }, _li)
- } else { /*默认样式*/
- $$('span', { "className": 'U_MD_UI_calendar_day', innerText: _d, "onclick": function () { U.MD.UI.calendar.day = this.innerText; U.MD.UI.calendar.outPutDate() } }, _li)
- }
- } else { /*显示下个月的星期,给上字体是灰色的样式*/
- $$('span', { "className": 'U_MD_UI_calendar_unavailable', innerText: (_i - (_fullDay + _monthFristDay) + 1) }, _li)
- }
- }
- U.MD.UI.calendar.tit.innerText = U.MD.UI.calendar.year + '-' + (U.MD.UI.calendar.month + 1) + '月'; /*转换格式,然后丢到日历标题文本框里*/
- }
- /**
- * 年月控制器
- * @param num 需要减的月数
- * @param check 如果是true表示点击了向右的小三角,是false表示点击了向左的小三角
- */
- U.MD.UI.calendar.fullDate = function (num, check) {
- var _year = (_n = Math.abs(num) / 12) >= 1 ? _n >>> 0 : 0, /*如果月份/12大于1,也就是超过12月或者说1年, _n>>>0取出整数部分*/
- _month = Math.abs(num) % 12; /*月份膜上12剩下的就是月份*/
- !check && (_month = -_month);
- !check && (_year = -_year);
- U.MD.UI.calendar.month += _month; /*月份加一或减一*/
- U.MD.UI.calendar.year += _year; /*年份加一或减一*/
- if (check) {
- if (U.MD.UI.calendar.month > 11) { /*如果月份大于11*/
- U.MD.UI.calendar.month = 0; /*月份清空*/
- U.MD.UI.calendar.year++; /*年份加一*/
- }
- } else {
- if (U.MD.UI.calendar.month < 0) { /*如果月份小于0*/
- U.MD.UI.calendar.month = 11; /*可变月赋值11,即表示12月*/
- U.MD.UI.calendar.year--; /*可变年减一*/
- }
- }
- if (U.MD.UI.calendar.mark == 1) { U.MD.UI.calendar.showDay() }; /*更新日期显示*/
- if (U.MD.UI.calendar.mark == 2) { U.MD.UI.calendar.tit.innerText = U.MD.UI.calendar.year }; /*标记数是2,即代表在选择月模块,*/
- if (U.MD.UI.calendar.mark == 3) { U.MD.UI.calendar.dateTenYear() }; /*标记数是3,即代表在选择年模块,*/
- }
- /**
- * 转换输出格式
- * @param symbol 分割符号
- * @param isnow 【boolean】 是否获取当前时间
- * @returns {*} 返回字符串
- */
- U.MD.UI.calendar.formartDate = function (symbol, isnow) {
- var _symbol, y, m, d, h, m, s;
- _symbol = symbol || '-'
- y = isnow ? U.MD.UI.calendar.CURRENTYEAR : U.MD.UI.calendar.year;
- m = isnow ? U.MD.UI.calendar.CURRENTMONTH + 1 : U.MD.UI.calendar.month + 1;
- d = isnow ? U.MD.UI.calendar.CURRENTDAY : U.MD.UI.calendar.day;
- m = (m.toString())[1] ? m : '0' + m;
- d = (d.toString())[1] ? d : '0' + d;
- var _dateStr = y + _symbol + m + _symbol + d;
- if (typeof U.MD.UI.calendar.datetimeformat == 'boolean' && U.MD.UI.calendar.datetimeformat) {
- if (isnow) {
- var _nowDate = new Date();
- U.MD.UI.calendar.hour = _nowDate.getHours();
- U.MD.UI.calendar.minute = _nowDate.getMinutes();
- U.MD.UI.calendar.second = _nowDate.getSeconds();
- }
- h = (U.MD.UI.calendar.hour.toString())[1] ? U.MD.UI.calendar.hour : '0' + U.MD.UI.calendar.hour;
- m = (U.MD.UI.calendar.minute.toString())[1] ? U.MD.UI.calendar.minute : '0' + U.MD.UI.calendar.minute;
- s = (U.MD.UI.calendar.second.toString())[1] ? U.MD.UI.calendar.second : '0' + U.MD.UI.calendar.second;
- _dateStr += " " + h + ":" + m + ":" + s;
- }
- return _dateStr;
- }
- /**
- * 创建选择天时需要循环绑定的函数
- */
- /*
- U.MD.UI.calendar.outPutDate = function () {
- if (U.MD.UI.calendar.fouseinp.value) {
- U.MD.UI.calendar.fouseinp.value = U.MD.UI.calendar.formartDate(U.MD.UI.calendar.year, U.MD.UI.calendar.month + 1, this.innerText);
- } else {
- U.MD.UI.calendar.fouseinp.innerText = U.MD.UI.calendar.formartDate(U.MD.UI.calendar.year, U.MD.UI.calendar.month + 1, this.innerText);
- }
- U.MD.UI.calendar.board.style.display = 'none';
- }
- */
- /**
- * 创建选择天时需要循环绑定的函数
- */
- U.MD.UI.calendar.outPutDate = function (isNow) {
- if (U.MD.UI.calendar.fouseinp.tagName === 'INPUT') {
- U.MD.UI.calendar.fouseinp.value = U.MD.UI.calendar.formartDate('-', isNow); /*选择天后进入转换年月日输入格式函数*/
- } else {
- U.MD.UI.calendar.fouseinp.innerText = U.MD.UI.calendar.formartDate('-', isNow); /*选择天后进入转换年月日输入格式函数*/
- }
- U.MD.UI.calendar.CheckedDay && U.MD.UI.calendar.CheckedDay();
- U.MD.UI.calendar.board.style.display = 'none'; /*隐藏日历控件*/
- }
- /**
- * 显示与隐藏
- * @param blockEl 需要显示的元素
- * @param noneEl 需要隐藏的元素
- * @param val 显示的方式
- * @returns {*[]} 返回数组[显示元素,隐藏元素]
- */
- U.MD.UI.calendar.changeDisplay = function (blockEl, noneEl, val) {
- val = val || 'block'; /*默认block*/
- if (blockEl && typeof blockEl === 'object') { blockEl.setAttribute('style', 'display:' + val) } /*如果blockEL存在且blockEl是个对象,进行属性的赋值*/
- if (noneEl && typeof noneEl === 'object') { noneEl.setAttribute('style', 'display:none') }; /*如果noneEl存在且noneEl是个对象,进行属性的赋值*/
- return [blockEl, noneEl];
- }
- /**
- * 更新选择年的模块内容
- */
- U.MD.UI.calendar.dateTenYear = function () {
- _yearArr = U.selectEl('#calendar_year > ul > li'); /*获取选择年模块里的li*/
- _startYear = U.MD.UI.calendar.year - (U.MD.UI.calendar.year % 10); /**/
- for (var i = 0; i < _yearArr.length; i++) {
- _yearArr[i].onclick = function () {
- U.MD.UI.calendar.mark = 2; /*标记数赋值2*/
- U.MD.UI.calendar.year = parseInt(this.innerText); /*修改年的的值*/
- U.MD.UI.calendar.changeDisplay($('#calendar_month')[0], U.selectEl('#calendar_year')[0]); /*显示选择月板块,隐藏选择年的板块*/
- U.MD.UI.calendar.tit.innerText = this.innerText; /*改变日历title显示格式*/
- }
- _yearArr[i].innerHTML = ''; /*清空li里面的内容*/
- if (i == 0 || i == _yearArr.length - 1) { /*头尾年*/
- $$('span', { "className": "U_MD_UI_calendar_unavailable", innerText: (_startYear + i - 1) }, _yearArr[i]);
- } else if ((_startYear + i - 1) === U.MD.UI.calendar.CURRENTYEAR) { /*当前年*/
- $$('span', { style: { "background-color": "#eed1bc" }, innerText: (_startYear + i - 1) }, _yearArr[i])
- } else { /*默认输出*/
- $$('span', { innerText: (_startYear + i - 1) }, _yearArr[i])
- }
- }
- U.MD.UI.calendar.tit.innerText = (t = (U.MD.UI.calendar.year - (U.MD.UI.calendar.year % 10))) + '-' + (t + 9); /*改变日历title显示格式*/
- }
- /**
- * 时分秒数据初始化
- * @param deafultflag 【boolean】是否初始化数据
- */
- U.MD.UI.calendar.ChooseDefault = function (deafultflag) {
- if (U.MD.UI.calendar.datetimeformat) { //判断是否显示时分秒模板
- if (deafultflag) { //是否初始化数据
- U.MD.UI.calendar.hour = '00'; //重置
- U.MD.UI.calendar.minute = '00'; //重置
- U.MD.UI.calendar.second = '00'; //重置
- U.selectEl(U.MD.UI.calendar.board).find('.U_MD_UI_calendar_timeRowActive').removeClass('U_MD_UI_calendar_timeRowActive'); //清除选中的样式
- !$('#U_MD_UI_calendar_timeText').length && U.MD.UI.calendar.createChooseTime($('#calendar_timeChoose')[0]); //是否有加载时分秒模块
- }
- U.selectEl('#calendar_time')[0].style.display = "block"; //显示选择时间的功能区
- U.selectEl('#calendar_timeChoose')[0].style.display = 'none'; //隐藏选择时分秒选择区
- U.selectEl('#U_MD_UI_calendar_timeText')[0].innerText = "选择时间"; //重置
- U.selectEl('#U_MD_UI_calendar_timeText').removeClass("U_MD_UI_calendar_timeTextClick"); //重置
- } else {
- U.selectEl('#calendar_time')[0].style.display = 'none'; //重置
- U.selectEl('#calendar_timeChoose')[0].style.display = 'none'; //重置
- }
- }
- U.MD.UI.calendar.SetCallBack = function (funcname, func) {
- if (typeof func != 'function' || !"CheckedDay ".match(funcname + ' '))
- return 0;
- U.MD.UI.calendar[funcname] = func
- }
|