Browse Source

add:订阅消息

seamwang 2 years ago
parent
commit
8e04da5db1
1 changed files with 19 additions and 1 deletions
  1. 19 1
      src/pages/class/shoppingCart.vue

+ 19 - 1
src/pages/class/shoppingCart.vue

@@ -105,6 +105,18 @@ export default {
105 105
     socket.initSocket()
106 106
   },
107 107
   methods: {
108
+    subscribeMsg() {
109
+      return new Promise((resolve, reject) => {
110
+        uni.requestSubscribeMessage({
111
+          tmplIds: ['dHzqAGRlTyCK260PDedQEnfOgHm7Q27Dj23Ugk1AJkM', 'tfuaGZ8IOk0-JDKMcr5bVhUiiqvIORJHR_74VoPuWH4'],
112
+          success(res) {},
113
+          fail(res) {},
114
+          complete(res) {
115
+            resolve(true)
116
+          }
117
+        })
118
+      })
119
+    },
108 120
     checkChange(e) {
109 121
       this.checkedIds = e.detail.value.map(x => Number(x))
110 122
       this.shoppingList = this.list.filter(item => this.checkedIds.includes(item.shopping_id))
@@ -155,6 +167,12 @@ export default {
155 167
         uni.showToast({ title: '请先选择课程', icon: 'none', duration: 1000 })
156 168
         return false
157 169
       }
170
+      //订阅消息
171
+      this.subscribeMsg().then(res => {
172
+        this.placeOrder() //下单
173
+      })
174
+    },
175
+    placeOrder() {
158 176
       uni.showLoading({
159 177
         mask: true,
160 178
         title: '加载中...'
@@ -162,7 +180,7 @@ export default {
162 180
       const order = JSON.stringify(this.shoppingList)
163 181
       let carts = deepClone(this.carts)
164 182
       const shoppingCarts = this.shoppingList.map(item => item.class_attend_id)
165
-      carts = carts.filter(item => !shoppingCarts.includes(item))
183
+      carts = carts.filter(item => !shoppingCarts.includes(item)) //购物车存储
166 184
       _createOrder({ result: order, notShowLoading: true }).then(res => {
167 185
         this.$store.dispatch('setCarts', carts)
168 186
         setTimeout(() => {