From 917252ef3ea2b63c74d162cc67a6fbe103cb9b4d Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期五, 25 十月 2024 14:06:09 +0800
Subject: [PATCH] 1.开关阀记录界面。2.虚拟卡充值相关。3.问题反馈相关

---
 pages/wxbind/wxbind.js |   99 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 79 insertions(+), 20 deletions(-)

diff --git a/pages/wxbind/wxbind.js b/pages/wxbind/wxbind.js
index d0ee79f..5a1ecb9 100644
--- a/pages/wxbind/wxbind.js
+++ b/pages/wxbind/wxbind.js
@@ -1,5 +1,10 @@
 // pages/wxbind/wxbind.js
 const app = getApp();
+const {
+  get,
+  post
+} = require('../../api/request.js');
+const storage = require('../../utils/storage.js');
 Page({
 
   /**
@@ -7,10 +12,13 @@
    */
   data: {
     mobile: '',
-    code: '',
+    phoneCode: '',
     codeSent: false,
     countdown: 60,
     isButtonEnabled: false
+  },
+  onLoad(options) {
+
   },
   bindMobileInput(e) {
     this.setData({
@@ -20,17 +28,18 @@
 
   bindCodeInput(e) {
     this.setData({
-      code: e.detail.value
-    }, this.checkButtonState);
+      phoneCode: e.detail.value
+    });
+    this.checkButtonState();
   },
   checkButtonState() {
     const {
       mobile,
-      code
+      phoneCode
     } = this.data;
-    const isButtonEnabled = mobile.length === 11 && code.length == 6;
+    const isButtonEnabled = mobile.length === 11 && phoneCode.length == 6;
     this.setData({
-      isButtonEnabled
+      isButtonEnabled: isButtonEnabled
     });
     console.log(isButtonEnabled);
   },
@@ -43,19 +52,19 @@
       });
       return;
     }
-
+    if (this.data.mobile.length != 11) {
+      wx.showToast({
+        title: '璇疯緭鍏ュ畬鏁存墜鏈哄彿',
+        icon: 'none',
+        duration: 2000,
+      });
+      return;
+    }
     // 鍦ㄨ繖閲屽鐞嗗彂閫侀獙璇佺爜鐨勯�昏緫锛屽彲浠ヨ皟鐢ㄥ悗鍙版帴鍙e疄鐜�
-    // 浠ヤ笅鏄竴涓畝鍗曠殑绀轰緥锛屼粎浣滃弬鑰�
-    wx.showToast({
-      title: '楠岃瘉鐮佸凡鍙戦��',
-      icon: 'success',
-      duration: 2000,
-    });
-
+    this.postCode();
     this.setData({
       codeSent: true,
     });
-
     // 鍚姩鍊掕鏃�
     this.startCountdown();
   },
@@ -77,26 +86,76 @@
       }
     }, 1000);
   },
-  bind: function () {
+  bindSuccess: function () {
     if (!this.data.isButtonEnabled) return;
     wx.showToast({
       title: '缁戝畾鎴愬姛',
       icon: 'success'
     });
     // 璺宠浆鍒� TabBar 椤甸潰
-    wx.switchTab({
+    wx.navigateTo({
       url: '/pages/home/home' // 杩欓噷濉啓浣犳兂瑕佽烦杞殑 TabBar 椤甸潰璺緞
     });
   },
+  //鑾峰彇楠岃瘉鐮�
   postCode: function () {
-    post('/items', { name: 'New Item' })
+    const params = {
+      url: 'wx/client/send_sms?phoneNumber=' + this.data.mobile
+    };
+    post(params)
       .then((data) => {
-        this.setData({
-          items: [...this.data.items, data]
+        wx.showToast({
+          title: '楠岃瘉鐮佸凡鍙戦��',
+          icon: 'success',
+          duration: 2000,
         });
       })
       .catch((error) => {
         console.error('Failed to add item:', error);
       });
+  },
+
+  bind() {
+    this.wsLogin();
+  },
+  wsLogin() {
+    wx.login({
+      success: res => {
+        if (res.code) {
+          console.log('鐧诲綍鎴愬姛锛岃幏鍙栧埌鐨刢ode:', res.code);
+          // 鍙戦�� res.code 鍒板悗鍙版湇鍔″櫒鎹㈠彇 openId, sessionKey, unionId
+          this.verify(res.code)
+        } else {
+          console.log('鐧诲綍澶辫触锛�' + res.errMsg);
+        }
+      }
+    });
+  },
+  //鐢ㄦ埛缁戝畾
+  verify(wxCode) {
+    const params = {
+      url: 'wx/client/verify',
+      data: {
+        phoneNumber: this.data.mobile,
+        securityCode: this.data.phoneCode,
+        code: wxCode
+      }
+    };
+    post(params)
+      .then((data) => {
+        getApp().globalData.sessionId = data.content.sessionId
+        storage.setItem("sessionId", data.content.sessionId)
+        getApp().globalData.clientId = data.content.clientId
+        storage.setItem("clientId", data.content.clientId)
+        this.bindSuccess();
+      })
+      .catch((error) => {
+        wx.showToast({
+          title: error.msg,
+          icon: 'error',
+          duration: 3000,
+        });
+        console.error('Failed to add item:', error);
+      });
   }
 })
\ No newline at end of file

--
Gitblit v1.8.0