xufenglei
2018-05-14 820cc14842e73c9980b87002eae127af626622fd
src/app/routes/reports/demo/demo.component.ts
@@ -28,12 +28,19 @@
    {value: 'bar', label: '柱状图'},
    {value: 'line', label: '折线图'}
  ];
  public professionOptions = [];
  public dimensionOptions = [
    {value: 'monitorPoint', label: '监测站点'},
    {value: 'profession', label: '行业'}
  ];
  monitorPointShow = true;
  professionShow = false;
  public items: any[] = [{
    id: 0,
    profession: null,
    monitorPoint: null,
    device: null,
    time: null,
    time: new Date(),
    monitorPointOptions: [],
    deviceOptions: []
  }];
@@ -53,6 +60,7 @@
  ) {
    this.timeType = this.typeOptions[1];
    this.query.reportType = this.reportOptions[1].value;
    this.query.dimension = this.dimensionOptions[0].value;
  }
  ngOnInit() {
@@ -64,6 +72,28 @@
      }
    });
    this.http.get(environment.SERVER_BASH_URL + 'mobile/profession').subscribe((res: any) => {
      if (res.errno !== 0) {
        this.msgSrv.error(res.message);
      } else {
        this.professionOptions = res.data;
      }
    });
  }
  dimensionChange(value) {
    this.items.forEach((item,index) => {
      item.profession = null;
      item.monitorPoint = null;
      item.device = null;
    });
    if (value === 'monitorPoint') {
      this.professionShow = false;
      this.monitorPointShow = true;
    } else {
      this.professionShow = true;
      this.monitorPointShow = false;
    }
  }
  public onTreeClickSelect(event): void {
@@ -112,9 +142,10 @@
    const id = (this.items.length > 0) ? this.items[this.items.length - 1].id + 1 : 0;
    const index = this.items.push({
      id: id,
      profession: null,
      monitorPoint: null,
      device: null,
      time: null,
      time: new Date(),
      monitorPointOptions: [],
      deviceOptions: []
    });
@@ -150,6 +181,7 @@
    let areaName = '';
    const option = event.option;
    this.items[i].monitorPoint = null;
    this.items[i].profession = null;
    this.items[i].areaCode = null;
    this.items[i].device = null;
    
@@ -195,6 +227,26 @@
    }
  }
  professionChange(value, i) {
    this.items[i].deviceOptions = [];
    this.items[i].device = null;
    if (value) {
      if (!!this.items[i].areaName) {
        this.items[i].professionId = value.id;
        this.http.get(environment.SERVER_BASH_URL + 'device/professionId', {params: this.items[i]}).subscribe((res: any) => {
          if (res.code === 0) {
            this.msgSrv.error(res.message);
          } else {
            this.items[i].deviceOptions = res.data;
          }
        });
      } else {
        this.msgSrv.error('请先选择 省市区!');
      }
    }
  }
  _disabledDate(current: Date): boolean {
    return current && current.getTime() > Date.now();
  }
@@ -204,20 +256,27 @@
    let validate = true;
    const queryItems = [];
    for (let i = 0; i < this.items.length; i++) {
      let areaName = '';
      let item = this.items[i];
      let queryItem: any = {};
      if ((!!item.time) && (item.monitorPointOptions.length > 0)) {
        for (var key in item) {
      const areaName = '';
      const item = this.items[i];
      const queryItem: any = {};
      if (item.monitorPointOptions.length > 0) {
        for (const key in item) {
          if (item[key]) {
            queryItem[key] = item[key];
          }
        }
        if (queryItem.profession) {
          queryItem.professionId = queryItem.profession.id;
          queryItem.professionName = queryItem.profession.name;
          delete queryItem.profession;
        }
        if (queryItem.monitorPoint) {
          queryItem.monitorPointId = queryItem.monitorPoint.id;
          queryItem.monitorPointName = queryItem.monitorPoint.name;
          queryItem.monitorPointAddress = queryItem.monitorPoint.address;
          delete queryItem.monitorPoint;
        } else {
          queryItem.monitorPointName = queryItem.areaName;
        }
        delete queryItem.monitorPointOptions;
        if (queryItem.device) {
@@ -238,9 +297,10 @@
      }
    }
    if (validate && this.timeType && query.reportType) {
      delete query.sensors;
      if (this._sensors) {
        const sensors = [];
        for (var key in this._sensors) {
        for (const key in this._sensors) {
          sensors.push(this._sensors[key]);
        }
        if (sensors.length > 0) {
@@ -249,7 +309,7 @@
      }
      query.items = JSON.stringify(queryItems);
      query.type = this.timeType.value;
      sessionStorage.setItem("queryParams", JSON.stringify(query));
      sessionStorage.setItem('queryParams', JSON.stringify(query));
    } else {
      this.msgSrv.error('请完善搜索项或删除查询条目');
      return false;