94bccfe5ddb4cf35354639fb1d70182ed9e44440
[usecase-ui.git] /
1 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { Util } from '../../../../../shared/utils/utils';
4 import { onboardService } from '../../../../../core/services/onboard.service';
5 import { Recorder } from '../../../../../shared/utils/recorder';
6
7 @Component({
8   selector: 'app-input-business-order',
9   templateUrl: './input-business-order.component.html',
10   styleUrls: ['./input-business-order.component.less']
11 })
12 export class InputBusinessOrderComponent implements OnInit {
13
14   constructor(
15     private Util: Util,
16     private Recorder: Recorder,
17     private myhttp: onboardService,
18     private msg: NzMessageService
19   ) { }
20
21   @Input() showModel: boolean;
22   @Output() modalOpreation = new EventEmitter();
23   isSpinning: boolean = false;
24   communicationMessage: String = "";
25   validateRulesShow: any[] = [];
26   rulesText: any[] = [];
27   radioValue: String = 'text';
28   isPlay: boolean = false;
29   clickRepeat: boolean = false;
30   isDisable: boolean = true;
31   ngOnInit() {
32     this.validateRulesShow = [];
33     this.rulesText = [];
34     this.communicationMessage = '';
35   }
36
37   ngOnChange() {
38   }
39
40   handleCancel(): void {
41     this.showModel = false;
42     this.communicationMessage = "";
43     this.modalOpreation.emit({ "cancel": true });
44   }
45
46   handleOk(): void {
47     if (this.clickRepeat) {
48       return;
49     }
50     this.clickRepeat = true;
51     if (this.radioValue === "text") {
52       this.submitFormMessage();
53       return;
54     }
55     this.clickRepeat = false;
56     this.communicationMessage = "";
57     this.showModel = false;
58     let defaultParams = {
59       coverageArea: "Beijing Beijing Haiding Wanshoulu",
60       expDataRateDL: "1000",
61       expDataRateUL: "1000",
62       latency: "10",
63       maxNumberofUEs: "10",
64       name: "exclusive slicing service",
65       resourceSharingLevel: "shared",
66       uEMobilityLevel: "stationary"
67     }
68     this.modalOpreation.emit({ "cancel": false, "param": defaultParams });
69   }
70   submitFormMessage(): void {
71     this.Util.validator("communicationMessage", "communicationMessage", this.communicationMessage, 0, this.rulesText, this.validateRulesShow);
72     if (this.validateRulesShow.indexOf(true) > -1) {
73       this.clickRepeat = false;
74       return
75     }
76     let params = {
77           "title": "predict",
78           "text": this.communicationMessage
79     };
80     this.myhttp["analysisInputText"](params)
81       .subscribe((data) => {
82         this.clickRepeat = false;
83         if (data === 0) {
84           return;
85         }
86         let orderForm = { ...data };
87         this.communicationMessage = "";
88         this.showModel = false;
89         this.modalOpreation.emit({ "cancel": false, "param": orderForm });
90       }, (err) => {
91         this.clickRepeat = false;
92         this.msg.error(`Error: Request failed with status code ${err.status}`);
93       })
94   }
95   startAudio(): void {
96     this.isPlay = true;
97     this.isDisable = true;
98     this.Recorder.beforeStartRecord();
99   }
100   stopAudio(): void {
101     this.isPlay = false;
102     this.isDisable = false;
103     this.Recorder.stopRecord();
104   }
105   playAudio(): void {
106     let audio = document.querySelector('audio');
107     audio["src"] = this.Recorder.playRecord();
108   }
109 }