UNPKG

book-picker

Version:

<p align="center"> <img width="409" height="331" src="https://raw.githubusercontent.com/ymxk/book-picker/master/book-picker.gif"> </p>

2 lines 10.8 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("ngx-moment"),require("moment"),require("jspath")):"function"==typeof define&&define.amd?define("book-picker",["exports","@angular/core","@angular/common","ngx-moment","moment","jspath"],e):e((t=t||self)["book-picker"]={},t.ng.core,t.ng.common,t.ngxMoment,t.moment,t.jspath)}(this,function(t,e,o,n,i,r){"use strict";i=i&&i.hasOwnProperty("default")?i["default"]:i,r=r&&r.hasOwnProperty("default")?r["default"]:r;var s=function(){function t(){this.name="Book Picker",this.bookeds=new Array,this.hours=new Array,this.selected=new e.EventEmitter,this.onerror=new e.EventEmitter}return t.prototype.onSelectedDate=function(t){this.selectedDate=t.clone(),this.timeRange=null},t.prototype.onSelectedTime=function(t){this.timeRange=t,this.selected.emit(t)},t.prototype.onErrorTime=function(){this.onerror.emit()},t.decorators=[{type:e.Component,args:[{selector:"book-picker",template:'<app-date-picker (selected)="onSelectedDate($event)"></app-date-picker>\n<app-time-picker [nowTime]="selectedDate" [bookeds]="bookeds" [hours]="hours" (selected)="onSelectedTime($event)" (onerror)="onErrorTime()"></app-time-picker>\n<app-book-info [timeRange]="timeRange"></app-book-info>',styles:["p{font-family:Lato}"]}]}],t.propDecorators={bookeds:[{type:e.Input}],hours:[{type:e.Input}],selected:[{type:e.Output}],onerror:[{type:e.Output}]},t}(),a=function(){return function(t,e){this.start=t,this.end=e}}(),c="time-booked",d="time-disable",p="time-selected",l="",u=function(){function t(){this.timeCells=[],this.nowTime=i(),this.bookeds=new Array,this.hours=new Array,this.selected=new e.EventEmitter,this.onerror=new e.EventEmitter}return t.prototype.ngOnInit=function(){this.initBooksOrHours(),this.getHoursForDays()},t.prototype.initBooksOrHours=function(){this.bookeds||(this.bookeds=new Array),this.hours||(this.hours=new Array)},t.prototype.onClear=function(){this.start=null,this.end=null},t.prototype.emitSelected=function(){this.selected.emit({start:this.start,end:this.addHalfHour(this.end)})},t.prototype.addHalfHour=function(t){return t?t.clone().add(30,"m"):null},t.prototype.emitError=function(){this.onerror.emit()},t.prototype.onSelected=function(t){if(this.start&&this.end&&this.start.isSame(t,"m")&&this.end.isSame(t,"m"))return this.onClear(),this.emitSelected(),!1;if(this.start&&this.end&&this.start.isSame(t,"m"))return this.start=this.end,this.emitSelected(),!1;if(this.start&&this.end&&this.end.isSame(t,"m"))return this.end=this.start,this.emitSelected(),!1;if(!this.start&&!this.end)return this.includesDisable(t.clone(),t.clone())?(this.emitError(),!1):(this.start=t,this.end=t,this.emitSelected(),!1);if(t.isBefore(this.start)){if(this.includesDisable(t.clone(),this.start.clone()))return this.emitError(),!1;this.end=this.start,this.start=t}if(t.isAfter(this.start)){if(this.includesDisable(this.start.clone(),t.clone()))return this.emitError(),!1;this.end=t}this.emitSelected()},t.prototype.includesDisable=function(t,e){for(var o=this,n=[],i=t;i.isBefore(e)||i.isSame(e);i.add(30,"m"))n.push(i.clone());return n.filter(function(t){return o.includesBooked(t)||o.includesCloses(t)}).length>0},t.prototype.includesBooked=function(t){var e=this;return this.bookeds.filter(function(o){return e.isBetweenDate(t,o.start,o.end)}).length>0},t.prototype.includesCloses=function(t){var e=this,o=this.getOpenHoursOnDated();return!(!o||0!=o.length)||0==o.filter(function(o){return e.isBetweenNotEnd(t,o.opens,o.closes)}).length},t.prototype.isBetweenNotEnd=function(t,e,o){var n=this.setHourMinuteIgnorDate(t),i=this.setHourMinuteIgnorDate(e),r=this.setHourMinuteIgnorDate(o);return!(!n.isBetween(i,r,"m")&&!n.isSame(i,"m"))},t.prototype.isBetweenDate=function(t,e,o){return t.isBetween(e,o)||t.isSame(e)||t.isSame(o)},t.prototype.isBetweenM=function(t,e,o){return t.isBetween(e,o,"m")||t.isSame(e,"m")||t.isSame(o,"m")},t.prototype.getClassBy=function(t){return this.includesBooked(t)?c:this.includesCloses(t)?d:this.isBetweenM(t,this.start,this.end)?p:l},t.prototype.isSameDay=function(t){return i().isSame(t,"month")&&i().isSame(t,"day")},t.prototype.getDefaultOpenHours=function(){return new a(this.nowTime.clone().startOf("day"),this.nowTime.clone().endOf("day"))},t.prototype.nextHalfHourInNow=function(){var t=parseFloat(this.nowTime.clone().format("mm"))%30;return this.addHalfHour(this.nowTime.clone().subtract(t,"m"))},t.prototype.replaceStartByNow=function(t){var e=this.setHourMinuteIgnorDate(t.start);return this.isSameDay(e)?new a(this.nextHalfHourInNow(),t.end):t},t.prototype.getHoursForDays=function(){var t=this.getOpenHoursOnDated();t&&t.length>0?this.createHours(this.toHoursOfDayFrom(t)):this.createHours(this.getDefaultOpenHours())},t.prototype.setHourMinuteIgnorDate=function(t){return this.nowTime.clone().hour(t.hour()).minute(t.minute())},t.prototype.createHours=function(t){var e=this.replaceStartByNow(t),o=e.start.clone(),n=e.end.clone();this.timeCells=[];for(var i=o;i.isBefore(n);i.add(30,"m"))this.timeCells.push(i.clone())},t.prototype.getOpenHoursOnDated=function(){var t=this;return this.hours.filter(function(e){return e.weeks.includes(t.nowTime.day())})},t.prototype.toHoursOfDayFrom=function(t){var e=r.apply(".opens",t),o=r.apply(".closes",t);return new a(this.setHourMinuteIgnorDate(i.min(e)),this.setHourMinuteIgnorDate(i.max(o)))},t.prototype.ngOnChanges=function(t){for(var e in t){var o=t[e];o.isFirstChange()?this.nowTime=i():(this.onClear(),this.nowTime=o.currentValue,this.getHoursForDays())}},t.decorators=[{type:e.Component,args:[{selector:"app-time-picker",template:'<section class="card">\n\n\t<div *ngFor="let c of timeCells" [ngClass]="getClassBy(c)">\n\t\t<div (click)="onSelected(c)">{{c | amDateFormat: \'HH:mm\'}}</div>\n\t</div>\n</section>',styles:['@charset "UTF-8";.card{display:-webkit-flex;display:flex;min-width:100%;min-height:54px;overflow-x:auto;border-top:1px solid #e9e9e9;border-bottom:1px solid #e9e9e9}.card>div{min-width:55px;height:54px;background-color:#fff;text-align:center;border-left:1px solid #e9e9e9}.card>div>div:first-child{font-size:13px;font-family:PingFangSC-Regular;font-weight:400;color:#242424;line-height:54px}.card>div:last-child{border-right:1px solid #e9e9e9}.card::-webkit-scrollbar{display:none}.time-disable div{background:#fbfbfb;color:#c4c4c4!important;line-height:14px!important;padding:20px 0 0 2px}.time-disable ::after{content:"\\a未营业";white-space:pre-wrap;font-size:10px;color:#c4c4c4}.time-selected div{background:#e5f2ff!important;color:#007aff!important;border-left:0!important}.time-booked div{background:#fbfbfb;color:#c4c4c4!important;line-height:14px!important;padding:20px 0 0 2px}.time-booked ::after{content:"\\a已预订";white-space:pre-wrap;font-size:10px;color:#c4c4c4}']}]}],t.ctorParameters=function(){return[]},t.propDecorators={nowTime:[{type:e.Input}],bookeds:[{type:e.Input}],hours:[{type:e.Input}],selected:[{type:e.Output}],onerror:[{type:e.Output}]},t}(),h=function(){function t(){this.days=[],this.selectedDate=i(),this.endDayForMonth=i().add(15,"d"),this.selected=new e.EventEmitter}return t.prototype.ngOnInit=function(){this.getDaysForMonth()},t.prototype.onSelected=function(t){this.selectedDate=t,this.selected.emit(t)},t.prototype.isSameDay=function(t){return this.selectedDate.isSame(t,"day")?"date-selected":""},t.prototype.getDaysForMonth=function(){for(var t=i();t.isBefore(this.endDayForMonth);t.add(1,"d"))this.days.push(t.clone())},t.decorators=[{type:e.Component,args:[{selector:"app-date-picker",template:'<div class="date-title">{{selectedDate | amDateFormat: \'YYYY\'}}</div>\n<section class="card">\n\t<div class="card--content" *ngFor="let day of days" [ngClass]="isSameDay(day)" (click)="onSelected(day)">\n\t\t<div>{{day | weekdays}}</div>\n\t\t<div>{{day | amDateFormat: \'M/D\'}}</div>\n\t</div>\n</section>',styles:[".card{display:-webkit-flex;display:flex;min-width:100%;min-height:86px;overflow-x:auto}.card::-webkit-scrollbar{display:none}.card--content{min-width:55px;height:86px;background-color:#fff;text-align:center}.card--content div:first-child{height:18px;font-size:13px;font-family:PingFangSC-Regular;font-weight:400;color:#999;line-height:18px;margin:19px 0 10px}.card--content div:last-child{height:21px;line-height:21px;font-size:15px;font-family:PingFangSC-Medium;font-weight:500;color:#242424}.date-title{width:100%;height:46px;line-height:46px;background:#f8f8f8;font-size:17px;font-family:PingFangSC-Medium;font-weight:1000;color:#242424;text-align:center}.date-selected div{color:#007aff!important}"]}]}],t.ctorParameters=function(){return[]},t.propDecorators={selected:[{type:e.Output}]},t}(),f=function(){function t(){}return t.prototype.ngOnInit=function(){},t.decorators=[{type:e.Component,args:[{selector:"app-book-info",template:'<div class="book-info" *ngIf="timeRange && timeRange.start && timeRange.end">\n\t<label>共计 {{timeRange | booktime}} 小时</label>\n <div><i class="iconfont icon-clock"></i> {{timeRange | timetable}} </div>\n</div>',styles:[".book-info{padding:17px 20px}.book-info label{width:90px;background:#f8f8f8;border-radius:2px;font-size:13px;font-family:PingFangSC-Regular;font-weight:400;color:#999;line-height:23px;display:inline-block;text-align:center}.book-info div:last-child{height:24px;line-height:24px;font-size:15px;font-family:PingFangSC-Regular;font-weight:400;color:#242424;margin-top:10px}"]}]}],t.ctorParameters=function(){return[]},t.propDecorators={timeRange:[{type:e.Input}]},t}(),m=function(){function t(){this.now=i(),this.weekdays=["日","一","二","三","四","五","六"]}return t.prototype.transform=function(t){return t?this.now.isSame(t,"day")?"今日":this.weekdays[t.day()]:""},t.decorators=[{type:e.Pipe,args:[{name:"weekdays"}]}],t}(),y=function(){function t(){}return t.prototype.transform=function(t){return t&&t.end&&t.start?this.formatTime(t):this.defaultFormatTime()},t.prototype.formatTime=function(t){return t.start.clone().format("M月D日 HH:mm")+"~"+t.end.clone().format("HH:mm")},t.prototype.defaultFormatTime=function(){return i().format("M月D日 HH:mm")+"~"+i().format("HH:mm")},t.decorators=[{type:e.Pipe,args:[{name:"timetable"}]}],t}(),g=function(){function t(){}return t.prototype.transform=function(t){return t&&t.end&&t.start?""+i.duration(t.end.diff(t.start)).asHours():"0"},t.decorators=[{type:e.Pipe,args:[{name:"booktime"}]}],t}(),w=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[o.CommonModule,n.MomentModule],declarations:[u,h,f,m,y,g,s],exports:[s]}]}],t}();t.BookPickerComponent=s,t.BookPickerModule=w,t.ɵa=u,t.ɵb=h,t.ɵc=f,t.ɵd=m,t.ɵe=y,t.ɵf=g,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=book-picker.umd.min.js.map