fengxiang
2018-06-25 27cd36be226ca2434f06b1ae9e4d43f1fea639ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Component, OnInit } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { OrganizationService } from '@business/services/http/organization.service';
import { Organization, OrganizationSensorUnit } from '@business/entity/data';
import { ResultBean } from '@business/entity/grid';
import { NzMessageService } from 'ng-zorro-antd';
 
@Component({
  selector: 'app-organization-config-unit',
  templateUrl: './organization-config-unit.component.html',
})
export class OrganizationConfigUnitComponent implements OnInit {
    public organization: Organization;
    constructor(
        private http: _HttpClient,
        private organizationService: OrganizationService,
        public msgSrv: NzMessageService
    ) { }
    public osuTowDimList: OrganizationSensorUnit[][] = [];
 
    public originalOsuList: OrganizationSensorUnit[] = [];
    public osuList: OrganizationSensorUnit[];
    public sensorUnitMap;
    ngOnInit() {
        this.organization = this.organizationService.data;
        this.sensorUnitMap = <OrganizationSensorUnit []> this.organizationService.config.resultBean.data.sensorUnitMap;
        const osuList = <OrganizationSensorUnit []> this.organizationService.config.resultBean.data.osuList;
        this.osuList = osuList;
        // 保存原始数据
        osuList.forEach(item => {
            const osu = {};
            Object.assign(osu, item);
            this.originalOsuList.push(osu);
        });
        if ( !!osuList ) {
            for (let index = 0 ; index < osuList.length; index += 3 ) {
                const osuListTemp: OrganizationSensorUnit[] = [];
                for (let n = 0 ; n < 3; n++ ) {
                        const nTemp =  index + n;
                        if (nTemp < osuList.length ) {
                            osuListTemp.push(osuList[nTemp]);
                        }
                }
                this.osuTowDimList.push(osuListTemp);
            }
        }
        console.log(this.osuTowDimList);
    }
    public isSaving = false;
    save() {
        this.isSaving = true;
        const modifyList = [];
        // 寻找发生修改的
        this.osuList.forEach(
            item => {
                const osu = this.originalOsuList.find(
                    su => {
                        return su.sensor.id === item.sensor.id && 
                        su.sensorUnitId !== item.sensorUnitId;
                    }
                );
                if (!!osu) {
                    modifyList.push(item);
                }
            }
        );
        if (!!modifyList.length) {
            this.http.post('org-sunit/saves', modifyList).subscribe(
                (res: ResultBean<any>) => {
                    if (res.code > 0 ) {
                        this.isSaving = false;
                        this.msgSrv.success(this.organization.name + ' 配置成功!');
                        // this.backToList();
                    }
                }
            );
        }
    }
    backToList() {
        this.organizationService.handle = 'list';
        this.organizationService.title = '组织列表';
      }
}