From c6ad105d1b743bcfd8aa6ee2781d39039f319a87 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期四, 04 七月 2024 11:28:51 +0800
Subject: [PATCH] 添加tag

---
 pages/home/home.js |  284 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 250 insertions(+), 34 deletions(-)

diff --git a/pages/home/home.js b/pages/home/home.js
index befb840..fb5c516 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -1,42 +1,37 @@
 // pages/home/home.js
+const storage = require('../../utils/storage.js');
+const {
+  get,
+  post
+} = require('../../api/request.js');
 Page({
 
   /**
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
+    sessionId: "",
+    showConfirm: false,
+    myItem: {},
+    waterIntakeName: "",
     image: "/images/ic_head_bg.jpg",
-    userCode: "寮犱笁",
-    userName: "1005535",
-    userBalance: "100.5鍏�",
+    userPhone: "158****0723",
+    userName: "寮犱笁",
     scrollViewHeight: 0,
-    listData: [{
-        name: '鍙栨按鍙� 1',
-        code: '1055201'
-      },
-      {
-        name: '鍙栨按鍙� 2',
-        code: '1055201'
-      },
-      {
-        name: '鍙栨按鍙� 3',
-        code: '1055201'
-      },
-      {
-        name: '鍙栨按鍙� 3',
-        code: '1055201'
-      },
-      {
-        name: '鍙栨按鍙� 3',
-        code: '1055201'
-      }
-    ]
+    listData: [],
+    isRefreshing: false,
+    isWXRefreshing: false,
+    errorData: '', //閿欒鍐呭
+    showErrorDialog: false,
+    confirmBtn: {
+      content: '纭'
+    },
   },
 
-  rechageTap:function (e) {
-   wx.navigateTo({
-     url: '/pages/recharge/recharge',
-   })
+  openValve: function (e) {
+    wx.navigateTo({
+      url: '/pages/waterIntake/waterIntake',
+    })
   },
   calculateScrollViewHeight: function () {
     wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => {
@@ -46,23 +41,72 @@
       });
     }).exec();
   },
+  startPullDownRefresh() {
+    if (!this.data.isWXRefreshing) {
+      var self = this;
+      console.log(this.data.isRefreshing);
+      this.setData({
+        isRefreshing: true
+      });
+      this.getOpenList();
+
+    }
+
+  },
+  //鑾峰彇鐢ㄦ埛鏁版嵁
+  getUserData() {
+    get('/items')
+      .then((data) => {
+        this.setData({
+          items: data
+        });
+      })
+      .catch((error) => {
+        console.error('Failed to fetch data:', error);
+      });
+  },
+
 
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-   // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
-   wx.nextTick(() => {
-    this.calculateScrollViewHeight();
-  });
+    // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
+    wx.nextTick(() => {
+      this.calculateScrollViewHeight();
+    });
+    //褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
+    console.log("onLoad锛�" + options.param);
+    if (options.param) {
+      wx.showToast({
+        title: '寮�闃�鎴愬姛',
+        icon: 'success',
+        duration: 3000
+      })
+      this.getOpenList();
+    }
+    this.getUserDataBySession();
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
    */
   onReady() {
-
+    //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
+    if (storage.isHasKeySync("sessionId")) {
+      storage.getItem('sessionId').then((data) => {
+        this.setData({
+          sessionId: data
+        });
+        if (sessionId !== "") {}
+      }).catch((err) => {
+        console.error('Failed to load parameter:', err);
+      });
+    } else {
+      console.log('Failed to load parameter:false');
+    }
+    this.getOpenList();
   },
 
   /**
@@ -90,7 +134,15 @@
    * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔
    */
   onPullDownRefresh() {
-
+    // 涓嬫媺鍒锋柊瑙﹀彂鐨勯�昏緫锛屽彲浠ユ槸璇锋眰鏁版嵁绛夋搷浣�
+    // 渚嬪锛岃姹傛暟鎹悗鏇存柊椤甸潰鍐呭
+    console.log(this.data.isRefreshing);
+    this.setData({
+      isWXRefreshing: true
+    });
+    console.log(this.data.isRefreshing);
+    // 鏁版嵁璇锋眰瀹屾垚鍚庯紝鍋滄涓嬫媺鍒锋柊鐨勫姩鐢�
+    this.getOpenList();
   },
 
   /**
@@ -105,5 +157,169 @@
    */
   onShareAppMessage() {
 
+  },
+  recharge() {
+    // wx.navigateTo({
+    //   url: '/pages/rechargeCard/rechargeCard',
+    // })
+    wx.showToast({
+      title: '鏆傛湭寮�鏀�',
+      icon: 'none'
+    })
+  },
+  openValveList() {
+    // wx.navigateTo({
+    //   url: '/pages/valveList/valveList',
+    // })
+    wx.showToast({
+      title: '鏆傛湭寮�鏀�',
+      icon: 'none'
+    })
+  },
+  feedBack() {
+    wx.showToast({
+      title: '鏆傛湭寮�鏀�',
+      icon: 'none'
+    })
+  },
+  handleChange(e) {
+    const item = e.currentTarget.dataset.item;
+    console.log(item);
+    this.setData({
+      showConfirm: true,
+      waterIntakeName: item.intakeNum,
+      myItem: item
+    });
+  },
+  closeDialog() {
+    this.setData({
+      showConfirm: false
+    });
+  },
+  /**
+   * 鍏抽棴闃�闂�
+   * @param {*} orderNo 璁㈠崟鍙�
+   * @param {*} rtuAddr 闃�鎺у櫒鍦板潃
+   * @param {*} vcNum 铏氭嫙鍗$紪鍙�
+   */
+  postCloseValaue(orderNo, rtuAddr, vcNum) {
+    wx.showLoading({
+      title: '姝e湪鍏抽榾璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+      mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+    });
+    const app = getApp();
+    const data = {
+      rtuAddr: rtuAddr,
+      vcNum: vcNum, //铏氭嫙鍗D
+      orderNo: orderNo,
+      operator: app.globalData.sessionId //鎿嶄綔鍛�
+    };
+    console.log("postCloseValaue" + data);
+    post({
+      url: "wx/valve/close_wx",
+      data: data,
+      isShowLoding: false,
+      timeout: 185000
+    }).then(response => {
+
+      // 澶勭悊鎴愬姛鍝嶅簲
+      console.log('璇锋眰鎴愬姛:', response);
+      // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+      wx.hideLoading();
+      this.getOpenList();
+      wx.showToast({
+        title: '鍏抽榾鎴愬姛',
+        icon: 'success',
+        duration: 3000
+      })
+    }).catch(error => {
+      wx.hideLoading();
+      this.setData({
+        showErrorDialog: true,
+        errorData: error.msg
+      })
+      // 澶勭悊閿欒鍝嶅簲
+      console.error('璇锋眰澶辫触:', error);
+
+    });
+  },
+  /**
+   * 鑾峰彇涓哄叧闃�璁板綍
+   */
+  getOpenList() {
+    const app = getApp();
+    const params = {
+      url: 'wx/valve/get',
+      data: {
+        operator: app.globalData.sessionId
+      }
+    };
+    get(params).then(data => {
+      this.setData({
+        listData: data.content,
+        isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+        isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+      })
+    }).catch(err => {
+      // 閿欒鍥炶皟
+      this.setData({
+        isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+        isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+      })
+      wx.showToast({
+        title: err.msg,
+        icon: 'error',
+        duration: 3000
+      })
+    });
+  },
+  /**
+   * 纭鍏抽棴鍥炶皟
+   * @param {} item 
+   */
+  confirmDialog() {
+    this.setData({
+      showConfirm: false
+    });
+    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
+    })
   }
+
+
+
 })
\ No newline at end of file

--
Gitblit v1.8.0