6409f0087b2c3012048adaf3b950eadab3b56623
[usecase-ui.git] /
1 import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
2 import { COMMUNICATION_FORM_ITEMS,MASKTEXT } 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         constructor(
14                 private myhttp: SlicingTaskServices,
15                 private message: NzMessageService,
16                 private Util: Util
17         ) {}
18
19         ngOnInit() {}
20
21         ngOnChanges() {
22             let areaList = ["Beijing;Beijing;Haidian District;Wanshoulu Street"];
23             if (this.modelParams && this.showModel) {
24                 this.slicing_order_info = {...this.modelParams};
25                 if (this.slicing_order_info.coverageArea) {
26                     areaList = [];
27                     areaList.push(this.slicing_order_info.coverageArea.split(" ").join(";"));
28                 }
29             }
30             this.AreaFormatting(areaList);
31         }
32         detailFn(flag){
33           COMMUNICATION_FORM_ITEMS.forEach((item, index) => {
34               if(item.key=='coverageAreaNumber'){
35                   item["coverflag"] = flag == true ? false:true
36               }
37           })
38         }
39
40         @Input() showModel: boolean;
41         @Input() modelParams: any;
42         @Output() cancel = new EventEmitter<boolean>();
43         comunicationFormItems = COMMUNICATION_FORM_ITEMS;
44         slicing_order_info = {
45                 name: null,
46                 maxNumberofUEs: null,
47                 expDataRateDL: null,
48                 latency: null,
49                 expDataRateUL: null,
50                 resourceSharingLevel: "shared",
51                 uEMobilityLevel: "stationary",
52                 coverageArea: "",
53                 coverageAreaNumber: null,
54         };
55         areaList: any[] = [];
56         validateRulesShow: any[] = [];
57         rulesText: any[] = [];
58         areaLevel: number = 4;
59         masktext: string = MASKTEXT ;
60         AreaFormatting(areaList): void {
61                 this.areaList = areaList.map((item: any) => {
62                         let arr = item.split(";");
63                         item = arr.map((it, index) => {
64                                 let key: string;
65                                 if (!index) {
66                                         key = "province";
67                                 } else if (index === 1) {
68                                         key = "city";
69                                 } else if (index === 2) {
70                                         key = "district";
71                                 } else {
72                                         key = "street";
73                                 }
74                                 const obj: any = {};
75                                 obj.key = key;
76                                 obj.selected = it;
77                                 obj.options = [{ name: it, id: it }];
78                                 return obj;
79                         });
80                         return item;
81                 });
82         }
83
84         handleCancel(): void {
85                 this.showModel = false;
86                 this.cancel.emit(this.showModel);
87                 this.slicing_order_info = {
88                         name: null,
89                         maxNumberofUEs: null,
90                         expDataRateDL: null,
91                         latency: null,
92                         expDataRateUL: null,
93                         resourceSharingLevel: "shared",
94                         uEMobilityLevel: "stationary",
95                         coverageArea: "",
96                         coverageAreaNumber: null,
97                 };
98                 this.validateRulesShow = [];
99         }
100
101         handleOk(): void {
102                 const coverage_list: string[] = [];
103                 let coverageAreas;
104                 COMMUNICATION_FORM_ITEMS.forEach((item, index) => {
105                         if (item.required && item.type === "input" ) {
106                                 this.Util.validator(
107                                         item.title,
108                                         item.key,
109                                         this.slicing_order_info[item.key],
110                                         index,
111                                         this.rulesText,
112                                         this.validateRulesShow
113                                 );
114                         }
115                 });
116                 if (this.validateRulesShow.indexOf(true) > -1) {
117                         return;
118                 }
119                 for(const key in this.areaList){
120                         const value  = this.areaList[key]
121                          let str = "";
122                          for(const val of value){
123                                  const area = val
124                                  str += area.selected + ";";
125                                  if(!area.selected){
126                                          this.message.error("Please complete the form");
127                                          return;
128                                          }
129                          }
130                          coverage_list.push(str.substring(0, str.length - 1));
131                  }
132                 if (coverage_list.length > 1) {
133                         coverageAreas = coverage_list.join("|");
134                 } else {
135                         coverageAreas = coverage_list.toString();
136                 }
137                 const coverageAreaNumber = this.slicing_order_info[
138                         "coverageAreaNumber"
139                 ];
140                 if (coverageAreaNumber) {
141                         this.slicing_order_info.coverageArea = `${coverageAreas}-${coverageAreaNumber}`;
142                 } else {
143                         this.slicing_order_info.coverageArea = `${coverageAreas}`;
144                 }
145                 delete this.slicing_order_info.coverageAreaNumber;
146
147                 const paramsObj = {
148                         slicing_order_info: this.slicing_order_info,
149                 };
150                 const csmfSlicingPurchaseFailedCallback = () => {
151                         this.handleCancel();
152                 };
153                 
154                 this.myhttp
155                         .csmfSlicingPurchase(paramsObj, csmfSlicingPurchaseFailedCallback)
156                         .then((res) => {
157                                 const result = res.result_header;
158                                 if (
159                                         result &&
160                                         result.result_code &&
161                                         +result.result_code === 200
162                                 ) {
163                                         console.log(res);
164                                 } else {
165                                         this.message.create("error", "Network error");
166                                 }
167                                 this.handleCancel();
168                         });
169         }
170 }