瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.2 KiB

  1. <template>
  2. <view>
  3. <uv-popup ref="popup" :round="30">
  4. <view class="comment-publish">
  5. <view class="content-input">
  6. <uv-textarea v-model="form.userValue" :maxlength="200" autoHeight count focus
  7. :placeholder="placeholder"></uv-textarea>
  8. </view>
  9. <view class="images box">
  10. <uv-upload :fileList="fileList" :maxCount="imageMax" multiple width="150rpx" height="150rpx"
  11. @delete="deleteImage" @afterRead="afterRead" :previewFullImage="true"></uv-upload>
  12. </view>
  13. <view class="uni-color-btn" @click="submit">
  14. 发布
  15. </view>
  16. </view>
  17. </uv-popup>
  18. <!-- 邮箱填写弹窗组件 -->
  19. <email-popup ref="emailPopup" @skip="handleEmailSkip" @confirm="handleEmailConfirm"></email-popup>
  20. </view>
  21. </template>
  22. <script>
  23. import { mapState } from 'vuex'
  24. import EmailPopup from './emailPopup.vue'
  25. import { subscribeBeforePublish } from '@/utils/subscribeMessage.js'
  26. export default {
  27. name: 'CommentPublish',
  28. components: {
  29. EmailPopup
  30. },
  31. props: {
  32. // 评论参数
  33. params: {
  34. type: Object,
  35. default: () => ({})
  36. },
  37. // 输入框占位符
  38. placeholder: {
  39. type: String,
  40. default: '说点什么吧...'
  41. }
  42. },
  43. computed: {
  44. ...mapState(['userInfo'])
  45. },
  46. data() {
  47. return {
  48. form: {
  49. userValue: ''
  50. },
  51. imageMax: 9,
  52. fileList: []
  53. }
  54. },
  55. methods: {
  56. // 打开弹窗
  57. open() {
  58. this.$refs.popup.open('bottom')
  59. },
  60. // 关闭弹窗
  61. close() {
  62. this.$refs.popup.close()
  63. },
  64. // 检查邮箱并提交
  65. async submit() {
  66. // 检查用户是否填写了邮箱
  67. if (!this.userInfo.mail) {
  68. this.$refs.emailPopup.show()
  69. return
  70. }
  71. this.doSubmit()
  72. },
  73. // 处理邮箱跳过事件
  74. handleEmailSkip() {
  75. this.doSubmit()
  76. },
  77. // 处理邮箱确认事件
  78. handleEmailConfirm(email) {
  79. this.doSubmit()
  80. },
  81. // 执行提交评论
  82. async doSubmit() {
  83. await subscribeBeforePublish()
  84. let data = {
  85. ...this.form,
  86. ...this.params,
  87. }
  88. if (this.$utils.verificationAll(data, {
  89. userValue: '说点什么吧',
  90. type: '缺少type',
  91. orderId: '缺少orderId',
  92. })) {
  93. return
  94. }
  95. data.userImage = this.fileList.map((item) => item.url).join(",")
  96. this.$api('addComment', data, res => {
  97. if (res.code == 200) {
  98. this.close()
  99. this.resetForm()
  100. uni.showToast({
  101. title: '发布成功!',
  102. icon: 'none'
  103. })
  104. this.$emit('success')
  105. }
  106. })
  107. },
  108. // 重置表单
  109. resetForm() {
  110. this.form.userValue = ''
  111. this.fileList = []
  112. },
  113. deleteImage(e) {
  114. this.fileList.splice(e.index, 1)
  115. },
  116. afterRead(e) {
  117. let self = this
  118. e.file.forEach(file => {
  119. self.$Oss.ossUpload(file.url).then(url => {
  120. self.fileList.push({
  121. url
  122. })
  123. })
  124. })
  125. },
  126. }
  127. }
  128. </script>
  129. <style scoped lang="scss">
  130. .comment-publish {
  131. .content-input {
  132. min-height: 400rpx;
  133. }
  134. .box {
  135. padding: 0 20rpx;
  136. }
  137. .images {
  138. display: flex;
  139. flex-wrap: wrap;
  140. padding: 20rpx;
  141. }
  142. .uni-color-btn {
  143. background-color: $uni-color-primary;
  144. color: #fff;
  145. text-align: center;
  146. padding: 20rpx;
  147. margin: 20rpx;
  148. border-radius: 10rpx;
  149. font-size: 32rpx;
  150. }
  151. }
  152. </style>