question.vue 10 KB

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