123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /* 问答社区 公共逻辑 */
- import {
- apiQuestionList
- } from '@/api/question'
- import { apiApplyPermission, apiUserInfo } from '@/api/user'
- const moment = require('@/utils/moment-with-locales.min')
- moment.locale('zh-cn');
- export default {
- data() {
- return {
- moment: moment,
- innerAudio: null, //该页面的音频
- currentAudioMsg: {
- id: '',
- audioCurrentTime: 0, //音频播放实时时间
- audioTime: 0, //当前音频时间
- audioCurrentUrl: '', //当前音频地址
- }, //当前正在播放音频的一些信息
- pupData: {
- show: false,
- content: '', //弹窗html字符串
- type: '',
- mobile: "",
- customer_info: {}
- },
- page: 1,
- pageSize: 20,
- finished: false,
- selectId: -1,
- }
- },
- onLoad() {
- //this.initAudio()
- },
- onShow(){
- this.initAudio()
- },
- onHide(){
- this.resetAudio()
- this.destroyAudio()
- },
- onUnload() {
- //this.destroyAudio()
- },
- methods: {
- //初始化audio
- initAudio() {
- this.innerAudio = uni.createInnerAudioContext()
- this.handleAudioFun()
- },
- //销毁audio
- destroyAudio() {
- if (this.innerAudio) {
- this.innerAudio.destroy()
- }
- },
- //重置音频播放信息
- resetAudio(){
- this.innerAudio.pause();
- this.questionList.map((i) => {
- if(i.id===this.currentAudioMsg.id){
- i.answer.isplay = false
- i.answer.ispause = false
- }
- })
- this.changeCurrentAudio({
- id: '',
- answer: {
- source: '',
- audioTime: 0
- }
- })
- },
- //audio事件
- handleAudioFun() {
- this.innerAudio.onPlay(() => {
- console.log('开始了')
- this.questionList.map(i => {
- if (i.id === this.currentAudioMsg.id) {
- i.loading = false
- }
- })
- })
- this.innerAudio.onTimeUpdate(() => {
- //console.log('时间更新')
- this.currentAudioMsg.audioCurrentTime = this.innerAudio.currentTime * 1000
- })
- this.innerAudio.onPause(() => {
- console.log("暂停");
- })
- this.innerAudio.onEnded(() => {
- console.log('音频播放完毕')
- const {
- id
- } = this.currentAudioMsg
- this.questionList.map(i => {
- if (i.id === id) {
- i.answer.isplay = false
- i.answer.ispause = false
- }
- })
- this.changeCurrentAudio({
- id: '',
- answer: {
- source: '',
- audioTime: 0
- }
- })
- })
- },
- //播放音频
- handleAudioPlay() {
- this.innerAudio.onCanplay(() => {
- this.innerAudio.play()
- })
- },
- //切换当前播放音频
- changeCurrentAudio(item) {
- const {
- id
- } = item
- const {
- source,
- audioTime
- } = item.answer
- this.currentAudioMsg = {
- id: id,
- audioCurrentTime: 0 * 1000,
- audioTime: audioTime,
- audioCurrentUrl: source
- }
- this.questionList.map(i => {
- if (i.id === item.id) {
- i.loading = true
- }
- })
- },
- //获取问答列表:status(问题状态) only_mine(只看我的)
- async getQuestionList(status,onlyMine=0) {
- let questionData = []
- const res = await apiQuestionList({
- page_index: this.page,
- page_size: this.pageSize,
- chart_permission_id: this.selectId === -1 ? '' : this.selectId,
- reply_status: status,
- only_mine:onlyMine
- })
- if (res.code === 200) {
- if (res.data) {
- questionData = res.data
- } else {
- this.finished = true
- }
- }
- let tempArr = []
- questionData.forEach(item => {
- let temp = item
- let audio_url = '',
- audio_play_seconds = 0;
- //问题状态为已回答,取audio_list第一项为音频
- if (item.reply_status === 3) {
- audio_url = item.audio_list[0].audio_url
- audio_play_seconds = item.audio_list[0].audio_play_seconds
- }
- //问题状态不为已回答,取默认值
- temp.answer = {
- source: audio_url,
- audioTime: parseInt(audio_play_seconds) * 1000,
- isplay: false,
- ispause: false
- }
- temp.id = item.community_question_id
- temp.loading = false
- tempArr.push(temp)
- })
- if (this.page > 1) {
- this.questionList = this.questionList.concat(tempArr)
- } else {
- this.questionList = tempArr
- }
- },
- //点击某条音频
- handleAudio(item) {
- //如果没有权限,弹窗并return
- if (!item.auth_ok) {
- this.initPupData(item)
- return
- }
- const {
- source,
- isplay
- } = item.answer
- if (isplay) {
- //说明是播放->暂停
- this.innerAudio.pause()
- } else if (item.id === this.currentAudioMsg.id) {
- //说明是暂停->播放
- this.innerAudio.play()
- } else {
- //console.log('aaa', source, this.innerAudio.src)
- //说明是第一次播放或点击其他播放项
- this.changeCurrentAudio(item)
- this.innerAudio.stop()
- this.innerAudio.src = source
- /* this.innerAudio.play() */
- this.handleAudioPlay()
- }
- this.questionList.map((i) => {
- if (i.id === item.id) {
- if (i.answer.isplay) {
- i.answer.ispause = true
- }
- i.answer.isplay = !i.answer.isplay
- } else {
- i.answer.isplay = false
- i.answer.ispause = false
- i.loading = false
- }
- })
- },
- //初始化无权限弹窗
- initPupData(item) {
- let str = '<p>您暂无权限查看语音回复</p>'
- const {
- type,
- mobile,
- name,
- customer_info
- } = item.permission_info
- if (type === 'apply') {
- this.pupData.type = 'apply'
- str += '<p>若想查看可以申请开通</p>'
- }
- if (type === 'contact') {
- this.pupData.mobile = mobile + ''
- this.pupData.saleName = name
- this.pupData.type = 'contact'
- str += `<p>若想查看可以联系对口销售</p>`
- }
- this.pupData.customer_info = customer_info
- this.pupData.content = str
- this.pupData.show = true
- },
- //拨号
- handleCallPhone(tel) {
- uni.makePhoneCall({
- phoneNumber: tel ? tel : '123456',
- success: () => {
- this.pupData.show = false
- }
- });
- },
- //申请权限
- async handleApply() {
- if (this.pupData.customer_info.has_apply) { //已经申请过
- this.pupData.content = `<p>您已提交过申请,请耐心等待</p>`
- this.pupData.type = ''
- } else {
- if (!this.pupData.customer_info.status || this.pupData.customer_info.status != '流失') {
- uni.navigateTo({
- url: "/pages-applyPermission/applyPermission?source=5&form_page=问答社区"
- })
- } else { //主动调一次申请权限接口
- const res = await apiApplyPermission({
- company_name: this.pupData.customer_info.company_name,
- real_name: this.pupData.customer_info.name,
- source: 5,
- from_page: '问答社区'
- })
- if (res.code === 200) {
- //重新获取页面数据
- const pages = getCurrentPages();
- const page = pages[pages.length - 1];
- /* page.onLoad(); */
- page.onShow();
- }
- this.pupData.content = `<p>申请已提交</p><p>请等待销售人员与您联系</p>`
- this.pupData.type = ''
- }
- }
- },
- }
- }
|