@wjya/ngx-webapp-icpc.group.pms
Version:
angular webapp : icpc.group.pms
192 lines • 15.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var data_source_helper_1 = require("../../service/data-source.helper");
var ngx_webapp_fx_1 = require("@wjya/ngx-webapp-fx");
var core_1 = require("@angular/core");
var forms_1 = require("@angular/forms");
var router_1 = require("@angular/router");
var ngx_utils_1 = require("@wjya/ngx-utils");
var CommunityDetailComponent = /** @class */ (function () {
function CommunityDetailComponent(fb, dataSourceHelper, activateRoute, userStorageService, dataDictService) {
var _this = this;
this.fb = fb;
this.dataSourceHelper = dataSourceHelper;
this.activateRoute = activateRoute;
this.userStorageService = userStorageService;
this.dataDictService = dataDictService;
this.isEdit = false;
this.data = { branchRegion: {} };
this.regionOptions = [];
this.regionItems = [];
this.province = { items: [] };
this.city = { items: [] };
this.county = { items: [] };
this.dataSource = dataSourceHelper.community;
this.regionDataSource = dataSourceHelper.regionsTree;
dataDictService.getItems('SYS_REGION').subscribe(function (res) {
_this.regionOptions = res;
_this.regionOptions = _this.toMultiLevel(_this.regionOptions);
});
this.validateForm = this.fb.group({
id: [null],
branchRegion: [null, [forms_1.Validators.required]],
name: [null, [forms_1.Validators.required]],
province: [null],
city: [null],
county: [null],
area: [null],
address: [null],
fullName: [null, [forms_1.Validators.required]],
contacts: [null],
phone: [null],
remarks: [null],
zipCode: [null]
});
}
CommunityDetailComponent.prototype.ngOnInit = function () {
this.id = this.activateRoute.snapshot.params['id'];
this.communityGroupId = this.userStorageService.getCurrentOffice().id;
this.loadAll();
this.loadRegion();
};
CommunityDetailComponent.prototype.loadAll = function () {
var _this = this;
this.dataSource.findOne(this.id, { communityGroupId: this.communityGroupId }).subscribe(function (res) {
_this.data = res.body;
var data = ngx_utils_1.ObjectUtils.cloneObject(_this.data, true);
_this.validateForm.patchValue(data);
if (data.area) {
var path = _this.dataDictService.getDictItemMuiltiLevelPath('SYS_REGION', data.area);
if (path.length === 3) {
_this.province = path[0];
_this.city = path[1];
_this.county = path[2];
_this.area = path[0].text + ' / ' + path[1].text + ' / ' + path[2].text;
}
else if (path.length === 2) {
_this.province = path[0];
_this.city = path[1];
_this.area = path[0].text + ' / ' + path[1].text;
}
else if (path.length === 1) {
_this.province = path[0];
_this.area = path[0].text;
}
}
});
};
CommunityDetailComponent.prototype.getFormControl = function (name) {
return this.validateForm.controls[name];
};
CommunityDetailComponent.prototype.onSave = function () {
var _this = this;
if (!this.validateForm.valid) {
return;
}
else {
this.isEdit = !this.isEdit;
if (this.validateForm.value.county) {
this.validateForm.value.area = this.validateForm.value.county.value;
}
else if (!this.validateForm.value.county && this.validateForm.value.city) {
this.validateForm.value.area = this.validateForm.value.city.value;
}
else if (!this.validateForm.value.county && !this.validateForm.value.city && this.validateForm.value.province) {
this.validateForm.value.area = this.validateForm.value.province.value;
}
var entity = ngx_utils_1.ObjectUtils.patchFieldValue(this.validateForm.value, this.data);
if (entity.province) {
delete entity.province;
}
if (entity.city) {
delete entity.city;
}
if (entity.county) {
delete entity.county;
}
if (entity.branchRegion) {
for (var i = 0; i < this.regionItems.length; i++) {
if (entity.branchRegion === this.regionItems[i].id) {
entity.branchRegion = this.regionItems[i];
}
}
}
this.dataSource.update(entity, { communityGroupId: this.communityGroupId }).subscribe(function (success) {
_this.loadAll();
});
}
};
CommunityDetailComponent.prototype.toMultiLevel = function (dict) {
for (var i = 0; i < dict.length; i++) {
dict[i].items = null;
}
var multilevelDict = [];
for (var i = 0; i < dict.length; i++) {
var item = dict[i];
var parentId = item.parentId;
var parent_1 = null;
if (parentId) {
for (var j = 0; j < dict.length; j++) {
if (dict[j].id === parentId) {
parent_1 = dict[j];
item.parent = parent_1;
if (parent_1.items == null) {
parent_1.items = [];
}
parent_1.items[parent_1.items.length] = item;
break;
}
}
}
if (parent_1 == null) {
multilevelDict[multilevelDict.length] = item;
}
}
return multilevelDict;
};
CommunityDetailComponent.prototype.loadRegion = function () {
var _this = this;
this.regionDataSource.findList({
communityGroupId: this.communityGroupId
}).subscribe(function (res) {
var result = [];
[res.body].forEach(function (item) {
_this.tree2Paint(item, result);
});
_this.regionItems = result;
});
};
CommunityDetailComponent.prototype.tree2Paint = function (option, result) {
var _this = this;
if (option.level == null) {
option.level = 0;
}
result.push(option);
if (option.children) {
option.children.forEach(function (item) {
item.level = option.level + 1;
_this.tree2Paint(item, result);
});
}
};
CommunityDetailComponent.decorators = [
{ type: core_1.Component, args: [{
selector: 'zx-community-detail',
template: "<zx-header-block [title]=\"'\u5C0F\u533A\u8BE6\u60C5'\" [showBottomLine]=\"false\" [showBreadcrumb]=\"true\" [breadcrumbAppendings]=\"['\u8BE6\u60C5']\"><p>\u8BBE\u7F6E\u5C0F\u533A\u57FA\u672C\u4FE1\u606F\u3001\u7CFB\u7EDF\u7BA1\u7406\u5458\u3001\u94F6\u884C\u8D26\u6237\u8D44\u6599\u7B49\u3002</p></zx-header-block><zx-content-block><nz-card nzNoHovering nzBordered=\"false\"><ng-template #title><h4>\u57FA\u672C\u4FE1\u606F</h4></ng-template><ng-template #extra><div *ngIf=\"!isEdit&&data\" class=\"extra\"><span><i class=\"anticon anticon-edit\"></i> <a (click)=\"isEdit = !isEdit\">\u4FEE\u6539</a></span></div><div *ngIf=\"isEdit\" class=\"extra\"><span><i class=\"anticon anticon-save\"></i> <a (click)=\"onSave()\">\u4FDD\u5B58</a> </span><span><i class=\"anticon anticon-reload\"></i> <a (click)=\"isEdit = !isEdit\">\u53D6\u6D88</a></span></div></ng-template><ng-template #body><div nz-row><form nz-form [formGroup]=\"validateForm\" class=\"ant-advanced-search-form\"><div nz-row><div nz-col [nzSpan]=\"8\"><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label nz-form-item-required>\u6240\u5C5E\u533A\u57DF</label></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"isEdit\"><nz-select [nzSize]=\"size\" [nzPlaceHolder]=\"'\u8BF7\u9009\u62E9\u533A\u57DF'\" formControlName=\"branchRegion\" [(ngModel)]=\"data.branchRegion.id\"><nz-option *ngFor=\"let option of regionItems\" [nzLabel]=\"option.name\" [nzValue]=\"option.id\"><ng-template #nzOptionTemplate><span [ngStyle]=\"{'padding-left': 30 * option.level + 'px'}\">{{option.name}}</span></ng-template></nz-option></nz-select><div nz-form-explain *ngIf=\"getFormControl('branchRegion').dirty&&getFormControl('branchRegion').hasError('required')\">\u6240\u5C5E\u533A\u57DF\u662F\u5FC5\u586B\u7684!</div></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"!isEdit\"><span *ngIf=\"data.branchRegion\">{{data.branchRegion.name}}</span></div></div></div><div nz-col [nzSpan]=\"16\"><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"2\"><label>\u6240\u5C5E\u57CE\u5E02</label></div><div nz-form-control nz-col [nzSpan]=\"22\" *ngIf=\"isEdit\"><div nz-col [nzSpan]=\"8\"><nz-select formControlName=\"province\" [nzPlaceHolder]=\"'\u7701'\" [(ngModel)]=\"province\" (nzOpenChange)=\"city = null;county = null\"><ng-container *ngIf=\"regionOptions\"><nz-option *ngFor=\"let option0 of regionOptions\" [nzLabel]=\"option0.text\" [nzValue]=\"option0\"></nz-option></ng-container></nz-select></div><div nz-col [nzSpan]=\"8\"><nz-select formControlName=\"city\" [nzPlaceHolder]=\"'\u5E02'\" [(ngModel)]=\"city\" (nzOpenChange)=\"county = null\"><ng-container *ngIf=\"province\"><nz-option *ngFor=\"let option1 of province.items\" [nzLabel]=\"option1.text\" [nzValue]=\"option1\"></nz-option></ng-container></nz-select></div><div nz-col [nzSpan]=\"8\"><nz-select formControlName=\"county\" [nzPlaceHolder]=\"'\u533A/\u53BF'\" [(ngModel)]=\"county\"><ng-container *ngIf=\"city\"><nz-option *ngFor=\"let option2 of city.items\" [nzLabel]=\"option2.text\" [nzValue]=\"option2\"></nz-option></ng-container></nz-select></div></div><div nz-form-control nz-col [nzSpan]=\"22\" *ngIf=\"!isEdit\"><span>{{area}}</span></div></div></div></div><div nz-row><div nz-col [nzSpan]=\"8\"><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label nz-form-item-required>\u5C0F\u533A\u7B80\u79F0</label></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"isEdit\" nzHasFeedback><nz-input [nzSize]=\"'large'\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u5C0F\u533A\u7B80\u79F0'\" formControlName=\"name\"></nz-input><div nz-form-explain *ngIf=\"getFormControl('name').dirty&&getFormControl('name').hasError('required')\">\u5C0F\u533A\u7B80\u79F0\u662F\u5FC5\u586B\u7684!</div></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"!isEdit\"><span>{{data.name}}</span></div></div></div><div nz-col [nzSpan]=\"8\"><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label>\u8BE6\u7EC6\u5730\u5740</label></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"isEdit\"><nz-input [nzSize]=\"'large'\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u8BE6\u7EC6\u5730\u5740'\" formControlName=\"address\"></nz-input></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"!isEdit\"><span>{{data.address}}</span></div></div></div><div nz-col [nzSpan]=\"8\"><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label>\u90AE\u7F16</label></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"isEdit\"><nz-input [nzSize]=\"'large'\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u90AE\u7F16'\" formControlName=\"zipCode\"></nz-input></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"!isEdit\"><span>{{data.zipCode}}</span></div></div></div></div><div nz-row><div nz-col [nzSpan]=\"8\"><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label nz-form-item-required>\u5C0F\u533A\u5168\u540D</label></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"isEdit\" nzHasFeedback><nz-input [nzSize]=\"'large'\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u5C0F\u533A\u5168\u540D'\" formControlName=\"fullName\"></nz-input><div nz-form-explain *ngIf=\"getFormControl('fullName').dirty&&getFormControl('fullName').hasError('required')\">\u5C0F\u533A\u5168\u540D\u662F\u5FC5\u586B\u7684!</div></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"!isEdit\"><span>{{data.fullName}}</span></div></div></div><div nz-col [nzSpan]=\"8\"><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label>\u8054\u7CFB\u4EBA</label></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"isEdit\"><nz-input [nzSize]=\"'large'\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u8054\u7CFB\u4EBA'\" formControlName=\"contacts\"></nz-input></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"!isEdit\"><span>{{data.contacts}}</span></div></div></div><div nz-col [nzSpan]=\"8\"><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label>\u8054\u7CFB\u7535\u8BDD</label></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"isEdit\"><nz-input [nzSize]=\"'large'\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u8054\u7CFB\u7535\u8BDD'\" formControlName=\"phone\"></nz-input></div><div nz-form-control nz-col [nzSpan]=\"20\" *ngIf=\"!isEdit\"><span>{{data.phone}}</span></div></div></div></div><div nz-row><div nz-col [nzSpan]=\"16\"><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"2\"><label>\u5907\u6CE8</label></div><div nz-form-control nz-col [nzSpan]=\"22\" *ngIf=\"isEdit\"><nz-input style=\"height:auto\" formControlName=\"remarks\" [nzType]=\"'textarea'\" [nzRows]=\"'4'\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u5907\u6CE8'\"></nz-input></div><div nz-form-control nz-col [nzSpan]=\"22\" *ngIf=\"!isEdit\"><span>{{data.remarks}}</span></div></div></div></div></form></div></ng-template></nz-card></zx-content-block><zx-community-detail-admin *ngIf=\"data\"></zx-community-detail-admin><zx-community-detail-offical *ngIf=\"data\"></zx-community-detail-offical>",
styles: [
"\n :host .extra {\n color: #108ee9;\n }\n :host .extra > span:nth-child(2) {\n margin-left:16px;\n }\n :host ::ng-deep nz-input textarea {\n height: auto !important;\n }\n "
]
},] },
];
/** @nocollapse */
CommunityDetailComponent.ctorParameters = function () { return [
{ type: forms_1.FormBuilder, },
{ type: data_source_helper_1.DataSourceHelper, },
{ type: router_1.ActivatedRoute, },
{ type: ngx_webapp_fx_1.UserStorageService, },
{ type: ngx_webapp_fx_1.DataDictService, },
]; };
return CommunityDetailComponent;
}());
exports.CommunityDetailComponent = CommunityDetailComponent;
//# sourceMappingURL=community-detail.component.js.map