70ef4ef87201f6c676b27e12b536685128dd3f0a
[usecase-ui.git] /
1 import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
2 import { NzMessageService } from "ng-zorro-antd";
3 import { SlicingTaskServices } from "../../../../../core/services/slicingTaskServices";
4 import { Util } from "../../../../../shared/utils/utils";
5 import { COMMUNICATION_FORM_ITEMS, MASKTEXT } from "./constants";
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);
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     intentContent: '',
55         };
56         areaList: any[] = [];
57         validateRulesShow: any[] = [];
58         rulesText: any[] = [];
59         areaLevel: number = 4;
60         masktext: string = MASKTEXT;
61         loading: boolean = false;
62         AreaFormatting(areaList): void {
63                 this.areaList = areaList.map((item: any) => {
64                         let arr = item.split(";");
65                         item = arr.map((it, index) => {
66                                 let key: string;
67                                 if (!index) {
68                                         key = "province";
69                                 } else if (index === 1) {
70                                         key = "city";
71                                 } else if (index === 2) {
72                                         key = "district";
73                                 } else {
74                                         key = "street";
75                                 }
76                                 const obj: any = {};
77                                 obj.key = key;
78                                 obj.selected = it;
79                                 obj.options = [{ name: it, id: it }];
80                                 return obj;
81                         });
82                         return item;
83                 });
84         }
85
86         handleCancel(): void {
87                 this.showModel = false;
88                 this.cancel.emit(this.showModel);
89                 this.slicing_order_info = {
90                         name: null,
91                         maxNumberofUEs: null,
92                         expDataRateDL: null,
93                         latency: null,
94                         expDataRateUL: null,
95                         resourceSharingLevel: "shared",
96                         uEMobilityLevel: "stationary",
97                         coverageArea: "",
98                         coverageAreaNumber: null,
99       intentContent: ''
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
158     // csmfSlicingPurchaseWithContent
159     const { intentContent } = this.slicing_order_info;
160     if (intentContent) {
161       this.csmfSlicingPurchaseWithContent(paramsObj, csmfSlicingPurchaseFailedCallback);
162       return;
163     }
164     this.csmfSlicingPurchase(paramsObj, csmfSlicingPurchaseFailedCallback);
165         }
166
167   csmfSlicingPurchase(paramsObj, csmfSlicingPurchaseFailedCallback): void {
168     this.myhttp
169                         .csmfSlicingPurchase(paramsObj, csmfSlicingPurchaseFailedCallback)
170                         .then((res) => {
171                                 const result = res.result_header;
172                                 if (
173                                         result &&
174                                         result.result_code &&
175                                         +result.result_code === 200
176                                 ) {
177                                         console.log(res);
178                                 } else {
179                                         this.message.create("error", "Network error");
180                                 }
181                                 this.loading = false;
182                                 this.handleCancel();
183                         });
184   }
185
186   csmfSlicingPurchaseWithContent(paramsObj, csmfSlicingPurchaseFailedCallback): void {
187     this.myhttp
188                         .csmfSlicingPurchaseWithContent(paramsObj, csmfSlicingPurchaseFailedCallback)
189                         .then((res) => {
190                                 const result = res.result_header;
191                                 if (
192                                         result &&
193                                         result.result_code &&
194                                         +result.result_code === 200
195                                 ) {
196                                         console.log(res);
197                                 } else {
198                                         this.message.create("error", "Network error");
199                                 }
200                                 this.loading = false;
201                                 this.handleCancel();
202                         });
203   }
204 }