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

205 lines
5.8 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. export default {
  26. name: 'CommentPublish',
  27. components: {
  28. EmailPopup
  29. },
  30. props: {
  31. // 评论参数
  32. params: {
  33. type: Object,
  34. default: () => ({})
  35. },
  36. // 输入框占位符
  37. placeholder: {
  38. type: String,
  39. default: '说点什么吧...'
  40. }
  41. },
  42. computed: {
  43. ...mapState(['userInfo'])
  44. },
  45. data() {
  46. return {
  47. form: {
  48. userValue: ''
  49. },
  50. imageMax: 9,
  51. fileList: []
  52. }
  53. },
  54. methods: {
  55. // 打开弹窗
  56. open() {
  57. this.$refs.popup.open('bottom')
  58. },
  59. // 关闭弹窗
  60. close() {
  61. this.$refs.popup.close()
  62. },
  63. // 检查邮箱并提交
  64. async submit() {
  65. // 检查用户是否填写了邮箱
  66. if (!this.userInfo.mail) {
  67. this.$refs.emailPopup.show()
  68. return
  69. }
  70. this.doSubmit()
  71. },
  72. // 处理邮箱跳过事件
  73. handleEmailSkip() {
  74. this.doSubmit()
  75. },
  76. // 处理邮箱确认事件
  77. handleEmailConfirm(email) {
  78. this.doSubmit()
  79. },
  80. // 执行提交评论
  81. async doSubmit() {
  82. await this.onSubscribeMessageTap()
  83. let data = {
  84. ...this.form,
  85. ...this.params,
  86. }
  87. if (this.$utils.verificationAll(data, {
  88. userValue: '说点什么吧',
  89. type: '缺少type',
  90. orderId: '缺少orderId',
  91. })) {
  92. return
  93. }
  94. data.userImage = this.fileList.map((item) => item.url).join(",")
  95. this.$api('addComment', data, res => {
  96. if (res.code == 200) {
  97. this.close()
  98. this.resetForm()
  99. uni.showToast({
  100. title: '发布成功!',
  101. icon: 'none'
  102. })
  103. this.$emit('success')
  104. }
  105. })
  106. },
  107. // 重置表单
  108. resetForm() {
  109. this.form.userValue = ''
  110. this.fileList = []
  111. },
  112. deleteImage(e) {
  113. this.fileList.splice(e.index, 1)
  114. },
  115. afterRead(e) {
  116. let self = this
  117. e.file.forEach(file => {
  118. self.$Oss.ossUpload(file.url).then(url => {
  119. self.fileList.push({
  120. url
  121. })
  122. })
  123. })
  124. },
  125. //订阅模版消息
  126. onSubscribeMessageTap() {
  127. return new Promise((resolve, reject) => {
  128. let templateIds = [
  129. 'uXZnHWrjtcX9JHlnMpdlWmzgJp71sKxCRiMn3TrE-EE',
  130. 'gTzGpOfJcYxtbvPG9OHnhbureKz5XLG8NPyECUGb2lw',
  131. ];
  132. wx.requestSubscribeMessage({
  133. tmplIds: templateIds, // 需要订阅的模板ID列表
  134. success(res) {
  135. resolve(res)
  136. console.log('订阅消息调用成功', res);
  137. // res[tmplId] 表示用户是否同意订阅该模板ID对应的消息
  138. // 例如:res['your_template_id_1'] === 'accept' 表示用户同意订阅
  139. templateIds.forEach(tmplId => {
  140. if (res[tmplId] === 'accept') {
  141. console.log(`用户同意订阅模板ID:${tmplId}`);
  142. // 这里可以添加用户同意后的逻辑,比如发送消息等(注意:发送消息需要在后端进行)
  143. } else if (res[tmplId] === 'reject') {
  144. console.log(`用户拒绝订阅模板ID:${tmplId}`);
  145. } else {
  146. console.log(`用户对该模板ID的订阅请求:${res[tmplId]}`); // 'ban' 表示用户被禁止订阅该模板
  147. }
  148. });
  149. },
  150. fail(err) {
  151. resolve(res)
  152. console.error('订阅消息调用失败', err);
  153. }
  154. });
  155. })
  156. },
  157. }
  158. }
  159. </script>
  160. <style scoped lang="scss">
  161. .comment-publish {
  162. .content-input {
  163. min-height: 400rpx;
  164. }
  165. .box {
  166. padding: 0 20rpx;
  167. }
  168. .images {
  169. display: flex;
  170. flex-wrap: wrap;
  171. padding: 20rpx;
  172. }
  173. .uni-color-btn {
  174. background-color: $uni-color-primary;
  175. color: #fff;
  176. text-align: center;
  177. padding: 20rpx;
  178. margin: 20rpx;
  179. border-radius: 10rpx;
  180. font-size: 32rpx;
  181. }
  182. }
  183. </style>