answerDetail.vue 29 KB

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