843cf5129e8dc1a52df5fa7876759c044637fe96
[usecase-ui.git] /
1 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { SlicingTaskServices } from '../../../../../core/services/slicingTaskServices'
4
5 @Component({
6         selector: 'app-check-process-model',
7         templateUrl: './check-process-model.component.html',
8         styleUrls: ['./check-process-model.component.less']
9 })
10 export class CheckProcessModelComponent implements OnInit {
11
12         @Input() moduleTitle: string;
13         @Input() showProcess: boolean;
14         @Input() taskId: string;
15         @Input() moduleOperation: string;
16
17         @Output() cancel = new EventEmitter<boolean>();
18
19         constructor(private http: SlicingTaskServices, private message: NzMessageService) { }
20
21         checkDetail: any[];
22         businessRequirement: any[];
23         NSTinfo: any[];
24         data: any[];
25         currentProgress: number = 1;
26         timer: any = null;
27         isSpinning: boolean = false;
28         isGetData: boolean = false;
29
30         ngOnInit() { }
31
32         ngOnChanges() {
33                 if (this.showProcess) {
34                         this.isSpinning = true;
35                         this.getInfo();
36                         this.getProgress();
37                 } else {
38                         clearTimeout(this.timer);
39                         this.isGetData = false;
40                 }
41         }
42
43         getInfo(): void {
44                 let getSlicingBasicInfoFailedCallback =  () => {
45                         this.isLoadingShow();
46                 }
47                 this.http.getSlicingBasicInfo(this.taskId, getSlicingBasicInfoFailedCallback).then(res => {
48                         const { result_body } = res;
49                         const {
50                                 task_id,
51                                 task_name,
52                                 create_time,
53                                 processing_status,
54                                 business_demand_info,
55                                 nst_info,
56                                 business_demand_info: { service_snssai, coverage_area_ta_list }
57                         } = result_body;
58                         // 处理配置审核详情数据
59                         this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }];
60                         // 业务需求信息数据
61                         business_demand_info.area = coverage_area_ta_list.map(item => {
62                                 item = item.split(';').join(' - ')
63                                 return item
64                         })
65                         // 前端模拟数据
66                         let area = ["Beijing;Beijing;Haidian District", "Beijing;Beijing;Xicheng District", "Beijing;Beijing;Changping District"].map(item => {
67                                 item = item.split(';').join(' - ')
68                                 return item
69                         })
70                         this.businessRequirement = [{ ...business_demand_info, area }];
71                         // 匹配NST信息
72                         this.NSTinfo = [nst_info];
73                         this.isLoadingShow();
74                 })
75         }
76
77         isLoadingShow() {
78                 if (this.isGetData) {
79                         this.isSpinning = false;
80                 } else {
81                         this.isGetData = true;
82                 }
83         }
84
85         getProgress(): void {
86                 let getSlicingCreateProgressFailedCallback =  () => {
87                         this.isLoadingShow();
88                 }
89                 this.http.getSlicingCreateProgress(this.taskId, getSlicingCreateProgressFailedCallback).then(res => {
90                         const { result_body } = res;
91                         this.data = [];
92                                 const nssiList: string[] = ['an', 'tn', 'cn'];
93                                 nssiList.forEach(item => {
94                                         const progress: number = +result_body[item + '_progress'];
95                                         const title: string = item.charAt(0).toUpperCase() + item.slice(1);
96                                         let status: string = result_body[item + '_status'];
97                                         if ((progress || progress === 0) && status) {
98                                                 let currentProgress = 1
99                                                 if (progress === 100 && status === 'finished') {
100                                                         currentProgress = 3;
101                                                         status = 'finish'
102                                                 }
103                                                 const obj = { progress, currentProgress, title, status };
104                                                 this.data.push(obj)
105                                         }
106                                 })
107                                 this.data = [this.data];
108                                 let flag: boolean = false;
109                                 nssiList.forEach(item => {
110                                         if (result_body[item + '_status'] === 'processing' && result_body[item + '_progress'] !== 0) {
111                                                 flag = true;
112                                         }
113                                 })
114                                 if (flag) {
115                                         this.timer = setTimeout(() => {
116                                                 this.getProgress()
117                                         }, 5000)
118                                 }
119                         this.isLoadingShow();
120                 })
121         }
122
123         handleCancel() {
124                 this.showProcess = false;
125                 this.cancel.emit(this.showProcess)
126         }
127 }