From d796875e4dee22341c48469973d03e1015db61e8 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期五, 05 七月 2024 11:40:28 +0800
Subject: [PATCH] 首页添加扫码

---
 pages/home/home.js |  149 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 113 insertions(+), 36 deletions(-)

diff --git a/pages/home/home.js b/pages/home/home.js
index 4bc1a09..5c6dad9 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -12,7 +12,7 @@
   data: {
     sessionId: "",
     showConfirm: false,
-    myItem:{},
+    myItem: {},
     waterIntakeName: "",
     image: "/images/ic_head_bg.jpg",
     userPhone: "158****0723",
@@ -20,7 +20,12 @@
     scrollViewHeight: 0,
     listData: [],
     isRefreshing: false,
-    isWXRefreshing: false
+    isWXRefreshing: false,
+    errorData: '', //閿欒鍐呭
+    showErrorDialog: false,
+    confirmBtn: {
+      content: '纭'
+    },
   },
 
   openValve: function (e) {
@@ -44,7 +49,7 @@
         isRefreshing: true
       });
       this.getOpenList();
- 
+
     }
 
   },
@@ -73,9 +78,15 @@
     });
     //褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
     console.log("onLoad锛�" + options.param);
-    if(options.param){
-      getOpenList() ;
+    if (options.param) {
+      wx.showToast({
+        title: '寮�闃�鎴愬姛',
+        icon: 'success',
+        duration: 3000
+      })
+      this.getOpenList();
     }
+    this.getUserDataBySession();
   },
 
   /**
@@ -131,13 +142,7 @@
     });
     console.log(this.data.isRefreshing);
     // 鏁版嵁璇锋眰瀹屾垚鍚庯紝鍋滄涓嬫媺鍒锋柊鐨勫姩鐢�
-    var self = this;
-    setTimeout(function () {
-      self.setData({
-        isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
-      })
-      console.log('涓嬫媺鍒锋柊宸插畬鎴�');
-    }, 3000);
+    this.getOpenList();
   },
 
   /**
@@ -154,19 +159,26 @@
 
   },
   recharge() {
-    wx.navigateTo({
-      url: '/pages/rechargeCard/rechargeCard',
+    // wx.navigateTo({
+    //   url: '/pages/rechargeCard/rechargeCard',
+    // })
+    wx.showToast({
+      title: '鏆傛湭寮�鏀�',
+      icon: 'none'
     })
   },
   openValveList() {
+    // wx.navigateTo({
+    //   url: '/pages/valveList/valveList',
+    // })
     wx.showToast({
-      title: '姝e湪寮�鍙戜腑',
+      title: '鏆傛湭寮�鏀�',
       icon: 'none'
     })
   },
   feedBack() {
     wx.showToast({
-      title: '姝e湪寮�鍙戜腑',
+      title: '鏆傛湭寮�鏀�',
       icon: 'none'
     })
   },
@@ -176,7 +188,7 @@
     this.setData({
       showConfirm: true,
       waterIntakeName: item.intakeNum,
-      myItem:item
+      myItem: item
     });
   },
   closeDialog() {
@@ -191,31 +203,44 @@
    * @param {*} vcNum 铏氭嫙鍗$紪鍙�
    */
   postCloseValaue(orderNo, rtuAddr, vcNum) {
+    wx.showLoading({
+      title: '姝e湪鍏抽榾璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+      mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+    });
     const app = getApp();
     const data = {
-      rtuAddr: rtuAddr, 
+      rtuAddr: rtuAddr,
       vcNum: vcNum, //铏氭嫙鍗D
-      orderNo:orderNo,
-      userType: 2, //鐢ㄦ埛绫诲瀷1-骞冲彴锛�2-App
+      orderNo: orderNo,
       operator: app.globalData.sessionId //鎿嶄綔鍛�
     };
-    console.log("postCloseValaue"+data);
+    console.log("postCloseValaue" + data);
     post({
-      url: "valve/close",
+      url: "wx/valve/close_wx",
       data: data,
-      isShowLoding:true
+      isShowLoding: false,
+      timeout: 185000
     }).then(response => {
+
       // 澶勭悊鎴愬姛鍝嶅簲
       console.log('璇锋眰鎴愬姛:', response);
       // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
       wx.hideLoading();
-      //瀹屾垚鍚庡洖鍒伴椤�
-      wx.reLaunch({
-        url: '/pages/home/home?param=true' // 棣栭〉鐨勮矾寰勶紝鏍规嵁瀹為檯鎯呭喌濉啓
-      });
+      this.getOpenList();
+      wx.showToast({
+        title: '鍏抽榾鎴愬姛',
+        icon: 'success',
+        duration: 3000
+      })
     }).catch(error => {
+      wx.hideLoading();
+      this.setData({
+        showErrorDialog: true,
+        errorData: error.msg
+      })
       // 澶勭悊閿欒鍝嶅簲
       console.error('璇锋眰澶辫触:', error);
+
     });
   },
   /**
@@ -224,7 +249,7 @@
   getOpenList() {
     const app = getApp();
     const params = {
-      url: 'valve/get',
+      url: 'wx/valve/get',
       data: {
         operator: app.globalData.sessionId
       }
@@ -233,12 +258,18 @@
       this.setData({
         listData: data.content,
         isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+        isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
       })
     }).catch(err => {
       // 閿欒鍥炶皟
-      console.error('Error:', err);
       this.setData({
         isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+        isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+      })
+      wx.showToast({
+        title: err.msg,
+        icon: 'error',
+        duration: 3000
       })
     });
   },
@@ -246,15 +277,61 @@
    * 纭鍏抽棴鍥炶皟
    * @param {} item 
    */
-  confirmDialog(){
+  confirmDialog() {
     this.setData({
       showConfirm: false
     });
-    this.postCloseValaue(this.data.myItem.orderNo,this.data.myItem.rtuAddr,this.data.myItem.vcNum);
+    this.postCloseValaue(this.data.myItem.orderNo, this.data.myItem.rtuAddr, this.data.myItem.vcNum);
+  },
+  //鏍规嵁session鑾峰彇鍐滄埛淇℃伅
+  getUserDataBySession() {
+    const app = getApp();
+    const params = {
+      url: 'wx/client/simple_info',
+      data: {
+        sessionId: app.globalData.sessionId
+      }
+    };
+    get(params).then(data => {
+      this.setData({
+        userName: data.content.clientName,
+        userPhone: this.maskPhoneNumber(data.content.phone)
+      })
+    }).catch(err => {
+      // 閿欒鍥炶皟
+      wx.showToast({
+        title: err.msg,
+        icon: 'error',
+        duration: 3000
+      })
+    })
+  },
+  maskPhoneNumber(phoneNumber) {
+    if (phoneNumber.length !== 11) {
+      throw new Error("Phone number must be 11 digits");
+    }
+    // 浣跨敤姝e垯琛ㄨ揪寮忔浛鎹腑闂村洓浣嶆暟瀛椾负鏄熷彿
+    const maskedPhoneNumber = phoneNumber.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
+    return maskedPhoneNumber;
+  },
+
+  closeDialog() {
+    this.setData({
+      showErrorDialog: false
+    })
+  },
+  scenCode() {
+    wx.scanCode({
+      success(res) {
+        console.log(res.result); // 褰撲笖浠呭綋鎵爜涓洪潪寰俊浜岀淮鐮佹椂锛屼細杩斿洖result  
+        // 濡傛灉鎵爜缁撴灉涓篣RL锛屼細鑷姩灏濊瘯鎵撳紑  
+        // 濡傛灉鎵爜缁撴灉涓哄井淇″皬绋嬪簭鐨勭爜锛屼細鐩存帴璺宠浆鍒板搴旂殑灏忕▼搴忛〉闈�  
+        // 濡傛灉鎵爜缁撴灉涓哄叕浼楀彿浜岀淮鐮侊紝鍒欎細鍦ㄦ墜鏈轰笂鎵撳紑寰俊骞惰烦杞埌瀵瑰簲鐨勫叕浼楀彿  
+      },
+      fail(err) {
+        console.error(err);
+      }
+
+    })
   }
-
-
-
-
-
 })
\ No newline at end of file

--
Gitblit v1.8.0