answerDetail.vue 31 KB

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