Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
feat: 账户支持冻结&&冻结账户不再出现再下拉框选项中
Browse files Browse the repository at this point in the history
  • Loading branch information
forecho committed Oct 21, 2020
1 parent aff660c commit d288924
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 56 deletions.
45 changes: 39 additions & 6 deletions src/app/routes/account/form/form.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
<div class="modal-header">
<div class="modal-title">任务编辑</div>
<div class="modal-title">账户编辑</div>
</div>
<sf #sf mode="edit" [schema]="schema" [formData]="record" button="none">
<div class="modal-footer">

<form nz-form #f="ngForm" se-container="1" (ngSubmit)="save(form)" labelWidth="100">
<se label="名称">
<input type="text" nz-input [(ngModel)]="form.name" name="name" required />
</se>
<se label="类型">
<nz-select [(ngModel)]="form.type" name="type" required>
<nz-option nzCustomContent [nzLabel]="i.name" [nzValue]="i.type" *ngFor="let i of accountTypes">
<i nz-icon nzIconfont="icon-{{ i.type }}"></i> {{ i.name }}
</nz-option>
</nz-select>
</se>
<se label="余额">
<nz-input-group [nzAddOnAfter]="addOnAfterBtn">
<input nz-input type="number" [(ngModel)]="form.currency_balance" name="currency_balance" required />
<ng-template #addOnAfterBtn>
<nz-select [(ngModel)]="form.currency_code" name="currency_code" style="width: 80px;">
<nz-option nzLabel="CNY" nzValue="CNY"></nz-option>
</nz-select>
</ng-template>
</nz-input-group>
</se>
<se label="状态">
<nz-radio-group [(ngModel)]="form.status" nzButtonStyle="solid" name="status">
<label nz-radio-button nzValue="active"> <span>启用</span> </label>
<label nz-radio-button nzValue="unactivated"> <span>冻结</span> </label>
</nz-radio-group>
</se>
<se label="默认账号" col="1">
<nz-switch [(ngModel)]="form.default" name="default" [nzDisabled]="form.default"></nz-switch>
</se>
<se label="不计入统计" col="1">
<nz-switch [(ngModel)]="form.exclude_from_stats" name="exclude_from_stats"></nz-switch>
</se>
<se col="1">
<button nz-button type="button" (click)="close()">关闭</button>
<button nz-button type="submit" [nzType]="'primary'" (click)="save(sf.value)" [disabled]="!sf.valid">保存</button>
</div>
</sf>
<button nz-button nzType="primary" [disabled]="f.invalid">保存</button>
</se>
</form>
65 changes: 17 additions & 48 deletions src/app/routes/account/form/form.component.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,30 @@
import { Component } from '@angular/core';
import { SFSchema, SFSelectWidgetSchema } from '@delon/form';
import { Component, OnInit } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { map } from 'rxjs/operators';

@Component({
selector: 'app-account-form',
templateUrl: './form.component.html',
})
export class AccountFormComponent {
export class AccountFormComponent implements OnInit {
record: any = {};
schema: SFSchema = {
properties: {
name: { type: 'string', title: '名称', maxLength: 50 },
type: {
type: 'string',
title: '帐户类别',
default: 'general_account',
ui: {
widget: 'select',
asyncData: () => {
return this.http.get('/api/accounts/types').pipe(
map((res) => {
return res.data.map((item: any) => {
return { value: item.type, label: item.name };
});
}),
);
},
} as SFSelectWidgetSchema,
},
currency_balance: { type: 'number', title: '起始金额', default: 0, ui: { widgetWidth: 200 } },
currency_code: {
type: 'string',
title: '货币',
default: 'CNY',
enum: [
{ value: 'CNY', label: 'CNY' },
// { value: 'USD', label: 'USD' },
],
},
// exclude_from_stats: {
// type: 'boolean',
// title: '从统计中排除',
// },
default: {
type: 'boolean',
title: '默认账户',
},
},
required: ['name', 'type', 'balance', 'currency_code'],
ui: {
spanLabelFixed: 150,
grid: { span: 24 },
},
accountTypes: [];

form = {
name: '',
type: 'general_account',
currency_balance: '',
currency_code: 'CNY',
status: 'active',
default: false,
exclude_from_stats: false,
};
ngOnInit(): void {
if (this.record) {
this.form = this.record;
}
}

constructor(private http: _HttpClient, private modal: NzModalRef, private msgSrv: NzMessageService) {}

Expand Down
1 change: 1 addition & 0 deletions src/app/routes/account/index/index.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<ng-template #footer>
<nz-tag>{{ item.type_name }}</nz-tag>
<nz-tag *ngIf="item.default">默认账户</nz-tag>
<nz-tag *ngIf="item.status == 'unactivated'">冻结</nz-tag>
</ng-template>
</g2-card>
</ng-template>
Expand Down
4 changes: 3 additions & 1 deletion src/app/routes/account/index/index.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export class AccountIndexComponent implements OnInit {
}

form(record: { id?: number } = {}): void {
this.modal.create(AccountFormComponent, { record }, { size: 'md' }).subscribe((res) => {
console.log(this.accountTypes);

this.modal.create(AccountFormComponent, { record, accountTypes: this.accountTypes }, { size: 'md' }).subscribe((res) => {
this.getData();
this.getOverview();
this.cdr.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class RecordSearchComponent implements OnInit {

ngOnInit() {
this.initQ = deepCopy(this.q);
this.loadSelect('/api/accounts', 'account_id');
this.loadSelect('/api/accounts?status=active', 'account_id');
this.loadSelect('/api/categories', 'category_id');
this.loadSelect('/api/tags', 'tags');
this.loadSelect('/api/transactions/types', 'transaction_type');
Expand Down

0 comments on commit d288924

Please sign in to comment.