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