commentPopup.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view class="popup">
  3. <view class="popup-header">
  4. <text class="wk wk-close icon" @click="handleClose" />
  5. <text class="text">
  6. 全部{{ journalData.replyNum }}条评论
  7. </text>
  8. </view>
  9. <scroll-view scroll-y class="popup-container">
  10. <comment-list
  11. :show-icon="false"
  12. :reply-list="replyData"
  13. class="comment-list"
  14. @choose="handleChooseUser" />
  15. </scroll-view>
  16. <add-comment
  17. ref="comment"
  18. v-model="content"
  19. :replay="replayInfo"
  20. :immediate-focus="immediateFocus"
  21. @change-user="changeUser"
  22. @submit="submit" />
  23. </view>
  24. </template>
  25. <script>
  26. import { SetComment } from 'API/oa/comment'
  27. import CommentList from '@/components/base/comment-list.vue'
  28. import AddComment from '@/components/base/add-comment.vue'
  29. export default {
  30. name: 'CommentPopup',
  31. components: {
  32. CommentList,
  33. AddComment
  34. },
  35. props: {
  36. journalData: {
  37. type: Object,
  38. required: true
  39. },
  40. replyData: {
  41. type: Array,
  42. required: true
  43. }
  44. },
  45. data() {
  46. return {
  47. content: '',
  48. replayInfo: null,
  49. immediateFocus: false,
  50. }
  51. },
  52. methods: {
  53. handleChooseUser(user) {
  54. console.log('selected: ', user)
  55. if (this.replayInfo) {
  56. let str = `回复@${this.replayInfo.user.realname} `
  57. if (this.content.startsWith(str)) {
  58. this.content = this.content.replace(str, `回复@${user.user.realname} `)
  59. } else {
  60. this.content = `回复@${user.user.realname} ` + this.content
  61. }
  62. } else {
  63. this.content = `回复@${user.user.realname} ` + this.content
  64. }
  65. this.replayInfo = user
  66. this.$refs.comment.focus()
  67. },
  68. changeUser(data) {
  69. this.replayInfo = data
  70. },
  71. submit() {
  72. let params = {
  73. type: 2,
  74. typeId: this.journalData.logId,
  75. content: this.content
  76. }
  77. if (this.replayInfo) {
  78. params.pid = this.replayInfo.userId; // 被回复人的id
  79. params.mainId = this.replayInfo.mainId != 0 ? this.replayInfo.mainId : this.replayInfo.commentId; // 回复主id
  80. let str = `回复@${this.replayInfo.user.realname} `
  81. if (params.content.startsWith(str)) {
  82. params.content = params.content.replace(str, '')
  83. }
  84. }
  85. if (this.$isEmpty(params.content)) {
  86. this.$toast('回复内容不能为空')
  87. return
  88. }
  89. console.log('save: ', params)
  90. SetComment(params).then(() => {
  91. this.$toast('回复成功')
  92. this.content = ''
  93. this.replayInfo = null
  94. this.showEmoji = false
  95. this.$emit('update')
  96. }).catch()
  97. },
  98. handleClose() {
  99. this.$emit('close')
  100. }
  101. }
  102. }
  103. </script>
  104. <style scoped lang="scss">
  105. .popup {
  106. padding-top: 20rpx;
  107. padding-bottom: 112rpx;
  108. .popup-header {
  109. position: relative;
  110. padding: 0 36rpx;
  111. margin-bottom: 36rpx;
  112. @include center;
  113. .text {
  114. font-size: $wk-font-large;
  115. }
  116. .icon {
  117. position: absolute;
  118. left: 20rpx;
  119. top: 50%;
  120. transform: translateY(-50%);
  121. color: $gray;
  122. font-size: $wk-font-medium;
  123. padding: 20rpx;
  124. &.wk-arrow-right {
  125. transform: rotate(180deg) translateY(50%);
  126. transform-origin: center center;
  127. }
  128. }
  129. }
  130. .popup-container {
  131. min-height: 45vh;
  132. max-height: 65vh;
  133. padding: 0 36rpx 15rpx;
  134. overflow: auto;
  135. box-sizing: border-box;
  136. .comment-list {
  137. overflow: initial;
  138. }
  139. }
  140. }
  141. </style>