recordingDetail.js
8.63 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// packageCrew/pages/recordingDetail/recordingDetail.js
import {getRecordingList, getShortUrl, findCheckResultByBatchId, submitOutstandingCases } from "~/api/crew/index"
import { getReceptionDetail } from '~/api/index/index'
import dayjs from 'dayjs'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/regional-assistant/'
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL,
navBarHeight: 84,
typeLists: ['对话', '质检'],
qualityAudio: '',
activeIndex: 0,
status: 'pause',
currentTime: '00:00', //当前音频的播放位置
isOperate: true,
reviewStatusTexts: {
0: '审核中',
1: '优秀案例提交通过',
2: '优秀案例提交驳回,重新提交'
}
},
/**
* 生命周期函数--监听页面加载
*/
async onLoad(options) {
const record = JSON.parse(options.record)
console.log(record, '22222222')
this.setData({
record,
detailInfo: {storeManagerName: record.storeManagerName},
title: `${dayjs(record.receptionTime).format('M月D日')}${record.storeManagerName}接待`,
}, () => {
wx.$util.getViewInfo('.reception-wrap', ({
height
}) => {
this.setData({
receptionWrapHeight: `${height}px`
})
})
})
this.setAudio()
this.findCheckResultByBatchId(record.batchId)
},
async findCheckResultByBatchId(batchId) {
try {
const data = await getReceptionDetail({
batchId
})
data.map(item => {
item.offset = item.offset != null ? Number(item.offset): item.offset
item.formatScore = `${item.score || item.score === 0 ? item.score : '-'}/${item.sumScore || item.sumScore === 0 ? item.sumScore : '-'}`
let hitTextList = JSON.parse(item.hitText),
matchedClass = 'no-hit',
matchedText = '意图不匹配'
if (hitTextList && hitTextList.length) {
item.hitTextList = hitTextList.map(e => e.replace(/\n/g, '<br>'))
matchedClass = 'hit'
matchedText = '意图匹配'
}
item.matchedClass = matchedClass
item.matchedText = matchedText
let [scriptRec] = JSON.parse(item.scriptRec)
if (scriptRec) scriptRec = scriptRec.replace(/\n/g, '<br>')
if (item.conversationDetailDTOList && item.conversationDetailDTOList.length) {
item.conversationDetailDTOList.map(e => {
e.time = this.formatTime(e.mergedOffset)
e.text_id = `text_${e.mergedOffset}`
if (e.mergedOffset == item.offset && !item.matched) {
e.scriptRec = scriptRec
item.matched = true
}
})
if (item.conversationDetailDTOList.findIndex(e => e.scriptRec) == -1) {
/**时间戳都对不上时 话术推荐加到最后 */
item.conversationDetailDTOList[item.conversationDetailDTOList.length - 1].scriptRec = scriptRec
}
} else item.conversationDetailDTOList = [{
scriptRec: scriptRec || '暂无建议'
}]
})
this.setData({
qualityData: data
})
} catch (error) {
wx.$util.showToast(error)
}
},
back() {
if (this.qualityAudio) this.qualityAudio.pause()
wx.navigateBack().catch(()=>{
wx.reLaunch({
url: '/pages/loading/loading',
})
})
},
onHandle(e) {
let {
isOperate
} = this.data;
if (isOperate) {
this.play()
} else {
this.onPause()
}
this.setData({
isOperate: !isOperate
})
},
//音频暂停
onPause() {
this.dialogueRef().onPause()
this.qualityAudio.pause()
},
//播放
play() {
if (!this.data.showPlayControl) {
return wx.showToast({
title: '音频暂不能播放,稍等...',
icon: 'none'
})
}
const {
paused
} = this.qualityAudio
if (paused) this.qualityAudio.play()
},
//跳转到指定位置
seek(time) {
this.qualityAudio.seek(time)
},
setAudio() {
this.qualityAudio = wx.createInnerAudioContext({
useWebAudioImplement: true
})
this.qualityAudio.src = this.data.record.recordingUrl
this.qualityAudio.onPause(() => {
this.setData({
status: 'pause'
})
this.setKeepScreenOn()
})
//监听音频的播放事件
this.qualityAudio.onPlay(() => {
this.setData({
status: 'start'
})
this.setKeepScreenOn(true)
})
this.qualityAudio.onCanplay(() => {
this.setData({
showPlayControl: true
})
})
this.qualityAudio.onTimeUpdate(this.onTimeUpdate)
this.qualityAudio.onEnded(() => {
this.setData({
status: 'ending',
currentTime: this.formatTime(this.qualityAudio.duration),
isOperate: true
})
this.dialogueRef().setData({
isPlayIng: false
})
this.setKeepScreenOn()
})
},
onTimeUpdate() {
this.setData({
currentTime: this.formatTime(this.qualityAudio.currentTime)
})
this.dialogueRef().onTimeUpdate()
this.qualityRef().onTimeUpdate()
},
formatTime(seconds) {
let minutes = Math.floor(seconds / 60);
let remainingSeconds = Math.floor(seconds % 60); // 直接取整
minutes = minutes.toString().padStart(2, '0');
remainingSeconds = remainingSeconds.toString().padStart(2, '0');
return `${minutes}:${remainingSeconds}`;
},
changeType(e) {
let {
index
} = e.currentTarget.dataset
this.setData({
activeIndex: index
})
},
navbarReady(e) {
let navBarHeight = e.detail.height;
this.setData({
navBarHeight,
});
},
dialogueRef() {
return this.selectComponent('#dialogue')
},
qualityRef() {
return this.selectComponent('#quality')
},
async share(e) {
let userInfo = wx.$util.getUserInfo() || {}
const {
record
} = this.data,
receptionStatus = {
1: '成交',
2: '战败',
3: '未知'
} [record.orderStatus], {
endTime,
totalDuration,
startTime,
merchantNo,
batchId,
receptionStartTimeTamp
} = record
console.log(record, 'record')
// 获取短链地址
const res = await getShortUrl({
merchantNo,
batchId,
receptionStartTime: receptionStartTimeTamp
})
console.log(res, 'res')
if (res.code == '0') {
// 门店 - 接待开始时间 - 接待时长 - 员工标记的接待结果 - 接待录音mp3地址(更换成短链)
let text = [record.merchantName, wx.$util.tsFormatTime(startTime, 'Y年M月D日 h:m:s'), wx.$util.tsFormatTime(endTime, 'Y年M月D日 h:m:s'), this.format(totalDuration), receptionStatus, res.data].join(' - ')
wx.$util.setCopyData(text)
} else {
wx.$util.showToast('获取短链失败')
}
// wx.$util.showToast('复制成功')
},
// 下载录音
async download(e) {
let { record } = this.data
wx.showModal({
title: '温馨提示',
content: '如需下载录音,请复制下载地址后到手机浏览器中打开。',
confirmText: '复制地址',
confirmColor: '#2C66F7',
success(res) {
if (res.confirm) {
wx.setClipboardData({
data: record.recordingUrl
})
}
}
})
},
format(seconds) {
seconds = Math.floor(seconds / 1000)
let formattedTime = ''
if (seconds < 60) return seconds + '秒'
else {
let hours = Math.floor(seconds / 3600),
minutes = Math.floor((seconds % 3600) / 60),
remainingSeconds = seconds % 60
if (hours > 0) formattedTime += hours + '小时'
if (minutes > 0 || hours > 0) formattedTime += minutes + '分'
if (remainingSeconds > 0) formattedTime += remainingSeconds + '秒'
return formattedTime
}
},
//屏幕是否常亮
setKeepScreenOn(keepScreenOn = false) {
wx.setKeepScreenOn({
keepScreenOn
})
},
// 提报优秀案例
handleSubmit() {
let { record } = this.data
if (record.reviewStatus == 0 || record.reviewStatus == 1) return
let params = {
recordingId: record.recordingId
}
wx.$util.showLoading()
submitOutstandingCases(params).then(res => {
wx.$util.hideLoading()
let { code, data, message } = res
if (code == 0) {
wx.$util.showToast('操作成功')
wx.navigateBack()
} else {
wx.$util.showToast(message)
}
}).catch(() => {
wx.$util.hideLoading()
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
this.qualityAudio.stop()
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
this.qualityAudio.stop()
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
}
})