community-comment.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <u-mask :show="show" @click="show = false" duration="0">
  3. <view class="comment-popup bg-white" :style="{'bottom': !isFocus?'0':height+'px'}" @click.stop>
  4. <view class="comment-popup-header flex row-between">
  5. <view class="lg normal" @click="show = false">取消</view>
  6. <view class="lg bold">评论</view>
  7. <view class="primary lg" @click="handleComment">确定</view>
  8. </view>
  9. <view class="comment-popup-content">
  10. <textarea class="comment-popup-textarea" cols="30" rows="10" v-model="content" :focus="show" :placeholder="commentPlaceholder" disable-default-padding :show-confirm-bar="false" @focus="handleFocus" @blur="handleBlur" fixed :adjust-position="false"></textarea>
  11. </view>
  12. </view>
  13. </u-mask>
  14. </template>
  15. <script>
  16. import {
  17. apiCommunityCommentAdd
  18. } from '@/api/community.js';
  19. import { currentPage, trottle } from "@/utils/tools.js"
  20. export default {
  21. name: "community-comment",
  22. props: {
  23. value: {
  24. type: Boolean
  25. },
  26. communityId: {
  27. type: [Number, String]
  28. },
  29. pid: {
  30. type: [String, Number]
  31. },
  32. placeholder:{
  33. type: [String, Number],
  34. default: '发表你的想法吧...'
  35. },
  36. },
  37. data() {
  38. return {
  39. isFocus: false,// 是否触发键盘
  40. height: '', // 键盘高度
  41. content: '',// 评论内容
  42. }
  43. },
  44. computed: {
  45. commentPlaceholder() {
  46. return this.placeholder
  47. },
  48. // 弹窗Popup显示状态
  49. show: {
  50. get: function() {
  51. return this.value
  52. },
  53. set: function(value) {
  54. this.$emit('input', value)
  55. }
  56. }
  57. },
  58. mounted() {
  59. this.handleComment = trottle(this.handleComment, 500, this)
  60. },
  61. methods: {
  62. // 需要输入时
  63. handleFocus(event) {
  64. this.isFocus = true
  65. if(currentPage().route == "pages/community/community") {
  66. this.height = (event.detail.height - 54)
  67. } else {
  68. this.height = event.detail.height
  69. }
  70. },
  71. // 失去焦点时
  72. handleBlur() {
  73. this.isFocus = false
  74. },
  75. // 评论
  76. handleComment() {
  77. if(!this.isLogin) return this.$Router.push('/pages/login/login')
  78. apiCommunityCommentAdd({
  79. article_id: this.communityId,
  80. pid: this.pid,
  81. comment: this.content
  82. }).then(res => {
  83. this.$toast({title: res.msg})
  84. if( res.code == 1 ) {
  85. this.show = false;
  86. this.$emit('change', res.data)
  87. this.content = ''
  88. }
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .comment-popup {
  96. width: 100%;
  97. height: 340rpx;
  98. border-radius: 20rpx 20rpx 0 0;
  99. position: absolute;
  100. z-index: 9999;
  101. bottom: 0;
  102. left: 0;
  103. padding-bottom: env(safe-area-inset-bottom);
  104. .comment-popup-header {
  105. view {
  106. padding: 28rpx 30rpx;
  107. }
  108. }
  109. .comment-popup-content {
  110. height: 240rpx;
  111. padding: 20rpx;
  112. .comment-popup-textarea {
  113. width: 100%;
  114. box-sizing: border-box;
  115. height: 200rpx;
  116. background: #f8f8f8;
  117. border-radius: 14rpx;
  118. padding: 20rpx;
  119. }
  120. }
  121. }
  122. </style>