text: "use strict";!function(A){function C(e){return e<=9?"0"+e:String(e)}$JqcLoader.importComponents("com.lifeonwalden.jqc",["baseElement","uniqueKey","valHooks","select","timepicker","notification","contextmenu","datetimepicker","dateUtil","confirm"]).importCss($JqcLoader.getCmpParentURL("com.lifeonwalden.jqc","calendar").concat("css/calendar.css")).execute(function(){var f=new Date,a={type:0,startTime:"startTime",endTime:"endTime",content:"content",tip:"tip"},n={title:"",currentYear:f.getFullYear(),currentMonth:f.getMonth()+1,currentDate:f.getDate(),startYear:f.getFullYear()-10,endYear:f.getFullYear()+10,cellHeight:90,cellTextAlign:"center",status:"view",data:[],memo:[],adapter:a,cache:{},cellRender:function(e,t,a){var n=[];return 6!=e.day&&7!=e.day||t.addClass("error"),a&&(n=n.concat(a)),n}},e=["一","二","三","四","五","六","日"],v=["","warn","success","info","error"],U=[{color:"#AEB3D3",value:0,label:"默认"},{color:"#EFC27B",value:1,label:"一般"},{color:"#A8CADD",value:2,label:"主要"},{color:"#E9A78F",value:3,label:"重要"},{color:"#E27275",value:4,label:"特别重要"}];A.jqcCalendar=function(e){if(Object.assign(this,n,e),e.adapter&&(this.adapter=Object.assign({},a,e.adapter)),!this.el)throw new Error("jqcCalendar:缺少el参数");this.yearData=[];for(var t=this.startYear;t<=this.endYear;t++)this.yearData.push({value:t,label:"".concat(t)});this.monthData=new Array(12).fill(1).map(function(e,t){return{value:t+1,label:"".concat(t+1,"月")}}),this.init()},A.jqcCalendar.prototype.init=function(){this.el.addClass("jqcCalendar-container"),this.decodeData(),this.renderHeader(),this.renderContextmenu(),this.canEditor&&this.body.addClass("canEditor")},A.jqcCalendar.prototype.renderHeader=function(){var t=this;this.header=A("<div>").addClass("jqcCalendar-header"),this.el.append(this.header),this.titleEl=A("<p>").addClass("jqcCalendar-title");var e=A("<div>").addClass("jqcCalendar-select"),a=A("<div>").addClass("jqcCalendar-switch-box");this.prev=A("<span>").addClass("jqcCalendar-prev-btn"),this.currentInfo=A("<span>").addClass("jqcCalendar-currentInfo"),this.next=A("<span>").addClass("jqcCalendar-next-btn"),a.append(this.prev,this.currentInfo,this.next),this.header.append(this.titleEl,a,e),this.yearSelect=A('<input type="text"/>').addClass("jqcCalendar-yearSelect"),this.monthSelect=A('<input type="text"/>').addClass("jqcCalendar-monthSelect"),e.append(this.yearSelect,this.monthSelect),this.renderBody(),new A.jqcSelect({el:this.yearSelect,data:this.yearData,defaultValue:this.currentYear,onSelect:function(e){t.currentYear=e.value,t.lockYear?t.lockYear=!1:(t.fillBody(),t.onMonthChange&&t.onMonthChange(t.currentYear,t.currentMonth))}}),new A.jqcSelect({el:this.monthSelect,data:this.monthData,defaultValue:this.currentMonth,onSelect:function(e){t.currentMonth=e.value,t.fillBody(),t.onMonthChange&&t.onMonthChange(t.currentYear,t.currentMonth)}}),this.prev.click(function(){t.toPrev()}),this.next.click(function(){t.toNext()})},A.jqcCalendar.prototype.renderBody=function(){var m=this,a=A("<div>").addClass("jqcCalendar-week");this.body=A("<div>").addClass("jqcCalendar-body"),this.el.append(a,this.body),e.forEach(function(e){var t=A("<div>").text(e);a.append(t)}),this.body.on("click.jqcCalendar",">div>div",function(e){var t=A(this).data("value"),a=A(this).data("memos");A(this).hasClass("jqcCalendar-prevMonth")?m.toPrev():A(this).hasClass("jqcCalendar-nextMonth")?m.toNext():m.onSelect&&m.onSelect(t,a)}),this.body.on("click",".jqcCalendar-item-more",function(e){if(e.stopPropagation(),m.contextmenu&&m.contextmenu.box&&m.contextmenu.box.remove(),A(this).hasClass("active"))m.removeMore();else{var t=A(this).siblings().clone(!0,!0),a=A(this).parent().parent(),n=a.position(),o=a.offset().top,r=a.outerWidth(),i=a.outerHeight(),d=window.innerHeight,c=n.top+i,s=A(this).position().top,l=!1;22*t.length+28+o+i>d&&(c=c-22*t.length-22-i+s,l=!0);var p=a.data("value");m.renderMore(n.left,c,t,r,p,l),A(this).addClass("active")}}),this.body.on("click",".jqcCalendar-item-tips",function(e){e.stopPropagation();var t=A(this).attr("data-index");m.onMemoSelect&&m.onMemoSelect(m.memos[t])}).on("mouseenter",".jqcCalendar-item-tips",function(){var e=A(this).attr("data-index");m.body.find("[data-index="+e+"]").addClass("hover")}).on("mouseleave",".jqcCalendar-item-tips",function(){var e=A(this).attr("data-index");m.body.find("[data-index="+e+"]").removeClass("hover")}),this.decodeMemo()},A.jqcCalendar.prototype.fillBody=function(){var i=this,d=this;this.body.empty();for(var e=new Date(+this.currentYear,+this.currentMonth-1,1),t=new Date(+this.currentYear,+this.currentMonth,0),a=e.getDay()||7,n=t.getDate(),o=new Array(n).fill(1).map(function(e,t){return{date:t+1,day:(t+a)%7||7,data:[i.currentYear,i.currentMonth,t+1]}}),r=+e,c=1;c<a;c++){var s=(h=new Date(r-=864e5)).getFullYear(),l=h.getMonth()+1,p=h.getDate();o.unshift({date:p,day:a-c||7,data:[s,l,p],type:"prev"})}a=t.getDay()||7;var m=+t;for(c=a+1;c<=7;c++){var h;s=(h=new Date(m+=864e5)).getFullYear(),l=h.getMonth()+1,p=h.getDate();o.push({date:p,day:c||7,data:[s,l,p],type:"next"})}var u=null;o.forEach(function(e,c){c%7==0&&(u=A("<div>").addClass("jqcCalendar-row"),i.body.append(u));var t=A("<div>").addClass("jqcCalendar-item").css({height:d.cellHeight});t.data("value",e),u.append(t);var a=A("<span>").addClass("jqcCalendar-date").text(C(e.date));t.append(a);var n=e.data.map(function(e){return C(e)}).join("-"),o=i.cache[n];t.data("memos",o);var s=A("<div>").addClass("jqcCalendar-item-container").text({}.content||"");t.append(s);var r=[].concat(i.cellRender(e,t,o)||{}),l=(c=0,s.innerHeight()),p=null;r.forEach(function(e){if(e&&e.data){var t=e.data;if(void 0!==t.content&&""!==t.content){if(-1!=c&&c++,l<22*c-4){var a=A("<div>").addClass("jqcCalendar-item-more").append(A("<p>").text("···"),A("<p>").text("查看全部日程"));p?p.before(a):s.append(a),c=-1}var n=t.type||0;p=A("<div>").addClass("jqcCalendar-item-tips").addClass(v[n]);var o=t.content||"",r=A("<p>").text(o).attr("title",o);p.attr("data-index",t.__index__),p.append(r);var i="";if("function"==typeof t.tip?i=_time.tip(rowData):"string"==typeof t.tip&&(i=t.tip),i){var d=A("<p>").addClass("jqcCalendar-item-tip");p.append(d),d.text(i)}s.append(p)}}}),"prev"==e.type?t.addClass("jqcCalendar-prevMonth"):"next"==e.type&&t.addClass("jqcCalendar-nextMonth"),e.data[2]==f.getDate()&&e.data[1]==f.getMonth()+1&&e.data[0]==f.getFullYear()&&t.addClass("jqcCalendar-today")}),this.setTitle(),this.currentInfo.text("".concat(C(this.currentYear),"/").concat(C(this.currentMonth)))},A.jqcCalendar.prototype.toPrev=function(){var e=this.currentMonth-1,t=this.currentYear;e<1&&(e=12,t--),t<this.startYear&&(e=1,t=this.startYear),this.currentYear!=t&&(this.lockYear=!0,this.yearSelect.val(t)),this.currentMonth!=e&&this.monthSelect.val(e)},A.jqcCalendar.prototype.toNext=function(){var e=this.currentMonth+1,t=this.currentYear;12<e&&(e=1,t++),t>this.endYear&&(e=12,t=this.endYear),this.currentYear!=t&&(this.lockYear=!0,this.yearSelect.val(t)),this.currentMonth!=e&&this.monthSelect.val(e)},A.jqcCalendar.prototype.renderContextmenu=function(){var r=this;this.contextmenu=new A.jqcContextMenu({menus:[{id:0,text:"查看日程",valid:function(e){return"item"==e.type}},{id:1,text:"新增日程",valid:function(e){return"all"==e.type&&r.canEditor}},{id:2,text:"编辑日程",valid:function(e){return"item"==e.type&&r.canEditor}},{id:3,text:"删除日程",valid:function(e){return"item"==e.type&&r.canEditor}}],onSelect:function(e){var t=e.menu.id,a=e.showData.data,n=e.showData.target;switch(t){case 0:r.viewMemo(a,n);break;case 1:r.addMemo(a,n);break;case 2:r.editorMemo(a,n);break;case 3:e=r.memos[a].data;A.jqcConfirm({icon:"warn",title:"删除日程",content:"请确认是否删除该日程 ( ".concat(e.content," )？"),onConfirm:function(){r.deleteMemo(a)}})}}}),this.body.on("contextmenu.jqcCalendar",".jqcCalendar-item,.jqcCalendar-more-container",function(e){e.preventDefault();var t=A(this).data("value"),a=A(e.target),n=null;if(1==(n=a.hasClass("jqcCalendar-item-tips")?a:a.parents(".jqcCalendar-item-tips")).length&&-1<n.attr("data-index")){var o=n.attr("data-index");r.contextmenu.show({type:"item",data:o,target:n})}else r.canEditor?r.contextmenu.show({type:"all",data:t,target:a}):r.contextmenu.hide()})},A.jqcCalendar.prototype.setTitle=function(e){if(e)return this.title=e,void this.titleEl.text(this.title);if("string"!=typeof this.title){if("function"==typeof this.title){var t=this.title(this.currentYear,this.currentMonth);this.titleEl.text(t)}}else this.titleEl.text(this.title)},A.jqcCalendar.prototype.reRender=function(e){var t=this;e&&(this.data=[].concat(e)),this.decodeData(),setTimeout(function(){t.decodeMemo()},20)},A.jqcCalendar.prototype.decodeData=function(){var a=this,n=this.adapter.type,o=this.adapter.startTime,r=this.adapter.endTime,i=this.adapter.content,d=this.adapter.tip;this.memos=[],this.data.forEach(function(e){var t={};t.type="function"==typeof n?n(e):e[n],t.startTime="function"==typeof o?o(e):e[o],t.endTime="function"==typeof r?r(e):e[r],t.content="function"==typeof i?i(e):e[i],"function"==typeof d?t.tip=d(e):"string"==typeof d&&(t.tip=e[d]),a.memos.push({data:t,dataSource:e})})},A.jqcCalendar.prototype.renderMore=function(e,t,a,n,o,r){var i=this;this.removeMore();var d=A("<div>").addClass("jqcCalendar-more-container").css({width:n,top:t,left:e});d.data("value",o),d.append(a),this.body.append(d),r&&d.addClass("is-bottom"),A(document).off("click.jqcCalendar-more"),A(document).on("click.jqcCalendar-more",function(e){2!=e.button&&(i.removeMore(),A(document).off("click.jqcCalendar-more"))})},A.jqcCalendar.prototype.removeMore=function(){this.body.find(".jqcCalendar-more-container").remove(),this.body.find(".jqcCalendar-item-more").removeClass("active")},A.jqcCalendar.prototype.createMemoEditor=function(i,e,t){var d=this,a=e.offset(),n=e.outerWidth(),o=window.innerWidth,r=window.innerHeight,c=A("<div>").addClass("jqcCalendar-memo-editor editor"),s=A(window).scrollTop(),l=t?200:313,p={left:a.left+n+5,top:a.top-12};p.top+224>=r+s&&(p.top="initial",p.bottom=r-a.top-30,c.addClass("bottom")),p.left+l>=o&&(p.left=a.left-5-l,c.addClass("jqcCalendar-memo-editor-arrow-right")),A("body").append(c),c.css(p);var m=A("<div>").addClass("jqcCalendar-memo-editor-content"),h=A("<span>").text("日程名称"),u=A("<div>"),f=A("<textarea>").addClass("jqcCalendar-memo-editor-textarea").attr("placeholder","请输入内容").attr("maxlength",140),v=A("<pre>");u.append(v,f),m.append(h,u),f.on("input",function(e){v.text(A(this).val())});var C=A("<div>").addClass("jqcCalendar-memo-editor-timebox"),y=A("<div>");h=A("<span>").text("开始时间"),u=A("<div>");var j=A("<input>").addClass("jqcCalendar-memo-editor-start").attr("placeholder","添加起始时间").prop("readonly",!0),q=A("<input>").addClass("jqcCalendar-memo-editor-start-time");u.append(j,q),y.append(h,u);var x=A("<div>");h=A("<span>").text("结束时间"),u=A("<div>");var M=A("<input>").addClass("jqcCalendar-memo-editor-end").attr("placeholder","添加结束时间").prop("readonly",!0),g=A("<input>").addClass("jqcCalendar-memo-editor-end-time");u.append(M,g),x.append(h,u),C.append(y,x);var b=A("<div>").addClass("jqcCalendar-memo-editor-type"),w=A("<span>"),k=A('<input type="text">').addClass("jqcCalendar-memo-type");h=A("<span>").text("日程标记"),(u=A("<div>")).append(w,k),b.append(h,u),c.append(m,C,b),new A.jqcSelect({el:k,data:U,defaultValue:0,cellRender:function(e,t){var a=A("<span>").css({background:t.color,width:12,height:12,"border-radius":2,display:"inline-block","margin-right":10});return A("<div>").append(a,e)},onSelect:function(e){w.css({background:e.color,width:8,height:8,"border-radius":1,display:"inline-block","margin-left":12})}});var D=A("<div>").addClass("jqcCalendar-mask");A("body").append(D);var Y=!1;if(t||(j.datetimepicker({format:"Y/m/d",onShow:function(){Y=!0},onClose:function(){setTimeout(function(){Y=!1},100)}}),M.datetimepicker({format:"Y/m/d",onShow:function(){Y=!0},onClose:function(){setTimeout(function(){Y=!1},100)}}),new A.jqcTimepicker({el:q,format:"HH:mm",onShow:function(e){Y=!0}}),new A.jqcTimepicker({el:g,format:"HH:mm",onShow:function(e){Y=!0}})),f.keyup(function(e){13==e.keyCode&&H()}),D.click(function(e){if(t)return A(document).off("keyup.memo"),j.datetimepicker("destroy"),M.datetimepicker("destroy"),c.remove(),void A(this).remove();Y?Y=!1:H()}),i){var T=A.jqcDateUtil.format(i.startTime,"yyyy/MM/dd"),S=A.jqcDateUtil.format(i.startTime,"HH:mm"),E=A.jqcDateUtil.format(i.endTime,"yyyy/MM/dd"),_=A.jqcDateUtil.format(i.endTime,"HH:mm");f.val(i.content),j.val(T),q.val(S),M.val(E),g.val(_),v.text(i.content),k.val(i.type||0)}function H(){var e=f.val().trim(),t=+new Date((j.val()+" "+q.val()).replace(/\-/g,"/")),a=+new Date((M.val()+" "+g.val()).replace(/\-/g,"/"));if(""==e)return A.jqcNotification({type:"warn",title:"取消添加日程"}),j.datetimepicker("destroy"),M.datetimepicker("destroy"),D.remove(),void c.remove();if(a<t)return A.jqcNotification({type:"error",title:"开始时间必须小于等于结束时间"}),j.datetimepicker("destroy"),void M.datetimepicker("destroy");var n=k.val();j.datetimepicker("destroy"),M.datetimepicker("destroy"),D.remove(),c.remove();var o={content:e,startTime:t,endTime:a,type:n},r={};i&&null!=i.__index__?(r={data:o,dataSource:Object.assign({},d.memos[i.__index__].dataSource,o)},d.memos[i.__index__]=r,d.onMemoUpdate&&d.onMemoUpdate(r)):(r={data:o,dataSource:o},d.memos.push(r),d.onMemoAdd&&d.onMemoAdd(r)),A(document).off("keyup.memo"),d.onMemoChange&&d.onMemoChange(r,d.memos),d.decodeMemo()}t&&(f.prop("disabled",!0),j.prop("disabled",!0),M.prop("disabled",!0),k.prop("disabled",!0),q.prop("disabled",!0),g.prop("disabled",!0)),c.click(function(e){e.stopPropagation()}),A(document).off("keyup.memo").on("keyup.memo",function(e){27==e.keyCode&&(A(document).off("keyup.memo"),j.datetimepicker("destroy"),M.datetimepicker("destroy"),c.remove(),D.remove())})},A.jqcCalendar.prototype.addMemo=function(e,t){this.createMemoEditor({startTime:+new Date(e.data),endTime:+new Date(e.data)},t)},A.jqcCalendar.prototype.editorMemo=function(e,t){var a=this.memos[e].data;this.createMemoEditor(a,t)},A.jqcCalendar.prototype.viewMemo=function(e,t){var a=this.memos[e].data,n=t.offset(),o=t.outerWidth(),r=window.innerWidth,i=window.innerHeight,d=A("<div>").addClass("jqcCalendar-memo-editor view"),c=A(window).scrollTop(),s={left:n.left+o+5,top:n.top-12};s.top+224>=i+c&&(s.top="initial",s.bottom=i-n.top-30,d.addClass("bottom")),s.left+200>=r&&(s.left=n.left-5-200,d.addClass("jqcCalendar-memo-editor-arrow-right")),A("body").append(d),d.css(s);var l=A("<div>").addClass("jqcCalendar-memo-editor-content"),p=A("<span>").text("日程名称"),m=A("<p>").text(a.content).addClass("jqcCalendar-memo-editor-text");l.append(p,m);var h=A("<div>").addClass("jqcCalendar-memo-editor-timebox");p=A("<span>").text("开始时间"),m=A("<p>").text(A.jqcDateUtil.format(+a.startTime,"yyyy/MM/dd HH:mm"));var u=A("<div>");u.append(p,m),h.append(u),p=A("<span>").text("结束时间"),m=A("<p>").text(A.jqcDateUtil.format(+a.endTime,"yyyy/MM/dd HH:mm"));var f=A("<div>");f.append(p,m),h.append(f);var v=A("<div>").addClass("jqcCalendar-memo-editor-type"),C=a.type||0;p=A("<span>").text("日程标记");var y=A("<span>").addClass("jqcCalendar-memo-editor-color");y.css({background:U[C].color}),m=A("<p>").append(y).append(U[C].label),v.append(p,m),d.append(l,h,v);var j=A("<div>").addClass("jqcCalendar-mask");A("body").append(j),j.click(function(e){A(document).off("keyup.memo"),d.remove(),A(this).remove()}),d.click(function(e){e.stopPropagation()}),A(document).off("keyup.memo").on("keyup.memo",function(e){27==e.keyCode&&(A(document).off("keyup.memo"),d.remove(),j.remove())})},A.jqcCalendar.prototype.deleteMemo=function(e){var t=this.memos[e];this.onMemoDelete&&this.onMemoDelete(t),this.memos.splice(e,1),this.onMemoChange&&this.onMemoChange(t,this.memos),this.decodeMemo()},A.jqcCalendar.prototype.decodeMemo=function(){var i=this,e=this;this.cache={},this.memos.forEach(function(t,e){var a=t.data.startTime||t.data.endTime,n=t.data.endTime||t.data.startTime,o=[];Object.assign({},t.data,{__index__:e});if(t.data.__index__=e,a==n)o.push(A.jqcDateUtil.format(a));else for(a=A.jqcDateUtil.format(a),n=A.jqcDateUtil.format(n);a<=n;){o.push(a);var r=A.jqcDateUtil.plusDays(a,1);a=A.jqcDateUtil.format(r)}o.forEach(function(e){i.cache[e]||(i.cache[e]=[]),i.cache[e].push(t)})}),setTimeout(function(){e.fillBody()},20)}})}(jQuery);