7fc95e4125e5ce9999592ed294396705063e505f
[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 @Component({
6   selector: 'app-business-order',
7   templateUrl: './business-order.component.html',
8   styleUrls: ['./business-order.component.less']
9 })
10 export class BusinessOrderComponent implements OnInit {
11
12     constructor(
13         private myhttp: SlicingTaskServices,
14         private message: NzMessageService
15         ) {
16     }
17
18     ngOnInit() {
19     }
20     ngOnChanges() {
21         this.AreaFormatting();
22     }
23     @Input() showModel: boolean;
24     @Output() cancel = new EventEmitter<boolean>();
25     comunicationFormItems = COMMUNICATION_FORM_ITEMS;
26     slicing_order_info = {
27         name: null,
28         maxNumberofUEs: null,
29         expDataRateDL: null,
30         latency: null,
31         expDataRateUL: null,
32         resourceSharingLevel: "shared",
33         uEMobilityLevel: "stationary",
34         useInterval: null,
35         coverageArea: ''
36     };
37     areaList: any[] = [];
38     isSpinning: boolean = false;
39     validateRules: any[] = [];
40     rulesText: any[] = [];
41     AreaFormatting() {
42         let areaList = ['Beijing;Beijing;Haidian District;Wanshoulu Street'];
43         this.areaList = areaList.map((item: any) => {
44             let arr = item.split(';');
45             item = arr.map((ite, index) => {
46                 let key: string;
47                 if (!index) {
48                     key = 'province';
49                 } else if (index === 1) {
50                     key = 'city'
51                 } else if (index === 2) {
52                     key = 'district'
53                 } else {
54                     key = 'street'
55                 }
56                 const obj: any = {};
57                 obj.key = key;
58                 obj.selected = ite
59                 obj.options = [{name: ite, id: ite}]
60                 return obj
61             })
62             return item;
63         })
64     }
65
66     creatAreaList (): void {
67         let arr = [
68             {
69                 key: 'province',
70                 selected: '',
71                 options: []
72             },
73             {
74                 key: 'city',
75                 selected: '',
76                 options: []
77             },
78             {
79                 key: 'district',
80                 selected: '',
81                 options: []
82             },
83             {
84                 key: 'street',
85                 selected: '',
86                 options: []
87             }
88         ]
89         this.areaList.push(arr)
90     }
91
92     deleteAreaList (index: number): void {
93         this.areaList.splice(index,1);
94     }
95
96     handleChange(area: any[], areaItem: any): void{
97         if (areaItem.key === 'province' && areaItem.options.length <= 1) {
98             areaItem.options = COMMUNICATION_FORM_ADDRESS;
99         } else if (areaItem.key === 'city' && areaItem.options.length <= 1) {
100             COMMUNICATION_FORM_ADDRESS.forEach( item => {
101                 if(item.name === area[0].selected) {
102                     areaItem.options = item.city;
103                 }
104             })
105         }else if (areaItem.key === 'district' && areaItem.options.length <= 1) {
106             COMMUNICATION_FORM_ADDRESS.forEach( (item: any) => {
107                 item.city.forEach(city => {
108                     if (city.name === area[1].selected) {
109                         areaItem.options = city.county;
110                     }
111                 })
112             })
113         }else if (areaItem.key === 'street' && areaItem.options.length <= 1) {
114             COMMUNICATION_FORM_ADDRESS.forEach( (item: any) => {
115                 item.city.forEach(city => {
116                     if (city.name === area[1].selected) {
117                         city.county.forEach(county => {
118                             if (county.name === area[2].selected) {
119                                 areaItem.options = county.street;
120                             }
121                         })
122                     }
123                 })
124             })
125         }
126     }
127
128     handleChangeSelected(area: any[], areaItem: any) {
129         if (areaItem.key === 'province') {
130             area[1].selected = ''
131             area[1].options = [];
132             area[2].selected = '';
133             area[2].options = [];
134             area[3].selected = '';
135             area[3].options = [];
136         } else if (areaItem.key === 'city') {
137             area[2].selected = '';
138             area[2].options = [];
139             area[3].selected = '';
140             area[3].options = [];
141         }else if (areaItem.key === 'district') {
142             area[3].selected = '';
143             area[3].options = [];
144         }
145     }
146
147     handleCancel() {
148         this.showModel = false;
149         this.cancel.emit(this.showModel)
150     }
151
152     getRulesText = (words,title,val,index) => {
153         return this.rulesText[index] = words + title
154     };
155
156     validator(key,val,i){
157         if(val === null || val.replace(/\s*/g,'').length<=0){
158             this.validateRules[i] = true;
159             this.getRulesText('Please enter',key,val,i);
160             return false
161         }else {
162             this.validateRules[i] = false;
163         }if(key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && isNaN(val)){
164             this.validateRules[i] = true;
165             this.getRulesText('Only numbers can be entered','','',i);
166             return false
167         }else if(key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && !isNaN(val)){
168             console.log("-----maxNumberofUEs")
169             this.validateRules[i] = true;
170             this.getRulesText('Scope: 1-100000','','',i);
171             return false
172         }else {
173             this.validateRules[i] = false;
174         }if((key === 'expDataRateDL' || key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && isNaN(val)){
175             this.validateRules[i] = true;
176             this.getRulesText('Only numbers can be entered','','',i);
177             return false
178         }else if((key === 'expDataRateDL' || key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && !isNaN(val)){
179             this.validateRules[i] = true;
180             this.getRulesText('Scope: 100-3000','','',i);
181             return false
182         }else {
183             this.validateRules[i] = false;
184         }if(key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && isNaN(val)){
185             this.validateRules[i] = true;
186             this.getRulesText('Only numbers can be entered','','',i);
187             return false
188         }else if(key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && !isNaN(val)){
189             this.validateRules[i] = true;
190             this.getRulesText('Scope: 10-200','','',i);
191             return false
192         }else {
193             this.validateRules[i] = false;
194         }if(key === 'useInterval' && !/^[1-9]\d*$/.test(val) && isNaN(val)){
195             this.validateRules[i] = true;
196             this.getRulesText('Only numbers can be entered','','',i);
197             return false
198         }else if(key === 'useInterval' && !/^[1-9]\d*$/.test(val) && !isNaN(val)){
199             this.validateRules[i] = true;
200             this.getRulesText('Scope: >=1','','',i);
201             return false
202         }else {
203             this.validateRules[i] = false;
204         }
205     }
206
207     handleOk(): void {
208         Object.keys(this.slicing_order_info).forEach((item,index)=>{
209             this.validator(item,this.slicing_order_info[item],index)
210         });
211         if(this.validateRules.indexOf(true)>-1){
212             return
213         };
214             const coverage_list: string[] = [];
215             this.areaList.forEach( item => {
216                 let str: string = '';
217                 item.forEach( area => {
218                     str += area.selected + ';';
219                 });
220                 coverage_list.push(str.substring(0, str.length-1));
221             });
222             if(coverage_list.length>1){
223                 this.slicing_order_info.coverageArea = coverage_list.join('|')
224             }else {
225                 this.slicing_order_info.coverageArea = coverage_list.toString();
226             }
227         let paramsObj = {
228             slicing_order_info:this.slicing_order_info
229         };
230         console.log(paramsObj,"-----paramsObj");
231         this.isSpinning = true;
232         this.myhttp.csmfSlicingPurchase(paramsObj).subscribe(res => {
233             const { result_header: { result_code, result_message }, result_body: { service_id,operation_id } } = res;
234             if (+result_code === 200) {
235                 this.isSpinning = false;
236                 this.handleCancel();
237             }
238         }, (err) => {
239             this.message.error(err);
240             this.handleCancel();
241             this.isSpinning = false;
242         })
243     }
244 }