瑶都万能墙
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.

169 lines
4.9 KiB

  1. <template>
  2. <uv-popup ref="popup" :round="30">
  3. <view class="comment-publish">
  4. <view class="content-input">
  5. <uv-textarea v-model="form.userValue" :maxlength="200" autoHeight count focus
  6. :placeholder="placeholder"></uv-textarea>
  7. </view>
  8. <view class="images box">
  9. <uv-upload :fileList="fileList" :maxCount="imageMax" multiple width="150rpx" height="150rpx"
  10. @delete="deleteImage" @afterRead="afterRead" :previewFullImage="true"></uv-upload>
  11. </view>
  12. <view class="uni-color-btn" @click="submit">
  13. 发布
  14. </view>
  15. </view>
  16. </uv-popup>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'CommentPublish',
  21. props: {
  22. // 评论参数
  23. params: {
  24. type: Object,
  25. default: () => ({})
  26. },
  27. // 输入框占位符
  28. placeholder: {
  29. type: String,
  30. default: '说点什么吧...'
  31. }
  32. },
  33. data() {
  34. return {
  35. form: {
  36. userValue: ''
  37. },
  38. imageMax: 9,
  39. fileList: [],
  40. }
  41. },
  42. methods: {
  43. // 打开弹窗
  44. open() {
  45. this.$refs.popup.open('bottom')
  46. },
  47. // 关闭弹窗
  48. close() {
  49. this.$refs.popup.close()
  50. },
  51. async submit() {
  52. await this.onSubscribeMessageTap()
  53. let data = {
  54. ...this.form,
  55. ...this.params,
  56. }
  57. if (this.$utils.verificationAll(data, {
  58. userValue: '说点什么吧',
  59. type: '缺少type',
  60. orderId: '缺少orderId',
  61. })) {
  62. return
  63. }
  64. data.userImage = this.fileList.map((item) => item.url).join(",")
  65. this.$api('addComment', data, res => {
  66. if (res.code == 200) {
  67. this.close()
  68. this.resetForm()
  69. uni.showToast({
  70. title: '发布成功!',
  71. icon: 'none'
  72. })
  73. this.$emit('success')
  74. }
  75. })
  76. },
  77. // 重置表单
  78. resetForm() {
  79. this.form.userValue = ''
  80. this.fileList = []
  81. },
  82. deleteImage(e) {
  83. this.fileList.splice(e.index, 1)
  84. },
  85. afterRead(e) {
  86. let self = this
  87. e.file.forEach(file => {
  88. self.$Oss.ossUpload(file.url).then(url => {
  89. self.fileList.push({
  90. url
  91. })
  92. })
  93. })
  94. },
  95. //订阅模版消息
  96. onSubscribeMessageTap() {
  97. return new Promise((resolve, reject) => {
  98. let templateIds = [
  99. 'uXZnHWrjtcX9JHlnMpdlWmzgJp71sKxCRiMn3TrE-EE',
  100. 'gTzGpOfJcYxtbvPG9OHnhbureKz5XLG8NPyECUGb2lw',
  101. ];
  102. wx.requestSubscribeMessage({
  103. tmplIds: templateIds, // 需要订阅的模板ID列表
  104. success(res) {
  105. resolve(res)
  106. console.log('订阅消息调用成功', res);
  107. // res[tmplId] 表示用户是否同意订阅该模板ID对应的消息
  108. // 例如:res['your_template_id_1'] === 'accept' 表示用户同意订阅
  109. templateIds.forEach(tmplId => {
  110. if (res[tmplId] === 'accept') {
  111. console.log(`用户同意订阅模板ID:${tmplId}`);
  112. // 这里可以添加用户同意后的逻辑,比如发送消息等(注意:发送消息需要在后端进行)
  113. } else if (res[tmplId] === 'reject') {
  114. console.log(`用户拒绝订阅模板ID:${tmplId}`);
  115. } else {
  116. console.log(`用户对该模板ID的订阅请求:${res[tmplId]}`); // 'ban' 表示用户被禁止订阅该模板
  117. }
  118. });
  119. },
  120. fail(err) {
  121. resolve(res)
  122. console.error('订阅消息调用失败', err);
  123. }
  124. });
  125. })
  126. },
  127. }
  128. }
  129. </script>
  130. <style scoped lang="scss">
  131. .comment-publish {
  132. .content-input {
  133. min-height: 400rpx;
  134. }
  135. .box {
  136. padding: 0 20rpx;
  137. }
  138. .images {
  139. display: flex;
  140. flex-wrap: wrap;
  141. padding: 20rpx;
  142. }
  143. .uni-color-btn {
  144. background-color: $uni-color-primary;
  145. color: #fff;
  146. text-align: center;
  147. padding: 20rpx;
  148. margin: 20rpx;
  149. border-radius: 10rpx;
  150. font-size: 32rpx;
  151. }
  152. }
  153. </style>