questionComment.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!-- 问答评论区 -->
  2. <template>
  3. <view class="question-comment-box">
  4. <!-- 第一条评论 -->
  5. <view class="first-comment" v-if="data.comment">
  6. <!-- <img :src="comment_img" alt="" class="icon"> -->
  7. <view class="flex comment">
  8. <image class="avatar" :src="data.qa_avatar_url" mode="aspectFill" lazy-load="true"/>
  9. <view>{{data.comment}}</view>
  10. <!-- {{data.comment_user_name}}:
  11. {{data.comment}} -->
  12. </view>
  13. </view>
  14. <!-- -->
  15. <view class="question-comment-wrapper">
  16. <view class="commetn-item-wrap" @click="setLikeHandle(2)">
  17. <img :src="data.op_type===2?tease_act_img:tease_img" alt="" class="icon">
  18. <text v-if="data.tease_total">{{data.tease_total}}</text>
  19. </view>
  20. <view class="commetn-item-wrap" @click="openCommentHandle" style="justify-content:center;">
  21. <img :src="comment_img" alt="" class="icon">
  22. <text v-if="data.comment_total">{{data.comment_total}}</text>
  23. </view>
  24. <view class="commetn-item-wrap" @click="setLikeHandle(1)" style="justify-content:flex-end;">
  25. <img :src="data.op_type===1?like_act_img:like_img" alt="" class="icon">
  26. <text v-if="data.like_total">{{data.like_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. display: flex;
  80. flex-wrap: wrap;
  81. .commenter {
  82. color: #000;
  83. }
  84. .avatar{
  85. width: 56rpx;
  86. height: 56rpx;
  87. margin-right: 20rpx;
  88. flex-shrink: 0;
  89. }
  90. view{
  91. flex: 1;
  92. position: relative;
  93. }
  94. }
  95. }
  96. .question-comment-wrapper {
  97. color: #999;
  98. display: flex;
  99. justify-content: space-between;
  100. align-items: center;
  101. padding: 30rpx 40rpx;
  102. .commetn-item-wrap {
  103. display: flex;
  104. align-items: center;
  105. flex: 1;
  106. .icon {
  107. width: 48rpx;
  108. height: 48rpx;
  109. margin-right: 10rpx;
  110. }
  111. }
  112. }
  113. </style>