xufenglei
2018-07-24 fd35962de838e033a8964e0959c99572f02b15f0
src/app/routes/reports/query2/query2.component.ts
@@ -209,30 +209,42 @@
    private http2: HttpClient
    ) { }
  
  _dataSet = [];
    _dataSet = [];
    sensorKey = 'e1';
    loading = false;
    sensorData = {};
    changeSensorKey(sensorKey) {
      const params = {sensorKey: sensorKey, dimension: 'monitorPoint', regionCode: '320583', accountId: '1', timeType: 'month'};
      this.http2.get(environment.SERVER_BASH_URL + 'screen/region_ranking_data', {params: params}).subscribe((res: any) => {
        this._dataSet = res.data;
      });
      this._dataSet = [];
      if (!!this.sensorData[sensorKey]) {
        this._dataSet = this.sensorData[sensorKey];
      } else {
        this.loading = true;
        const params = {sensorKey: sensorKey, dimension: 'monitorPoint', regionCode: '320583', accountId: '1', timeType: 'month'};
        this.http2.get(environment.SERVER_BASH_URL + 'screen/region_ranking_data', {params: params}).subscribe((res: any) => {
          this._dataSet = this.sensorData[sensorKey] = res.data;
          this.loading = false;
        });
      }
    }
      sort(sortName, sortValue) {
        this._dataSet = [
            ...(<any[]>this._dataSet).sort((a, b) => {
                if (a[sortName] > b[sortName]) {
                    return (sortValue === 'ascend') ? 1 : -1;
                } else if (a[sortName] < b[sortName]) {
                    return (sortValue === 'ascend') ? -1 : 1;
                } else {
                    return 0;
                }
            })
        ];
    sort(sortName, sortValue) {
      this._dataSet = [
        ...(<any[]>this._dataSet).sort((a, b) => {
          if (a[sortName] > b[sortName]) {
            return (sortValue === 'ascend') ? 1 : -1;
          } else if (a[sortName] < b[sortName]) {
            return (sortValue === 'ascend') ? -1 : 1;
          } else {
            return 0;
          }
        })
      ];
    }
    ngOnInit() {
      this.changeSensorKey('e1');
      this.changeSensorKey(this.sensorKey);
//        const searchData = [];
//        for (let i = 0; i < 50; i += 1) {
//            searchData.push({