flowCommentPopup.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. 全部{{ commentNum }}条评论
  7. </text>
  8. </view>
  9. <scroll-view scroll-y class="popup-container">
  10. <comment-list
  11. :show-icon="false"
  12. :reply-list="commandData"
  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 {
  27. QueryCommentListAPI,
  28. SetCommentAPI
  29. } from '@/api/crm/flow.js'
  30. import AddComment from '@/components/base/add-comment.vue'
  31. import CommentList from '@/components/base/comment-list.vue'
  32. export default {
  33. name: 'CustomCommentPopup',
  34. components: {
  35. AddComment,
  36. CommentList
  37. },
  38. props: {
  39. dataId: {
  40. type: [String, Number],
  41. required: true
  42. },
  43. commentNum: {
  44. type: Number,
  45. default: 0
  46. }
  47. },
  48. data() {
  49. return {
  50. commandData: [],
  51. content: '',
  52. replayInfo: null,
  53. immediateFocus: false
  54. }
  55. },
  56. mounted() {
  57. this.getCommentData()
  58. },
  59. methods: {
  60. getCommentData() {
  61. QueryCommentListAPI({
  62. id: this.dataId
  63. }).then(res => {
  64. this.commandData = res || []
  65. }).catch(() => {})
  66. },
  67. handleClose() {
  68. this.$emit('close')
  69. },
  70. handleChooseUser(user) {
  71. console.log('selected: ', user)
  72. if (this.replayInfo) {
  73. let str = `回复@${this.replayInfo.user.realname} `
  74. if (this.content.startsWith(str)) {
  75. this.content = this.content.replace(str, `回复@${user.user.realname} `)
  76. } else {
  77. this.content = `回复@${user.user.realname} ` + this.content
  78. }
  79. } else {
  80. this.content = `回复@${user.user.realname} ` + this.content
  81. }
  82. this.replayInfo = user
  83. this.$refs.comment.focus()
  84. },
  85. changeUser(data) {
  86. this.replayInfo = data
  87. },
  88. submit() {
  89. let params = {
  90. dataId: this.dataId,
  91. content: this.content
  92. }
  93. if (this.replayInfo) {
  94. params.replyId = this.replayInfo.createUserId; // 被回复人的id
  95. params.mainId = this.replayInfo.mainId || this.replayInfo.commentId; // 回复主id
  96. let str = `回复@${this.replayInfo.user.realname} `
  97. if (params.content.startsWith(str)) {
  98. params.content = params.content.replace(str, '')
  99. }
  100. }
  101. if (this.$isEmpty(params.content)) {
  102. this.$toast('回复内容不能为空')
  103. return
  104. }
  105. // console.log('save: ', params)
  106. SetCommentAPI(params).then(() => {
  107. this.$toast('回复成功')
  108. this.content = ''
  109. this.replayInfo = null
  110. this.showEmoji = false
  111. this.$emit('update')
  112. this.handleClose()
  113. }).catch(() => {})
  114. }
  115. }
  116. }
  117. </script>
  118. <style scoped lang="scss">
  119. .popup {
  120. padding-top: 20rpx;
  121. padding-bottom: 112rpx;
  122. .popup-header {
  123. position: relative;
  124. padding: 0 36rpx;
  125. margin-bottom: 36rpx;
  126. @include center;
  127. .text {
  128. font-size: $wk-font-large;
  129. }
  130. .icon {
  131. position: absolute;
  132. left: 20rpx;
  133. top: 50%;
  134. transform: translateY(-50%);
  135. color: $gray;
  136. font-size: $wk-font-medium;
  137. padding: 20rpx;
  138. &.wk-arrow-right {
  139. transform: rotate(180deg) translateY(50%);
  140. transform-origin: center center;
  141. }
  142. }
  143. }
  144. .popup-container {
  145. min-height: 45vh;
  146. max-height: 65vh;
  147. padding: 0 36rpx 15rpx;
  148. overflow: auto;
  149. box-sizing: border-box;
  150. .comment-list {
  151. overflow: initial;
  152. }
  153. }
  154. }
  155. </style>