lrf402788946 3 tahun lalu
induk
melakukan
8c0bcc444f
2 mengubah file dengan 30 tambahan dan 5 penghapusan
  1. 6 3
      app.js
  2. 24 2
      pages/reserve/index.js

+ 6 - 3
app.js

@@ -8,7 +8,6 @@ App({
     // 登录
     wx.login({
       success: res => {
-        console.log(res);
         const { code: js_code } = res
         // 发送 res.code 到后台换取 openId, sessionKey, unionId
         wx.request({
@@ -18,7 +17,10 @@ App({
             'x-tenant': 'test'
           },
           success: res => {
-            console.log(res)
+            const { errcode, data } = res.data
+            if (errcode === 0) {
+              this.globalData.openid = data;
+            }
           },
           error: err => {
             wx.showToast({
@@ -42,7 +44,8 @@ App({
     height: 0,
     windowHeight: 0,
     publicUrl: 'http://192.168.1.19:9901',
-    fileUrl: "http://broadcast.waityou24.cn"
+    fileUrl: "http://broadcast.waityou24.cn",
+    openid: null
   }
 })
 

+ 24 - 2
pages/reserve/index.js

@@ -100,10 +100,10 @@ Page({
     // 查询数据
     let arr = meal.list.find(i => i.id === data.id);
     if (arr) {//已有值
-      let qwe = { id: arr.id, title: arr.title, num: arr.num + 1 }
+      let qwe = { ...arr, num: arr.num + 1 } //id: arr.id, title: arr.title
       meal.list.splice(res, 1, qwe)
     } else {//没有值
-      let arr = { id: data.id, title: data.title, num: 1 }
+      let arr = { ...data, num: 1 } //id: data.id, title: data.title
       meal.list.push(arr)
     }
   },
@@ -140,6 +140,28 @@ Page({
   // 提交
   onSubmit: function () {
     console.log(this.data.form);
+    console.log(app.globalData.openid)
+    const data = JSON.parse(JSON.stringify(this.data.form))
+    if (app.globalData.openid) data.openid = app.globalData.openid;
+    if (this.data.today) data.date = this.data.today
+    console.log(data)
+    // wx.request({
+    //   url: `${app.globalData.publicUrl}/api/st/dining/order`,
+    //   method: "post",
+    //   header: {
+    //     'x-tenant': 'test'
+    //   },
+    //   data,
+    //   success: res => {
+    //     console.log(res)
+    //   },
+    //   error: err => {
+    //     wx.showToast({
+    //       title: err.msg,
+    //       icon: 'error'
+    //     })
+    //   }
+    // })
     wx.showToast({
       title: '完成点餐',
     })