question.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <template>
  2. <view class="question-wrap">
  3. <view class="question-top">
  4. <text class="text" :class="{'active':selectType==='all'}" @click="changeSelect('all')">热门问答</text>
  5. <view class="text" :class="{'active':selectType==='me'}" @click="changeSelect('me')">我的{{ vistor.type === 1 ? '回答' : '提问' }}</view>
  6. <template>
  7. <image src="../../static/chart/menu.png" mode="widthFix" class="menu-icon"
  8. @click="showPopup" />
  9. 筛选
  10. </template>
  11. <van-popup :show="isPopupShow" position="bottom" round :close-on-click-overlay="false"
  12. @close="isPopupShow = false" :style="{ height: '30%' }">
  13. <view class="pop-wrap">
  14. <view class="pop-top">
  15. <text>全部筛选</text>
  16. <text @click="isPopupShow=false">取消</text>
  17. </view>
  18. <view class="pop-option-list">
  19. <van-collapse :value="activeName" @change="changeSelecOption" accordion :border="false">
  20. <van-collapse-item :border="false" :title="item.title" :name="index" v-for="(item, index) in optionList"
  21. :key="index">
  22. <view class="option-btn-wrap">
  23. <view class="option-btn" @click="selectName=i.name" :class="{'active':selectName===i.name}" v-for="(i, _index) in item.btnList" :key="_index">
  24. {{ i.name }}
  25. </view>
  26. </view>
  27. </van-collapse-item>
  28. </van-collapse>
  29. </view>
  30. <view class="pop-btn" @click="changeSelect('name')">完成</view>
  31. </view>
  32. </van-popup>
  33. </view>
  34. <view class="question-list">
  35. <view class="question-item" v-for="item in quesionList" :key="item.id">
  36. <text class="item-title">{{ item.question.text }}</text>
  37. <text class="item-time">提问时间:{{ item.question.time }}</text>
  38. <view class="item-answer">
  39. <view class="answer-img"></view>
  40. <view class="answer-other">
  41. <view class="answer-info">
  42. <text class="name">{{ item.answer.name }}</text>
  43. <text class="group">弘则{{ item.answer.group }}组研究员</text>
  44. <text class="label">{{ item.label }}</text>
  45. </view>
  46. <view class="answer" @click="handleAudio(item)">
  47. <text>{{ item.answer.isplay ? '暂停' : '播放' }}</text>
  48. <template v-if="item.answer.isplay || item.answer.ispause">
  49. <text>{{ currentAudioMsg.audioCurrentTime }}/{{ item.answer.audioTime }}</text>
  50. </template>
  51. <template v-else>
  52. <text>{{ item.answer.audioTime }}</text>
  53. </template>
  54. </view>
  55. </view>
  56. </view>
  57. <text class="item-time">回答时间:{{ item.answer.time }}</text>
  58. </view>
  59. </view>
  60. <view class="topage-btn" @click="toPage(vistor)">
  61. {{ vistor.type === 1 ? '待回答' : '我要提问' }}
  62. </view>
  63. <!-- 弹窗 -->
  64. <van-popup :show="pupData.show" @close="pupData.show = false" closeable :close-on-click-overlay="false">
  65. <view class="global-pup">
  66. <view class="content">
  67. <rich-text :nodes="pupData.content"></rich-text>
  68. </view>
  69. <view class="flex bot" v-if="pupData.type == 'contact'">
  70. <view @click="handleCallPhone(pupData.mobile)">拨号</view>
  71. </view>
  72. <view class="flex bot" v-else-if="pupData.type == 'apply'">
  73. <view @click="handleApply">立即申请</view>
  74. </view>
  75. </view>
  76. </van-popup>
  77. </view>
  78. </template>
  79. <script>
  80. import { varietyData, questionData } from './mock.js'
  81. import { apiApplyPermission, apiUserInfo } from '@/api/user'
  82. const moment = require('@/utils/moment-with-locales.min')
  83. moment.locale('zh-cn');
  84. export default {
  85. data() {
  86. return {
  87. onlySeeAuth: false,//只看我的
  88. quesionList: questionData,
  89. isPopupShow: false,//弹出层是否展示
  90. optionList: varietyData,
  91. activeNames: [],//collapse
  92. activeName:'',
  93. innerAudio: null,//该页面的音频
  94. vistor: {//用户信息
  95. type: 1,//1研究员,2客户
  96. status: '潜在',//type为2的时候才判断
  97. premission: {
  98. seeAuth: true,//只看我的筛选框
  99. option: true,//弹窗筛选框
  100. isApply: false,//之前是否提交过申请
  101. canPlay: false,//是否能够播放音频
  102. }
  103. },
  104. currentAudioMsg: {
  105. id: '',
  106. audioCurrentTime: 0,//音频播放实时时间
  107. audioTime: 0,//当前音频时间
  108. audioCurrentUrl: '',//当前音频地址
  109. },//当前正在播放音频的一些信息
  110. pupData: {
  111. show: false,
  112. content: '',//弹窗html字符串
  113. type: '',
  114. mobile: "",
  115. customer_info:{}
  116. },
  117. selectType:'all',
  118. selectName:'宏观'
  119. }
  120. },
  121. onLoad() {
  122. this.initAudio()
  123. this.getVistor()
  124. },
  125. onShow() {
  126. },
  127. ononUnload() {
  128. this.destoryAudio()
  129. },
  130. methods: {
  131. //初始化audio
  132. initAudio() {
  133. this.innerAudio = uni.createInnerAudioContext()
  134. this.handleAudioFun()
  135. },
  136. //销毁audio
  137. destoryAudio() {
  138. if (this.innerAudio) {
  139. this.innerAudio.destory()
  140. }
  141. },
  142. //获取访客信息:研究员/客户
  143. getVistor() {
  144. this.vistor = {
  145. type: 2,
  146. status: '正式',
  147. premission: {
  148. seeAuth: true,//只看我的筛选框
  149. option: true,//弹窗筛选框
  150. isApply: true,//之前是否提交过申请
  151. canPlay: true,//是否能够播放音频
  152. }
  153. }
  154. },
  155. //audio事件
  156. handleAudioFun() {
  157. this.innerAudio.onPlay(() => {
  158. console.log('开始了')
  159. })
  160. this.innerAudio.onTimeUpdate(() => {
  161. //console.log('时间更新')
  162. this.currentAudioMsg.audioCurrentTime = moment(this.innerAudio.currentTime * 1000).format('mm:ss')
  163. //console.log('duration',this.innerAudio.duration)
  164. })
  165. this.innerAudio.onEnded(() => {
  166. console.log('音频播放完毕')
  167. const { id } = this.currentAudioMsg
  168. this.quesionList.map(i => {
  169. if (i.id === id) {
  170. i.answer.isplay = false
  171. i.answer.ispause = false
  172. }
  173. })
  174. this.changeCurrentAudio({ id: '', answer: { source: '', audioTime: 0 } })
  175. })
  176. },
  177. //初始化无权限弹窗
  178. initPupData() {
  179. let str = '<p>您暂无权限查看语音回复</p>'
  180. const { status} = this.vistor
  181. if (['潜在', '流失'].includes(status)) {
  182. this.pupData.type = 'apply'
  183. str += '<p>若想查看可以申请开通</p>'
  184. }
  185. if (['冻结', '暂停试用'].includes(status)) {
  186. this.pupData.mobile = 123456
  187. this.pupData.type = 'contact'
  188. str += '<p>若想查看可以联系对口销售</p>'
  189. }
  190. this.pupData.customer_info.status = status
  191. this.pupData.customer_info.has_apply = this.vistor.premission.isApply
  192. this.pupData.content = str
  193. this.pupData.show = true
  194. },
  195. //拨号
  196. handleCallPhone(mobile) {
  197. },
  198. //申请权限
  199. async handleApply() {
  200. if (this.pupData.customer_info.has_apply) {//已经申请过
  201. this.pupData.content = `<p>您已提交过申请,请耐心等待</p>`
  202. this.pupData.type = ''
  203. } else {
  204. if (!this.pupData.customer_info.status || this.pupData.customer_info.status != '流失') {
  205. uni.navigateTo({
  206. url: "/pages-applyPermission/applyPermission?source=4"
  207. })
  208. } else {//主动调一次申请权限接口
  209. /* const res=await apiApplyPermission({
  210. company_name:this.pupData.customer_info.company_name,
  211. real_name:this.pupData.customer_info.name,
  212. source:2,
  213. from_page:'活动列表'
  214. })
  215. if(res.code===200){} */
  216. this.pupData.content = `<p>申请已提交</p><p>请等待销售人员与您联系</p>`
  217. this.pupData.type = ''
  218. }
  219. }
  220. },
  221. //播放音频
  222. handleAudioPlay() {
  223. this.innerAudio.onCanplay(() => {
  224. this.innerAudio.play()
  225. //console.log('音频长度:', this.innerAudio)
  226. //this.currentAudioMsg.audioTime = this.innerAudio.duration
  227. })
  228. },
  229. //切换当前播放音频
  230. changeCurrentAudio(item) {
  231. const { id } = item
  232. const { source, audioTime } = item.answer
  233. this.currentAudioMsg = {
  234. id: id,
  235. audioCurrentTime: 0,
  236. audioTime: audioTime,
  237. audioCurrentUrl: source
  238. }
  239. },
  240. //点击'热门回答'/'只看我的'/筛选弹窗的按钮
  241. changeSelect(type) {
  242. if(type!=='name'){
  243. this.selectType = type
  244. }else{
  245. this.isPopupShow = false
  246. }
  247. //getData()
  248. },
  249. //点击筛选
  250. showPopup() {
  251. console.log('a')
  252. this.isPopupShow = true
  253. },
  254. changeBtnShow() {
  255. },
  256. changeSelecOption(e) {
  257. this.activeName = e.detail
  258. },
  259. //点击某条音频
  260. handleAudio(item) {
  261. //如果没有权限,弹窗并return
  262. if (!this.vistor.premission.canPlay) {
  263. this.initPupData()
  264. return
  265. }
  266. const { source, isplay } = item.answer
  267. if (isplay) {
  268. //说明是播放->暂停
  269. this.innerAudio.pause()
  270. } else if (item.id === this.currentAudioMsg.id) {
  271. //说明是暂停->播放
  272. this.innerAudio.play()
  273. } else {
  274. console.log('aaa', source, this.innerAudio.src)
  275. //说明是第一次播放或点击其他播放项
  276. this.changeCurrentAudio(item)
  277. this.innerAudio.stop()
  278. this.innerAudio.src = source
  279. /* this.innerAudio.play() */
  280. this.handleAudioPlay()
  281. }
  282. this.quesionList.map((i) => {
  283. if (i.id === item.id) {
  284. if (i.answer.isplay) {
  285. i.answer.ispause = true
  286. }
  287. i.answer.isplay = !i.answer.isplay
  288. } else {
  289. i.answer.isplay = false
  290. i.answer.ispause = false
  291. }
  292. })
  293. },
  294. //点击'我要提问'/'待回答'
  295. toPage(item) {
  296. const { type } = item
  297. if (type === 1) {
  298. uni.navigateTo({ url: '/pages-question/answerList' })
  299. } else {
  300. uni.navigateTo({ url: '/pages-question/hasQuestion' })
  301. }
  302. }
  303. }
  304. }
  305. </script>
  306. <style lang="scss">
  307. .question-wrap {
  308. .van-popup--bottom{
  309. padding-bottom: 0 !important;
  310. }
  311. /deep/ .van-cell__title,
  312. .van-cell__value {
  313. flex: none !important;
  314. }
  315. .van-collapse-item{
  316. &.van-hairline--top{
  317. &::after{
  318. border: none !important;
  319. }
  320. }
  321. .van-cell{
  322. padding-left:0 !important;
  323. }
  324. }
  325. .van-collapse-item__content{
  326. padding:0;
  327. }
  328. }
  329. page {
  330. padding-bottom: env(safe-area-inset-bottom);
  331. }
  332. </style>
  333. <style lang="scss" scoped>
  334. .question-wrap {
  335. padding: 0 30rpx 80rpx 30rpx;
  336. background-color: #FFFFFF;
  337. .question-top {
  338. display: flex;
  339. justify-content: space-between;
  340. align-items: center;
  341. height: 100rpx;
  342. background-color: white;
  343. position: sticky;
  344. top: 0;
  345. left: 0;
  346. z-index: 99;
  347. .text{
  348. width:240rpx;
  349. height:70rpx;
  350. line-height: 70rpx;
  351. background-color: #F5F5F5;
  352. border-radius: 4rpx;
  353. color:#666666;
  354. text-align: center;
  355. &.active{
  356. color:#E3B377;
  357. background-color: #FDF8F2;
  358. }
  359. }
  360. .auth-box {
  361. flex: 1;
  362. }
  363. .menu-icon {
  364. width: 40rpx;
  365. }
  366. .pop-wrap{
  367. padding: 50rpx 34rpx 0 34rpx;
  368. .pop-top {
  369. display: flex;
  370. justify-content: space-between;
  371. text{
  372. font-size: 32rpx;
  373. &:first-child{
  374. color: #000000;
  375. }
  376. &:last-child{
  377. color: #E3B377;
  378. }
  379. }
  380. }
  381. .pop-option-list {
  382. .option-btn-wrap {
  383. display: flex;
  384. flex-wrap: wrap;
  385. margin-bottom: 20rpx;
  386. .option-btn {
  387. width: 215rpx;
  388. height:76rpx;
  389. line-height: 76rpx;
  390. text-align: center;
  391. color: black;
  392. background-color: #F6F6F6;
  393. border-radius: 4rpx;
  394. margin: 10rpx 10rpx 0 0;
  395. &.active{
  396. background-color: #FAEEDE;
  397. }
  398. }
  399. }
  400. }
  401. .pop-btn{
  402. height:80rpx;
  403. margin:0 -34rpx;
  404. text-align: center;
  405. line-height: 80rpx;
  406. color:#FFFFFF;
  407. background-color: #E6B77D;
  408. }
  409. }
  410. }
  411. .question-list {
  412. .question-item {
  413. margin-bottom: 20rpx;
  414. &::after{
  415. content: '';
  416. display: block;
  417. height:10rpx;
  418. margin:0 -30rpx;
  419. background-color: #F9F9F9;
  420. }
  421. &:last-child{
  422. &::after{
  423. background-color: #FFFFFF;
  424. }
  425. }
  426. .item-title {
  427. display: block;
  428. font-size: 32rpx;
  429. color:#333333
  430. }
  431. .item-time {
  432. color: #999999;
  433. font-size: 24rpx;
  434. margin:20rpx 0;
  435. display: block;
  436. }
  437. .item-answer {
  438. display: flex;
  439. width:100%;
  440. height: 213rpx;
  441. background-color: #FDF8F2;
  442. box-sizing: border-box;
  443. padding:20rpx;
  444. align-items: center;
  445. position:relative;
  446. .answer-img {
  447. width: 146rpx;
  448. height: 146rpx;
  449. border: 4rpx solid #FFFFFF;
  450. border-radius: 50%;
  451. margin-right: 20rpx;
  452. }
  453. .answer-other {
  454. display: flex;
  455. flex-direction: column;
  456. .answer-info {
  457. .name {
  458. color: #333333;
  459. font-size: 28rpx;
  460. margin-right: 20rpx;
  461. }
  462. .group {
  463. color: #999999;
  464. font-size: 24rpx;
  465. }
  466. .label {
  467. position: absolute;
  468. right:0;
  469. top:0;
  470. width: 90rpx;
  471. height:41rpx;
  472. font-size: 24rpx;
  473. text-align: center;
  474. line-height: 41rpx;
  475. background-color: #333333;
  476. color: #E4B478;
  477. }
  478. }
  479. }
  480. .answer {
  481. margin-top: 20rpx;
  482. width: 340rpx;
  483. height: 74rpx;
  484. box-sizing: border-box;
  485. padding:20rpx 30rpx;
  486. border-radius: 37rpx;
  487. background:linear-gradient(253deg, #E3B377 0%, #FBCA8E 100%);
  488. display: flex;
  489. justify-content: space-between;
  490. color: #FFFFFF;
  491. }
  492. }
  493. }
  494. }
  495. .topage-btn {
  496. position: fixed;
  497. left:0;
  498. right:0;
  499. bottom: 0;
  500. height: 80rpx;
  501. text-align: center;
  502. line-height: 80rpx;
  503. background-color: #333333;
  504. box-shadow: 0px 4px 20px 1px rgba(160, 126, 84, 0.25);
  505. color: #E3B377;
  506. }
  507. }
  508. </style>