| | |
| | | import { AreaNames, MonitorPoint } from '@business/entity/data'; |
| | | import { CoorPickerService } from 'app/routes/map/coordinates-picker/coordinates-picker.service'; |
| | | import { AreaNames, MonitorPoint } from '@business/entity/data'; |
| | | import { Version, ValueTransformer } from '@angular/compiler/src/util'; |
| | | import { Subject } from 'rxjs/Subject'; |
| | | import { Component, OnInit } from '@angular/core'; |
| | |
| | | import { filter } from 'rxjs/operators/filter'; |
| | | import { MonitorPointEditComponent } from 'app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component'; |
| | | import { MonitorPointService } from '@business/services/http/monitor-point.service'; |
| | | import { CoordinatesPickerComponent } from 'app/routes/map/coordinates-picker/coordinates-picker.component'; |
| | | |
| | | |
| | | @Component({ |
| | |
| | | |
| | | private monitorPoint: MonitorPoint; |
| | | grid: Grid<MonitorPoint> = new Grid(null); |
| | | queryMap = { text: '请输入名称', value: ''}; |
| | | queryMap = { text: '请输入名称', value: '' }; |
| | | queryTextStream: Subject<string> = new Subject<string>(); |
| | | private initPage() { |
| | | this.monitorPoint = { |
| | | private initPage() { |
| | | this.monitorPoint = { |
| | | name: { |
| | | text: '名称', |
| | | width: '300px' |
| | | width: '300px' |
| | | }, |
| | | address: { |
| | | text: '地址', |
| | | width: '300px', |
| | | format: (value: any, col: Column, row: any) => { |
| | | value = value == null ? '' : value ; |
| | | if (row['areaNames'] != null) { |
| | | return row['areaNames']['provinceName'] + row['areaNames']['cityName'] + row['areaNames']['areaName'] + value; |
| | | } else { |
| | | return value; |
| | | } |
| | | |
| | | value = value == null ? '' : value; |
| | | if (row['areaNames'] != null) { |
| | | return row['areaNames']['provinceName'] + row['areaNames']['cityName'] + row['areaNames']['areaName'] + value; |
| | | } else { |
| | | return value; |
| | | } |
| | | |
| | | } |
| | | }, |
| | | description: { |
| | |
| | | this.grid.pageSize = 10; |
| | | } |
| | | constructor( |
| | | private coorPickerService:CoorPickerService, |
| | | private monitorPointService: MonitorPointService, |
| | | |
| | | |
| | | private confirmServ: NzModalService, |
| | | public msgSrv: NzMessageService, |
| | | private modalHelper: ModalHelper, |
| | | ) {} |
| | | ) { } |
| | | |
| | | ngOnInit() { |
| | | this.initPage(); |
| | | this.queryTextStream |
| | | .debounceTime(500) |
| | | .distinctUntilChanged() |
| | | .subscribe(queryText => { |
| | | .debounceTime(500) |
| | | .distinctUntilChanged() |
| | | .subscribe(queryText => { |
| | | this.load(); |
| | | }); |
| | | }); |
| | | } |
| | | queryTextChanged($event) { |
| | | this.queryTextStream.next(this.queryMap.value); |
| | | this.queryTextStream.next(this.queryMap.value); |
| | | } |
| | | load(reload: boolean = false) { |
| | | load(reload: boolean = false) { |
| | | if (reload) { |
| | | this.grid.pageIndex = 1 ; |
| | | this.grid.pageIndex = 1; |
| | | } |
| | | // 延时加载避免ExpressionChangedAfterItHasBeenCheckedError |
| | | setTimeout(() => { |
| | | this.grid.loading = true; |
| | | }, 1); |
| | | }, 1); |
| | | this.monitorPointService.getPagingList(this.grid, this.queryMap.value).subscribe( |
| | | (res: PageBean) => { |
| | | this.grid.loading = true; |
| | | if (res != null && res.data != null) { |
| | | this.grid.initData(res); |
| | | this.grid.refreshStatus(); |
| | | setTimeout(() => { |
| | | this.grid.loading = false; |
| | | }, 1); |
| | | } |
| | | } |
| | | (res: PageBean) => { |
| | | this.grid.loading = true; |
| | | if (res != null && res.data != null) { |
| | | this.grid.initData(res); |
| | | this.grid.refreshStatus(); |
| | | setTimeout(() => { |
| | | this.grid.loading = false; |
| | | }, 1); |
| | | } |
| | | } |
| | | ); |
| | | } |
| | | |
| | | // rowData为null时,为新增 |
| | | // rowData为null时,为新增 |
| | | addOrModify(d) { |
| | | const data = {}; |
| | | if ( d != null) { |
| | | if (d != null) { |
| | | Object.assign(data, d); |
| | | } |
| | | this.modalHelper.static(MonitorPointEditComponent, { data }).subscribe( |
| | | ( ret: { data: any, close: Function} ) => { |
| | | // 修改状态 |
| | | if (ret.data['index'] != null ) { |
| | | const index: number = ret.data['index'] ; |
| | | this.modalHelper.static(MonitorPointEditComponent, { data }).subscribe( |
| | | (ret: { data: any, close: Function }) => { |
| | | // 修改状态 |
| | | if (ret.data['index'] != null) { |
| | | const index: number = ret.data['index']; |
| | | const origData = this.grid.data[index]; |
| | | const isModified = Object.keys(origData).some( |
| | | const isModified = Object.keys(origData).some( |
| | | (key: string) => { |
| | | return ret.data[key] !== origData[key]; |
| | | } |
| | | return ret.data[key] !== origData[key]; |
| | | } |
| | | ); |
| | | // 未作修改 |
| | | if (!isModified) { |
| | | if (!isModified) { |
| | | ret.close(); |
| | | this.msgSrv.success(this.grid.title + '未作任何修改!'); |
| | | return; |
| | | } |
| | | } |
| | | this.monitorPointService.save(ret.data).subscribe( |
| | | ( res: any) => { |
| | | } |
| | | this.monitorPointService.save(ret.data).subscribe( |
| | | (res: any) => { |
| | | if (res.code === 1) { |
| | | this.load(); |
| | | ret.close(); |
| | | this.msgSrv.success(this.grid.title + '保存成功!'); |
| | | } |
| | | } |
| | | ); |
| | | }); |
| | | } |
| | | ); |
| | | }); |
| | | } |
| | | |
| | | delete(...id: number[]) { |
| | | this.monitorPointService.delete( ...id ).subscribe( |
| | | ( res: any) => { |
| | | if (res.code === 1) { |
| | | this.load(); |
| | | this.msgSrv.success(this.grid.title + '删除成功!'); |
| | | } |
| | | this.monitorPointService.delete(...id).subscribe( |
| | | (res: any) => { |
| | | if (res.code === 1) { |
| | | this.load(); |
| | | this.msgSrv.success(this.grid.title + '删除成功!'); |
| | | } |
| | | } |
| | | ); |
| | | ); |
| | | } |
| | | |
| | | deleteSelected() { |
| | | deleteSelected() { |
| | | this.confirmServ.confirm({ |
| | | title: '批量删除', |
| | | content: '注意:数据一旦删除,将不可恢复!', |
| | | okText: '确定', |
| | | cancelText: '取消' |
| | | }).on('onOk', () => { |
| | | if (this.grid.selectedIndexs != null && this.grid.selectedIndexs.length > 0) { |
| | | const ids = this.grid.selectedIndexs.map( |
| | | (index: number) => { |
| | | const id = this.grid.data[index].id; |
| | | return Number.parseInt(id); |
| | | } |
| | | ); |
| | | this.delete( ...ids ); |
| | | } |
| | | if (this.grid.selectedIndexs != null && this.grid.selectedIndexs.length > 0) { |
| | | const ids = this.grid.selectedIndexs.map( |
| | | (index: number) => { |
| | | const id = this.grid.data[index].id; |
| | | return Number.parseInt(id); |
| | | } |
| | | ); |
| | | this.delete(...ids); |
| | | } |
| | | }); |
| | | } |
| | | sort(field: string, value: string) { |
| | | // 删除当前field |
| | | this.grid.sorts = this.grid.sorts.filter( |
| | | (fn: string) => { |
| | | return fn !== field; |
| | | } |
| | | ); |
| | | // 如果value不为null,在排序数组最后加上filed |
| | | if ( value != null ) { |
| | | this.grid.sorts.push(field); |
| | | } |
| | | this.load(); |
| | | (fn: string) => { |
| | | return fn !== field; |
| | | } |
| | | ); |
| | | // 如果value不为null,在排序数组最后加上filed |
| | | if (value != null) { |
| | | this.grid.sorts.push(field); |
| | | } |
| | | this.load(); |
| | | } |
| | | configCoord(record: MonitorPoint): void { |
| | | Object.assign(this.coorPickerService.data, record); |
| | | let _data = this.coorPickerService.data; |
| | | const areaNames = record.areaNames; |
| | | let adress = null; |
| | | if (areaNames != null) { |
| | | adress = areaNames.provinceName + areaNames.cityName + areaNames.areaName + record.address; |
| | | } |
| | | this.coorPickerService.data.address = adress; |
| | | this.coorPickerService.data['describe'] = '监控点名称'; |
| | | this.modalHelper.static(CoordinatesPickerComponent).subscribe( |
| | | (staticComp) => { |
| | | const data: MonitorPoint = { |
| | | id: record.id, |
| | | longitude: _data.longitude, |
| | | latitude: _data.latitude, |
| | | } |
| | | this.monitorPointService.save(data).subscribe( |
| | | (res: any) => { |
| | | if (res.code === 1) { |
| | | this.load(); |
| | | this.msgSrv.success('坐标配置成功!'); |
| | | } |
| | | } |
| | | ); |
| | | |
| | | } |
| | | ); |
| | | } |
| | | } |