From 06b93604f8f9bfbcc740decfe5a5b922d75a0de3 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 03 七月 2024 10:05:51 +0800
Subject: [PATCH] 完成界面

---
 pages/home/home.js |  126 ++++++++++++++++++++++++++++-------------
 1 files changed, 85 insertions(+), 41 deletions(-)

diff --git a/pages/home/home.js b/pages/home/home.js
index 023bfac..e88ea82 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -4,23 +4,26 @@
   get,
   post
 } = require('../../api/request.js');
+const app = getApp();
 Page({
 
   /**
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
-    sessionId: "",
     showConfirm: false,
     myItem: {},
     waterIntakeName: "",
     image: "/images/ic_head_bg.jpg",
-    userPhone: "158****0723",
-    userName: "寮犱笁",
+    userPhone: "鏈櫥褰�",
+    userName: "璇风櫥褰�",
     scrollViewHeight: 0,
     listData: [],
     isRefreshing: false,
-    isWXRefreshing: false
+    isWXRefreshing: false,
+    wxCode: '',
+    errorData: '', //閿欒鍐呭
+    showErrorDialog: false
   },
 
   openValve: function (e) {
@@ -44,9 +47,7 @@
         isRefreshing: true
       });
       this.getOpenList();
-
     }
-
   },
   //鑾峰彇鐢ㄦ埛鏁版嵁
   getUserData() {
@@ -60,9 +61,6 @@
         console.error('Failed to fetch data:', error);
       });
   },
-
-
-
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
@@ -81,7 +79,6 @@
       })
       this.getOpenList();
     }
-    this.getUserDataBySession();
   },
 
   /**
@@ -94,14 +91,13 @@
         this.setData({
           sessionId: data
         });
-        if (sessionId !== "") {}
-      }).catch((err) => {
-        console.error('Failed to load parameter:', err);
-      });
+        if (sessionId) {
+          this.getOpenList();
+        }
+      }).catch((err) => {});
     } else {
-      console.log('Failed to load parameter:false');
+      this.wxLogin();
     }
-    this.getOpenList();
   },
 
   /**
@@ -154,27 +150,20 @@
 
   },
   recharge() {
-    // wx.navigateTo({
-    //   url: '/pages/rechargeCard/rechargeCard',
-    // })
-    wx.showToast({
-      title: '鏆傛湭寮�鏀�',
-      icon: 'none'
+    wx.navigateTo({
+      url: '/pages/rechargeCard/rechargeCard',
     })
+
   },
   openValveList() {
-    // wx.navigateTo({
-    //   url: '/pages/valveList/valveList',
-    // })
-    wx.showToast({
-      title: '鏆傛湭寮�鏀�',
-      icon: 'none'
+    wx.navigateTo({
+      url: '/pages/valveList/valveList',
     })
+
   },
   feedBack() {
-    wx.showToast({
-      title: '鏆傛湭寮�鏀�',
-      icon: 'none'
+    wx.navigateTo({
+      url: '/pages/feedback/feedback',
     })
   },
   handleChange(e) {
@@ -213,7 +202,8 @@
     post({
       url: "wx/valve/close_wx",
       data: data,
-      isShowLoding: false
+      isShowLoding: false,
+      timeout: 185000
     }).then(response => {
 
       // 澶勭悊鎴愬姛鍝嶅簲
@@ -228,13 +218,10 @@
       })
     }).catch(error => {
       wx.hideLoading();
-      if (error.code === "1002") {
-        wx.showToast({
-          title: '鍏抽榾澶辫触',
-          icon: 'error',
-          duration: 3000 // 鎻愮ず鐨勬寔缁椂闂达紝鍗曚綅姣
-        })
-      }
+      this.setData({
+        showErrorDialog: true,
+        errorData: error.msg
+      })
       // 澶勭悊閿欒鍝嶅簲
       console.error('璇锋眰澶辫触:', error);
 
@@ -244,7 +231,6 @@
    * 鑾峰彇涓哄叧闃�璁板綍
    */
   getOpenList() {
-    const app = getApp();
     const params = {
       url: 'wx/valve/get',
       data: {
@@ -261,6 +247,12 @@
       // 閿欒鍥炶皟
       this.setData({
         isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+        isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+      })
+      wx.showToast({
+        title: err.msg,
+        icon: 'error',
+        duration: 3000
       })
     });
   },
@@ -278,7 +270,7 @@
   getUserDataBySession() {
     const app = getApp();
     const params = {
-      url: 'sell/client/simple_info',
+      url: 'wx/client/simple_info',
       data: {
         sessionId: app.globalData.sessionId
       }
@@ -293,6 +285,7 @@
 
     })
   },
+  //灏嗘墜鏈哄彿涓棿鍥涗綅闅愯棌
   maskPhoneNumber(phoneNumber) {
     if (phoneNumber.length !== 11) {
       throw new Error("Phone number must be 11 digits");
@@ -300,8 +293,59 @@
     // 浣跨敤姝e垯琛ㄨ揪寮忔浛鎹腑闂村洓浣嶆暟瀛椾负鏄熷彿
     const maskedPhoneNumber = phoneNumber.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
     return maskedPhoneNumber;
+  },
+  //娌℃湁sessionID鏃惰幏鍙杝essionID
+  getSessionID(code) {
+    const params = {
+      url: 'https://44978f7456.imdo.co/wx/client/code_login ',
+      data: {
+        code: code
+      }
+    };
+    post(params).then(data => {
+      if (data.content.client.sessionId) {
+        //褰撳墠鐢ㄦ埛缁戝畾杩�
+        getApp().globalData.sessionId = data.content.client.sessionId
+        storage.setItem("sessionId", data.content.client.sessionId);
+        this.getOpenList();
+        this.getUserDataBySession();
+
+      } else {
+        //褰撳墠鐢ㄦ埛娌$粦瀹氳繃锛岃烦杞埌缁戝畾鐣岄潰
+        wx.navigateTo({
+          url: '/pages/wxbind/wxbind?wxCode=' + this.data.wxCode,
+        })
+      }
+
+    }).catch(err => {
+      // 閿欒鍥炶皟
+
+    })
+  },
+  wxLogin() {
+    // 鐧诲綍
+    wx.login({
+      success: res => {
+        if (res.code) {
+          console.log('鐧诲綍鎴愬姛锛岃幏鍙栧埌鐨刢ode:', res.code);
+          this.setData({
+            wxCode: res.code
+          })
+          // 鍙戦�� res.code 鍒板悗鍙版湇鍔″櫒鎹㈠彇 openId, sessionKey, unionId
+          this.getSessionID(res.code)
+        } else {
+          console.log('鐧诲綍澶辫触锛�' + res.errMsg);
+        }
+      }
+    });
+  },
+  closeDialog() {
+    this.setData({
+      showErrorDialog:false
+    })
   }
 
 
 
+
 })
\ No newline at end of file

--
Gitblit v1.8.0