xufenglei
2018-05-14 820cc14842e73c9980b87002eae127af626622fd
src/app/routes/reports/query/query.component.ts
@@ -16,6 +16,7 @@
import * as $ from 'jquery';
import { DateService } from '@business/services/util/date.service';
import { zip } from 'rxjs/observable/zip';
import { Subject } from 'rxjs/Subject';
@Component({
  selector: 'app-query',
@@ -48,10 +49,10 @@
     * @memberof QueryComponent
     */
    public timeUnitOptions = [
        {label: '某年', value: TimeUnits.MONTH},
        {label: '某月', value: TimeUnits.DAY},
        {label: '某日', value: TimeUnits.HOUR},
        {label: '某时', value: TimeUnits.MINUTE},
        {label: '年', value: TimeUnits.MONTH},
        {label: '月', value: TimeUnits.DAY},
        {label: '日', value: TimeUnits.HOUR},
        {label: '时', value: TimeUnits.MINUTE},
    ];
    public timeUnit: {label: string, value: TimeUnits} = this.timeUnitOptions[2];
    // 默认时间为昨天,今天无数据
@@ -130,7 +131,7 @@
            if (!!text) {
                example.or().andEqualTo({ name: 'monitorPointId', value: this.monitorPoint.id })
                .andLike({name: 'text', value: text});
            }else {
            } else {
                example.or().andEqualTo({ name: 'monitorPointId', value: this.monitorPoint.id });
            }
            this.deviceService.getPageByExample(null, example).subscribe(
@@ -165,6 +166,46 @@
    ) { }    
    ngOnInit() {
        this.initPage();
        // 监测项目 tree click 事件
        this.treeClickStream.debounceTime(1).subscribe( event => {
            const data = event.node.data;
            // console.log(data);
            if (data.id === -1) {
                const children = data.children;
                // 全选状态
                if (!data.halfChecked && data.checked) {
                    // 全取消操作
                    data['checked'] = false;
                    data['halfChecked'] = false;
                    children.forEach(element => {
                        element['checked'] = false;
                    });
                    this._sensors = {};
                    // 未选 或者 半选状态
                } else {
                    // 全选操作
                    children.forEach(element => {
                        element['checked'] = true;
                        this._sensors [element.id] = element.sensorKey;
                    });
                    data['checked'] = true;
                    data['halfChecked'] = false;
                }
            } else {
                const parentData = event.node.parent.data;
                data['checked'] = !data['checked'];
                if (data['checked']) {
                    this._sensors [data.id] = data.sensorKey;
                } else {
                    delete this._sensors [data.id];
                }
                const length = Object.keys(this._sensors).length;
                parentData['halfChecked'] = length > 0
                && this.sensorOptions[0].children.length > length;
                parentData['checked'] = !parentData['halfChecked'] && length !== 0;
            }
            this.reloadSensorNames();
        });
    }
    private initPage() {
        this.sensorsService.getPagingList(null, null).subscribe(
@@ -237,11 +278,11 @@
                ); break;
        }
    }
    // 第一步,省市区 赋值变 并 改变监控点选项
    // 第一步,省市区 赋值变 并 改变监控站点选项
    public  setAreasData(areas: {label: string, value: string}[] ) {
        let isChanged = false;
        isChanged = areas.some( (item , index: number) => {
            // this._areas[index] 为null 改变 监控点选项
            // this._areas[index] 为null 改变 监控站点选项
            return this._areas.length < areas.length 
            || !this._areas[index] 
            || this._areas[index].value !== item.value;
@@ -253,7 +294,7 @@
        }
    }
     // 第二步 设置 监控点, 值变 改变设备选项,值为null 置空设备选项和设备值
     // 第二步 设置 监控站点, 值变 改变设备选项,值为null 置空设备选项和设备值
     public _monitorPoint: MonitorPoint;
     get monitorPoint(): MonitorPoint {
         return this._monitorPoint;
@@ -274,7 +315,7 @@
        }
        
     }
    // 第三步 设置 监控点
    // 第三步 设置 监控站点
    public _device: Device;
    set device(val: Device) {
        this._device = val;
@@ -292,6 +333,10 @@
     * @type {string}
     * @memberof QueryComponent
     */  
    private treeClickStream: Subject<any> = new Subject<any>();
    public onTreeClickSelect(event): void {
          this.treeClickStream.next(event);
    }
    public onSensorSelect(event): void {
        const data = event.node.data;
        if (data.id === -1 && data.halfChecked === false) {
@@ -304,24 +349,29 @@
            } else {
                this._sensors = {};
            }
        }else {
        } else {
             if (!!data.checked) {
                this._sensors [data.id] = data.sensorKey;
             }else {
             } else {
                delete this._sensors[data.id];
             }
        }
        this._sensorNames = '';
        this.sensorOptions[0].children.forEach(
            sensor => {
               const hasSensor = Object.keys(this._sensors).some(
                     id => Number(id) === Number(sensor.id)
                );
                if (hasSensor) {
                    this._sensorNames += sensor.name + ',';
        this.reloadSensorNames();
    }
    private reloadSensorNames(): void {
        // 异步提升展现速度
        setTimeout(() => {
            this._sensorNames = '';
            const sensorNameList = Object.keys(this._sensors).map(
                id => {
                  const sensor =  this.sensorOptions[0].children.find(item => {
                        return Number(id) === Number(item.id)   ;
                    });
                    return sensor.name;
                }
            }
        );
            );
            this._sensorNames = sensorNameList.join(', ');
        }, 1);
    }
    public setTimeUnit(val: {label: string, value: TimeUnits} ) {       
        switch (val.value) {
@@ -453,6 +503,7 @@
      this.reloadChartTitle();
      // 清空数据
      this.grid.data = [];
      console.log(lineChartCriteria);
      this.http.post(environment.SERVER_BASH_URL + '/report/line-chart', lineChartCriteria).subscribe(
        (res: ResultBean<{[key: string]: Array<Array<number>>}>) => {
           if (res.code === 1) {
@@ -476,7 +527,7 @@
                                    weight = !!value ? weight : weight + 1;
                                }
                                // 四舍五入,保留2位
                                return !!value ? String(Math.round(value * 100) / 100) : '-';
                                return value != null ? String(Math.round(value * 100) / 100) : '-';
                           }
                       );
                       this.grid.data.push({sensor: sensor, data: sensorData, weight: weight});
@@ -565,7 +616,7 @@
        const names = ['辖区', '地区', '时间', '项目'];
        switch ( this.dataCondition.areaRange ) {
            case AreaRange.MONITORPOINT :
            names[0] = '监控点';
            names[0] = '监控站点';
            names[1] = this._monitorPoint.name; break;          
            case AreaRange.DEVICE :
              names[0] = '设备';
@@ -642,9 +693,23 @@
    public sensorTableFocus(index) {
        this.sensorTableFocusIndex = index;
    }
    public sensorTableBlur(index) {
        this.sensorTableFocusIndex = -1;
    }
    public sensorSelectVisible = false;
    public treeMouseOverOccur = false;
    public onTreeMouseOver(event) {
        this.treeMouseOverOccur = true;
    }
    public onTreeMouseOut(event) {
        this.treeMouseOverOccur = false;
        setTimeout(() => {
            if (!this.treeMouseOverOccur) {
                this.sensorSelectVisible =  false;
            }
        }, 900);
    }
}