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[] = [];
41 tooltipText: string = 'Scope: 1-100000';
43 let areaList = ['Beijing;Beijing;Haidian District;Wanshoulu Street'];
44 this.areaList = areaList.map((item: any) => {
45 let arr = item.split(';');
46 item = arr.map((ite, index) => {
50 } else if (index === 1) {
52 } else if (index === 2) {
60 obj.options = [{name: ite, id: ite}]
67 creatAreaList (): void {
90 this.areaList.push(arr)
93 deleteAreaList (index: number): void {
94 this.areaList.splice(index,1);
97 handleChange(area: any[], areaItem: any): void{
98 if (areaItem.key === 'province' && areaItem.options.length <= 1) {
99 areaItem.options = COMMUNICATION_FORM_ADDRESS;
100 } else if (areaItem.key === 'city' && areaItem.options.length <= 1) {
101 COMMUNICATION_FORM_ADDRESS.forEach( item => {
102 if(item.name === area[0].selected) {
103 areaItem.options = item.city;
106 }else if (areaItem.key === 'district' && areaItem.options.length <= 1) {
107 COMMUNICATION_FORM_ADDRESS.forEach( (item: any) => {
108 item.city.forEach(city => {
109 if (city.name === area[1].selected) {
110 areaItem.options = city.county;
114 }else if (areaItem.key === 'street' && areaItem.options.length <= 1) {
115 COMMUNICATION_FORM_ADDRESS.forEach( (item: any) => {
116 item.city.forEach(city => {
117 if (city.name === area[1].selected) {
118 city.county.forEach(county => {
119 if (county.name === area[2].selected) {
120 areaItem.options = county.street;
129 handleChangeSelected(area: any[], areaItem: any) {
130 if (areaItem.key === 'province') {
131 area[1].selected = ''
132 area[1].options = [];
133 area[2].selected = '';
134 area[2].options = [];
135 area[3].selected = '';
136 area[3].options = [];
137 } else if (areaItem.key === 'city') {
138 area[2].selected = '';
139 area[2].options = [];
140 area[3].selected = '';
141 area[3].options = [];
142 }else if (areaItem.key === 'district') {
143 area[3].selected = '';
144 area[3].options = [];
149 this.showModel = false;
150 this.cancel.emit(this.showModel);
151 this.slicing_order_info = {
153 maxNumberofUEs: null,
157 resourceSharingLevel: "shared",
158 uEMobilityLevel: "stationary",
164 changeTooltipText(title){
165 if(title === 'Max Number of UEs'){
166 this.tooltipText = 'Scope: 1-100000'
167 }else if(title === 'Data Rate Downlink (Mbps)' || title === 'Data Rate Uplink (Mbps)'){
168 this.tooltipText = 'Scope: 100-3000'
169 }else if(title === 'Latency'){
170 this.tooltipText = 'Scope: 10-200'
171 }else if(title === 'Use Interval (Month)'){
172 this.tooltipText = 'Scope: ≥1'
176 getRulesText = (words,title,val,index) => {
177 return this.rulesText[index] = words + title
180 validator(key,val,i){
181 if(val === null || val.replace(/\s*/g,'').length<=0){
182 this.validateRules[i] = true;
183 this.getRulesText('Please enter',key,val,i,);
186 this.validateRules[i] = false;
188 if(key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && isNaN(val)){
189 this.validateRules[i] = true;
190 this.getRulesText('Only numbers can be entered','','',i);
192 }else if(key === 'maxNumberofUEs' && !/^([1-9]\d{0,4}|100000)$/.test(val) && !isNaN(val)){
193 console.log("-----maxNumberofUEs")
194 this.validateRules[i] = true;
195 this.getRulesText('Scope: 1-100000','','',i);
198 this.validateRules[i] = false;
199 }if((key === 'expDataRateDL' || key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && isNaN(val)){
200 this.validateRules[i] = true;
201 this.getRulesText('Only numbers can be entered','','',i);
203 }else if((key === 'expDataRateDL' || key === 'expDataRateUL') && !/^([1-9]\d{2}|[1-3]\d{3}|3000)$/.test(val) && !isNaN(val)){
204 this.validateRules[i] = true;
205 this.getRulesText('Scope: 100-3000','','',i);
208 this.validateRules[i] = false;
209 }if(key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && isNaN(val)){
210 this.validateRules[i] = true;
211 this.getRulesText('Only numbers can be entered','','',i);
213 }else if(key === 'latency' && !/^1[0-9]$|^[2-9]\d$|^1\d{2}$|^200$/.test(val) && !isNaN(val)){
214 this.validateRules[i] = true;
215 this.getRulesText('Scope: 10-200','','',i);
218 this.validateRules[i] = false;
219 }if(key === 'useInterval' && !/^[1-9]\d*$/.test(val) && isNaN(val)){
220 this.validateRules[i] = true;
221 this.getRulesText('Only numbers can be entered','','',i);
223 }else if(key === 'useInterval' && !/^[1-9]\d*$/.test(val) && !isNaN(val)){
224 this.validateRules[i] = true;
225 this.getRulesText('Scope: ≥1','','',i);
228 this.validateRules[i] = false;
233 Object.keys(this.slicing_order_info).forEach((item,index)=>{
234 if(item !== 'resourceSharingLevel' && item !== 'uEMobilityLevel' && item !== 'coverageArea'){
235 this.validator(item,this.slicing_order_info[item],index)
238 if(this.validateRules.indexOf(true)>-1){
241 const coverage_list: string[] = [];
242 this.areaList.forEach( item => {
243 let str: string = '';
244 item.forEach( area => {
245 str += area.selected + ';';
247 coverage_list.push(str.substring(0, str.length-1));
249 if(coverage_list.length>1){
250 this.slicing_order_info.coverageArea = coverage_list.join('|')
252 this.slicing_order_info.coverageArea = coverage_list.toString();
255 slicing_order_info:this.slicing_order_info
257 console.log(paramsObj,"-----paramsObj");
258 this.isSpinning = true;
259 this.myhttp.csmfSlicingPurchase(paramsObj).subscribe(res => {
260 const { result_header: { result_code, result_message }, result_body: { service_id,operation_id } } = res;
261 if (+result_code === 200) {
262 this.isSpinning = false;
266 this.message.error(err);
268 this.isSpinning = false;