【发布时间】:2020-01-23 03:16:47
【问题描述】:
我正在使用 primeng 日历来管理医疗预约的安排,我希望在为医生选择日期时,将他的开始和结束时间分为 30 分钟并显示在我的 html 中。
这里是我医生的计划数据的json渲染:[{"id":18,"planning":null,"day":"Lundi","startHour":"08:00","endHour":"17:00","isFree":true},{"id":19,"planning":null,"day":"Mardi","startHour":"09:00","endHour":"18:00","isFree":true},{"id":20,"planning":null,"day":"Mercredi","startHour":"10:00","endHour":"19:00","isFree":true},{"id":21,"planning":null,"day":"Jeudi","startHour":"11:00","endHour":"20:00","isFree":true},{"id":22,"planning":null,"day":"Vendredi","startHour":"12:00","endHour":"21:00","isFree":true},{"id":23,"planning":null,"day":"Samedi","startHour":"00:00","endHour":"00:00","isFree":false},{"id":24,"planning":null,"day":"Dimanche","startHour":"00:00","endHour":"00:00","isFree":false}]
我希望我的 html 以 30 分钟为单位显示医生的工作时间(开始和结束时间)。 这是我检索医生计划数据的 ts:
private loadDocdate() {
this.httpClient.get<UserResponse>('http://127.0.0.1:8000/api/medecin/details/' + this.medecinId, this.options).subscribe((data: any) => {
this.DocPlanning = data.medecin.planning;
console.log(JSON.stringify(this.DocPlanning.planningLines));
});
}
还有我的 HTML:
<ion-content fullscreen>
<ion-text style="font-weight: bold; text-align: center">Choisissez votre Date</ion-text>
<p-calendar [hidden]="dateValue" [(ngModel)]="dateValue" [inline]="true" [locale]="fr" dateFormat="dd-mm-yy"
(click)="presentAlert()">
</p-calendar>
<div>
<p-calendar [hidden]="!dateValue" [(ngModel)]="value" [timeOnly]="true" hourFormat="24"
></p-calendar>
</div>
</ion-content>
HTML 的 presentAlert() 函数
presentAlert() {
const currentDate = this.dateValue;
const weekdays = ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"];
this.days = weekdays[currentDate.getDay()];
console.log(this.days);
this.planningMedecin = this.DocPlanning.planningLines;
this.planningMedecin.forEach(element => {
if (element.day === this.days && element.isFree === true ) {
this.getAlert();
let slots = this.getTimeSlots(element.startHour, element.endHour);
console.log(slots);
}
if (element.day === this.days && element.isFree !== true) {
this.errorAlert();
}
});
}
async getAlert() {
const alert = await this.alertCtrl.create({
message: 'Low battery',
subHeader: '10% of battery remaining',
buttons: ['ok']
});
await alert.present();
}
async errorAlert() {
const alert = await this.alertCtrl.create({
message: 'La date que vous avez choisie est indisponible',
subHeader: 'Nous sommes desoles',
buttons: ['ok']
});
await alert.present();
}
谢谢
【问题讨论】:
标签: html datetime ionic-framework ionic4 datetimepicker