answerDetail.vue 33 KB

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