questionComment.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <!-- 问答评论区 -->
  2. <template>
  3. <view class="question-comment-box">
  4. <!-- 第一条评论 -->
  5. <view class="first-comment" v-if="data.comment_list.length>0">
  6. <!-- <img :src="comment_img" alt="" class="icon"> -->
  7. <view class="comment">
  8. <template v-for="(item,index) in data.comment_list">
  9. <image class="avatar" :src="item.qa_avatar_url" mode="aspectFill" lazy-load="false" :key="index"/>
  10. <text :key="index">{{item.comment}}</text>
  11. </template>
  12. </view>
  13. </view>
  14. <!-- -->
  15. <view class="question-comment-wrapper">
  16. <view class="commetn-item-wrap" @click.stop="setLikeHandle(1)">
  17. <img :src="data.op_type===1?like_act_img:like_img" alt="" class="icon">
  18. <text v-if="data.like_total">{{data.like_total}}</text>
  19. </view>
  20. <view class="commetn-item-wrap" @click.stop="setLikeHandle(2)" style="justify-content:center;">
  21. <img :src="data.op_type===2?tease_act_img:tease_img" alt="" class="icon">
  22. <text v-if="data.tease_total">{{data.tease_total}}</text>
  23. </view>
  24. <view class="commetn-item-wrap" @click.stop="openCommentHandle" style="justify-content:flex-end;">
  25. <img :src="comment_img" alt="" class="icon">
  26. <text v-if="data.comment_total">{{data.comment_total}}</text>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import * as $api from '@/api/question.js'
  33. export default {
  34. props: {
  35. item: {
  36. type: Object,
  37. }
  38. },
  39. data() {
  40. return {
  41. data: this.item,
  42. tease_img: require('@/static/question/tease.png'),
  43. tease_act_img: require('@/static/question/tease_act.png'),
  44. like_img: require('@/static/question/like.png'),
  45. like_act_img: require('@/static/question/like_act.png'),
  46. comment_img: require('@/static/question/comment.png'),
  47. };
  48. },
  49. methods: {
  50. openCommentHandle() {
  51. this.$emit('show_comment',this.data)
  52. },
  53. /* 吐槽/点赞 */
  54. async setLikeHandle(type) {
  55. const { community_question_id } = this.data;
  56. const { data, code } = await $api.apiSetLike({
  57. op_type: type,
  58. community_question_id: community_question_id,
  59. enable: type === 1 ? Number(this.data.op_type!==1) : Number(this.data.op_type!==2)
  60. })
  61. if(code !== 200) return
  62. const { enabled,op_type,like_total,tease_total } = data;
  63. this.data.tease_total = tease_total;
  64. this.data.like_total = like_total;
  65. this.data.op_type = enabled === 0 ? 0 : op_type ;
  66. uni.showToast({
  67. title: enabled === 0 ? '取消成功' : op_type=== 1 ? '点赞成功' : '吐槽成功'
  68. })
  69. },
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .first-comment {
  75. background-color: #f4f4f4;
  76. padding: 10rpx;
  77. .comment {
  78. color: #666;
  79. font-size: 28rpx;
  80. .avatar{
  81. width: 56rpx;
  82. height: 56rpx;
  83. border-radius: 50%;
  84. margin-right: 14rpx;
  85. vertical-align: middle;
  86. }
  87. text{
  88. vertical-align: middle;
  89. line-height: 56rpx;
  90. margin-right: 20rpx;
  91. }
  92. // display: flex;
  93. // flex-wrap: wrap;
  94. // .commenter {
  95. // color: #000;
  96. // }
  97. // .avatar{
  98. // width: 56rpx;
  99. // height: 56rpx;
  100. // margin-right: 20rpx;
  101. // flex-shrink: 0;
  102. // border-radius: 50%;
  103. // }
  104. // view{
  105. // flex: 1;
  106. // position: relative;
  107. // }
  108. }
  109. }
  110. .question-comment-wrapper {
  111. color: #999;
  112. display: flex;
  113. justify-content: space-between;
  114. align-items: center;
  115. padding: 30rpx 40rpx;
  116. .commetn-item-wrap {
  117. display: flex;
  118. align-items: center;
  119. flex: 1;
  120. .icon {
  121. width: 48rpx;
  122. height: 48rpx;
  123. margin-right: 10rpx;
  124. }
  125. }
  126. }
  127. </style>