click.js
6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-08 11:28:48
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-04-26 10:04:31
* @FilePath: \gl_tape\mixin\click.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
const recorderManager = uni.getRecorderManager();
const plug = uni.requireNativePlugin("html5app-recordaudio");
import upload from "@/utils/ossUploadFile/uploadFile.js";
import { mapMutations, mapState } from "vuex";
import utils from "@/utils/utils.js";
export default {
data () {
return {
voicePath: "",
timer: null,
times: 0,
timeout: 240,
reaction: 1,
};
},
mounted () {
this.initTime();
// this.checkVoice();
},
computed: {
...mapState("audio", [
"isEnd",
"receptionStatus",
"endReasonType",
"booksList",
"audioList",
"isStart",
"receptionEndTime",
"receptionStartTime",
]),
...mapState(["user.customerInfo"]),
},
created () {
console.log("created");
},
onHide () {
console.log("隐藏");
// recorderManager.stop();
// recorderManager.start({
// duration: 10000,
// });
},
onShow () {
// console.log(utils.requestAndroidPermission());
},
methods: {
...mapMutations("audio", [
"setReceptionStatus",
"setReasonType",
"setAudioStart",
"setAudioList",
"setAudioEnd",
"setBooks",
]),
//关闭提示
tipCancel () {
this.stopAudio();
this.setReceptionStatus(0);
this.setReasonType(1);
this.$refs.tipBox.close();
let { sceneType } = uni.$storage.get("userInfo");
uni.reLaunch({
url: sceneType == 0 ? "/pages/home/home" : "/pages/boutique/index" ,
});
},
//结束提示
tipConfirm () {
this.times = 0;
this.$refs.tipBox.close();
},
//检查缓存录音
checkVoice () {
const file = uni.$storage.get("storageFile");
if (file) this.uploadVoice(file);
},
//保存录音记录及其他信息
async uploadVoice (tempFilePath) {
try {
const { shopMerchantId, phone,sceneType } = uni.$storage.get("userInfo"),
{ customerName, phoneNumber, salesUuid, carModel, staffName } =
this.$store.state.user.customerInfo,
receptionCustomerPaySourceList = this.booksList.map((item) => {
return {
id: item.id,
sourceType: item.id,
sourceUrl: item.imgUrl,
};
}),
params = {
carModel,
endReasonType: this.endReasonType, //原因 1.异常 0.正常
customerName,
phoneNumber,
loginPhone: phone,
salesName: staffName,
salesUuid,
receptionStatus: this.receptionStatus, //接待结果 1.成交 0.战败
recordUrlList: tempFilePath,
receptionStartTime: this.receptionStartTime,
receptionEndTime: this.receptionEndTime,
receptionCustomerPaySourceList, //1.付款凭证文件路径 2.客户购车发票文件路径 3.客户延保合同文件路径
merchantId: shopMerchantId,
bussinessType: sceneType == 0 ? 1 : 2 // sceneType 0延保 1精品。 bussinessType 1.延保 2.轻改
};
console.log(
customerName,
phoneNumber,
salesUuid,
carModel,
tempFilePath
);
if (customerName && phoneNumber && salesUuid && carModel)
uni.$api.commonApi.saveRecCustomer(params).then((res) => {
console.log(res, params);
});
this.setBooks([]);
this.$store.dispatch("clearCustomerInfo");
this.setReceptionStatus(1);
this.setReasonType(0);
uni.$storage.set("storageFile", "");
} catch (error) {
this.$store.dispatch("clearCustomerInfo");
console.log(error);
}
},
//开始录音
async startAudio () {
if (this.isStart) return;
this.setAudioStart(true);
this.setAudioList([]);
this.setAudioEnd(false);
this.initTime();
recorderManager.start({
duration: 600000,
sampleRate: 16000,
numberOfChannels: 1,
});
recorderManager.onStop(async (res) => {
console.log("结束录音");
if (!this.isEnd) {
uni.getRecorderManager().start({
duration: 600000,
sampleRate: 16000,
numberOfChannels: 1,
});
}
const result = await upload(res.tempFilePath);
const storageFile = [...this.audioList, result];
uni.$storage.set("storageFile", storageFile);
this.setAudioList(storageFile);
console.log(storageFile, this.isEnd, "this.isEnd");
if (!this.isEnd) return true;
if (this.isEnd) this.uploadVoice(storageFile);
return true;
});
},
//结束录音
stopAudio: utils.throttle(async function () {
const result = await this.$permision.requestAndroidPermission(
"android.permission.RECORD_AUDIO"
);
if (result !== 1) {
uni.showToast({
title: "为了记录语音通话,请打开录音权限",
icon: "none",
});
return;
}
this.setAudioStart(false);
this.setAudioEnd(true);
this.times = 0;
clearInterval(this.timer);
this.timer = null;
recorderManager.stop();
}, 1500),
//监听点击事件
initTime () {
if (!this.isStart) return;
this.timer = setInterval(() => {
this.times++;
if (this.times >= this.timeout) {
this.$refs.tipBox.open();
}
if (this.times >= this.reaction + this.timeout) {
//结束接待
this.tipCancel();
clearInterval(this.timer);
}
}, 1000 * 10);
},
handleTouchStart () {
this.times = 0;
},
},
beforeCreate () {
clearInterval(this.timer);
this.timer = null;
},
};