comment.vue 11 KB

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