Parcourir la source

feat(page):首页打开扫码

Zhenghanjv il y a 3 mois
Parent
commit
f5f253752f
2 fichiers modifiés avec 33 ajouts et 39 suppressions
  1. 32 38
      pages/scan/scan.js
  2. 1 1
      pages/scan/scan.wxml

+ 32 - 38
pages/scan/scan.js

@@ -5,53 +5,29 @@ const {
 Page({
   data: {
     isLoggedIn: false,
-    userInfo: null,
+    userInfo: {},
     scanTitle: '扫码加油',
-    scanTip: '请扫描加油机键盘上的二维码'
+    scanTip: '请扫描加油机键盘上的二维码',
+    paymentMode:0
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
-    var wxChatID = wx.getStorageSync("WachatID")
-    console.log("wxchatid", wxChatID);
-    if (wxChatID) {
-      api.request_GetSiteInfo().then(res => {
-        console.log("站点信息",res)
-      })
-      // 获取用户信息授权
-      // wx.getUserProfile({
-      //   desc: '用于完善用户资料', // 声明获取用户信息的目的
-      //   success(res) {
-      //     console.log('用户信息:', res.userInfo);
-      //     var user = {
-      //       UserName: res.userInfo.nickName,
-      //       UserAvatarUrl: res.userInfo.avatarUrl,
-      //       UserPhoneNumber: '',
-      //       Address: ''
-      //     };
-      //     api.request_AddMiniprogramUser(user)
-      //       .then(res => {
-      //         debugger
-      //         return api.request_GetSiteInfo()
-      //       }).then(res => {
-      //         console.log("获取站点信息", res)
-      //       });
-      //     // 将用户信息发送到服务器
-      //     // 例如:wx.request({ url: 'https://example.com/userInfo', data: res.userInfo })
-      //   },
-      //   fail(err) {
-      //     console.error('获取用户信息失败:', err);
-      //   },
-      // });
+    api.request_GetSiteInfo().then(res => {
+      if(res.data.statusCode != 200) return
+      console.log("站点信息",res)
       this.setData({
         isLoggedIn: true,
-        userInfo: null,
+        userInfo: res.data.data.userInfo,
         scanTitle: '扫码加油',
-        scanTip: '请扫码加油机键盘上的二维码'
+        scanTip: '请扫码加油机键盘上的二维码',
+        paymentMode:res.data.data.site.paymentMode
       })
-    }
+    }).catch(err => {
+      console.log("获取站点信息失败",err)
+    })
   },
 
   toLoginOrOrderPage: function () {
@@ -64,8 +40,26 @@ Page({
         url: '../historyOrder/historyOrder',
       })
     }
+  },
 
-
-
+  // 打开扫码功能
+  scanCode: function () {
+    const that = this;
+    wx.scanCode({
+      success(res) {
+        console.log('扫码结果:', res.result);
+        wx.showToast({
+          title: res.result,
+          icon: 'none'
+        });
+      },
+      fail(err) {
+        console.error('扫码失败:', err);
+        wx.showToast({
+          title: '扫码失败',
+          icon: 'none'
+        });
+      }
+    });
   }
 });

+ 1 - 1
pages/scan/scan.wxml

@@ -28,7 +28,7 @@
     <view class="line"></view>
 
     <!-- 扫码区 -->
-    <view class="scan-container">
+    <view class="scan-container" bind:tap="scanCode">
       <view class="scan-image-box">
         <view class="scan-bg-1" />
         <view class="scan-bg-2" />