UNPKG

@wjya/ngx-webapp-icpc.group.pms

Version:

angular webapp : icpc.group.pms

291 lines 16.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ngx_utils_1 = require("@wjya/ngx-utils"); var core_1 = require("@angular/core"); var ng_zorro_antd_1 = require("ng-zorro-antd"); var ngx_webapp_fx_1 = require("@wjya/ngx-webapp-fx"); var router_1 = require("@angular/router"); var data_source_helper_1 = require("../../service/data-source.helper"); var room_import_help_modal_1 = require("./room-import-help.modal"); var RoomImportComponent = /** @class */ (function () { function RoomImportComponent(authServerProvider, config, dataDictService, dataSourceHelper, confirmServ, _message, router, principal) { var _this = this; this.authServerProvider = authServerProvider; this.config = config; this.dataDictService = dataDictService; this.dataSourceHelper = dataSourceHelper; this.confirmServ = confirmServ; this._message = _message; this.router = router; this.principal = principal; this.fileList = []; this.regionOptions = []; this.data = []; this.isDisabled = true; this.beforeUpload = function (file) { if (_this.index === 0 || _this.index) { _this.data[_this.index].fileName = file.name; _this.data[_this.index].fileList = [file]; } return true; }; this.communityGroupAccountCommunitiesDataSource = this.dataSourceHelper.communityGroupAccountCommunities; this.communityGroupAccountImportTemplateDataSource = this.dataSourceHelper.communityGroupAccountImportTemplate; this.generateFileStoragesDataSource = this.dataSourceHelper.generateFileStorages; this.communityGroupAccountImportRoomsDataSource = this.dataSourceHelper.communityGroupAccountImportRooms; this.completeRegisterStepDataSource = this.dataSourceHelper.completeRegisterStep; this.dataDictService.getItems('SYS_REGION').subscribe(function (res) { _this.regionOptions = res; _this.regionOptions = _this.toMultiLevel(_this.regionOptions); }); } RoomImportComponent.prototype.ngOnInit = function () { this.loadAll(); }; RoomImportComponent.prototype.loadAll = function () { var _this = this; this.communityGroupAccountCommunitiesDataSource.findList({ size: 9999 }).subscribe(function (res) { _this.data = res.body; if (_this.data.length === 0) { _this.addCommunity(); _this.isDisabled = true; } else { _this.isDisabled = false; } for (var i = 0; i < _this.data.length; i++) { if (_this.data[i].area) { var path = _this.dataDictService.getDictItemMuiltiLevelPath('SYS_REGION', _this.data[i].area); if (path.length === 3) { _this.data[i].province = path[0]; _this.data[i].city = path[1]; _this.data[i].county = path[2]; } else if (path.length === 2) { _this.data[i].province = path[0]; _this.data[i].city = path[1]; } else if (path.length === 1) { _this.data[i].province = path[0]; } } } }); }; RoomImportComponent.prototype.addCommunity = function () { this.data.push({ name: null, area: null }); }; RoomImportComponent.prototype.removeCommunity = function (value, idx) { var _self = this; if (value.id) { this.confirmServ.confirm({ title: '您确定要删除此小区?', onOk: function () { _self.communityGroupAccountCommunitiesDataSource.delete(value.id).subscribe(function (success) { _self.loadAll(); }); }, }); } else { _self.data.splice(idx, 1); } }; RoomImportComponent.prototype.downloadTemplate = function (value) { var _this = this; if (value.id) { this.communityGroupAccountImportTemplateDataSource.create(null, { communityId: value.id }).subscribe(function (success) { _this.getDownLoadUrl(success.body.fileKey); value.enabledUpload = true; }, function (error) { _this._message.error('下载模板失败'); }); } else { var items = ngx_utils_1.ObjectUtils.cloneObject(value, true); if (!items.name) { value.confirmRequired = true; return; } else { value.confirmRequired = false; } if (value.county) { items.area = value.county.value; } else if (!value.county && value.city) { items.area = value.city.value; } if (items.province) { delete items.province; } if (items.city) { delete items.city; } this.communityGroupAccountCommunitiesDataSource.create(items).subscribe(function (res) { _this.communityGroupAccountImportTemplateDataSource.create(null, { communityId: res.body.id }).subscribe(function (success) { _this.getDownLoadUrl(success.body.fileKey); value.enabledUpload = true; }, function (error) { _this._message.error('下载模板失败'); }); }); } }; RoomImportComponent.prototype.saveCommunity = function (value) { var _this = this; var items = ngx_utils_1.ObjectUtils.cloneObject(value, true); if (!items.name) { value.confirmRequired = true; return; } else { value.confirmRequired = false; } if (value.county) { items.area = value.county.value; } else if (!value.county && value.city) { items.area = value.city.value; } if (items.province) { delete items.province; } if (items.city) { delete items.city; } this.communityGroupAccountCommunitiesDataSource.create(items).subscribe(function (success) { _this.loadAll(); _this._message.success('保存小区成功'); }, function (error) { _this._message.error('保存小区失败'); }); }; RoomImportComponent.prototype.getDownLoadUrl = function (fileKey) { var _this = this; var t = setInterval(function () { _this.generateFileStoragesDataSource.findOne(fileKey).subscribe(function (success) { if (success.body.status === 'DONE') { _this._message.success('下载模板成功'); window.location.href = success.body.downLoadUrl; _this.loadAll(); clearInterval(t); } else if (success.body.status === 'ERROR') { _this._message.error('下载模板失败'); clearInterval(t); } }, function (error) { _this._message.error('下载模板失败'); clearInterval(t); }); }, 1000); }; RoomImportComponent.prototype.getUploadIndex = function (idx) { this.index = idx; }; RoomImportComponent.prototype.getUploadStatus = function (e) { if (e.file.status === 'done') { this._message.success('上传成功'); } else if (e.file.status === 'error') { this._message.error('上传失败'); } }; Object.defineProperty(RoomImportComponent.prototype, "uploadUrl", { get: function () { return this.config.apiUrls.uploadPic; }, enumerable: true, configurable: true }); RoomImportComponent.prototype.getAuthToken = function () { return this.authServerProvider.getToken(); }; RoomImportComponent.prototype.enter = function () { var _this = this; this.completeRegisterStepDataSource.create(null, { registerStep: 'IMPORT_ROOMS' }).subscribe(function (success) { _this.principal.identity(true); _this.router.navigate(['/home']); }); }; RoomImportComponent.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; }; RoomImportComponent.prototype.provinceChange = function (value, item) { if (value.items.length === 0) { return; } item.city = value.items[0]; }; RoomImportComponent.prototype.confirmName = function (item) { item.confirmRequired = false; if (item.name.length < 2 || item.name.length > 20) { item.confirmLength = true; } else { item.confirmLength = false; } }; RoomImportComponent.prototype.readHelp = function () { this.roomImportHelp.modalIsVisible = true; }; RoomImportComponent.prototype.back = function () { this.router.navigate(['/login']); }; RoomImportComponent.decorators = [ { type: core_1.Component, args: [{ selector: 'zx-room-import', template: "<div nz-row *ngFor=\"let item of data;let i = index\" class=\"row\"><div class=\"delete\" (click)=\"removeCommunity(item, i)\">\u5220\u9664\u5C0F\u533A</div><div class=\"save\" (click)=\"saveCommunity(item)\">\u4FDD\u5B58\u5C0F\u533A</div><div nz-col [nzSpan]=\"8\"><div nz-col [nzSpan]=\"4\"><label>\u5C0F\u533A\u540D\u79F0:</label></div><div nz-col [nzSpan]=\"20\"><input nz-input placeholder=\"\u8BF7\u586B\u5199\u5C0F\u533A\u540D\u79F0\" [nzSize]=\"'large'\" [(ngModel)]=\"item.name\" (ngModelChange)=\"confirmName(item)\"><div *ngIf=\"item.confirmRequired\" style=\"color: red\">\u5C0F\u533A\u540D\u79F0\u662F\u5FC5\u586B\u7684</div><div *ngIf=\"item.confirmLength\" style=\"color: red\">\u5C0F\u533A\u540D\u79F0\u6700\u77ED\u6700\u77ED2\u4F4D\uFF0C\u6700\u957F20\u4F4D</div><div class=\"tip\">\u8BF7\u5728\u8F93\u5165\u6846\u586B\u5199\u5C0F\u533A\u540D\u79F0\uFF0C\u6700\u77ED2\u4F4D\uFF0C\u6700\u957F20\u4F4D</div></div></div><div nz-col [nzSpan]=\"8\"><div nz-col [nzSpan]=\"4\"><label>\u6240\u5C5E\u57CE\u5E02:</label></div><div nz-col [nzSpan]=\"20\" style=\"font-size: 0;\"><nz-select [nzPlaceHolder]=\"'\u7701'\" [(ngModel)]=\"item.province\" [nzSize]=\"'large'\" (ngModelChange)=\"provinceChange($event, item)\"><ng-container *ngIf=\"regionOptions\"><nz-option *ngFor=\"let option0 of regionOptions\" [nzLabel]=\"option0.text\" [nzValue]=\"option0\"></nz-option></ng-container></nz-select><nz-select [nzPlaceHolder]=\"'\u5E02'\" [(ngModel)]=\"item.city\" [nzSize]=\"'large'\"><ng-container *ngIf=\"item.province\"><nz-option *ngFor=\"let option1 of item.province.items\" [nzLabel]=\"option1.text\" [nzValue]=\"option1\"></nz-option></ng-container></nz-select></div></div><div nz-col [nzSpan]=\"24\"><div nz-col [nzSpan]=\"2\"><label>\u623F\u4EA7\u5BFC\u5165:</label></div><div nz-col [nzSpan]=\"22\"><nz-upload [nzAction]=\"'/base/api/_my/community-group-account/import-rooms?communityId=' + item.id\" (click)=\"getUploadIndex(i)\" [nzBeforeUpload]=\"beforeUpload\" [nzHeaders]=\"{ 'Authorization':'Bearer '+getAuthToken() }\" [(nzFileList)]=\"item.fileList\" [nzShowUploadList]=\"false\" [nzLimit]=\"1\" [nzAccept]=\"'.xlsx'\" (nzChange)=\"getUploadStatus($event)\"><button nz-button [disabled]=\"!item.id && !item.enabledUpload\"><i class=\"anticon anticon-upload\"></i> <span>\u4E0A\u4F20\u6587\u4EF6</span></button></nz-upload><span class=\"tip\" style=\"margin:0 10px;\">{{item.fileName ? item.fileName : '\u6682\u65E0\u6587\u4EF6'}}</span> <a (click)=\"downloadTemplate(item)\">\u6A21\u677F\u4E0B\u8F7D</a><div class=\"tip\">\u6A21\u677F\u4E2D\u4F1A\u81EA\u52A8\u751F\u6210\u5C0F\u533A\u7F16\u53F7\u4EE5\u53CA\u5BF9\u5E94\u7684\u5C0F\u533A\u540D\u79F0\uFF1B\u5C0F\u533A\u540D\u79F0\u4EE5\u53CA\u5C0F\u533A\u7F16\u53F7\u4E0D\u53EF\u968F\u610F\u4FEE\u6539\uFF1B\u5982\u679C\u589E\u52A0\u6570\u636E\uFF0C\u5219\u590D\u5236\u751F\u6210\u7684\u5C0F\u533A\u7F16\u53F7\u4EE5\u53CA\u5C0F\u533A\u540D\u79F0\u53E6\u8D77\u4E00\u884C\u3002 <a (click)=\"readHelp()\">\u67E5\u770B\u793A\u4F8B</a></div></div></div><div class=\"br\"></div></div><div class=\"add\" (click)=\"addCommunity()\">\u6DFB\u52A0\u5C0F\u533A+</div><div class=\"br\"></div><div nz-form-item nz-row><button nz-button class=\"login-form-button\" [nzType]=\"'primary'\" (click)=\"enter()\" [disabled]=\"isDisabled\">\u8FDB\u5165\u7CFB\u7EDF</button> <button nz-button class=\"login-form-button\" [nzType]=\"'default'\" (click)=\"back()\">\u8FD4 \u56DE</button></div><zx-room-import-help #roomImportHelp></zx-room-import-help>", styles: [ "\n :host .br {\n height: 1px;\n width: 100%;\n margin: 30px 0;\n border-top: 1px dashed #ddd;\n overflow:hidden;\n }\n :host .tip{\n color:#c0c0c0;\n }\n :host .add{\n width: 100%;\n height: 54px;\n border: 1px dashed #999;\n text-align: center;\n line-height: 50px;\n font-size: 16px;\n cursor: pointer;\n }\n :host ::ng-deep .ant-form-item{\n margin-bottom:0;\n }\n :host ::ng-deep .row > div{\n margin-bottom:30px;\n margin-right:30px;\n }\n :host ::ng-deep .row > div > div:nth-child(1){\n width:100px;\n height: 32px;\n line-height: 32px;\n text-align: right;\n padding-right: 10px;\n }\n :host ::ng-deep .row > div > div:nth-child(2){\n width:calc(100% - 100px);\n }\n :host .delete, :host .save{\n margin-bottom: 10px;\n margin-right: 20px;\n color: red;\n cursor: pointer;\n float: right;\n }\n :host .save {\n color:#108ee9\n }\n :host ::ng-deep nz-select{\n width:50%;\n }\n :host .row > div:nth-child(3) > div > label::before, :host .row > div:nth-child(4) > div > label::before{\n content: '*';\n color:red;\n margin-right:3px;\n }\n " ] },] }, ]; /** @nocollapse */ RoomImportComponent.ctorParameters = function () { return [ { type: ngx_webapp_fx_1.AuthServerProvider, }, { type: ngx_webapp_fx_1.CoreConfigService, }, { type: ngx_webapp_fx_1.DataDictService, }, { type: data_source_helper_1.DataSourceHelper, }, { type: ng_zorro_antd_1.NzModalService, }, { type: ng_zorro_antd_1.NzMessageService, }, { type: router_1.Router, }, { type: ngx_webapp_fx_1.Principal, }, ]; }; RoomImportComponent.propDecorators = { "roomImportHelp": [{ type: core_1.ViewChild, args: ['roomImportHelp',] },], }; return RoomImportComponent; }()); exports.RoomImportComponent = RoomImportComponent; //# sourceMappingURL=room-import.component.js.map