comment.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view class="video-comment-wrap">
  3. <view :class="['flex action-wrap',showDanmu?'showDanmu':'']">
  4. <view class="item" @click="handleSetLike(1)">
  5. <image :src="info.op_type===1?like_act_img:like_img" mode="aspectFill"/>
  6. <text>{{info.like_total>0?info.like_total:''}}</text>
  7. </view>
  8. <view class="item" @click="handleSetLike(2)" style="text-align:center">
  9. <image :src="info.op_type===2?tease_act_img:tease_img" mode="aspectFill"/>
  10. <text>{{info.tease_total>0?info.tease_total:''}}</text>
  11. </view>
  12. <view class="item" @click="showComment" style="text-align:right">
  13. <image :src="comment_img" mode="aspectFill"/>
  14. <text>{{info.comment_total>0?info.comment_total:''}}</text>
  15. </view>
  16. <view class="item" v-if="info.report_id" @click="goReport" style="text-align:right" >
  17. <image :src="report_img" mode="aspectFill"/>
  18. </view>
  19. </view>
  20. <view class="list-commnet-box" v-if="info.comment_list.length>0">
  21. <template class="item" v-for="(item,index) in info.comment_list" >
  22. <image class="avatar" :src="item.qa_avatar_url" mode="aspectFill" lazy-load="false" :key="index"/>
  23. <text :key="index">{{item.comment}}</text>
  24. </template>
  25. </view>
  26. <!-- 评论弹窗 -->
  27. <van-action-sheet
  28. :show="isShowComment"
  29. title="视频评论"
  30. @close="closeCommentHandle"
  31. @clickOverlay="isShowComment=false"
  32. z-index="99999"
  33. >
  34. <view class="comment-cont" @touchmove.stop>
  35. <view class="commment-top">
  36. <text class="title">{{comment_obj.title}} {{comment_obj.total}}</text>
  37. <view class="comment-top-right">
  38. <text :class="select_comment_type === 1 && 'act'" @click="changeCommentTypeHandle(1)">全部</text>
  39. <text :class="select_comment_type === 2 && 'act'" @click="changeCommentTypeHandle(2)">我的</text>
  40. </view>
  41. </view>
  42. <scroll-view class="comment-list-cont" v-if="comment_obj.total" scroll-y>
  43. <view class="comment-list-item" v-for="(item,index) in commentList" :key="item.community_question_comment_id">
  44. <view class="flex comment">
  45. <image class="avatar" :src="item.qa_avatar_url" mode="aspectFill" lazy-load="true"/>
  46. <view style="display:flex;align-items:center">{{item.content}}</view>
  47. </view>
  48. <view class="del" v-if="select_comment_type === 2" @click="delCommentHandle(item,index)">删除该评论</view>
  49. </view>
  50. </scroll-view>
  51. <view class="nodata" v-else>
  52. <image src="@/static/nodata.png"></image>
  53. <view>暂无评论</view>
  54. </view>
  55. <view class="write-wrap" :style="{bottom: writeBottom+'px'}">
  56. <textarea
  57. v-model="comment_cont"
  58. placeholder="发布一条友善的评论"
  59. auto-height
  60. :adjust-position="false"
  61. :show-confirm-bar="false"
  62. :cursor-spacing="20"
  63. class="write-ipt"
  64. @blur="setWritePosition(0)"
  65. @focus="checkNickHandle"
  66. />
  67. <view class="confirm-btn" @click="publishMessageHandle">发布</view>
  68. </view>
  69. </view>
  70. </van-action-sheet>
  71. </view>
  72. </template>
  73. <script>
  74. import {apiSetLike,apiHotComment,apiMyComment,apiPublishComment,apiDelComment} from '@/api/question'
  75. export default {
  76. props:{
  77. showDanmu:{
  78. type:Boolean,
  79. default:false
  80. },
  81. videoInfo:null,//{source:2-视频社区\3-路演视频,id:视频社区id\路演视频id,...其他数据}
  82. },
  83. data() {
  84. return {
  85. info:this.videoInfo,
  86. tease_img: require('@/static/question/tease.png'),
  87. tease_act_img: require('@/static/question/tease_act.png'),
  88. like_img: require('@/static/question/like.png'),
  89. like_act_img: require('@/static/question/like_act.png'),
  90. comment_img: require('@/static/question/comment.png'),
  91. report_img:require('@/static/report-btn.png'),
  92. isShowComment: false,
  93. comment_cont: '',
  94. writeBottom: 0,
  95. select_comment_type:1,//默认全部
  96. comment_obj: {
  97. title: '全部评论',
  98. total: 0
  99. },
  100. comment_total: 0,
  101. commentList: []
  102. }
  103. },
  104. methods: {
  105. /* 关闭评论弹窗 */
  106. closeCommentHandle() {
  107. this.isShowComment = false;
  108. this.comment_cont = '';
  109. this.select_comment_type = 1;//默认全部
  110. },
  111. /* 切换评论类型*/
  112. changeCommentTypeHandle(type) {
  113. if(type === this.select_comment_type) return
  114. this.commentList = [];
  115. this.select_comment_type = type;
  116. this.getComment();
  117. },
  118. showComment(){
  119. this.getComment()
  120. this.isShowComment=true
  121. },
  122. // 获取评论
  123. async getComment(flag){
  124. const params={
  125. community_question_id:this.info.id,
  126. curr_page: 1,
  127. page_size: 10000,
  128. source:this.info.source
  129. }
  130. const { code,data } = this.select_comment_type===1 ? await apiHotComment(params) : await apiMyComment(params);
  131. if(code !== 200) return
  132. this.commentList = data.list || [];
  133. this.comment_obj = {
  134. title: this.select_comment_type === 1 ? '全部评论' : '我的评论',
  135. total: data.paging.totals
  136. }
  137. // 如果flag='refresh' 则获取一次全部留言 更新到列表上面去
  138. if(flag==='refresh'){
  139. const res=await apiHotComment(params)
  140. const arr=res.data.list||[]
  141. this.info.comment_list=arr.map(item=>{
  142. return {
  143. comment:item.content,
  144. qa_avatar_url:item.qa_avatar_url
  145. }
  146. })
  147. this.info.comment_total=arr.length
  148. }
  149. },
  150. //删除我的评论
  151. delCommentHandle({community_question_comment_id},index){
  152. wx.showModal({
  153. title: "",
  154. content: "评论删除后不可恢复,确认删除吗?",
  155. confirmColor: "#EE3636",
  156. cancelColor: '#333',
  157. success: async(res) => {
  158. if( res.cancel) return
  159. const { code } = await apiDelComment({ community_question_comment_id });
  160. if( code !== 200 ) return
  161. this.commentList.splice(index,1)
  162. this.comment_obj.total--
  163. wx.showToast({title: '删除成功'});
  164. this.getComment('refresh')
  165. }
  166. })
  167. },
  168. setWritePosition(val=50) {
  169. console.log(val)
  170. this.writeBottom = val < 50 ? 0 : val-8;
  171. },
  172. checkNickHandle(e){
  173. this.setWritePosition(e.detail.height);
  174. },
  175. //发布留言
  176. async publishMessageHandle(){
  177. if(!this.comment_cont) return wx.showToast({title: '请输入留言内容',icon: 'none'})
  178. const { code } = await apiPublishComment({
  179. content: this.comment_cont,
  180. community_question_id: this.info.id,
  181. source:this.info.source,
  182. })
  183. if(code===200){
  184. wx.showToast({title: '发布成功'});
  185. this.comment_cont = '';
  186. this.getComment('refresh')
  187. }
  188. },
  189. //吐槽/点赞
  190. async handleSetLike(type){
  191. const res=await apiSetLike({
  192. community_question_id:this.info.id,
  193. op_type: type,
  194. enable: type === 1 ? Number(this.info.op_type!==1) : Number(this.info.op_type!==2),
  195. source:this.info.source
  196. })
  197. if(res.code===200){
  198. const { enabled,op_type,like_total,tease_total } = res.data;
  199. this.info.tease_total = tease_total;
  200. this.info.like_total = like_total;
  201. this.info.op_type = enabled === 0 ? 0 : op_type ;
  202. uni.showToast({
  203. title: enabled === 0 ? '取消成功' : op_type=== 1 ? '点赞成功' : '吐槽成功'
  204. })
  205. }
  206. },
  207. //跳转至报告详情
  208. goReport(){
  209. if(this.videoInfo.fromPage==='report'){
  210. uni.navigateBack()
  211. }else{
  212. uni.navigateTo({url: `/pages-report/reportDetail?reportId=${this.videoInfo.report_id}&fromPage=video`})
  213. }
  214. //uni.navigateTo({url:'/pages-report/reportDetail?reportId='+item.report_id})
  215. }
  216. },
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .video-comment-wrap{
  221. .action-wrap{
  222. justify-content: space-between;
  223. padding: 0 56rpx;
  224. .item{
  225. min-width: 80rpx;
  226. image{
  227. width: 48rpx;
  228. height: 48rpx;
  229. vertical-align: middle;
  230. }
  231. text{
  232. font-size: 28rpx;
  233. color: #999;
  234. vertical-align: middle;
  235. }
  236. }
  237. }
  238. .showDanmu{
  239. width: 50%;
  240. padding: 0;
  241. }
  242. }
  243. .list-commnet-box{
  244. margin-top: 34rpx;
  245. background-color: #F9F9F9;
  246. padding: 20rpx;
  247. // .item{
  248. color: #666;
  249. font-size: 28rpx;
  250. .avatar{
  251. width: 56rpx;
  252. height: 56rpx;
  253. border-radius: 50%;
  254. margin-right: 14rpx;
  255. vertical-align: middle;
  256. }
  257. text{
  258. vertical-align: middle;
  259. line-height: 56rpx;
  260. margin-right: 20rpx;
  261. }
  262. // }
  263. }
  264. .comment-cont {
  265. height: calc(100vh - 250rpx);
  266. border-top: 4rpx solid #F4F4F4;
  267. position: relative;
  268. padding: 24rpx 0;
  269. overflow: hidden;
  270. .commment-top {
  271. display: flex;
  272. justify-content: space-between;
  273. align-items: center;
  274. padding: 0 24rpx;
  275. .title {
  276. font-weight: bold;
  277. font-size: 30rpx;
  278. color: #000;
  279. }
  280. .comment-top-right {
  281. display: flex;
  282. align-items: center;
  283. background-color: #F6F6F6;
  284. border: 1px solid #F6F6F6;
  285. color: #666;
  286. border-radius: 48rpx;
  287. text {
  288. padding: 0 12rpx;
  289. height: 48rpx;
  290. line-height: 48rpx;
  291. &.act {
  292. background-color: #FFFFFF;
  293. color: #000;
  294. border-radius: 48rpx;
  295. }
  296. }
  297. }
  298. }
  299. .comment-list-cont {
  300. height: calc(100vh - 550rpx);
  301. overflow-y: auto;
  302. position: relative;
  303. padding: 30rpx 0;
  304. .comment-list-item {
  305. margin-bottom: 30rpx;
  306. padding: 0 24rpx;
  307. .comment {
  308. color: #666;
  309. .avatar{
  310. width: 56rpx;
  311. height: 56rpx;
  312. border-radius: 50%;
  313. flex-shrink: 0;
  314. margin-right: 20rpx;
  315. }
  316. view{
  317. flex: 1;
  318. }
  319. }
  320. .del {
  321. color: #D80000;
  322. margin-top: 10rpx;
  323. margin-left: 76rpx;
  324. width: 200rpx;
  325. }
  326. }
  327. }
  328. .write-wrap {
  329. padding: 0 24rpx;
  330. border-top: 4rpx solid #F4F4F4;
  331. position: absolute;
  332. // bottom: 50px;
  333. left: 0;
  334. right: 0;
  335. display: flex;
  336. align-items: center;
  337. z-index: 99;
  338. background-color: #fff;
  339. padding-bottom: calc(5px + constant(safe-area-inset-bottom));
  340. padding-bottom: calc(5px + env(safe-area-inset-bottom));
  341. ::-webkit-scrollbar {
  342. display: none;
  343. }
  344. .write-ipt {
  345. padding: 30rpx 0;
  346. flex: 1;
  347. }
  348. .confirm-btn {
  349. width: 100rpx;
  350. margin-left: 20rpx;
  351. text-align: center;
  352. padding: 20rpx 0;
  353. color: #E3B377;
  354. }
  355. }
  356. }
  357. .nodata {
  358. text-align: center;
  359. color: #999;
  360. }
  361. </style>