From 4f65f8c746fced7bce54a1073e7cbfaf3b104713 Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Tue, 02 Jan 2018 15:51:29 +0800 Subject: [PATCH] 账户管理 --- src/app/routes/systems/account/account.component.ts | 75 ++++++++++++++---------- src/app/routes/systems/account/account-edit/account-edit.component.html | 31 +++++----- src/app/routes/systems/account/account-edit/account-edit.component.ts | 38 ++++++++++-- src/app/routes/systems/account/account.component.html | 12 ++- 4 files changed, 96 insertions(+), 60 deletions(-) diff --git a/src/app/routes/systems/account/account-edit/account-edit.component.html b/src/app/routes/systems/account/account-edit/account-edit.component.html index eb904a2..0b0e58f 100644 --- a/src/app/routes/systems/account/account-edit/account-edit.component.html +++ b/src/app/routes/systems/account/account-edit/account-edit.component.html @@ -1,49 +1,48 @@ <div class="modal-header"> <div class="modal-title">{{account.id > 0 ? '������' : '������'}} - ������</div> </div> -<form #f="ngForm" (ngSubmit)="save()" nz-form [nzType]="'horizontal'"> +<form (ngSubmit)="save()" nz-form [nzType]="'horizontal'" [formGroup]="validateForm"> <div nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSpan]="4"> - <label>������</label> + <label nz-form-item-required>������</label> </div> - <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="account.accountName" name="name" maxlength="30" required [nzDisabled]="account.id > 0 ? true : false" /> + <div nz-form-control nz-col [nzSpan]="8" nzHasFeedback [nzValidateStatus]="accountName"> + <input nz-input formControlName="accountName" maxlength="30" required [nzDisabled]="account.id > 0 ? true : false" /> + <div nz-form-explain *ngIf="validateForm.controls.accountName.dirty&&validateForm.controls.accountName.hasError('required')">Please input your username!</div> </div> <div nz-form-label nz-col [nzSpan]="4"> <label>������</label> </div> - <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="account.mobile" name="mobile" maxlength="11" required /> + <div nz-form-control nz-col [nzSpan]="8" > + <input nz-input maxlength="11" formControlName="mobile"/> </div> </div> <div nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSpan]="4"> <label>������������</label> </div> - <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="account.email" name="email" required /> + <div nz-form-control nz-col [nzSpan]="8" > + <input nz-input formControlName="email" /> </div> <div nz-form-label nz-col [nzSpan]="4"> <label>���������</label> </div> - <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="account.weixin" name="weixin" /> + <div nz-form-control nz-col [nzSpan]="8" > + <input nz-input formControlName="weixin" /> </div> </div> <div nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSpan]="4"> <label>������</label> </div> - <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="account.organizationId" name="organizationId" maxlength="20" placeholder="20���������" /> + <div nz-form-control nz-col [nzSpan]="8" > + <input nz-input formControlName="organizationId" maxlength="20" placeholder="20���������" /> </div> <div nz-form-label nz-col [nzSpan]="4"> <label>������������</label> </div> - <div nz-form-control nz-col [nzSpan]="8"> - <div nz-form-control [nzValidateStatus]="expireTime" > - <nz-datepicker [(ngModel)]="account.expireTime" name="expireTime"></nz-datepicker> - </div> + <div nz-form-control nz-col [nzSpan]="8" > + <nz-datepicker formControlName="expireTime" nzShowTime></nz-datepicker> </div> </div> <!-- <div nz-form-item nz-row class="mb-sm"> diff --git a/src/app/routes/systems/account/account-edit/account-edit.component.ts b/src/app/routes/systems/account/account-edit/account-edit.component.ts index 52ec4e7..b4999f5 100644 --- a/src/app/routes/systems/account/account-edit/account-edit.component.ts +++ b/src/app/routes/systems/account/account-edit/account-edit.component.ts @@ -4,6 +4,7 @@ import {HttpClient} from '@angular/common/http'; import {environment} from '../../../../../environments/environment'; import {DateService} from '../../../../core/services/date.service'; +import {FormGroup, FormBuilder, Validators} from '@angular/forms'; @Component({ selector: 'app-account-edit', @@ -13,23 +14,46 @@ export class AccountEditComponent implements OnInit { account: any; + validateForm: FormGroup; constructor(private modalHelper: ModalHelper, private subject: NzModalSubject, public dateSrv: DateService, public msgSrv: NzMessageService, - public http: HttpClient) {} + public http: HttpClient, + private formBuilder: FormBuilder + ) { + + } ngOnInit() { - } - - save() { - this.http.post(environment.SERVER_BASH_URL + '/account/account', this.account).subscribe(() => { - this.subject.next('true'); - this.close(); + this.validateForm = this.formBuilder.group({ + accountName: [this.account.accountName], + mobile: [this.account.mobile], + email: [this.account.email], + weixin: [this.account.weixin], + organizationId: [this.account.organizationId], + expireTime: [this.account.expireTime], + id:[this.account.id] }); } + save() { + if (this.validateForm.valid) { + for (const i in this.validateForm.controls) { + this.validateForm.controls[i].disable(); + } + this.http.post(environment.SERVER_BASH_URL + '/account/account', this.validateForm.value).subscribe(() => { + this.subject.next('true'); + this.close(); + }); + } else { + for (const i in this.validateForm.controls) { + this.validateForm.controls[i].markAsDirty(); + } + } + } + close() { this.subject.destroy(); } diff --git a/src/app/routes/systems/account/account.component.html b/src/app/routes/systems/account/account.component.html index 09d86a2..5c458ac 100644 --- a/src/app/routes/systems/account/account.component.html +++ b/src/app/routes/systems/account/account.component.html @@ -43,11 +43,11 @@ </form> <div class="mb-md"> - <button nz-button (click)="add()" [nzType]="'primary'" [nzSize]="'large'"> + <button nz-button (click)="edit()" [nzType]="'primary'" [nzSize]="'large'"> <i class="anticon anticon-plus"></i><span>������</span> </button> <ng-container *ngIf="selectedRows.length > 0"> - <button nz-button [nzSize]="'large'" (click)="remove()">������������</button> + <button nz-button [nzSize]="'large'" (click)="remove()" >������������</button> </ng-container> </div> @@ -72,7 +72,9 @@ <th nz-th [nzCheckbox]="true"> <label nz-checkbox [(ngModel)]="allChecked" [nzIndeterminate]="indeterminate" (ngModelChange)="checkAll($event)"></label> </th> - <th nz-th><span>������</span></th> + <th nz-th><span>������</span> + <nz-table-sort (nzValueChange)="sort('account_name', $event)"></nz-table-sort> + </th> <th nz-th><span>������</span></th> <th nz-th><span>������������</span></th> <th nz-th><span>���������</span></th> @@ -81,7 +83,7 @@ <th nz-th><span>������������</span></th> <th nz-th> <span>������������</span> - <nz-table-sort [(nzValue)]="sortMap.updatedAt" (nzValueChange)="sort('expire_time', $event)"></nz-table-sort> + <nz-table-sort (nzValueChange)="sort('expire_time', $event)"></nz-table-sort> </th> <th nz-th><span>������</span></th> </tr> @@ -103,7 +105,7 @@ <a (click)="edit(account)">������</a> <ng-container *ngIf="account.isDelete == '0'"> <span nz-table-divider></span> - <nz-popconfirm [nzTitle]="'���������������������������?'" [nzOkText]="'Yes'" [nzCancelText]="'No'" (nzOnConfirm)="delete(account)" > + <nz-popconfirm [nzTitle]="'���������������������������?'" [nzOkText]="'Yes'" [nzCancelText]="'No'" (nzOnConfirm)="remove(account.id)" > <a nz-popconfirm>������</a> </nz-popconfirm> </ng-container> diff --git a/src/app/routes/systems/account/account.component.ts b/src/app/routes/systems/account/account.component.ts index 7d925d8..0f532d3 100644 --- a/src/app/routes/systems/account/account.component.ts +++ b/src/app/routes/systems/account/account.component.ts @@ -1,5 +1,5 @@ import {Component, OnInit} from '@angular/core'; -import {NzMessageService} from 'ng-zorro-antd'; +import {NzMessageService, NzModalService} from 'ng-zorro-antd'; import {ModalHelper} from '@delon/theme'; import {HttpClient} from '@angular/common/http'; import * as moment from 'moment'; @@ -31,18 +31,20 @@ selectedRows: any[] = []; allChecked = false; indeterminate = false; - sortMap: any = {}; + sortMap: string[] = []; constructor( public http: HttpClient, + private confirmServ: NzModalService, public dateSrv: DateService, public msgSrv: NzMessageService, - private modalHelper: ModalHelper) { + private modalHelper: ModalHelper + ) { } load(reload: boolean = false) { - if (reload) { + if (reload) { this.query.pageIndex = 1; } this.http.get(environment.SERVER_BASH_URL + '/account/list', {params: this.query}).subscribe((res: any) => { @@ -58,23 +60,30 @@ } edit(account) { - this.modalHelper.static(AccountEditComponent, {account}).subscribe(() => { - this.load(true); - this.msgSrv.success('���������������������'); + if (account == null) { + account = {}; + } + this.modalHelper.static(AccountEditComponent, {account}).subscribe((res: any) => { + if (res.code == 0) { + this.msgSrv.error(res.message); + } else { + this.msgSrv.success('���������������������'); + this.load(true); + } }); } - add() { - const account = {}; - this.modalHelper.static(AccountEditComponent, {account}).subscribe(() => { - this.load(true); - this.msgSrv.success('���������������������'); - }); - } - - delete(account) { - this.http.post(environment.SERVER_BASH_URL + '/account/account/id' , account).subscribe((res: any) => { - if(res.data > 0){ + remove(accountId) { + const ids = []; + if (accountId == null) { + this.selectedRows.forEach(i => { + ids.push(i.id); + }); + } else { + ids.push(accountId); + } + this.http.post(environment.SERVER_BASH_URL + '/account/ids', ids).subscribe((res: any) => { + if (res.data > 0) { this.msgSrv.success('���������������������'); this.load(true); } else { @@ -83,19 +92,13 @@ }); } - remove() { - const ids = []; - this.selectedRows.forEach(i => { - ids.push(i.id); - }); - this.http.post(environment.SERVER_BASH_URL + '/account/accounts/ids', ids).subscribe((res: any) => { - this.load(true); - }); - } - checkAll(value: boolean) { this.data.forEach(i => { - i.checked = value; + if (i.isDelete == '1') { + i.checked = false; + } else { + i.checked = value; + } }); this.refreshStatus(); } @@ -109,9 +112,17 @@ } sort(field: string, value: any) { - this.sortMap = {}; - this.sortMap[field] = value; - this.query.sorter = value ? `${field} ${value}` : ''; + const ids = this.sortMap; + this.sortMap = []; + ids.forEach(i => { + if (!i.startsWith(field)) { + this.sortMap.push(i); + } + }); + if (value != null) { + this.sortMap.push(`${field} ${value}`); + } + this.query.sorter = this.sortMap.length > 0 ? this.sortMap.join(",") : ''; this.load(true); } -- Gitblit v1.8.0