question.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <template>
  2. <view class="question-wrap" :style="isShowComment ? 'height: 100vh;overflow:hidden' : ''">
  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">
  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">精选</text>
  121. <text :class="select_comment_type === 2 && 'act'" @click="changeCommentTypeHandle">我的</text>
  122. </view>
  123. </view>
  124. <view class="comment-list-cont" v-if="comment_obj.total">
  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. </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. export default {
  175. mixins: [mixin],
  176. data() {
  177. return {
  178. questionList: [],
  179. isPopupShow: false,//弹出层是否展示
  180. optionList: [],
  181. activeNames: [],//collapse
  182. activeName:'',
  183. selectName:'',
  184. pauseImgSrc:'../../static/question/recordplay.png',
  185. playImgSrc:'../../static/question/recordpause.png',
  186. waitNum:0,
  187. isShowComment: false,
  188. comment_cont: '',
  189. select_comment_type:1,//默认精选
  190. select_question_item: {},
  191. comment_obj: {
  192. title: '精选评论',
  193. total: 0
  194. },
  195. comment_total: 0,
  196. commentList: []
  197. }
  198. },
  199. watch:{
  200. selectName(){
  201. this.getQuestionList(3)
  202. }
  203. },
  204. components:{
  205. questionComment
  206. },
  207. onLoad() {
  208. /* this.getVistor()
  209. this.getOptionList()
  210. this.getQuestionList(3) */
  211. },
  212. onShow() {
  213. this.getWaitNum()
  214. this.getOptionList()
  215. this.getQuestionList(3)
  216. },
  217. onReachBottom() {
  218. if(this.finished) return
  219. this.page++
  220. this.getQuestionList(3)
  221. },
  222. onPullDownRefresh() {
  223. this.resetAudio()
  224. this.refreshPage()
  225. setTimeout(() => {
  226. uni.stopPullDownRefresh()
  227. }, 1500);
  228. },
  229. methods: {
  230. //获取研究员问答列表数量统计
  231. getWaitNum() {
  232. if(this.userInfo.is_inner!==1) return
  233. //如果是研究员,则请求问答列表数量统计
  234. apiBarTotal().then(res=>{
  235. if(res.code===200){
  236. this.waitNum = res.data.wait
  237. }
  238. })
  239. },
  240. //获取筛选列表
  241. async getOptionList(){
  242. const res = await apiOptionGroupList()
  243. if(res.code===200){
  244. this.optionList = res.data
  245. }
  246. },
  247. //点击筛选
  248. showPopup() {
  249. this.isPopupShow = true
  250. },
  251. //点击一级分类
  252. changeSelecOption(e) {
  253. this.activeName = e.detail
  254. },
  255. //点击二级分类
  256. handleOptionClick(item){
  257. //重复点击代表取消
  258. if(this.selectId===item.research_group_id){
  259. this.selectId=-1
  260. this.selectName=''
  261. }else{
  262. this.selectId = item.research_group_id
  263. this.selectName = item.research_group_name
  264. }
  265. this.page = 1
  266. this.isPopupShow = false
  267. },
  268. //点击'我要提问' or '待回答'
  269. toPage() {
  270. //const {is_inner} = this.userInfo
  271. if (this.isUserResearcher) {
  272. uni.navigateTo({ url: '/pages-question/answerList' })
  273. } else {
  274. uni.navigateTo({ url: '/pages-question/hasQuestion' })
  275. }
  276. },
  277. //转发分享
  278. onShareAppMessage(){
  279. return{
  280. title:'问答社区',
  281. path:'/pages/question/question'
  282. }
  283. },
  284. refreshPage() {
  285. this.page = 1
  286. this.selectId = -1
  287. this.questionList = []
  288. this.finished = false
  289. this.getQuestionList(3)
  290. },
  291. /* 打开评论弹窗 */
  292. showCommentHandle(item) {
  293. this.select_question_item = item;
  294. this.getComment();
  295. this.isShowComment = true;
  296. },
  297. /* 关闭评论弹窗 */
  298. closeCommentHandle() {
  299. this.isShowComment = false;
  300. this.select_question_item = {};
  301. this.comment_cont = '';
  302. this.select_comment_type = 1;//默认精选
  303. },
  304. /* 切换评论类型*/
  305. changeCommentTypeHandle() {
  306. this.select_comment_type = this.select_comment_type === 1 ? 2 : 1;
  307. this.getComment();
  308. },
  309. /* 获取评论 */
  310. async getComment() {
  311. const params = {
  312. community_question_id: this.select_question_item.community_question_id,
  313. curr_page: 1,
  314. page_size: 10000
  315. }
  316. const { code,data } = this.select_comment_type===1 ? await apiHotComment(params) : await apiMyComment(params);
  317. if(code !== 200) return
  318. this.commentList = data.list || [];
  319. this.comment_obj = {
  320. title: this.select_comment_type === 1 ? '精选评论' : '我的评论',
  321. total: data.paging.totals
  322. }
  323. },
  324. /* 删除留言*/
  325. delCommentHandle({community_question_comment_id},index) {
  326. wx.showModal({
  327. title: "",
  328. content: "评论删除后不可恢复,确认删除吗?",
  329. confirmColor: "#EE3636",
  330. cancelColor: '#333',
  331. success: async(res) => {
  332. // res.cancel && return
  333. if( res.cancel) return
  334. const { code } = await apiDelComment({ community_question_comment_id });
  335. if( code !== 200 ) return
  336. this.commentList.splice(index,1)
  337. wx.showToast({title: '删除成功'});
  338. }
  339. })
  340. },
  341. /* 校验昵称状态*/
  342. async checkNickHandle() {
  343. const { data,code } = await apiCheckNick();
  344. if(code !== 200) return
  345. !data && wx.showModal({
  346. title: '',
  347. content: '检测到您还未设置头像和昵称,您的留言将发布为匿名,是否立即去设置?',
  348. confirmText: '去设置',
  349. confirmColor: '#E3B377',
  350. cancelText : '暂时不用',
  351. cancelColor: '#666',
  352. success: (res)=> {
  353. res.confirm && wx.navigateTo({ url:'/pages-user/mysetting' });
  354. res.cancel && this.setCancelNickHandle();
  355. }
  356. })
  357. },
  358. /* 不在提醒弹窗 */
  359. async setCancelNickHandle() {
  360. await apiCanelNickTip()
  361. },
  362. /* 发布留言*/
  363. async publishMessageHandle() {
  364. const { code } = await apiPublishComment({
  365. content: this.comment_cont,
  366. community_question_id: this.select_question_item.community_question_id
  367. })
  368. if(code !== 200) return
  369. wx.showToast({title: '发布成功'});
  370. this.comment_cont = '';
  371. this.select_comment_type === 2 && this.getComment();
  372. }
  373. }
  374. }
  375. </script>
  376. <style lang="scss">
  377. .question-wrap {
  378. .van-popup--bottom{
  379. padding-bottom: 0 !important;
  380. }
  381. /deep/ .van-cell__title,
  382. .van-cell__value {
  383. flex: none !important;
  384. }
  385. .van-collapse-item{
  386. &.van-hairline--top{
  387. &::after{
  388. border: none !important;
  389. }
  390. }
  391. .van-cell{
  392. padding-left:0 !important;
  393. }
  394. }
  395. .van-collapse-item__content{
  396. padding:0;
  397. }
  398. }
  399. page {
  400. padding-bottom: env(safe-area-inset-bottom);
  401. }
  402. </style>
  403. <style lang="scss" scoped>
  404. .question-wrap {
  405. padding: 0 30rpx 80rpx 30rpx;
  406. background-color: #FFFFFF;
  407. .question-top {
  408. display: flex;
  409. flex: auto;
  410. align-items: center;
  411. height: 100rpx;
  412. background-color: white;
  413. position: sticky;
  414. top: 0;
  415. left: 0;
  416. margin:0 -30rpx;
  417. z-index: 99;
  418. &.noAuth{
  419. height:20rpx;
  420. }
  421. /* border-top: 1rpx solid rgba(0, 0, 0, 0.1); */
  422. .text{
  423. width:240rpx;
  424. height:70rpx;
  425. line-height: 70rpx;
  426. background-color: #F5F5F5;
  427. border-radius: 4rpx;
  428. color:#666666;
  429. text-align: center;
  430. &.active{
  431. color:#E3B377;
  432. background-color: #FDF8F2;
  433. }
  434. }
  435. .auth-box {
  436. flex: 1;
  437. }
  438. .menu-icon {
  439. width: 34rpx;
  440. height:34rpx;
  441. }
  442. .pop-wrap{
  443. height: 100%;
  444. padding: 50rpx 34rpx;
  445. .pop-option-list {
  446. .option-btn-wrap {
  447. display: flex;
  448. justify-content: space-between;
  449. flex-wrap: wrap;
  450. margin-bottom: 20rpx;
  451. .option-btn {
  452. min-width: 145rpx;
  453. height:76rpx;
  454. line-height: 76rpx;
  455. text-align: center;
  456. color: black;
  457. background-color: #F6F6F6;
  458. border-radius: 4rpx;
  459. margin-top: 10rpx;
  460. &.active{
  461. background-color: #FAEEDE;
  462. }
  463. &.full{
  464. width:100%;
  465. }
  466. }
  467. }
  468. }
  469. .pop-btn{
  470. height:80rpx;
  471. margin:0 -34rpx;
  472. text-align: center;
  473. line-height: 80rpx;
  474. color:#FFFFFF;
  475. background-color: #E6B77D;
  476. }
  477. }
  478. }
  479. .question-list {
  480. padding-bottom: 34rpx;
  481. &.last{
  482. padding-bottom: 260rpx;
  483. }
  484. }
  485. .topage-btn {
  486. position: fixed;
  487. left:50%;
  488. margin-left: -257rpx;
  489. bottom: 215rpx;
  490. width:514rpx;
  491. height: 80rpx;
  492. text-align: center;
  493. line-height: 80rpx;
  494. border-radius: 40rpx;
  495. background-color: #333333;
  496. box-shadow: 0px 4px 20px 1px rgba(160, 126, 84, 0.25);
  497. color: #E3B377;
  498. display: flex;
  499. justify-content: center;
  500. align-items: center;
  501. image{
  502. margin-right: 10rpx;
  503. margin-top: -2rpx;
  504. }
  505. }
  506. .global-pup{
  507. .content{
  508. padding:90rpx 34rpx;
  509. flex-direction: column;
  510. .contact{
  511. text{
  512. margin-left: 15rpx;
  513. color:#E6B77D;
  514. }
  515. }
  516. .apply{
  517. margin-top: 40rpx;
  518. width:390rpx;
  519. height:80rpx;
  520. background-color: #E6B77D;
  521. color: #FFFFFF;
  522. text-align: center;
  523. line-height: 80rpx;
  524. border-radius: 40rpx;
  525. }
  526. }
  527. }
  528. }
  529. .comment-cont {
  530. height: calc(100vh - 250rpx);
  531. border-top: 4rpx solid #F4F4F4;
  532. position: relative;
  533. padding: 24rpx 0;
  534. overflow: hidden;
  535. .commment-top {
  536. display: flex;
  537. justify-content: space-between;
  538. align-items: center;
  539. padding: 0 24rpx;
  540. .title {
  541. font-weight: bold;
  542. font-size: 30rpx;
  543. color: #000;
  544. }
  545. .comment-top-right {
  546. display: flex;
  547. align-items: center;
  548. background-color: #F6F6F6;
  549. border: 1px solid #F6F6F6;
  550. color: #666;
  551. border-radius: 48rpx;
  552. text {
  553. padding: 0 12rpx;
  554. height: 48rpx;
  555. line-height: 48rpx;
  556. &.act {
  557. background-color: #FFFFFF;
  558. color: #000;
  559. border-radius: 48rpx;
  560. }
  561. }
  562. }
  563. }
  564. .comment-list-cont {
  565. height: calc(100vh - 550rpx);
  566. overflow-y: auto;
  567. position: relative;
  568. padding: 0 24rpx;
  569. .comment-list-item {
  570. margin: 30rpx 0;
  571. .comment { color: #666; }
  572. .del { color: #D80000;margin-top: 10rpx; }
  573. }
  574. }
  575. .write-wrap {
  576. padding: 0 24rpx;
  577. border-top: 4rpx solid #F4F4F4;
  578. position: absolute;
  579. bottom: 100rpx;
  580. left: 0;
  581. right: 0;
  582. display: flex;
  583. align-items: center;
  584. z-index: 99;
  585. background-color: #fff;
  586. ::-webkit-scrollbar {
  587. display: none;
  588. }
  589. .write-ipt {
  590. padding: 30rpx 0;
  591. flex: 1;
  592. }
  593. .confirm-btn {
  594. width: 100rpx;
  595. margin-left: 20rpx;
  596. text-align: center;
  597. padding: 20rpx 0;
  598. color: #E3B377;
  599. }
  600. }
  601. }
  602. .nodata {
  603. text-align: center;
  604. color: #999;
  605. }
  606. </style>