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