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";
6 selector: 'app-business-order',
7 templateUrl: './business-order.component.html',
8 styleUrls: ['./business-order.component.less']
10 export class BusinessOrderComponent implements OnInit {
13 private myhttp: SlicingTaskServices,
14 private message: NzMessageService
21 this.AreaFormatting();
23 @Input() showModel: boolean;
24 @Output() cancel = new EventEmitter<boolean>();
25 comunicationFormItems = COMMUNICATION_FORM_ITEMS;
26 slicing_order_info = {
32 resourceSharingLevel: "shared",
33 uEMobilityLevel: "stationary",
38 isSpinning: boolean = false;
39 validateRules: any[] = [];
40 rulesText: any[] = [];
42 let areaList = ['Beijing;Beijing;Haidian District;Wanshoulu Street'];
43 this.areaList = areaList.map((item: any) => {
44 let arr = item.split(';');
45 item = arr.map((ite, index) => {
49 } else if (index === 1) {
51 } else if (index === 2) {
59 obj.options = [{name: ite, id: ite}]
66 creatAreaList (): void {
89 this.areaList.push(arr)
92 deleteAreaList (index: number): void {
93 this.areaList.splice(index,1);
96 handleChange(area: any[], areaItem: any): void{
97 if (areaItem.key === 'province' && areaItem.options.length <= 1) {
98 areaItem.options = COMMUNICATION_FORM_ADDRESS;
99 } else if (areaItem.key === 'city' && areaItem.options.length <= 1) {
100 COMMUNICATION_FORM_ADDRESS.forEach( item => {
101 if(item.name === area[0].selected) {
102 areaItem.options = item.city;
105 }else if (areaItem.key === 'district' && areaItem.options.length <= 1) {
106 COMMUNICATION_FORM_ADDRESS.forEach( (item: any) => {
107 item.city.forEach(city => {
108 if (city.name === area[1].selected) {
109 areaItem.options = city.county;
113 }else if (areaItem.key === 'street' && areaItem.options.length <= 1) {
114 COMMUNICATION_FORM_ADDRESS.forEach( (item: any) => {
115 item.city.forEach(city => {
116 if (city.name === area[1].selected) {
117 city.county.forEach(county => {
118 if (county.name === area[2].selected) {
119 areaItem.options = county.street;
128 handleChangeSelected(area: any[], areaItem: any) {
129 if (areaItem.key === 'province') {
130 area[1].selected = ''
131 area[1].options = [];
132 area[2].selected = '';
133 area[2].options = [];
134 area[3].selected = '';
135 area[3].options = [];
136 } else if (areaItem.key === 'city') {
137 area[2].selected = '';
138 area[2].options = [];
139 area[3].selected = '';
140 area[3].options = [];
141 }else if (areaItem.key === 'district') {
142 area[3].selected = '';
143 area[3].options = [];
148 this.showModel = false;
149 this.cancel.emit(this.showModel);
150 this.slicing_order_info = {
152 maxNumberofUEs: null,
156 resourceSharingLevel: "shared",
157 uEMobilityLevel: "stationary",
163 getRulesText = (words,title,val,index) => {
164 return this.rulesText[index] = words + title
167 validator(key,val,i){
168 if(val === null || val.replace(/\s*/g,'').length<=0){
169 this.validateRules[i] = true;
170 this.getRulesText('Please enter',key,val,i,);
173 this.validateRules[i] = false;
175 if(key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && isNaN(val)){
176 this.validateRules[i] = true;
177 this.getRulesText('Only numbers can be entered','','',i);
179 }else if(key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && !isNaN(val)){
180 console.log("-----maxNumberofUEs")
181 this.validateRules[i] = true;
182 this.getRulesText('Scope: 1-100000','','',i);
185 this.validateRules[i] = false;
186 }if((key === 'expDataRateDL' || key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && isNaN(val)){
187 this.validateRules[i] = true;
188 this.getRulesText('Only numbers can be entered','','',i);
190 }else if((key === 'expDataRateDL' || key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && !isNaN(val)){
191 this.validateRules[i] = true;
192 this.getRulesText('Scope: 100-3000','','',i);
195 this.validateRules[i] = false;
196 }if(key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && isNaN(val)){
197 this.validateRules[i] = true;
198 this.getRulesText('Only numbers can be entered','','',i);
200 }else if(key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && !isNaN(val)){
201 this.validateRules[i] = true;
202 this.getRulesText('Scope: 10-200','','',i);
205 this.validateRules[i] = false;
206 }if(key === 'useInterval' && !/^[1-9]\d*$/.test(val) && isNaN(val)){
207 this.validateRules[i] = true;
208 this.getRulesText('Only numbers can be entered','','',i);
210 }else if(key === 'useInterval' && !/^[1-9]\d*$/.test(val) && !isNaN(val)){
211 this.validateRules[i] = true;
212 this.getRulesText('Scope: >=1','','',i);
215 this.validateRules[i] = false;
220 Object.keys(this.slicing_order_info).forEach((item,index)=>{
221 if(item !== 'resourceSharingLevel' && item !== 'uEMobilityLevel' && item !== 'coverageArea'){
222 this.validator(item,this.slicing_order_info[item],index)
225 if(this.validateRules.indexOf(true)>-1){
228 const coverage_list: string[] = [];
229 this.areaList.forEach( item => {
230 let str: string = '';
231 item.forEach( area => {
232 str += area.selected + ';';
234 coverage_list.push(str.substring(0, str.length-1));
236 if(coverage_list.length>1){
237 this.slicing_order_info.coverageArea = coverage_list.join('|')
239 this.slicing_order_info.coverageArea = coverage_list.toString();
242 slicing_order_info:this.slicing_order_info
244 console.log(paramsObj,"-----paramsObj");
245 this.isSpinning = true;
246 this.myhttp.csmfSlicingPurchase(paramsObj).subscribe(res => {
247 const { result_header: { result_code, result_message }, result_body: { service_id,operation_id } } = res;
248 if (+result_code === 200) {
249 this.isSpinning = false;
253 this.message.error(err);
255 this.isSpinning = false;