answerDetail.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. <template>
  2. <view class="answerdetail-page flex-column">
  3. <template v-if="questionItem&&hasAuth">
  4. <template>
  5. <view class="question-wrap">
  6. <view class="question-item">
  7. <view class="question-info">
  8. <view style="flex: 1" class="question-title">
  9. <text class="item-label">{{
  10. questionItem.variety_tag_name
  11. }}</text>
  12. {{ questionItem.question_content }}
  13. </view>
  14. <view class="item-answer" v-if="questionItem.reply_status === 3&&!isUserResearcher">
  15. <view class="answer" @click.stop="handlePlayAudioByBg(questionItem)">
  16. <!-- 改为背景音频播放 -->
  17. <image class="music-img" :src="questionItem.community_question_id==curVoiceId&&!curAudioPaused?playImgSrc:pauseImgSrc" mode="widthFix"/>
  18. <text>{{ formatAudioTime(questionItem.audio_list[0].audio_play_seconds*1000) }}</text>
  19. <!-- <template v-if="!questionItem.loading">
  20. <image
  21. class="music-img"
  22. :src="questionItem.answer.isplay ? playImgSrc : pauseImgSrc"
  23. mode="widthFix"
  24. />
  25. <template
  26. v-if="
  27. questionItem.answer.isplay || questionItem.answer.ispause
  28. "
  29. >
  30. <text>{{
  31. questionItem.answer.audioTime -
  32. currentAudioMsg.audioCurrentTime >
  33. 0
  34. ? dayjs(
  35. (questionItem.answer.audioTime -
  36. currentAudioMsg.audioCurrentTime) *
  37. 1000
  38. ).format("mm:ss")
  39. : "00:00"
  40. }}</text>
  41. </template>
  42. <template v-else>
  43. <text>{{
  44. dayjs(questionItem.answer.audioTime * 1000).format(
  45. "mm:ss"
  46. )
  47. }}</text>
  48. </template>
  49. </template>
  50. <template v-else>
  51. <image
  52. class="load-img"
  53. src="../static/loading.png"
  54. mode="aspectFill"
  55. />
  56. <text>{{
  57. dayjs(questionItem.answer.audioTime).format("mm:ss")
  58. }}</text>
  59. </template> -->
  60. </view>
  61. <!-- 普通用户进入的音频悬浮 -->
  62. <audioBox v-if="showAudioPop"/>
  63. </view>
  64. </view>
  65. <text class="item-time">提问时间:{{ questionItem.create_time }}</text>
  66. </view>
  67. </view>
  68. <view
  69. class="record-wrap flex-column"
  70. v-if="questionItem.reply_status === 2&&isUserResearcher"
  71. >
  72. <view class="record flex-column" v-if="questionItem.recordStatus !== 4">
  73. <view class="no-record" v-if="questionItem.recordStatus === 1">
  74. <image
  75. src="./static/record.png"
  76. mode="widthFix"
  77. style="width: 90rpx; height: 180rpx"
  78. />
  79. <view>无录音(录音时长超过三分钟自动结束)</view>
  80. <view class="black-btn" style="margin-top:100rpx" @click.stop="showRemoveQ=true">转移问题</view>
  81. <view class="black-btn" style="margin-top:50rpx" @click.stop="stopQuestion.show=true">终止问答</view>
  82. </view>
  83. <!-- <view class="record-time" v-else>{{ audioTime }}</view> -->
  84. <view class="recode-image" v-else>
  85. <scroll-view scroll-x style="height: 100rpx" class="scroll-view" :scroll-left="scrollTop" @scrolltolower="handleScrolltolower" :show-scrollbar="false">
  86. <view style="width:100%;height:100rpx;display:inline-block;"></view>
  87. <image
  88. src="./static/record-img.png"
  89. mode="scaleToFill"
  90. />
  91. <image
  92. src="./static/record-img.png"
  93. mode="scaleToFill"
  94. />
  95. <image
  96. src="./static/record-img.png"
  97. mode="scaleToFill"
  98. />
  99. </scroll-view>
  100. </view>
  101. </view>
  102. <view
  103. class="record-tool flex-column"
  104. v-if="questionItem.recordStatus !== 4"
  105. >
  106. <view class="hint" v-if="questionItem.recordStatus === 1"
  107. >点击开始录音</view
  108. >
  109. <view class="record-time" v-else>{{ audioTime }}</view>
  110. <view
  111. class="record-btn-wrap center"
  112. v-if="questionItem.recordStatus === 1"
  113. >
  114. <view class="switch" @click="changeRecodeStatus"> </view>
  115. </view>
  116. <view class="record-btn-wrap" v-else>
  117. <text
  118. @click="questionItem.recordStatus === 3 && handleRecode('delete')"
  119. v-if="questionItem.recordStatus >= 2"
  120. :class="{ active: questionItem.recordStatus === 3 }"
  121. >删除</text
  122. >
  123. <view class="switch" @click="changeRecodeStatus">
  124. <image
  125. v-if="questionItem.recordStatus >= 2"
  126. :src="
  127. questionItem.recordStatus === 2 ? playImgSrc : pauseImgSrc
  128. "
  129. :key="playIconKey"
  130. :style="{
  131. 'margin-left': questionItem.recordStatus !== 2 ? '7rpx' : 0,
  132. width: '36rpx',
  133. height: '44rpx',
  134. }"
  135. mode="widthFix"
  136. />
  137. </view>
  138. <text
  139. @click="handleRecode('finish')"
  140. v-if="questionItem.recordStatus >= 2"
  141. :class="{ active: questionItem.recordStatus >= 2 }"
  142. >完成</text
  143. >
  144. </view>
  145. </view>
  146. <view class="record-play" v-if="questionItem.recordStatus === 4">
  147. <view class="audio-wrap">
  148. <view v-if="pageLoading">音频生成中...</view>
  149. <view class="play" v-else>
  150. <van-icon
  151. :name="isplay ? 'pause' : 'play'"
  152. @click="handleAudioByReplay"
  153. color="#E6B77DFF"
  154. size="64rpx"
  155. style="align-items: flex-start; margin-left: -20rpx"
  156. />
  157. <!-- 进度条 -->
  158. <view class="slider-box">
  159. <slider
  160. :value="currentAudioMsg.audioCurrentTime"
  161. :max="currentAudioMsg.audioTime"
  162. @change="sliderChange($event)"
  163. @changing="sliderChanging"
  164. activeColor="#E6B77DFF"
  165. backgroundColor="#EBEBEBFF"
  166. block-color="#E6B77DFF"
  167. block-size="12"
  168. />
  169. <view class="slider-time">
  170. <text>{{
  171. formatAudioTime(currentAudioMsg.audioCurrentTime * 1000)
  172. }}</text>
  173. <text>{{
  174. formatAudioTime(currentAudioMsg.audioTime * 1000)
  175. }}</text>
  176. </view>
  177. </view>
  178. </view>
  179. </view>
  180. <view class="audio-delete" @click="handleRecode('delete')">
  181. <image
  182. src="./static/delerecord.png"
  183. mode="heightFix"
  184. style="width: 32rpx; height: 35rpx"
  185. />
  186. <text>删除</text></view
  187. >
  188. <view class="audio-pub" @click="handleRecode('pub')">发布</view>
  189. </view>
  190. </view>
  191. <view
  192. class="record-wrap flex-column"
  193. v-if="questionItem.reply_status === 2&&!isUserResearcher"
  194. >
  195. <view style="text-align: center;color: #999999;font-size: 32rpx;margin-top:100rpx;">该问题暂无回答,请等待研究员回答</view>
  196. </view>
  197. <view class="record-wrap flex-column" v-if="questionItem.reply_status===3&&isUserResearcher">
  198. <view class="record-play" v-if="questionItem.recordStatus === 4">
  199. <view class="audio-wrap">
  200. <view class="play">
  201. <van-icon
  202. :name="questionItem.community_question_id==curVoiceId&&!curAudioPaused ? 'pause' : 'play'"
  203. @click="handlePlayAudioByBg(questionItem)"
  204. color="#E6B77DFF"
  205. size="64rpx"
  206. style="align-items: flex-start; margin-left: -20rpx"
  207. />
  208. <!-- 进度条 -->
  209. <view class="slider-box">
  210. <slider
  211. :value="curTime"
  212. :max="currentAudioMsg.audioTime"
  213. @change="bgAudiosliderChange($event)"
  214. @changing="sliderChanging"
  215. activeColor="#E6B77DFF"
  216. backgroundColor="#EBEBEBFF"
  217. block-color="#E6B77DFF"
  218. block-size="12"
  219. />
  220. <view class="slider-time">
  221. <text>{{
  222. formatAudioTime(curTime*1000)
  223. }}</text>
  224. <text>{{
  225. formatAudioTime(questionItem.answer.audioTime * 1000)
  226. }}</text>
  227. </view>
  228. </view>
  229. </view>
  230. </view>
  231. <view class="audio-pub disable">已发布</view>
  232. <!-- 音频悬浮 -->
  233. <view v-show="false">
  234. <audioBox v-if="showAudioPop"/>
  235. </view>
  236. </view>
  237. </view>
  238. </template>
  239. </template>
  240. <!-- 没有该问题权限 -->
  241. <template v-else-if="!hasAuth">
  242. <view class="noAuth-wrap">
  243. <image class="img" :src="globalImgUrls.activityNoAuth" mode="widthFix"></image>
  244. <view class="auth-text">您暂无权限查看问答社区</view>
  245. <view class="auth-text" v-if="noAuthInfo.type==='contact'">若想查看可以联系对口销售</view>
  246. <view class="auth-text" v-else>若想查看可以申请开通</view>
  247. <view class="auth-text" v-if="noAuthInfo.type==='contact'">
  248. {{noAuthInfo.name||''}}:<text @click="handleCallPhone(noAuthInfo.mobile+'')">{{noAuthInfo.mobile||''}}</text>
  249. </view>
  250. <view class="global-btn-yellow-change btn" @click="handleGoApply" v-else>立即申请</view>
  251. </view>
  252. </template>
  253. <!-- 终止问答弹窗 -->
  254. <van-dialog
  255. use-slot
  256. title="终止问答"
  257. :show="stopQuestion.show"
  258. show-cancel-button
  259. confirm-button-open-type="getUserInfo"
  260. @close="stopQuestion.show=false;stopQuestion.reason=''"
  261. @confirm="handleConfirmStopQuestion"
  262. >
  263. <view style="padding:48rpx">
  264. <textarea
  265. style="background: #F7F8FA;border-radius: 8px;padding: 20rpx;display:block;box-sizing:border-box;width:100%"
  266. maxlength="-1"
  267. cols="30"
  268. rows="10"
  269. placeholder="请输入终止理由"
  270. v-model="stopQuestion.reason"
  271. ></textarea>
  272. </view>
  273. </van-dialog>
  274. <!-- 转移问答弹窗 -->
  275. <removeQuestionDig :show="showRemoveQ" :qid="qid" @close="showRemoveQ=false" ></removeQuestionDig>
  276. </view>
  277. </template>
  278. <script>
  279. import mixin from "../mixin/questionMixin";
  280. import { apiReplayAsk, apiGetQuestion, apiSetRead,apiCountAudioClick,apiQuestionStop } from "@/api/question";
  281. import { apiApplyPermission} from '@/api/user';
  282. import {apiGetSceneToParams} from "../api/common.js"
  283. import { uploadAudioToServer } from "@/utils/upload";
  284. import audioBox from '@/components/audioBox/audioBox.vue'
  285. import removeQuestionDig from './components/removeQuestionDig.vue'
  286. export default {
  287. mixins: [mixin],
  288. components:{
  289. audioBox,
  290. removeQuestionDig
  291. },
  292. computed:{
  293. showAudioPop(){//是否显示音频弹窗
  294. return this.$store.state.audio.show
  295. },
  296. showAudioBigPop(){
  297. return this.$store.state.audio.showBig
  298. },
  299. curVoiceId(){//当前正在播放的音频id
  300. return this.$store.state.audio.questionId
  301. },
  302. curAudioPaused(){//当前音频是否暂停状态
  303. return this.$store.state.audio.paused
  304. },
  305. curTime(){
  306. let t=0
  307. if(this.questionItem?.community_question_id==this.$store.state.audio.questionId){
  308. t=this.$store.state.audio.curTime
  309. }
  310. return t
  311. }
  312. },
  313. data() {
  314. return {
  315. qid:0,
  316. questionItem: null /* {
  317. recordStatus: 1, //1:未录音;2:正在录音;3:已暂停;4:完成录音
  318. permission_info:{
  319. type:'',
  320. name:'梁娜',
  321. mobile:'123456',
  322. customer_info:{
  323. has_apply:false,
  324. company_name:'',
  325. name:'',
  326. status:'流失',
  327. }
  328. }
  329. }, */,
  330. pauseImgSrc: "../static/question/recordplay.png",
  331. playImgSrc: "../static/question/recordpause.png",
  332. innerAudio: null, //该页面的音频
  333. audioCount: 0, //录音计时,毫秒
  334. audioSrc:'',//tempSrc
  335. audioTime: "00:00", //录音时间(格式化后):string
  336. timer: null,
  337. audioItem: null,
  338. pageLoading: false,
  339. playIconKey: 0,
  340. isplay: false,
  341. isSlider: false,
  342. scrollTop:0,
  343. isStart:false,//判断录音是否开始
  344. //globalRecorder:uni.getRecorderManager(),
  345. /* userInfo:{
  346. is_inner:1,//0:外部客户;1内部员工
  347. status:'正式',
  348. is_suspend:1,
  349. is_researcher:0,
  350. }, *///mock用户信息
  351. stopQuestion:{
  352. show:false,
  353. reason:'',
  354. },//终止问答
  355. showRemoveQ:false,//展示转移问题弹窗
  356. };
  357. },
  358. async onLoad(options) {
  359. this.initAudio();
  360. let obj={}
  361. if(options.scene){
  362. // 小程序码进来的
  363. let res = await apiGetSceneToParams({scene_key:options.scene})
  364. if(res.code==200){
  365. obj=JSON.parse(res.data)
  366. }
  367. }
  368. this.qid=obj.id || options.id
  369. this.getQuestionItem(obj.id || options.id);
  370. },
  371. onShow(){
  372. uni.authorize({
  373. scope: 'scope.record',
  374. success() {
  375. },
  376. fail(e){
  377. console.log('fail',e);
  378. }
  379. })
  380. },
  381. onUnload() {
  382. this.resetAudio();
  383. this.destroyAudio();
  384. //录音时误操作退出页面的情况
  385. if(this.questionItem.recordStatus!==4&&this.questionItem.recordStatus!==1){
  386. this.globalRecorder.stop()
  387. }
  388. },
  389. //转发分享
  390. onShareAppMessage(){
  391. const {community_question_id} = this.questionItem
  392. return{
  393. title:'问答详情',
  394. path:`/pages-question/answerDetail?id=${community_question_id}`
  395. }
  396. },
  397. methods: {
  398. //初始化audio,onShow执行
  399. initAudio() {
  400. this.innerAudio = uni.createInnerAudioContext();
  401. this.handleAudioFun();
  402. this.handleRecorderFun();
  403. //录音完成后,切出其他页面再切回来
  404. if(this.questionItem?.recordStatus===4){
  405. console.log('count',this.audioCount,'src',this.audioSrc)
  406. this.setAudio(this.audioSrc,this.audioCount)
  407. }
  408. },
  409. //录音完成or从其他app切回本页面时,初始化音频
  410. setAudio(src,audioCount){
  411. this.innerAudio.stop();
  412. this.isplay = false;
  413. this.innerAudio.src = src;
  414. console.log('秒数',audioCount)
  415. this.changeCurrentAudio({
  416. id: "",
  417. answer: {
  418. source: src,
  419. audioTime: audioCount/1000,
  420. },
  421. });
  422. },
  423. //麦克风被占用,初始化录音相关变量 其他状态->未录音状态
  424. setRecorder(){
  425. this.questionItem.recordStatus = 1;
  426. this.innerAudio.stop();
  427. this.isplay = false;
  428. this.audioItem = null;
  429. this.audioCount = 0;
  430. this.scrollTop = 0;
  431. this.audioTime = this.formatAudioTime(this.audioCount * 1000)
  432. },
  433. //onHide触发
  434. resetAudio(){
  435. this.innerAudio.stop();
  436. this.isplay = false;
  437. this.changeCurrentAudio({
  438. id: '',
  439. answer: {
  440. source: '',
  441. audioTime: 0
  442. }
  443. })
  444. },
  445. //audio事件
  446. handleAudioFun() {
  447. this.innerAudio.onPlay(() => {
  448. this.isplay = true;
  449. console.log("播放录音了");
  450. this.questionItem.loading = false;
  451. });
  452. this.innerAudio.onTimeUpdate(() => {
  453. //console.log("时间更新", this.innerAudio.currentTime);
  454. /* this.currentAudioMsg.audioCurrentTime = parseInt(
  455. this.innerAudio.currentTime
  456. ); */
  457. this.currentAudioMsg.audioCurrentTime = this.innerAudio.currentTime;
  458. });
  459. this.innerAudio.onSeeked(() => {
  460. //取this.innerAudio.currentTime为0
  461. console.log("seek完成");
  462. this.isSlider = false;
  463. });
  464. this.innerAudio.onPause(() => {
  465. this.isplay = false;
  466. console.log("暂停");
  467. console.log(this.innerAudio.paused);
  468. });
  469. this.innerAudio.onEnded(() => {
  470. console.log("音频播放完毕");
  471. this.questionItem.answer.isplay = false;
  472. this.questionItem.answer.ispause = false;
  473. /* this.changeCurrentAudio({
  474. id: "",
  475. answer: {
  476. source: "",
  477. audioTime: 0,
  478. },
  479. }); */
  480. this.currentAudioMsg.audioCurrentTime = 0;
  481. this.isplay = false;
  482. });
  483. },
  484. //录音事件
  485. handleRecorderFun() {
  486. this.globalRecorder.onStart(() => {
  487. console.log("开始录音");
  488. if(this.questionItem.recordStatus===1){
  489. this.questionItem.recordStatus=2
  490. }
  491. uni.hideToast();
  492. this.clockTime();
  493. });
  494. this.globalRecorder.onPause(() => {
  495. console.log("暂停录音");
  496. if(this.questionItem.recordStatus===2){
  497. this.questionItem.recordStatus = 3
  498. }
  499. this.cleanTime();
  500. });
  501. this.globalRecorder.onStop((res) => {
  502. console.log("录音完成");
  503. //录音自动结束 和 暂停时点击删除 的情况
  504. if (this.questionItem.recordStatus === 2) {
  505. this.questionItem.recordStatus = 4;
  506. }
  507. console.log('status',this.questionItem.recordStatus)
  508. console.log("res", JSON.stringify(res));
  509. this.cleanTime();
  510. //初始化音频播放
  511. this.audioSrc = res.tempFilePath
  512. this.setAudio(this.audioSrc ,this.audioCount)
  513. this.pageLoading = false;
  514. });
  515. this.globalRecorder.onError((res) => {
  516. console.log('err',res)
  517. console.log('errMsg',res.errMsg)
  518. /* uni.showToast({
  519. title:res.errMsg,
  520. icon:'none'
  521. }) */
  522. //开始录音失败
  523. if(res.errMsg.includes('start')){
  524. this.questionItem.recordStatus = 1;
  525. }
  526. //麦克风被占用的情况
  527. if(res.errCode===1){
  528. uni.showToast({
  529. title:'麦克风被占用,已停止录音',
  530. icon:'none'
  531. })
  532. this.globalRecorder.stop();
  533. this.setRecorder()
  534. }
  535. });
  536. /* this.globalRecorder.onFrameRecorded((res) => {
  537. console.log("?", res);
  538. }); */
  539. },
  540. async getQuestionItem(id) {
  541. const res = await apiGetQuestion({
  542. question_id: id,
  543. });
  544. if (res.code === 200) {
  545. this.questionItem = {...res.data,recordStatus:1};
  546. const { audio_list } = res.data;
  547. let temp = {};
  548. if (audio_list.length > 0) {
  549. temp = {
  550. source: res.data.audio_list[0].audio_url,
  551. audioTime: parseInt(res.data.audio_list[0].audio_play_seconds)||0,
  552. isplay: false,
  553. ispause: false,
  554. };
  555. } else {
  556. temp = {
  557. source: "",
  558. audioTime: 0,
  559. isplay: false,
  560. ispause: false,
  561. };
  562. }
  563. let readKey = "";
  564. //const { is_inner } = this.userInfo;
  565. if (this.isUserResearcher) {
  566. readKey = "replier_is_read";
  567. } else {
  568. readKey = "is_read";
  569. }
  570. console.log('readKey',readKey)
  571. this.questionItem[readKey] !== 1 &&
  572. (await apiSetRead({
  573. question_ids: this.questionItem.community_question_id + "",
  574. }));
  575. this.questionItem.id = res.data.community_question_id;
  576. this.questionItem.answer = temp;
  577. this.questionItem.loading = false;
  578. this.questionItem.recordStatus = res.data.reply_status === 3 ? 4 : 1;
  579. //研究员查看已回复的问题,初始化音频
  580. if(res.data.reply_status===3&&this.isUserResearcher){
  581. this.innerAudio.src = res.data.audio_list[0].audio_url
  582. this.audioSrc = res.data.audio_list[0].audio_url
  583. this.audioCount = parseInt(res.data.audio_list[0].audio_play_seconds)*1000
  584. this.changeCurrentAudio({
  585. id: "",
  586. answer: {
  587. source: res.data.audio_list[0].audio_url,
  588. audioTime: parseInt(res.data.audio_list[0].audio_play_seconds)||0,
  589. },
  590. });
  591. }
  592. }else if(res.code===403){
  593. this.hasAuth=false
  594. this.noAuthInfo = res.data
  595. }else{
  596. //问题被删除的情况,返回小程序首页
  597. setTimeout(()=>{
  598. uni.switchTab({ url:'/pages/report/report' });
  599. },1000)
  600. }
  601. },
  602. changeRecodeStatus() {
  603. console.log('a',this.questionItem.recordStatus)
  604. //根据questionItem.recordStatus
  605. if (this.questionItem.recordStatus === 1) {
  606. const that = this
  607. //检查是否有权限
  608. uni.getSetting({
  609. success(res){
  610. console.log('res',res)
  611. if(res.authSetting['scope.record']){
  612. that.startRecord()
  613. }else{
  614. that.getRecordAuth()
  615. }
  616. }
  617. });
  618. } else if (this.questionItem.recordStatus === 2) {
  619. //暂停录音
  620. this.globalRecorder.pause();
  621. this.questionItem.recordStatus = 3;
  622. } else if (this.questionItem.recordStatus === 3) {
  623. //继续录音
  624. this.globalRecorder.resume();
  625. this.clockTime();
  626. this.questionItem.recordStatus = 2;
  627. } else {
  628. //结束录音
  629. this.globalRecorder.stop();
  630. //this.cleanTime();
  631. }
  632. },
  633. //获取录音授权
  634. getRecordAuth(){
  635. const {community_question_id} = this.questionItem
  636. uni.openSetting({
  637. success(res){
  638. //刷新页面
  639. if(res.authSetting['scope.record']){
  640. uni.redirectTo({url: `/pages-question/answerDetail?id=${community_question_id}`})
  641. }
  642. }
  643. })
  644. //this.questionItem.recordStatus = 1
  645. },
  646. //开启录音
  647. startRecord(){
  648. console.log(this.globalRecorder)
  649. this.globalRecorder.start({ duration: 180000, format: "mp3" });
  650. uni.showToast({
  651. title:'加载中',
  652. icon:'loading'
  653. })
  654. this.questionItem.recordStatus = 2;
  655. },
  656. //上传音频
  657. async uploadAudio() {
  658. const res = await uploadAudioToServer(this.innerAudio.src);
  659. if (res.code === 200) {
  660. this.audioItem = res.data;
  661. } else {
  662. //重新录
  663. this.setRecorder()
  664. }
  665. },
  666. //录音操作:完成/删除/发布
  667. async handleRecode(type) {
  668. if (type==='finish') {
  669. this.questionItem.recordStatus = 4;
  670. this.changeRecodeStatus();
  671. }
  672. if (type === "finish") {
  673. //生成音频,更改页面布局
  674. this.pageLoading = true;
  675. } else if (type === "delete") {
  676. //重新录
  677. if(this.questionItem.recordStatus===3)this.globalRecorder.stop();
  678. this.setRecorder()
  679. } else {
  680. //发布
  681. if (!this.audioItem) {
  682. await this.uploadAudio();
  683. }
  684. //如果上传音频成功
  685. if (this.questionItem.recordStatus === 4) {
  686. //发布回答
  687. const res = await apiReplayAsk({
  688. question_id: this.questionItem.community_question_id,
  689. audio_list: [{ ...this.audioItem, sort: 1 }],
  690. });
  691. if (res.code === 200) {
  692. uni.showToast({
  693. title: "发布成功",
  694. icon: "success",
  695. duration: 500,
  696. });
  697. setTimeout(() => {
  698. //关闭当前页面,跳转到我的回答
  699. // 返回失败 从公众号模板消息过来的,导航至我的问答
  700. uni.navigateBack({
  701. delta: 1 ,
  702. fail:()=>{
  703. uni.redirectTo({
  704. url: '/pages-question/answerList'
  705. })
  706. }
  707. });
  708. }, 500);
  709. }
  710. }
  711. }
  712. },
  713. //(提问者)问题已被回答,点击回答音频
  714. handleAudio(item) {
  715. const { source, isplay, ispause } = item.answer;
  716. if (isplay) {
  717. //说明是播放->暂停
  718. this.innerAudio.pause();
  719. this.questionItem.answer.isplay = false;
  720. this.questionItem.answer.ispause = true;
  721. } else if (ispause) {
  722. //说明是暂停->播放
  723. this.innerAudio.play();
  724. this.questionItem.answer.isplay = true;
  725. this.questionItem.answer.ispause = false;
  726. } else {
  727. //console.log("aaa", source, this.innerAudio.src);
  728. //说明是第一次播放或播放完
  729. this.changeCurrentAudio(item);
  730. this.innerAudio.stop();
  731. this.innerAudio.src = source;
  732. this.handleAudioPlay();
  733. this.questionItem.answer.isplay = true;
  734. //音频点击次数+1
  735. const audio_id = this.questionItem.audio_list[0].community_question_audio_id
  736. apiCountAudioClick({
  737. community_question_audio_id:audio_id,
  738. source_agent:1
  739. }).then((res)=>{
  740. if(res.code===200){
  741. console.log('音频id为'+audio_id+'点击次数+1')
  742. }
  743. })
  744. }
  745. },
  746. //(回答者)问题被回答,点击回答音频
  747. handleAudioByReplay() {
  748. this.isplay = !this.isplay;
  749. if (this.innerAudio.paused) {
  750. this.innerAudio.play();
  751. } else {
  752. this.innerAudio.pause();
  753. }
  754. this.playIconKey++; //更新音频播放图标
  755. },
  756. //拖动音频进度条
  757. sliderChange(e) {
  758. console.log("拖动完成?");
  759. //this.innerAudio.pause();
  760. const value = e.detail.value;
  761. this.innerAudio.seek(value);
  762. this.currentAudioMsg.audioCurrentTime = value;
  763. },
  764. sliderChanging() {
  765. this.isSlider = true;
  766. },
  767. // 背景音频播放的拖动
  768. bgAudiosliderChange(e){
  769. const value=e.detail.value
  770. this.globalBgMusic.seek(value)
  771. },
  772. //切换当前播放音频
  773. changeCurrentAudio(item) {
  774. const { id } = item;
  775. const { source, audioTime } = item.answer;
  776. this.currentAudioMsg = {
  777. id: id,
  778. audioCurrentTime: 0 * 1000,
  779. audioTime: audioTime,
  780. audioCurrentUrl: source,
  781. };
  782. if (id) {
  783. this.questionItem.loading = true;
  784. }
  785. },
  786. //录音计时
  787. clockTime() {
  788. console.log("开始录音计时");
  789. if(this.timer) return
  790. this.timer = setInterval(() => {
  791. if (this.timer) {
  792. this.audioCount += 30;
  793. this.audioTime = this.formatAudioTime(this.audioCount)
  794. this.scrollTop+=1;
  795. }
  796. }, 30);
  797. },
  798. //清除录音计时
  799. cleanTime() {
  800. console.log("结束录音计时");
  801. clearInterval(this.timer);
  802. this.timer=null
  803. this.playIconKey++; //更新录音暂停播放图标
  804. //this.audioTime = this.dayjs(this.audioCount).format("mm:ss.SS");
  805. },
  806. //scroll-view滑动到最右
  807. handleScrolltolower(){
  808. console.log('a',this.scrollTop)
  809. this.scrollTop-=150;
  810. },
  811. //权限相关
  812. handleContact(mobile){
  813. uni.makePhoneCall({
  814. phoneNumber: mobile+''
  815. });
  816. },
  817. async handleGoApply(){
  818. const {customer_info} = this.questionItem.permission_info
  819. const {community_question_id} = this.questionItem
  820. if (customer_info.has_apply) { //已经申请过
  821. uni.showToast({
  822. title:'您已提交过申请,请耐心等待',
  823. icon:'none'
  824. })
  825. } else {
  826. if (!customer_info.status || customer_info.status != '流失'|| customer_info.status != '关闭') {
  827. uni.navigateTo({
  828. url: "/pages-applyPermission/applyPermission?source=5&form_page=问答社区"
  829. })
  830. } else { //主动调一次申请权限接口
  831. const res = await apiApplyPermission({
  832. company_name: customer_info.company_name,
  833. real_name: customer_info.name,
  834. source: 5,
  835. from_page: '问答社区'
  836. })
  837. if (res.code === 200) {
  838. uni.showToast({
  839. title:'您已提交过申请,请耐心等待',
  840. icon:'none'
  841. })
  842. uni.redirectTo({url: `/pages-question/answerDetail?id=${community_question_id}`})
  843. }
  844. }
  845. }
  846. },
  847. // 终止问答
  848. async handleConfirmStopQuestion(){
  849. console.log('stop question');
  850. if(!this.stopQuestion.reason){
  851. uni.showToast({
  852. title:"请填写终止理由",
  853. icon:"none"
  854. })
  855. return
  856. }
  857. const res=await apiQuestionStop({
  858. community_question_id:this.questionItem.community_question_id,
  859. reason:this.stopQuestion.reason
  860. })
  861. if(res.code===200){
  862. uni.showToast({
  863. title:"成功终止",
  864. icon:"success"
  865. })
  866. setTimeout(() => {
  867. uni.navigateBack({
  868. delta:1,
  869. fail(){
  870. uni.switchTab({
  871. url: '/pages/question/question'
  872. })
  873. }
  874. })
  875. }, 1500);
  876. }
  877. }
  878. },
  879. };
  880. </script>
  881. <style scoped lang="scss">
  882. .flex-column {
  883. display: flex;
  884. flex-direction: column;
  885. }
  886. .answerdetail-page {
  887. padding: 50rpx 30rpx 0 30rpx;
  888. height: calc(100vh - calc(50px + env(safe-area-inset-bottom)));
  889. box-sizing: border-box;
  890. .question-wrap {
  891. .question-item::after {
  892. height: 0;
  893. }
  894. }
  895. .record-wrap {
  896. margin: 0 -30rpx;
  897. flex: 1;
  898. .record {
  899. flex: 1;
  900. justify-content: center;
  901. align-items: center;
  902. .no-record {
  903. text-align: center;
  904. color: #999999ff;
  905. font-size: 28rpx;
  906. // height:130rpx;
  907. image {
  908. width: 94rpx;
  909. }
  910. .black-btn{
  911. width: 100%;
  912. height: 80rpx;
  913. line-height: 80rpx;
  914. background: #333333;
  915. box-shadow: 0px 4rpx 20rpx rgba(160, 126, 84, 0.25);
  916. border-radius: 40rpx;
  917. color: #E3B377;
  918. text-align: center;
  919. font-size: 32rpx;
  920. }
  921. }
  922. /* .record-time {
  923. justify-self: flex-end;
  924. font-size: 60rpx;
  925. } */
  926. .recode-image {
  927. width: 100%;
  928. height: 100%;
  929. background-color: #fafafaff;
  930. display: flex;
  931. align-items: center;
  932. .scroll-view {
  933. width: 100%;
  934. white-space: nowrap;
  935. ::-webkit-scrollbar{
  936. width:0;
  937. height:0;
  938. display:none;
  939. color:transparent;
  940. }
  941. image {
  942. width: 421rpx;
  943. height: 100rpx;
  944. margin-right: 6rpx;
  945. }
  946. }
  947. }
  948. }
  949. .record-tool {
  950. justify-content: center;
  951. align-items: center;
  952. border-top: 1rpx solid #e6e6e6ff;
  953. height: 400rpx;
  954. position: relative;
  955. .hint {
  956. color: #ee3636ff;
  957. font-size: 28rpx;
  958. position: absolute;
  959. top: 50rpx;
  960. }
  961. .record-time{
  962. font-size: 60rpx;
  963. }
  964. .record-btn-wrap {
  965. margin-top: 38rpx;
  966. display: flex;
  967. width: 100%;
  968. justify-content: space-around;
  969. align-items: center;
  970. &.center {
  971. justify-content: center;
  972. }
  973. text {
  974. color: #999999ff;
  975. font-size: 32rpx;
  976. &.active {
  977. color: #ee3636ff;
  978. }
  979. }
  980. .switch {
  981. width: 118rpx;
  982. height: 118rpx;
  983. padding: 12rpx;
  984. box-sizing: border-box;
  985. border-radius: 50%;
  986. border: 1rpx solid #ee3636ff;
  987. /* background-color: rgb(68, 46, 46); */
  988. position: relative;
  989. display: flex;
  990. align-items: center;
  991. justify-content: center;
  992. image {
  993. position: absolute;
  994. width: 36rpx;
  995. z-index: 5;
  996. }
  997. &::after {
  998. content: "";
  999. display: inline-block;
  1000. width: 100%;
  1001. height: 100%;
  1002. border-radius: 50%;
  1003. background-color: #ee3636ff;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. .record-play {
  1009. margin: 20rpx 30rpx;
  1010. .audio-wrap {
  1011. background-color: #fdf8f2ff;
  1012. padding: 30rpx;
  1013. border-radius: 16rpx;
  1014. }
  1015. .play {
  1016. display: flex;
  1017. justify-content: space-between;
  1018. .slider-box {
  1019. margin-left: 15rpx;
  1020. flex: 1;
  1021. slider {
  1022. margin: 15rpx 0 0 0;
  1023. }
  1024. .slider-time {
  1025. display: flex;
  1026. justify-content: space-between;
  1027. text {
  1028. color: #999999ff;
  1029. font-size: 22rpx;
  1030. }
  1031. }
  1032. }
  1033. }
  1034. .audio-delete {
  1035. margin-top: 20rpx;
  1036. width: 100%;
  1037. height: 40rpx;
  1038. display: flex;
  1039. justify-content: flex-end;
  1040. align-items: center;
  1041. image {
  1042. height: 40rpx;
  1043. }
  1044. text {
  1045. margin-left: 10rpx;
  1046. color: #999999ff;
  1047. font-size: 28rpx;
  1048. }
  1049. }
  1050. .audio-pub {
  1051. margin-top: 120rpx;
  1052. background-color: #e6b77dff;
  1053. color: #fff;
  1054. height: 80rpx;
  1055. line-height: 80rpx;
  1056. border-radius: 40rpx;
  1057. text-align: center;
  1058. position: relative;
  1059. width: 390rpx;
  1060. left: 50%;
  1061. margin-left: -170rpx;
  1062. &.disable{
  1063. background-color:#999999ff;
  1064. color: #fff;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. }
  1070. </style>