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)
152 getRulesText = (words,title,val,index) => {
153 return this.rulesText[index] = words + title
156 validator(key,val,i){
157 if(val === null || val.replace(/\s*/g,'').length<=0){
158 this.validateRules[i] = true;
159 this.getRulesText('Please enter',key,val,i);
162 this.validateRules[i] = false;
163 }if(key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && isNaN(val)){
164 this.validateRules[i] = true;
165 this.getRulesText('Only numbers can be entered','','',i);
167 }else if(key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && !isNaN(val)){
168 console.log("-----maxNumberofUEs")
169 this.validateRules[i] = true;
170 this.getRulesText('Scope: 1-100000','','',i);
173 this.validateRules[i] = false;
174 }if((key === 'expDataRateDL' || key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && isNaN(val)){
175 this.validateRules[i] = true;
176 this.getRulesText('Only numbers can be entered','','',i);
178 }else if((key === 'expDataRateDL' || key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && !isNaN(val)){
179 this.validateRules[i] = true;
180 this.getRulesText('Scope: 100-3000','','',i);
183 this.validateRules[i] = false;
184 }if(key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && isNaN(val)){
185 this.validateRules[i] = true;
186 this.getRulesText('Only numbers can be entered','','',i);
188 }else if(key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && !isNaN(val)){
189 this.validateRules[i] = true;
190 this.getRulesText('Scope: 10-200','','',i);
193 this.validateRules[i] = false;
194 }if(key === 'useInterval' && !/^[1-9]\d*$/.test(val) && isNaN(val)){
195 this.validateRules[i] = true;
196 this.getRulesText('Only numbers can be entered','','',i);
198 }else if(key === 'useInterval' && !/^[1-9]\d*$/.test(val) && !isNaN(val)){
199 this.validateRules[i] = true;
200 this.getRulesText('Scope: >=1','','',i);
203 this.validateRules[i] = false;
208 Object.keys(this.slicing_order_info).forEach((item,index)=>{
209 this.validator(item,this.slicing_order_info[item],index)
211 if(this.validateRules.indexOf(true)>-1){
214 const coverage_list: string[] = [];
215 this.areaList.forEach( item => {
216 let str: string = '';
217 item.forEach( area => {
218 str += area.selected + ';';
220 coverage_list.push(str.substring(0, str.length-1));
222 if(coverage_list.length>1){
223 this.slicing_order_info.coverageArea = coverage_list.join('|')
225 this.slicing_order_info.coverageArea = coverage_list.toString();
228 slicing_order_info:this.slicing_order_info
230 console.log(paramsObj,"-----paramsObj");
231 this.isSpinning = true;
232 this.myhttp.csmfSlicingPurchase(paramsObj).subscribe(res => {
233 const { result_header: { result_code, result_message }, result_body: { service_id,operation_id } } = res;
234 if (+result_code === 200) {
235 this.isSpinning = false;
239 this.message.error(err);
241 this.isSpinning = false;