src/app/crm/contact/contact.component.ts
| encapsulation | ViewEncapsulation.None |
| selector | crm-contact-upate |
| styleUrls | ./update.component.scss |
| templateUrl | ./update.component.html |
Properties |
|
constructor(data: any)
|
||||||
|
Defined in src/app/crm/contact/contact.component.ts:109
|
||||||
|
Parameters :
|
| Public data |
Type : any
|
Decorators :
@Inject(MAT_DIALOG_DATA)
|
|
Defined in src/app/crm/contact/contact.component.ts:110
|
import {
Component,
OnInit,
Inject,
ViewEncapsulation,
ViewChild
} from '@angular/core';
import { MatDialog } from '@angular/material';
import { MAT_DIALOG_DATA } from '@angular/material';
import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
import { SelectionModel } from '@angular/cdk/collections';
import { ContactService } from './contact.service';
@Component({
selector: 'crm-contact',
templateUrl: './contact.component.html',
styleUrls: ['./contact.component.scss']
})
export class ContactComponent implements OnInit {
displayedColumns: string[] = [
'select',
'name',
'phone',
'relation',
'company',
'mail',
'star'
];
dataSource: any = new MatTableDataSource([]);
selection = new SelectionModel(true, []);
@ViewChild(MatPaginator, { static: false }) paginator: MatPaginator;
@ViewChild(MatSort, { static: false }) sort: MatSort;
constructor(private service: ContactService, private dialog: MatDialog) { }
ngOnInit() {
this.service.getList().subscribe(res => {
this.dataSource = new MatTableDataSource(res);
this.dataSource.paginator = this.paginator;
});
}
isAllSelected() {
const numSelected = this.selection.selected.length;
const numRows = this.dataSource.data.length;
return numSelected === numRows;
}
masterToggle() {
this.isAllSelected()
? this.selection.clear()
: this.dataSource.data.forEach(row => this.selection.select(row));
}
rowSelection(row, event) {
this.selection.toggle(row);
this.onUpdateContact(row);
}
onNew(event) {
let dialogRef = this.dialog.open(ContactUpdateComponent, {
width: '500px',
data: {}
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
});
}
onEditorTriggered(item) {
console.log(item);
let dialogRef = this.dialog.open(ContactUpdateComponent, {
width: '500px',
data: item
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
});
}
onDeleteTriggered() {
console.log(this.selection.selected);
// this.service.delete(this.selection.selected);
}
onUpdateContact(contact) {
const dialogRef = this.dialog.open(ContactUpdateComponent, {
width: '400px',
panelClass: 'contact-dialog-form',
data: contact
});
dialogRef.afterClosed().subscribe(result => {
console.log(result);
});
}
}
@Component({
selector: 'crm-contact-upate',
templateUrl: './update.component.html',
styleUrls: ['./update.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class ContactUpdateComponent {
constructor(@Inject(MAT_DIALOG_DATA) public data: any) { }
}
<div class="header-container">
<div class="contact-dialog-title" fxLayout="row" fxLayoutAlign="space-between">
<div class="text-white">联系人</div>
<button mat-icon-button mat-dialog-close>
<mat-icon>close</mat-icon>
</button>
</div>
</div>
<mat-dialog-content>
<form>
<mat-form-field class="display-block">
<mat-icon class="form-icon" matPrefix>account_circle</mat-icon>
<input type="text" matInput placeholder="姓名" [value]="data.name">
</mat-form-field>
<mat-form-field class="display-block">
<mat-icon class="form-icon" matPrefix>account_circle</mat-icon>
<input type="text" matInput placeholder="手机号码" [value]="data.phone">
</mat-form-field>
<mat-form-field class="display-block">
<mat-icon class="form-icon" matPrefix>account_circle</mat-icon>
<input type="text" matInput placeholder="邮箱" [value]="data.mail">
</mat-form-field>
</form>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button mat-dialog-close>取消</button>
<button mat-raised-button color="primary" [mat-dialog-close]="true" cdkFocusInitial>更新</button>
</mat-dialog-actions>
./update.component.scss
.display-block {
display: block !important;
}
.form-icon {
margin-right: 12px;
}
.header-container {
margin: 0 -30px;
height: 200px;
background: linear-gradient(90deg, #00d9bf, #00d977);
margin-bottom: 30px;
}
.contact-dialog-title {
padding: {
top: 10px;
bottom: 10px;
}
margin: {
left: 20px;
right: 20px;
}
line-height: 40px;
}
.mat-dialog-container {
padding-top: 0 !important;
}