questionComment.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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="comment">
  8. {{data.comment_user_name}}:
  9. {{data.comment}}
  10. </view>
  11. </view>
  12. <!-- -->
  13. <view class="question-comment-wrapper">
  14. <view class="commetn-item-wrap" @click.stop="setLikeHandle(2)">
  15. <img :src="data.op_type===2?tease_act_img:tease_img" alt="" class="icon">
  16. <text v-if="data.tease_total">{{data.tease_total}}</text>
  17. </view>
  18. <view class="commetn-item-wrap" @click.stop="openCommentHandle" style="justify-content:center;">
  19. <img :src="comment_img" alt="" class="icon">
  20. <text v-if="data.comment_total">{{data.comment_total}}</text>
  21. </view>
  22. <view class="commetn-item-wrap" @click.stop="setLikeHandle(1)" style="justify-content:flex-end;">
  23. <img :src="data.op_type===1?like_act_img:like_img" alt="" class="icon">
  24. <text v-if="data.like_total">{{data.like_total}}</text>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import * as $api from '@/api/question.js'
  31. export default {
  32. props: {
  33. item: {
  34. type: Object,
  35. }
  36. },
  37. data() {
  38. return {
  39. data: this.item,
  40. tease_img: require('@/static/question/tease.png'),
  41. tease_act_img: require('@/static/question/tease_act.png'),
  42. like_img: require('@/static/question/like.png'),
  43. like_act_img: require('@/static/question/like_act.png'),
  44. comment_img: require('@/static/question/comment.png'),
  45. };
  46. },
  47. methods: {
  48. openCommentHandle() {
  49. this.$emit('show_comment',this.data)
  50. },
  51. /* 吐槽/点赞 */
  52. async setLikeHandle(type) {
  53. const { community_question_id } = this.data;
  54. const { data, code } = await $api.apiSetLike({
  55. op_type: type,
  56. community_question_id: community_question_id,
  57. enable: type === 1 ? Number(this.data.op_type!==1) : Number(this.data.op_type!==2)
  58. })
  59. if(code !== 200) return
  60. const { enabled,op_type,like_total,tease_total } = data;
  61. this.data.tease_total = tease_total;
  62. this.data.like_total = like_total;
  63. this.data.op_type = enabled === 0 ? 0 : op_type ;
  64. uni.showToast({
  65. title: enabled === 0 ? '取消成功' : op_type=== 1 ? '点赞成功' : '吐槽成功'
  66. })
  67. },
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .first-comment {
  73. background-color: #f4f4f4;
  74. padding: 10rpx;
  75. .comment {
  76. color: #666;
  77. display: flex;
  78. flex-wrap: wrap;
  79. .commenter {
  80. color: #000;
  81. }
  82. }
  83. }
  84. .question-comment-wrapper {
  85. color: #999;
  86. display: flex;
  87. justify-content: space-between;
  88. align-items: center;
  89. padding: 30rpx 40rpx;
  90. .commetn-item-wrap {
  91. display: flex;
  92. align-items: center;
  93. flex: 1;
  94. .icon {
  95. width: 48rpx;
  96. height: 48rpx;
  97. margin-right: 10rpx;
  98. }
  99. }
  100. }
  101. </style>