From 4a33335da6f6ccbb13427d317d23b0c74d019fbb Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期一, 14 四月 2025 17:56:16 +0800
Subject: [PATCH] 新增测试数据功能,允许在首页和取水口页面使用模拟数据进行测试,优化用户体验。

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

diff --git a/pages/home/home.js b/pages/home/home.js
index b20556c..f6cf3e9 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -34,7 +34,8 @@
     showInfoDialog: false,
     showTipDialog: false,
     options: '',
-    showUnBind: false
+    showUnBind: false,
+    useTestData: false  // 鏂板锛氭槸鍚︿娇鐢ㄦ祴璇曟暟鎹殑鏍囧織
   },
 
   openValve: function (e) {
@@ -58,6 +59,14 @@
     }).exec();
   },
   startPullDownRefresh() {
+    if (this.data.useTestData) {
+      this.setData({
+        isRefreshing: true
+      });
+      this.getOpenList();
+      return;
+    }
+    
     if (this.data.isLogin) {
       if (!this.data.isWXRefreshing) {
         var self = this;
@@ -105,6 +114,17 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
    */
   onReady() {
+    // 鐩存帴鍔犺浇娴嬭瘯鏁版嵁
+    if (this.data.useTestData) {
+      this.setData({
+        isLogin: true, // 璁剧疆涓哄凡鐧诲綍鐘舵�佷互渚胯兘鐪嬪埌娴嬭瘯鏁版嵁
+        userName: "娴嬭瘯鐢ㄦ埛",
+        userPhone: "135****6789"
+      });
+      this.getOpenList();
+      return;
+    }
+
     //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
     if (storage.isHasKeySync("sessionId")) {
       const app = getApp();
@@ -344,10 +364,83 @@
     });
   },
   /**
+   * 鐢熸垚娴嬭瘯鏁版嵁 - 鏂板鍑芥暟
+   */
+  generateTestData() {
+    const now = new Date();
+    const year = now.getFullYear();
+    const month = String(now.getMonth() + 1).padStart(2, '0');
+    const day = String(now.getDate()).padStart(2, '0');
+    const hours = String(now.getHours()).padStart(2, '0');
+    const minutes = String(now.getMinutes()).padStart(2, '0');
+    const seconds = String(now.getSeconds()).padStart(2, '0');
+
+    const dateString = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
+    const orderBase = `TEST-${year}${month}${day}-`;
+
+    const testData = [
+      {
+        intakeNum: "鍙栨按鍙�1",
+        isOnLine: true,
+        dt: dateString,
+        waterInstant: "1.23",
+        orderNo: orderBase + "001",
+        rtuAddr: "TEST-RTU-001",
+        vcNum: "TEST-VC-001",
+        planned: false,
+        time: this.extractTime(dateString),
+        deleteText: "鍒犻櫎",
+        displayText: "鍏抽榾",
+        isOpen: true
+      },
+      {
+        intakeNum: "鍙栨按鍙�2",
+        isOnLine: false,
+        dt: dateString,
+        waterInstant: "2.45",
+        orderNo: orderBase + "002",
+        rtuAddr: "TEST-RTU-002",
+        vcNum: "TEST-VC-002",
+        planned: false,
+        time: this.extractTime(dateString),
+        deleteText: "鍒犻櫎",
+        displayText: "鍏抽榾",
+        isOpen: true
+      },
+      {
+        intakeNum: "鍙栨按鍙�3",
+        isOnLine: true,
+        dt: dateString,
+        waterInstant: "3.67",
+        orderNo: orderBase + "003",
+        rtuAddr: "TEST-RTU-003",
+        vcNum: "TEST-VC-003",
+        planned: true,
+        time: this.extractTime(dateString),
+        deleteText: "鍒犻櫎",
+        displayText: "鍙栨秷",
+        isOpen: true
+      }
+    ];
+    return testData;
+  },
+  /**
    * 鑾峰彇涓哄叧闃�璁板綍
    */
   getOpenList() {
     if (this.data.isLogin) {
+      // 濡傛灉璁剧疆浜嗕娇鐢ㄦ祴璇曟暟鎹紝鍒欑洿鎺ヤ娇鐢ㄦ祴璇曟暟鎹�
+      if (this.data.useTestData) {
+        const testData = this.generateTestData();
+        this.setData({
+          listData: testData,
+          isRefreshing: false,
+          isWXRefreshing: false,
+        });
+        this.updateDisplayText();
+        return;
+      }
+
       const app = getApp();
       const params = {
         url: 'wx/valve/get',
@@ -394,6 +487,30 @@
     this.setData({
       showConfirm: false
     });
+    if (this.data.useTestData) {
+      // 娴嬭瘯鏁版嵁妯″紡涓嬶紝妯℃嫙鍏抽榾鎿嶄綔
+      wx.showLoading({
+        title: '姝e湪鍏抽榾璇风◢鍊�...', 
+        mask: true
+      });
+      
+      // 妯℃嫙璇锋眰寤惰繜
+      setTimeout(() => {
+        wx.hideLoading();
+        
+        // 浠庡垪琛ㄤ腑绉婚櫎琚叧闂殑闃�闂�
+        const updatedList = this.data.listData.filter(item => 
+          item.orderNo !== this.data.myItem.orderNo
+        );
+        
+        this.setData({
+          listData: updatedList,
+          showTipDialog: true,
+          tipData: "鍏抽榾鍛戒护涓嬪彂鎴愬姛锛岀害20-60绉掑悗鍙埛鏂板揩閫熷叧闃�鍒楄〃鏌ョ湅鎵ц缁撴灉銆�"
+        });
+      }, 1500);
+      return;
+    }
     this.postCloseValaue(this.data.myItem.orderNo, this.data.myItem.rtuAddr, this.data.myItem.vcNum);
   },
   //鏍规嵁session鑾峰彇鍐滄埛淇℃伅
@@ -563,6 +680,36 @@
   onDelete(e) {
     const item = e.currentTarget.dataset.item;
     const that = this;
+    
+    if (this.data.useTestData) {
+      // 娴嬭瘯鏁版嵁妯″紡涓嬶紝妯℃嫙鍒犻櫎鎿嶄綔
+      wx.showLoading({
+        title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', 
+        mask: true 
+      });
+      
+      // 妯℃嫙璇锋眰寤惰繜
+      setTimeout(() => {
+        wx.hideLoading();
+        
+        // 浠庡垪琛ㄤ腑绉婚櫎琚垹闄ょ殑椤�
+        const updatedList = this.data.listData.filter(listItem => 
+          listItem.orderNo !== item.orderNo
+        );
+        
+        this.setData({
+          listData: updatedList
+        });
+        
+        wx.showToast({
+          title: '鍒犻櫎鎴愬姛',
+          icon: 'success',
+          duration: 2000
+        });
+      }, 1500);
+      return;
+    }
+    
     wx.showLoading({
       title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
       mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false

--
Gitblit v1.8.0