import {
OnInit,
Component,
Input,
HostBinding,
Output,
EventEmitter,
AfterContentInit
} from '@angular/core';
import { WizardComponent } from '../wizard/wizard.component';
import { PageService } from '../service/page.service';
@Component({
selector: 'wizard-page',
template: '',
styleUrls: ['./page.component.scss'],
providers: [PageService]
})
export class FarrisWizardPageComponent implements OnInit,AfterContentInit {
// 唯一标记
@Input() pageId = '';
// 默认class
@HostBinding('class.f-component-wizard-page') addClass = true;
@HostBinding('class.active') get activeCls() {
return this._active;
}
private _active = false;
// 当前选中
@Input()
set active(value: boolean) {
this._active = value;
if (this.pageId) {
this.doAfterActive();
}
}
get active(): boolean {
return this._active;
}
@Output() pageSelected: EventEmitter = new EventEmitter();
wizardSet: WizardComponent;
constructor(wizardSet: WizardComponent, private pageSer: PageService) {
this.wizardSet = wizardSet;
this.wizardSet.addPage(this);
}
ngOnInit() {
//console.log('FarrisWizardPageComponent——' + this.pageId);
this.pageSer.setPageId(this.pageId);
}
ngAfterContentInit(){
this.doAfterActive();
}
getPageId() {
return this.pageId;
}
/**
*
* @param value
*/
setPageActive(value: boolean) {
if (this.active !== value) {
this.active = value;
}
}
/**
* 处理Active
*/
doAfterActive() {
this.pageSelected.emit({
pageId: this.pageId,
state: this.active
});
//console.log('FarrisWizardPageComponent——' + this.pageid + this.active);
this.pageSer.activeState.next({
pageId: this.pageId,
state: this.active
});
}
}