question.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <template>
  2. <view class="question-wrap">
  3. <template v-if="hasAuth">
  4. <view class="question-top" :class="{'noAuth':!(isUserResearcher||userInfo.status&&userAuth)}">
  5. <view @click="showPopup" v-if="isUserResearcher||userInfo.status&&userAuth"
  6. style="display:flex;align-items: center;margin-left:30rpx;">
  7. <image src="../../static/question/select.png" mode="widthFix" class="menu-icon"/>
  8. <text style="color:#E3B377;font-size:28rpx;">筛选</text>
  9. </view>
  10. <van-popup :show="isPopupShow" position="left" :close-on-click-overlay="true"
  11. @close="isPopupShow = false"
  12. custom-style="height: 100%;width:50%;"
  13. @touchmove.stop.prevent>
  14. <view class="pop-wrap">
  15. <view class="pop-option-list">
  16. <van-collapse :value="activeName" @change="changeSelecOption" accordion :border="false">
  17. <van-collapse-item :border="false" :title="item.research_group_name" :name="index" v-for="(item, index) in optionList"
  18. :key="index">
  19. <view class="option-btn-wrap">
  20. <view class="option-btn"
  21. v-for=" i in item.children" :key="i.research_group_id"
  22. @click="handleOptionClick(i)"
  23. :class="{'active':selectName===i.research_group_name,'full':i.research_group_name.length>4}"
  24. >
  25. {{ i.research_group_name }}
  26. </view>
  27. </view>
  28. </van-collapse-item>
  29. </van-collapse>
  30. </view>
  31. </view>
  32. </van-popup>
  33. </view>
  34. <view class="report-empty-box" v-if="questionList.length==0">
  35. <image :src="globalImgUrls.activityNoAuth" mode="widthFix" style="width:100%;"/>
  36. <view>暂无提问<text v-if="userInfo.is_inner!==1">,快试试提问功能吧</text></view>
  37. </view>
  38. <view class="question-list" :class="{'last':finished}">
  39. <view class="question-item" v-for="item in questionList" :key="item.community_question_id">
  40. <text class="item-time">提问时间:{{ item.create_time }}</text>
  41. <view class="question-info">
  42. <view style="flex:1;" class="question-title">
  43. <text class="item-label">{{item.research_group_second_name}}</text>
  44. <!-- <text class="item-title"> -->{{ item.question_content }}<!-- </text> -->
  45. </view>
  46. <view class="item-answer">
  47. <view class="answer" @click="handleAudio(item)">
  48. <template v-if="!item.loading">
  49. <image class="music-img" :src="item.answer.isplay?playImgSrc:pauseImgSrc" mode="widthFix"/>
  50. <template v-if="item.answer.isplay || item.answer.ispause">
  51. <text>{{
  52. item.answer.audioTime - currentAudioMsg.audioCurrentTime>0?
  53. moment(item.answer.audioTime - currentAudioMsg.audioCurrentTime).format('mm:ss')
  54. :'00:00'}}
  55. </text>
  56. </template>
  57. <template v-else>
  58. <text>{{ moment(item.answer.audioTime).format('mm:ss') }}</text>
  59. </template>
  60. </template>
  61. <template v-else>
  62. <image class="load-img" src="../../static/loading.png" mode="aspectFill" />
  63. <text>{{ moment(item.answer.audioTime).format('mm:ss') }}</text>
  64. </template>
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 评论区域 -->
  69. <questionComment :item="item" @show_comment="showCommentHandle"/>
  70. </view>
  71. </view>
  72. <view class="topage-btn" @click="toPage" v-if="isUserResearcher||userInfo.status&&userAuth">
  73. <image
  74. v-if="!isUserResearcher"
  75. src="../../static/question/askquestion.png"
  76. mode="scaleToFill"
  77. style="width:34rpx;height:34rpx;"
  78. />
  79. {{ isUserResearcher ? '待回答' : '我要提问' }} <text v-if="isUserResearcher" style="margin-left:5rpx;">{{'('+waitNum+')'}}</text>
  80. </view>
  81. </template>
  82. <!-- 没有权限 -->
  83. <template v-else>
  84. <view class="noAuth-wrap">
  85. <image class="img" :src="globalImgUrls.activityNoAuth" mode="widthFix"></image>
  86. <view class="auth-text">您暂无权限查看问答社区</view>
  87. <view class="auth-text" v-if="noAuthInfo.type==='contact'">若想查看可以联系对口销售</view>
  88. <view class="auth-text" v-else>若想查看可以申请开通</view>
  89. <view class="auth-text" v-if="noAuthInfo.type==='contact'">
  90. {{noAuthInfo.name||''}}:<text @click="handleCallPhone(noAuthInfo.mobile+'')">{{noAuthInfo.mobile||''}}</text>
  91. </view>
  92. <view class="apply" @click="handleGoApply" v-else>立即申请</view>
  93. </view>
  94. </template>
  95. <!-- 弹窗 -->
  96. <van-popup :show="pupData.show" round @close="pupData.show = false" closeable :close-on-click-overlay="false">
  97. <view class="global-pup">
  98. <view class="content">
  99. <rich-text style="flex:none;margin-bottom:20rpx;" :nodes="pupData.content"></rich-text>
  100. <view class="contact" v-if="pupData.type == 'contact'">
  101. {{pupData.saleName||''}}:<text @click="handleCallPhone(pupData.mobile)">{{pupData.mobile||''}}</text>
  102. </view>
  103. <view class="apply" v-else-if="pupData.type == 'apply'">
  104. <view @click="handleApply">立即申请</view>
  105. </view>
  106. </view>
  107. </view>
  108. </van-popup>
  109. <!-- 评论弹窗 -->
  110. <van-action-sheet
  111. :show="isShowComment"
  112. title="全部评论"
  113. @close="closeCommentHandle"
  114. @clickOverlay="isShowComment=false"
  115. >
  116. <view class="comment-cont" catchtouchmove="return">
  117. <view class="commment-top">
  118. <text class="title">{{comment_obj.title}} {{comment_obj.total}}</text>
  119. <view class="comment-top-right">
  120. <text :class="select_comment_type === 1 && 'act'" @click="changeCommentTypeHandle(1)">精选</text>
  121. <text :class="select_comment_type === 2 && 'act'" @click="changeCommentTypeHandle(2)">我的</text>
  122. </view>
  123. </view>
  124. <scroll-view class="comment-list-cont" v-if="comment_obj.total" scroll-y>
  125. <view class="comment-list-item" v-for="(item,index) in commentList" :key="item.community_question_comment_id">
  126. <view class="comment">
  127. <text style="color: #333;">{{item.user_name}}:</text>
  128. {{item.content}}
  129. </view>
  130. <view class="del" v-if="select_comment_type === 2" @click="delCommentHandle(item,index)">删除该评论</view>
  131. </view>
  132. </scroll-view>
  133. <view class="nodata" v-else>
  134. <image src="@/static/nodata.png"></image>
  135. <view>暂无评论</view>
  136. </view>
  137. <view class="write-wrap">
  138. <textarea
  139. v-model="comment_cont"
  140. placeholder="发布一条友善的评论"
  141. auto-height
  142. :show-confirm-bar="false"
  143. :cursor-spacing="20"
  144. class="write-ipt"
  145. @focus="checkNickHandle"
  146. />
  147. <!-- <input
  148. v-model="message"
  149. class="write-ipt"
  150. placeholder="发布一条友善的评论"
  151. confirm-type="send"
  152. :cursor-spacing="20"
  153. /> -->
  154. <view class="confirm-btn" @click="publishMessageHandle">发布</view>
  155. </view>
  156. </view>
  157. </van-action-sheet>
  158. </view>
  159. </template>
  160. <script>
  161. import mixin from "../../mixin/questionMixin";
  162. import {
  163. apiOptionGroupList,
  164. apiBarTotal,
  165. apiHotComment,
  166. apiMyComment,
  167. apiCheckNick,
  168. apiCanelNickTip,
  169. apiDelComment,
  170. apiPublishComment,
  171. } from '@/api/question'
  172. import questionComment from '@/components/questionComment/questionComment.vue'
  173. import Dialog from '@/wxcomponents/vant/dialog/dialog.js';
  174. import { debounce } from '@/utils/common.js';
  175. export default {
  176. mixins: [mixin],
  177. data() {
  178. return {
  179. questionList: [],
  180. isPopupShow: false,//弹出层是否展示
  181. optionList: [],
  182. activeNames: [],//collapse
  183. activeName:'',
  184. selectName:'',
  185. pauseImgSrc:'../../static/question/recordplay.png',
  186. playImgSrc:'../../static/question/recordpause.png',
  187. waitNum:0,
  188. isShowComment: false,
  189. comment_cont: '',
  190. select_comment_type:1,//默认精选
  191. select_question_item: {},
  192. comment_obj: {
  193. title: '精选评论',
  194. total: 0
  195. },
  196. comment_total: 0,
  197. commentList: []
  198. }
  199. },
  200. watch:{
  201. selectName(){
  202. this.getQuestionList(3)
  203. }
  204. },
  205. components:{
  206. questionComment
  207. },
  208. onLoad() {
  209. /* this.getVistor()
  210. this.getOptionList()
  211. this.getQuestionList(3) */
  212. },
  213. onShow() {
  214. this.getWaitNum()
  215. this.getOptionList()
  216. this.getQuestionList(3)
  217. },
  218. onReachBottom() {
  219. if(this.finished) return
  220. this.page++
  221. this.getQuestionList(3)
  222. },
  223. onPullDownRefresh() {
  224. this.resetAudio()
  225. this.refreshPage()
  226. setTimeout(() => {
  227. uni.stopPullDownRefresh()
  228. }, 1500);
  229. },
  230. methods: {
  231. //获取研究员问答列表数量统计
  232. getWaitNum() {
  233. if(this.userInfo.is_inner!==1) return
  234. //如果是研究员,则请求问答列表数量统计
  235. apiBarTotal().then(res=>{
  236. if(res.code===200){
  237. this.waitNum = res.data.wait
  238. }
  239. })
  240. },
  241. //获取筛选列表
  242. async getOptionList(){
  243. const res = await apiOptionGroupList()
  244. if(res.code===200){
  245. this.optionList = res.data
  246. }
  247. },
  248. //点击筛选
  249. showPopup() {
  250. this.isPopupShow = true
  251. },
  252. //点击一级分类
  253. changeSelecOption(e) {
  254. this.activeName = e.detail
  255. },
  256. //点击二级分类
  257. handleOptionClick(item){
  258. //重复点击代表取消
  259. if(this.selectId===item.research_group_id){
  260. this.selectId=-1
  261. this.selectName=''
  262. }else{
  263. this.selectId = item.research_group_id
  264. this.selectName = item.research_group_name
  265. }
  266. this.page = 1
  267. this.isPopupShow = false
  268. },
  269. //点击'我要提问' or '待回答'
  270. toPage() {
  271. //const {is_inner} = this.userInfo
  272. if (this.isUserResearcher) {
  273. uni.navigateTo({ url: '/pages-question/answerList' })
  274. } else {
  275. uni.navigateTo({ url: '/pages-question/hasQuestion' })
  276. }
  277. },
  278. //转发分享
  279. onShareAppMessage(){
  280. return{
  281. title:'问答社区',
  282. path:'/pages/question/question'
  283. }
  284. },
  285. refreshPage() {
  286. this.page = 1
  287. this.selectId = -1
  288. this.questionList = []
  289. this.finished = false
  290. this.getQuestionList(3)
  291. },
  292. /* 打开评论弹窗 */
  293. showCommentHandle(item) {
  294. this.select_question_item = item;
  295. this.getComment();
  296. this.isShowComment = true;
  297. },
  298. /* 关闭评论弹窗 */
  299. closeCommentHandle() {
  300. this.isShowComment = false;
  301. this.select_question_item = {};
  302. this.comment_cont = '';
  303. this.select_comment_type = 1;//默认精选
  304. },
  305. /* 切换评论类型*/
  306. changeCommentTypeHandle(type) {
  307. if(type === this.select_comment_type) return
  308. this.commentList = [];
  309. this.select_comment_type = type;
  310. this.getComment();
  311. },
  312. /* 获取评论 */
  313. async getComment() {
  314. const params = {
  315. community_question_id: this.select_question_item.community_question_id,
  316. curr_page: 1,
  317. page_size: 10000
  318. }
  319. const { code,data } = this.select_comment_type===1 ? await apiHotComment(params) : await apiMyComment(params);
  320. if(code !== 200) return
  321. this.commentList = data.list || [];
  322. this.comment_obj = {
  323. title: this.select_comment_type === 1 ? '精选评论' : '我的评论',
  324. total: data.paging.totals
  325. }
  326. },
  327. /* 删除留言*/
  328. delCommentHandle({community_question_comment_id},index) {
  329. wx.showModal({
  330. title: "",
  331. content: "评论删除后不可恢复,确认删除吗?",
  332. confirmColor: "#EE3636",
  333. cancelColor: '#333',
  334. success: async(res) => {
  335. if( res.cancel) return
  336. const { code } = await apiDelComment({ community_question_comment_id });
  337. if( code !== 200 ) return
  338. this.commentList.splice(index,1)
  339. wx.showToast({title: '删除成功'});
  340. }
  341. })
  342. },
  343. /* 校验昵称状态*/
  344. async checkNickHandle() {
  345. const { data,code } = await apiCheckNick();
  346. if(code !== 200) return
  347. !data && wx.showModal({
  348. title: '',
  349. content: '检测到您还未设置头像和昵称,您的留言将发布为匿名,是否立即去设置?',
  350. confirmText: '去设置',
  351. confirmColor: '#E3B377',
  352. cancelText : '暂时不用',
  353. cancelColor: '#666',
  354. success: (res)=> {
  355. res.confirm && wx.navigateTo({ url:'/pages-user/mysetting' });
  356. res.cancel && this.setCancelNickHandle();
  357. }
  358. })
  359. },
  360. /* 不在提醒弹窗 */
  361. async setCancelNickHandle() {
  362. await apiCanelNickTip()
  363. },
  364. /* 发布留言*/
  365. publishMessageHandle: debounce( async function() {
  366. if(!this.comment_cont) return wx.showToast({title: '请输入留言内容',icon: 'none'});
  367. const { code } = await apiPublishComment({
  368. content: this.comment_cont,
  369. community_question_id: this.select_question_item.community_question_id
  370. })
  371. if(code !== 200) return
  372. wx.showToast({title: '发布成功'});
  373. this.comment_cont = '';
  374. this.select_comment_type === 2 && this.getComment();
  375. })
  376. }
  377. }
  378. </script>
  379. <style lang="scss">
  380. .question-wrap {
  381. .van-popup--bottom{
  382. padding-bottom: 0 !important;
  383. }
  384. /deep/ .van-cell__title,
  385. .van-cell__value {
  386. flex: none !important;
  387. }
  388. .van-collapse-item{
  389. &.van-hairline--top{
  390. &::after{
  391. border: none !important;
  392. }
  393. }
  394. .van-cell{
  395. padding-left:0 !important;
  396. }
  397. }
  398. .van-collapse-item__content{
  399. padding:0;
  400. }
  401. }
  402. page {
  403. padding-bottom: env(safe-area-inset-bottom);
  404. }
  405. </style>
  406. <style lang="scss" scoped>
  407. .question-wrap {
  408. padding: 0 30rpx 80rpx 30rpx;
  409. background-color: #FFFFFF;
  410. .question-top {
  411. display: flex;
  412. flex: auto;
  413. align-items: center;
  414. height: 100rpx;
  415. background-color: white;
  416. position: sticky;
  417. top: 0;
  418. left: 0;
  419. margin:0 -30rpx;
  420. z-index: 99;
  421. &.noAuth{
  422. height:20rpx;
  423. }
  424. /* border-top: 1rpx solid rgba(0, 0, 0, 0.1); */
  425. .text{
  426. width:240rpx;
  427. height:70rpx;
  428. line-height: 70rpx;
  429. background-color: #F5F5F5;
  430. border-radius: 4rpx;
  431. color:#666666;
  432. text-align: center;
  433. &.active{
  434. color:#E3B377;
  435. background-color: #FDF8F2;
  436. }
  437. }
  438. .auth-box {
  439. flex: 1;
  440. }
  441. .menu-icon {
  442. width: 34rpx;
  443. height:34rpx;
  444. }
  445. .pop-wrap{
  446. height: 100%;
  447. padding: 50rpx 34rpx;
  448. .pop-option-list {
  449. .option-btn-wrap {
  450. display: flex;
  451. justify-content: space-between;
  452. flex-wrap: wrap;
  453. margin-bottom: 20rpx;
  454. .option-btn {
  455. min-width: 145rpx;
  456. height:76rpx;
  457. line-height: 76rpx;
  458. text-align: center;
  459. color: black;
  460. background-color: #F6F6F6;
  461. border-radius: 4rpx;
  462. margin-top: 10rpx;
  463. &.active{
  464. background-color: #FAEEDE;
  465. }
  466. &.full{
  467. width:100%;
  468. }
  469. }
  470. }
  471. }
  472. .pop-btn{
  473. height:80rpx;
  474. margin:0 -34rpx;
  475. text-align: center;
  476. line-height: 80rpx;
  477. color:#FFFFFF;
  478. background-color: #E6B77D;
  479. }
  480. }
  481. }
  482. .question-list {
  483. padding-bottom: 34rpx;
  484. &.last{
  485. padding-bottom: 260rpx;
  486. }
  487. }
  488. .topage-btn {
  489. position: fixed;
  490. left:50%;
  491. margin-left: -257rpx;
  492. bottom: 215rpx;
  493. width:514rpx;
  494. height: 80rpx;
  495. text-align: center;
  496. line-height: 80rpx;
  497. border-radius: 40rpx;
  498. background-color: #333333;
  499. box-shadow: 0px 4px 20px 1px rgba(160, 126, 84, 0.25);
  500. color: #E3B377;
  501. display: flex;
  502. justify-content: center;
  503. align-items: center;
  504. image{
  505. margin-right: 10rpx;
  506. margin-top: -2rpx;
  507. }
  508. }
  509. .global-pup{
  510. .content{
  511. padding:90rpx 34rpx;
  512. flex-direction: column;
  513. .contact{
  514. text{
  515. margin-left: 15rpx;
  516. color:#E6B77D;
  517. }
  518. }
  519. .apply{
  520. margin-top: 40rpx;
  521. width:390rpx;
  522. height:80rpx;
  523. background-color: #E6B77D;
  524. color: #FFFFFF;
  525. text-align: center;
  526. line-height: 80rpx;
  527. border-radius: 40rpx;
  528. }
  529. }
  530. }
  531. }
  532. .comment-cont {
  533. height: calc(100vh - 250rpx);
  534. border-top: 4rpx solid #F4F4F4;
  535. position: relative;
  536. padding: 24rpx 0;
  537. overflow: hidden;
  538. .commment-top {
  539. display: flex;
  540. justify-content: space-between;
  541. align-items: center;
  542. padding: 0 24rpx;
  543. .title {
  544. font-weight: bold;
  545. font-size: 30rpx;
  546. color: #000;
  547. }
  548. .comment-top-right {
  549. display: flex;
  550. align-items: center;
  551. background-color: #F6F6F6;
  552. border: 1px solid #F6F6F6;
  553. color: #666;
  554. border-radius: 48rpx;
  555. text {
  556. padding: 0 12rpx;
  557. height: 48rpx;
  558. line-height: 48rpx;
  559. &.act {
  560. background-color: #FFFFFF;
  561. color: #000;
  562. border-radius: 48rpx;
  563. }
  564. }
  565. }
  566. }
  567. .comment-list-cont {
  568. height: calc(100vh - 550rpx);
  569. overflow-y: auto;
  570. position: relative;
  571. padding: 30rpx 24rpx 0;
  572. .comment-list-item {
  573. margin-bottom: 30rpx;
  574. .comment { color: #666; }
  575. .del { color: #D80000;margin-top: 10rpx;width: 200rpx; }
  576. }
  577. }
  578. .write-wrap {
  579. padding: 0 24rpx;
  580. border-top: 4rpx solid #F4F4F4;
  581. position: absolute;
  582. bottom: 100rpx;
  583. left: 0;
  584. right: 0;
  585. display: flex;
  586. align-items: center;
  587. z-index: 99;
  588. background-color: #fff;
  589. padding-bottom: calc(5px + constant(safe-area-inset-bottom));
  590. padding-bottom: calc(5px + env(safe-area-inset-bottom));
  591. ::-webkit-scrollbar {
  592. display: none;
  593. }
  594. .write-ipt {
  595. padding: 30rpx 0;
  596. flex: 1;
  597. }
  598. .confirm-btn {
  599. width: 100rpx;
  600. margin-left: 20rpx;
  601. text-align: center;
  602. padding: 20rpx 0;
  603. color: #E3B377;
  604. }
  605. }
  606. }
  607. .nodata {
  608. text-align: center;
  609. color: #999;
  610. }
  611. </style>