bfef2d20faf489e16b31ddfd9b9d2248a0f6c26f
[usecase-ui.git] /
1 import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2 import {COMMUNICATION_FORM_ITEMS, COMMUNICATION_FORM_ADDRESS} from "./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     validateRulesShow: any[] = [];
44     rulesText: any[] = [];
45
46     AreaFormatting(): void {
47         let areaList = ['Beijing;Beijing;Haidian District;Wanshoulu Street'];
48         this.areaList = areaList.map((item: any) => {
49             let arr = item.split(';');
50             item = arr.map((it, index) => {
51                 let key: string;
52                 if (!index) {
53                     key = 'province';
54                 } else if (index === 1) {
55                     key = 'city'
56                 } else if (index === 2) {
57                     key = 'district'
58                 } else {
59                     key = 'street'
60                 }
61                 const obj: any = {};
62                 obj.key = key;
63                 obj.selected = it;
64                 obj.options = [{name: it, id: it}]
65                 return obj
66             })
67             return item;
68         })
69     }
70
71     creatAreaList(): void {
72         const arr = [
73             {
74                 key: 'province',
75                 selected: '',
76                 options: []
77             },
78             {
79                 key: 'city',
80                 selected: '',
81                 options: []
82             },
83             {
84                 key: 'district',
85                 selected: '',
86                 options: []
87             },
88             {
89                 key: 'street',
90                 selected: '',
91                 options: []
92             }
93         ]
94         this.areaList.push(arr)
95     }
96
97     deleteAreaList(index: number): void {
98         this.areaList.splice(index, 1);
99     }
100
101     handleChange(area: any[], areaItem: any): void {
102         if (areaItem.key === 'province' && areaItem.options.length <= 1) {
103             areaItem.options = COMMUNICATION_FORM_ADDRESS;
104         } else if (areaItem.key === 'city' && areaItem.options.length <= 1) {
105             COMMUNICATION_FORM_ADDRESS.forEach(item => {
106                 if (item.name === area[0].selected) {
107                     areaItem.options = item.city;
108                 }
109             })
110         } else if (areaItem.key === 'district' && areaItem.options.length <= 1) {
111             COMMUNICATION_FORM_ADDRESS.forEach((item: any) => {
112                 item.city.forEach(city => {
113                     if (city.name === area[1].selected) {
114                         areaItem.options = city.county;
115                     }
116                 })
117             })
118         } else if (areaItem.key === 'street' && areaItem.options.length <= 1) {
119             COMMUNICATION_FORM_ADDRESS.forEach((item: any) => {
120                 item.city.forEach(city => {
121                     if (city.name === area[1].selected) {
122                         city.county.forEach(county => {
123                             if (county.name === area[2].selected) {
124                                 areaItem.options = county.street;
125                             }
126                         })
127                     }
128                 })
129             })
130         }
131     }
132
133     handleChangeSelected(area: any[], areaItem: any): void {
134         let areaItemIndex = area.indexOf(areaItem);
135         area.map((item,index)=>{
136             if(index > areaItemIndex){
137                 item.selected = '';
138                 item.options = [];
139             }
140         })
141     }
142
143     handleCancel(): void {
144         this.showModel = false;
145         this.cancel.emit(this.showModel);
146         this.slicing_order_info = {
147             name: null,
148             maxNumberofUEs: null,
149             expDataRateDL: null,
150             latency: null,
151             expDataRateUL: null,
152             resourceSharingLevel: "shared",
153             uEMobilityLevel: "stationary",
154             coverageArea: '',
155             coverageAreaNumber: null
156         };
157         this.validateRulesShow = []
158     }
159
160     handleOk(): void {
161         const coverage_list: string[] = [];
162         let coverageAreas;
163
164         COMMUNICATION_FORM_ITEMS.forEach((item, index) => {
165             if (item.required && item.type==="input") {
166                 this.Util.validator(item.title,item.key, this.slicing_order_info[item.key], index, this.rulesText, this.validateRulesShow)
167             }
168         });
169         if (this.validateRulesShow.indexOf(true) > -1) {
170             return
171         }
172         
173         this.areaList.forEach(item => {
174             let str = '';
175             item.forEach(area => {
176                 str += area.selected + ';';
177             });
178             coverage_list.push(str.substring(0, str.length - 1));
179         });
180         if (coverage_list.length > 1) {
181             coverageAreas = coverage_list.join('|')
182         } else {
183             coverageAreas = coverage_list.toString();
184         }
185         const coverageAreaNumber = this.slicing_order_info["coverageAreaNumber"];
186         if(coverageAreaNumber){
187             this.slicing_order_info.coverageArea = `${coverageAreas}-${coverageAreaNumber}`;
188         }else{
189             this.slicing_order_info.coverageArea = `${coverageAreas}`;
190         }
191         delete this.slicing_order_info.coverageAreaNumber
192
193         const paramsObj = {
194             slicing_order_info: this.slicing_order_info
195         };
196         const csmfSlicingPurchaseFailedCallback  = () => {
197             this.handleCancel();
198         }
199         this.myhttp.csmfSlicingPurchase(paramsObj, csmfSlicingPurchaseFailedCallback).then(res => {
200             const result = res.result_header;
201             if(result&&result.result_code&&+result.result_code===200){
202                 console.log(res)
203             }else{
204                 this.message.create('error','Network error')
205             }
206             this.handleCancel();
207         })
208     }
209 }