1.html:

1  <ul class="search-content">
2             <li>
3               <span class="name" (click)="selectorChange('扩样数据', true)">扩样数据</span>
4             </li>
5             <li>
6               <span class="name" (click)="selectorChange('原始数据', false)">原始数据</span>
7             </li>
8           </ul>

1.ts:

import { CommonService } from './../../service/common.service';

 dataType = this.commonService.expandName;
  isShowList: boolean = false;

 selectorChange(item, isExpand) {
    if (this.commonService.expand !== isExpand) {
      this.isShowList = false;
      this.commonService.expandName = item;
      this.dataType = item;
      this.commonService.expand = isExpand;
      this.commonService.expandType.next(isExpand);
    }
  }

common.service.ts:

import { of, Subject, Subscription } from 'rxjs'; 

expandType = new Subject();
expand: boolean = true;
expandName: string = '扩样数据';

  // 数据扩样处理
  HandleData(data) {
    if (this.expand) {
      if (typeof data === 'number') {
        //
        data = Math.round((data / 0.73) / 0.9165);
      } else if (!(data instanceof Array)) {
        // 对象
        if (data['subscriberCounts']) {
          data['subscriberCounts'].forEach((item, index) => {
            if (item['countList']) {
              item['countList'].forEach((item1, index1) => {
                data['subscriberCounts'][index]['countList'][index1] = Math.round((item1 / 0.73) / 0.9165);
              });
            }
          });
        } else if (data['countList']) {
          data['countList'].forEach((item, index) => {
            data['countList'][index] = Math.round((item / 0.73) / 0.9165);
          });
        } else if (data['populations']) {
          data['populations'].forEach((item, index) => {
            if (item['countList']) {
              item['countList'].forEach((item1, index1) => {
                data['populations'][index]['countList'][index1] = Math.round((item1 / 0.73) / 0.9165);
              });
            }
          });
        }
      } else {
        // 数组
        data.forEach(item => {
          if (item.subscriberCount) {
            item.subscriberCount = Math.round((item.subscriberCount / 0.73) / 0.9165);
          } else if (item['currentCount']) {
            item.currentCount = Math.round((item.currentCount / 0.73) / 0.9165);
          }else {
            item.populations = Math.round((item.populations / 0.73) / 0.9165);
          }
        });

      }
    }
    return data;
  }

 

 posted on 2020-11-27 12:00  楼顶铁板烧  阅读(304)  评论(0编辑  收藏  举报