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";
7 selector: 'app-business-order',
8 templateUrl: './business-order.component.html',
9 styleUrls: ['./business-order.component.less']
11 export class BusinessOrderComponent implements OnInit {
14 private myhttp: SlicingTaskServices,
15 private message: NzMessageService
23 this.AreaFormatting();
26 @Input() showModel: boolean;
27 @Output() cancel = new EventEmitter<boolean>();
28 comunicationFormItems = COMMUNICATION_FORM_ITEMS;
29 slicing_order_info = {
35 resourceSharingLevel: "shared",
36 uEMobilityLevel: "stationary",
40 isSpinning: boolean = false;
41 validateRules: any[] = [];
42 rulesText: any[] = [];
43 tooltipText: string = 'Scope: 1-100000';
46 let areaList = ['Beijing;Beijing;Haidian District;Wanshoulu Street'];
47 this.areaList = areaList.map((item: any) => {
48 let arr = item.split(';');
49 item = arr.map((ite, index) => {
53 } else if (index === 1) {
55 } else if (index === 2) {
63 obj.options = [{name: ite, id: ite}]
70 creatAreaList(): void {
93 this.areaList.push(arr)
96 deleteAreaList(index: number): void {
97 this.areaList.splice(index, 1);
100 handleChange(area: any[], areaItem: any): void {
101 if (areaItem.key === 'province' && areaItem.options.length <= 1) {
102 areaItem.options = COMMUNICATION_FORM_ADDRESS;
103 } else if (areaItem.key === 'city' && areaItem.options.length <= 1) {
104 COMMUNICATION_FORM_ADDRESS.forEach(item => {
105 if (item.name === area[0].selected) {
106 areaItem.options = item.city;
109 } else if (areaItem.key === 'district' && areaItem.options.length <= 1) {
110 COMMUNICATION_FORM_ADDRESS.forEach((item: any) => {
111 item.city.forEach(city => {
112 if (city.name === area[1].selected) {
113 areaItem.options = city.county;
117 } else if (areaItem.key === 'street' && areaItem.options.length <= 1) {
118 COMMUNICATION_FORM_ADDRESS.forEach((item: any) => {
119 item.city.forEach(city => {
120 if (city.name === area[1].selected) {
121 city.county.forEach(county => {
122 if (county.name === area[2].selected) {
123 areaItem.options = county.street;
132 handleChangeSelected(area: any[], areaItem: any) {
133 if (areaItem.key === 'province') {
134 area[1].selected = ''
135 area[1].options = [];
136 area[2].selected = '';
137 area[2].options = [];
138 area[3].selected = '';
139 area[3].options = [];
140 } else if (areaItem.key === 'city') {
141 area[2].selected = '';
142 area[2].options = [];
143 area[3].selected = '';
144 area[3].options = [];
145 } else if (areaItem.key === 'district') {
146 area[3].selected = '';
147 area[3].options = [];
152 this.showModel = false;
153 this.cancel.emit(this.showModel);
154 this.slicing_order_info = {
156 maxNumberofUEs: null,
160 resourceSharingLevel: "shared",
161 uEMobilityLevel: "stationary",
166 changeTooltipText(title) {
167 if (title === 'Max Number of UEs') {
168 this.tooltipText = 'Scope: 1-100000'
169 } else if (title === 'Data Rate Downlink (Mbps)' || title === 'Data Rate Uplink (Mbps)') {
170 this.tooltipText = 'Scope: 100-3000'
171 } else if (title === 'Latency') {
172 this.tooltipText = 'Scope: 10-200'
173 } else if (title === 'Use Interval (Month)') {
174 this.tooltipText = 'Scope: ≥1'
178 getRulesText = (words, title, val, index) => {
179 return this.rulesText[index] = words + title
182 validator(item, val, i) {
183 if (val === null || val.replace(/\s*/g, '').length <= 0) {
184 this.validateRules[i] = true;
185 this.getRulesText('Please enter ', item.title, val, i,);
188 this.validateRules[i] = false;
190 if (item.key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && isNaN(val)) {
191 this.validateRules[i] = true;
192 this.getRulesText('Only numbers can be entered', '', '', i);
194 } else if (item.key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && !isNaN(val)) {
195 console.log("-----maxNumberofUEs")
196 this.validateRules[i] = true;
197 this.getRulesText('Scope: 1-100000', '', '', i);
200 this.validateRules[i] = false;
202 if ((item.key === 'expDataRateDL' || item.key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && isNaN(val)) {
203 this.validateRules[i] = true;
204 this.getRulesText('Only numbers can be entered', '', '', i);
206 } else if ((item.key === 'expDataRateDL' || item.key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && !isNaN(val)) {
207 this.validateRules[i] = true;
208 this.getRulesText('Scope: 100-3000', '', '', i);
211 this.validateRules[i] = false;
213 if (item.key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && isNaN(val)) {
214 this.validateRules[i] = true;
215 this.getRulesText('Only numbers can be entered', '', '', i);
217 } else if (item.key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && !isNaN(val)) {
218 this.validateRules[i] = true;
219 this.getRulesText('Scope: 10-200', '', '', i);
222 this.validateRules[i] = false;
227 COMMUNICATION_FORM_ITEMS.forEach((item, index) => {
228 if (item.key !== 'resourceSharingLevel' && item.key !== 'uEMobilityLevel' && item.key !== 'coverageArea') {
229 this.validator(item, this.slicing_order_info[item.key], index)
232 if (this.validateRules.indexOf(true) > -1) {
235 const coverage_list: string[] = [];
236 this.areaList.forEach(item => {
238 item.forEach(area => {
239 str += area.selected + ';';
241 coverage_list.push(str.substring(0, str.length - 1));
243 if (coverage_list.length > 1) {
244 this.slicing_order_info.coverageArea = coverage_list.join('|')
246 this.slicing_order_info.coverageArea = coverage_list.toString();
249 slicing_order_info: this.slicing_order_info
251 console.log(paramsObj, "-----paramsObj");
252 this.isSpinning = true;
253 this.myhttp.csmfSlicingPurchase(paramsObj).subscribe(res => {
254 const {result_header: {result_code, result_message}, result_body: {service_id, operation_id}} = res;
255 if (+result_code === 200) {
256 this.isSpinning = false;
260 this.message.error(err);
262 this.isSpinning = false;