comment.vue 11 KB

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