f31f4dd198de62d15a317956a4f3d3c4f86fadd9
[usecase-ui.git] /
1 import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2 import {COMMUNICATION_FORM_ITEMS, COMMUNICATION_FORM_ADDRESS} from "../../../../../../constants/constants";
3 import {SlicingTaskServices} from "../../../../../core/services/slicingTaskServices";
4 import {NzMessageService} from "ng-zorro-antd";
5
6 @Component({
7   selector: 'app-business-order',
8   templateUrl: './business-order.component.html',
9   styleUrls: ['./business-order.component.less']
10 })
11 export class BusinessOrderComponent implements OnInit {
12
13     constructor(
14         private myhttp: SlicingTaskServices,
15         private message: NzMessageService
16         ) {
17     }
18
19     ngOnInit() {
20     }
21     ngOnChanges() {
22         this.AreaFormatting();
23     }
24     @Input() showModel: boolean;
25     @Output() cancel = new EventEmitter<boolean>();
26     comunicationFormItems = COMMUNICATION_FORM_ITEMS;
27     slicing_order_info = {
28         name: null,
29         maxNumberofUEs: null,
30         expDataRateDL: null,
31         latency: null,
32         expDataRateUL: null,
33         resourceSharingLevel: "shared",
34         uEMobilityLevel: null,
35         useInterval: null,
36         coverageArea: ''
37     };
38     areaList: any[] = [];
39     isSpinning: boolean = false;
40     AreaFormatting() {
41         let areaList = ['Beijing;Beijing;Haidian District;Wanshoulu Street'];
42         this.areaList = areaList.map((item: any) => {
43             let arr = item.split(';');
44             item = arr.map((ite, index) => {
45                 let key: string;
46                 if (!index) {
47                     key = 'province';
48                 } else if (index === 1) {
49                     key = 'city'
50                 } else if (index === 2) {
51                     key = 'district'
52                 } else {
53                     key = 'street'
54                 }
55                 const obj: any = {};
56                 obj.key = key;
57                 obj.selected = ite
58                 obj.options = [{name: ite, id: ite}]
59                 return obj
60             })
61             return item;
62         })
63     }
64
65     creatAreaList (): void {
66         let arr = [
67             {
68                 key: 'province',
69                 selected: '',
70                 options: []
71             },
72             {
73                 key: 'city',
74                 selected: '',
75                 options: []
76             },
77             {
78                 key: 'district',
79                 selected: '',
80                 options: []
81             },
82             {
83                 key: 'street',
84                 selected: '',
85                 options: []
86             }
87         ]
88         this.areaList.push(arr)
89     }
90
91     deleteAreaList (index: number): void {
92         this.areaList.splice(index,1);
93     }
94
95     handleChange(area: any[], areaItem: any): void{
96         if (areaItem.key === 'province' && areaItem.options.length <= 1) {
97             areaItem.options = COMMUNICATION_FORM_ADDRESS;
98         } else if (areaItem.key === 'city' && areaItem.options.length <= 1) {
99             COMMUNICATION_FORM_ADDRESS.forEach( item => {
100                 if(item.name === area[0].selected) {
101                     areaItem.options = item.city;
102                 }
103             })
104         }else if (areaItem.key === 'district' && areaItem.options.length <= 1) {
105             COMMUNICATION_FORM_ADDRESS.forEach( (item: any) => {
106                 item.city.forEach(city => {
107                     if (city.name === area[1].selected) {
108                         areaItem.options = city.county;
109                     }
110                 })
111             })
112         }else if (areaItem.key === 'street' && areaItem.options.length <= 1) {
113             COMMUNICATION_FORM_ADDRESS.forEach( (item: any) => {
114                 item.city.forEach(city => {
115                     if (city.name === area[1].selected) {
116                         city.county.forEach(county => {
117                             if (county.name === area[2].selected) {
118                                 areaItem.options = county.street;
119                             }
120                         })
121                     }
122                 })
123             })
124         }
125     }
126
127     handleChangeSelected(area: any[], areaItem: any) {
128         if (areaItem.key === 'province') {
129             area[1].selected = ''
130             area[1].options = [];
131             area[2].selected = '';
132             area[2].options = [];
133             area[3].selected = '';
134             area[3].options = [];
135         } else if (areaItem.key === 'city') {
136             area[2].selected = '';
137             area[2].options = [];
138             area[3].selected = '';
139             area[3].options = [];
140         }else if (areaItem.key === 'district') {
141             area[3].selected = '';
142             area[3].options = [];
143         }
144     }
145
146     handleCancel() {
147         this.showModel = false;
148         this.cancel.emit(this.showModel)
149     }
150
151     handleOk(): void {
152             const coverage_list: string[] = [];
153             this.areaList.forEach( item => {
154                 let str: string = '';
155                 item.forEach( area => {
156                     str += area.selected + ';';
157                 });
158                 coverage_list.push(str.substring(0, str.length-1));
159             });
160             if(coverage_list.length>1){
161                 this.slicing_order_info.coverageArea = coverage_list.join('|')
162             }else {
163                 this.slicing_order_info.coverageArea = coverage_list.toString();
164             }
165         let paramsObj = {
166             slicing_order_info:this.slicing_order_info
167         };
168         console.log(paramsObj,"-----paramsObj");
169         this.isSpinning = true;
170         this.myhttp.csmfSlicingPurchase(paramsObj).subscribe(res => {
171             const { result_header: { result_code, result_message }, result_body: { service_id,operation_id } } = res;
172             if (+result_code === 200) {
173                 this.isSpinning = false;
174                 this.handleCancel();
175             }
176         }, (err) => {
177             this.message.error(err);
178             this.handleCancel();
179             this.isSpinning = false;
180         })
181     }
182 }