commentList.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="comment">
  3. <view class="comment-avatar-info" v-for="(item, index) in commentList" :key="index">
  4. <image class="comment-avatar" :src="$isEmpty(item.avatar)?defHeadImg:item.avatar" mode="aspectFill"></image>
  5. <view class="comment-box">
  6. <view class="comment-people">
  7. <view class="comment-people-name">{{item.nickName}}</view>
  8. <view class="comment-time">{{ $isEmpty(item.createTime)?"":$formatDate(item.createTime) }}</view>
  9. </view>
  10. <view class="comment-text">{{item.content}}</view>
  11. <view class="comment-footer" >
  12. <view class="comment-footer-l">
  13. <view class="comment-footer-dianzan" @tap="doLike(item)">
  14. <image :src="(item.isLike!=undefined && item.isLike==true)?'/static/image/hall/dianzan_on_icon.png':'/static/image/hall/dianzan_icon.png'"></image>
  15. <text>{{item.likes || '点赞'}}</text>
  16. </view>
  17. <view class="comment-footer-pingjia">
  18. <image src="/static/image/hall/pingjia_icon.png"></image>
  19. <text>{{item.replyCount || '回复'}}</text>
  20. </view>
  21. </view>
  22. <image class="more-icon" v-if="isMySend(item)" @tap="delComment(item)" src="@/static/image/hall/more_icon16.png"></image>
  23. </view>
  24. <!-- 子评论 -->
  25. <view class="comment-avatar-info" style="padding-top: 24rpx;" v-for="(reply,idx) in item.commentReplys" :key="idx">
  26. <image class="comment-avatar" src="@/static/image/hall/my_heads_icon.png" mode="aspectFill"></image>
  27. <view class="comment-box">
  28. <view class="comment-people">
  29. <view class="comment-people-name">
  30. <text>{{reply.replyInfo.userName}}</text>
  31. <text class="reply" v-if="reply.parentReply.itemId != 0">回复</text>
  32. <text v-if="reply.parentReply.itemId != 0">{{reply.parentReply.userName}}</text>
  33. </view>
  34. <view class="comment-time">{{reply.replyInfo.ctime}}</view>
  35. </view>
  36. <view class="comment-text">{{reply.replyInfo.content}}</view>
  37. </view>
  38. </view>
  39. <view class="comment-morereply" v-if="item.replyCount > 2">
  40. <text>查看全部{{item.replyCount}}条回复</text>
  41. <image src="@/static/image/hall/reply_more_icon.png"></image>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import { addComment,commentDoLike,deleteComment } from '@/api/course'
  49. export default {
  50. name: "commentList",
  51. props: {
  52. commentList: {
  53. type: Array,
  54. default:function(){
  55. return [ ];
  56. }
  57. }
  58. },
  59. data() {
  60. return {
  61. defHeadImg:"@/static/image/hall/my_heads_icon.png",
  62. delCommentId:null,
  63. isLastPage:false,
  64. myUserInfo:{userId:0},
  65. };
  66. },
  67. mounted() {
  68. if(!this.$isLogin()){
  69. let useInfo=uni.getStorageSync('userInfo');
  70. if(!!useInfo && useInfo!=null){
  71. this.myUserInfo=JSON.parse(useInfo);
  72. }
  73. }
  74. },
  75. methods: {
  76. doLike(item){
  77. if(!this.$isLogin()){
  78. this.$showLoginPage();
  79. return;
  80. }
  81. const params={"commentId":item.commentId};
  82. uni.showLoading({title:""});
  83. commentDoLike(params).then(res => {
  84. uni.hideLoading();
  85. if(res.code==200){
  86. if(!!item.isLike){
  87. item.likes-=1;
  88. }
  89. else{
  90. item.likes+=1;
  91. }
  92. item.isLike=!item.isLike;
  93. uni.showToast({title: '操作成功',icon: 'none'});
  94. }else{
  95. uni.showToast({title: res.msg,icon: 'none'});
  96. }
  97. //this.refreshPage();
  98. },
  99. rej => {}
  100. );
  101. },
  102. delComment(item){
  103. if(!this.$isLogin()){
  104. this.$showLoginPage();
  105. return;
  106. }
  107. let that = this;
  108. uni.showModal({
  109. title: '系统提示',
  110. content: '确定删除吗',
  111. success: function (res) {
  112. if (res.confirm) {
  113. console.log("qxj confirm");
  114. that.delCommentAct(item,type);
  115. } else if (res.cancel) {
  116. }
  117. }
  118. });
  119. },
  120. delCommentAct(item,type){
  121. this.delCommentId=item.commentId;
  122. let params={"commentId":this.delCommentId};
  123. if(type==1){
  124. params["parentId"]=item.parentId;
  125. }
  126. this.delCommentRequest(params);
  127. },
  128. delCommentRequest(params){
  129. let that=this;
  130. uni.showLoading({title:""});
  131. deleteComment(params).then(res => {
  132. uni.hideLoading();
  133. if(res.code==200){
  134. uni.showToast({title: '操作成功',icon: 'none'});
  135. this.sendNotify(this.totalNum-1);
  136. setTimeout(function(){
  137. that.refreshPage();
  138. },1000)
  139. }else{
  140. uni.showToast({title: res.msg,icon: 'none'});
  141. }
  142. },
  143. rej => {}
  144. );
  145. },
  146. isMySend(item){
  147. if(this.myUserInfo!=null && this.myUserInfo.userId==item.userId){
  148. return true;
  149. }
  150. return false;
  151. },
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. @mixin u-flex($flexD, $alignI, $justifyC) {
  157. display: flex;
  158. flex-direction: $flexD;
  159. align-items: $alignI;
  160. justify-content: $justifyC;
  161. }
  162. .comment {
  163. font-family: PingFang SC, PingFang SC;
  164. font-size: 28rpx;
  165. font-weight: 400;
  166. color: #222222;
  167. &-avatar-info {
  168. // @include u-flex(row, flex-start, flex-start);
  169. display: flex;
  170. flex:1;
  171. flex-direction: row;
  172. }
  173. &-avatar {
  174. flex-shrink: 0;
  175. width: 72rpx;
  176. height: 72rpx;
  177. border-radius: 50%;
  178. overflow: hidden;
  179. margin-right: 20rpx;
  180. }
  181. &-box {
  182. display: flex;
  183. flex:1;
  184. flex-direction: column;
  185. }
  186. &-people-name {
  187. @include u-flex(row, center, flex-start);
  188. font-weight: 600;
  189. margin-bottom: 4rpx;
  190. }
  191. .reply {
  192. font-weight: 500;
  193. font-size: 28rpx;
  194. color: #999999;
  195. margin: 0 12rpx;
  196. }
  197. &-time {
  198. font-size: 22rpx;
  199. color: #999999;
  200. }
  201. &-text {
  202. padding: 20rpx 0 38rpx;
  203. line-height: 38rpx;
  204. word-break:break-all;
  205. }
  206. &-footer {
  207. margin-bottom: 24rpx;
  208. @include u-flex(row, center, space-between);
  209. font-size: 24rpx;
  210. color: #757575;
  211. image {
  212. width: 32rpx;
  213. height: 32rpx;
  214. }
  215. &-l {
  216. @include u-flex(row, center, flex-start);
  217. view {
  218. @include u-flex(row, center, flex-start);
  219. margin-right: 28rpx;
  220. image {
  221. margin-right: 8rpx;
  222. }
  223. }
  224. }
  225. }
  226. &-morereply {
  227. padding-bottom: 24rpx;
  228. font-size: 24rpx;
  229. color: #999999;
  230. @include u-flex(row, center, flex-start);
  231. image {
  232. width: 24rpx;
  233. height: 24rpx;
  234. }
  235. }
  236. }
  237. </style>