9e31c7055269b3d9030cfb37aa4a8b237f94b5ae
[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 { Util } from '../../../../../shared/utils/utils';
4 import {SlicingTaskServices} from "../../../../../core/services/slicingTaskServices";
5 import {NzMessageService} from "ng-zorro-antd";
6
7 @Component({
8     selector: 'app-business-order',
9     templateUrl: './business-order.component.html',
10     styleUrls: ['./business-order.component.less']
11 })
12 export class BusinessOrderComponent implements OnInit {
13
14     constructor(
15         private myhttp: SlicingTaskServices,
16         private message: NzMessageService,
17         private Util: Util
18     ) {
19     }
20
21     ngOnInit() {
22     }
23
24     ngOnChanges() {
25         this.AreaFormatting();
26     }
27
28     @Input() showModel: boolean;
29     @Output() cancel = new EventEmitter<boolean>();
30     comunicationFormItems = COMMUNICATION_FORM_ITEMS;
31     slicing_order_info = {
32         name: null,
33         maxNumberofUEs: null,
34         expDataRateDL: null,
35         latency: null,
36         expDataRateUL: null,
37         resourceSharingLevel: "shared",
38         uEMobilityLevel: "stationary",
39         coverageArea: '',
40         coverageAreaNumber: null
41     };
42     areaList: any[] = [];
43     isSpinning: boolean = false;
44     validateRulesShow: any[] = [];
45     rulesText: any[] = [];
46     tooltipText: string = 'Scope: 1-100000';
47
48     AreaFormatting(): void {
49         let areaList = ['Beijing;Beijing;Haidian District;Wanshoulu Street'];
50         this.areaList = areaList.map((item: any) => {
51             let arr = item.split(';');
52             item = arr.map((it, index) => {
53                 let key: string;
54                 if (!index) {
55                     key = 'province';
56                 } else if (index === 1) {
57                     key = 'city'
58                 } else if (index === 2) {
59                     key = 'district'
60                 } else {
61                     key = 'street'
62                 }
63                 const obj: any = {};
64                 obj.key = key;
65                 obj.selected = it;
66                 obj.options = [{name: it, id: it}]
67                 return obj
68             })
69             return item;
70         })
71     }
72
73     creatAreaList(): void {
74         let arr = [
75             {
76                 key: 'province',
77                 selected: '',
78                 options: []
79             },
80             {
81                 key: 'city',
82                 selected: '',
83                 options: []
84             },
85             {
86                 key: 'district',
87                 selected: '',
88                 options: []
89             },
90             {
91                 key: 'street',
92                 selected: '',
93                 options: []
94             }
95         ]
96         this.areaList.push(arr)
97     }
98
99     deleteAreaList(index: number): void {
100         this.areaList.splice(index, 1);
101     }
102
103     handleChange(area: any[], areaItem: any): void {
104         if (areaItem.key === 'province' && areaItem.options.length <= 1) {
105             areaItem.options = COMMUNICATION_FORM_ADDRESS;
106         } else if (areaItem.key === 'city' && areaItem.options.length <= 1) {
107             COMMUNICATION_FORM_ADDRESS.forEach(item => {
108                 if (item.name === area[0].selected) {
109                     areaItem.options = item.city;
110                 }
111             })
112         } else if (areaItem.key === 'district' && areaItem.options.length <= 1) {
113             COMMUNICATION_FORM_ADDRESS.forEach((item: any) => {
114                 item.city.forEach(city => {
115                     if (city.name === area[1].selected) {
116                         areaItem.options = city.county;
117                     }
118                 })
119             })
120         } else if (areaItem.key === 'street' && areaItem.options.length <= 1) {
121             COMMUNICATION_FORM_ADDRESS.forEach((item: any) => {
122                 item.city.forEach(city => {
123                     if (city.name === area[1].selected) {
124                         city.county.forEach(county => {
125                             if (county.name === area[2].selected) {
126                                 areaItem.options = county.street;
127                             }
128                         })
129                     }
130                 })
131             })
132         }
133     }
134
135     handleChangeSelected(area: any[], areaItem: any): void {
136         let areaItemIndex = area.indexOf(areaItem);
137         area.map((item,index)=>{
138             if(index > areaItemIndex){
139                 item.selected = '';
140                 item.options = [];
141             }
142         })
143     }
144
145     handleCancel(): void {
146         this.showModel = false;
147         this.cancel.emit(this.showModel);
148         this.slicing_order_info = {
149             name: null,
150             maxNumberofUEs: null,
151             expDataRateDL: null,
152             latency: null,
153             expDataRateUL: null,
154             resourceSharingLevel: "shared",
155             uEMobilityLevel: "stationary",
156             coverageArea: '',
157             coverageAreaNumber: null
158         };
159     }
160
161     changeTooltipText(title: string): void {
162         if (title === 'Max Number of UEs') {
163             this.tooltipText = 'Scope: 1-100000'
164         } else if (title === 'Data Rate Downlink (Mbps)' || title === 'Data Rate Uplink (Mbps)') {
165             this.tooltipText = 'Scope: 100-3000'
166         } else if (title === 'Latency') {
167             this.tooltipText = 'Scope: 10-200'
168         } else if (title === 'Use Interval (Month)') {
169             this.tooltipText = 'Scope: ≥1'
170         }
171     }
172
173     handleOk(): void {
174         const coverage_list: string[] = [];
175         let coverageAreaNumber = null;
176         let coverageAreas;
177         
178         COMMUNICATION_FORM_ITEMS.forEach((item, index) => {
179             if (item.key !== 'resourceSharingLevel' && item.key !== 'uEMobilityLevel' && item.key !== 'coverageArea' && item.key !== 'coverageAreaNumber') {
180                 this.Util.validator(item.title,item.key, this.slicing_order_info[item.key], index, this.rulesText, this.validateRulesShow)
181             }else if(item.key === 'coverageAreaNumber'){
182                 coverageAreaNumber = this.slicing_order_info[item.key]
183             }
184         });
185         if (this.validateRulesShow.indexOf(true) > -1) {
186             return
187         }
188         
189         this.areaList.forEach(item => {
190             let str = '';
191             item.forEach(area => {
192                 str += area.selected + ';';
193             });
194             coverage_list.push(str.substring(0, str.length - 1));
195         });
196         
197         if (coverage_list.length > 1) {
198             coverageAreas = coverage_list.join('|')
199         } else {
200             coverageAreas = coverage_list.toString();
201         }
202         if(coverageAreaNumber){
203             this.slicing_order_info.coverageArea = `${coverageAreas}-${coverageAreaNumber}`;
204         }else{
205             this.slicing_order_info.coverageArea = `${coverageAreas}`;
206         }
207         delete this.slicing_order_info.coverageAreaNumber
208
209         const paramsObj = {
210             slicing_order_info: this.slicing_order_info
211         };
212         this.isSpinning = true;
213         const csmfSlicingPurchaseFailedCallback  = () => {
214             this.handleCancel();
215             this.isSpinning = false;
216         }
217         this.myhttp.csmfSlicingPurchase(paramsObj, csmfSlicingPurchaseFailedCallback).then(res => {
218             this.isSpinning = false;
219             this.handleCancel();
220         })
221     }
222 }