answerDetail.vue 33 KB

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