From 5dc54a59184b305a85aaad31dd4cce01b31a8a2d Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期四, 13 六月 2024 14:58:06 +0800
Subject: [PATCH] 开关泵定版

---
 pages/waterIntake/waterIntake.js |  186 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 163 insertions(+), 23 deletions(-)

diff --git a/pages/waterIntake/waterIntake.js b/pages/waterIntake/waterIntake.js
index bcfb618..81ded95 100644
--- a/pages/waterIntake/waterIntake.js
+++ b/pages/waterIntake/waterIntake.js
@@ -1,11 +1,19 @@
 // pages/waterIntake/waterIntake.js
+const {
+  get,
+  post
+} = require('../../api/request.js');
 Page({
-
-
   data: {
     currentTab: 0, // 褰撳墠鏄剧ず鐨勮〃鏍硷紝榛樿涓虹涓�涓〃鏍�
-    commonWaterPoints: [ "甯哥敤鍙栨按鍙�2", "甯哥敤鍙栨按鍙�3"], // 甯哥敤鍙栨按鍙f暟鎹�
-    allWaterPoints: ["鎵�鏈夊彇姘村彛1", "鎵�鏈夊彇姘村彛2", "鎵�鏈夊彇姘村彛3"], // 鎵�鏈夊彇姘村彛鏁版嵁
+    searchQuery: "",
+    commonWaterPoints: [], // 甯哥敤鍙栨按鍙f暟鎹�
+    allWaterPoints: [], // 鎵�鏈夊彇姘村彛鏁版嵁
+    isRefreshing_all: false,
+    isRefreshing_common: false,
+    showConfirm: false,
+    waterIntakeName: "",
+    choseItem: null
   },
 
   // 鍒囨崲 Tabs
@@ -15,19 +23,18 @@
       currentTab: tab
     });
   },
-  onSearch: function() {
+  onInput(e) {
+    this.setData({
+      searchQuery: e.detail.value // 灏嗚緭鍏ユ鐨勫�煎瓨鍌ㄥ埌 inputValue
+    });
+  },
+  onSearch: function () {
     const query = this.data.searchQuery;
     if (query) {
-      wx.showToast({
-        title: '鎼滅储: ' + query,
-        icon: 'success'
-      });
+      this.getallWaterPoints(query)
       // 鍦ㄨ繖閲岃繘琛屾悳绱㈡搷浣滐紝鏇存柊 allWaterPoints 鏁版嵁
     } else {
-      wx.showToast({
-        title: '璇疯緭鍏ユ悳绱㈠唴瀹�',
-        icon: 'none'
-      });
+      this.getallWaterPoints(query)
     }
   },
 
@@ -35,12 +42,57 @@
    * 閫夋嫨铏氭嫙鍗�
    * @param {} event 
    */
-  choseCard(event){
-    wx.navigateTo({
-      url: '/pages/openCard/openCard',
+  choseCard(event) {
+    this.setData({
+      showConfirm: true,
+      choseItem: event.currentTarget.dataset.item
     })
-  },
+    //  console.log(intakeId);
+    //   wx.navigateTo({
+    //     url: '/pages/openCard/openCard?intakeId='+intakeId,
+    //   })
 
+  },
+  //寮�娉甸�氫俊
+  postOpenValva(intakeId) {
+    wx.showLoading({
+      title: '姝e湪寮�闃�璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+      mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+    });
+    const app = getApp();
+    const data = {
+      intakeId: intakeId, //鍙栨按鍙D
+      // vcId: vcId, //铏氭嫙鍗D
+      operator: app.globalData.sessionId //鎿嶄綔鍛�
+    };
+    post({
+      url: "wx/valve/open_wx",
+      data: data
+    }).then(response => {
+
+      // 澶勭悊鎴愬姛鍝嶅簲
+      console.log('璇锋眰鎴愬姛:', response);
+      // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+      wx.hideLoading();
+      //瀹屾垚鍚庡洖鍒伴椤�
+      wx.reLaunch({
+        url: '/pages/home/home?param=true' // 棣栭〉鐨勮矾寰勶紝鏍规嵁瀹為檯鎯呭喌濉啓
+      });
+
+    }).catch(error => {
+      // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+      wx.hideLoading();
+      // 澶勭悊閿欒鍝嶅簲
+      console.error('璇锋眰澶辫触:', error);
+      if (error.code === "1002") {
+        wx.showToast({
+          title: '寮�闃�澶辫触',
+          icon: 'error',
+          duration: 3000 // 鎻愮ず鐨勬寔缁椂闂达紝鍗曚綅姣
+        })
+      }
+    });
+  },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
@@ -53,7 +105,8 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
    */
   onReady() {
-
+    this.getallWaterPoints();
+    this.getcommonWaterPoints();
   },
 
   /**
@@ -77,12 +130,8 @@
 
   },
 
-  /**
-   * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔
-   */
-  onPullDownRefresh() {
 
-  },
+
 
   /**
    * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁�
@@ -96,5 +145,96 @@
    */
   onShareAppMessage() {
 
+  },
+  /**
+   * 鑾峰彇鎵�鏈夊彇姘村彛
+   */
+  getallWaterPoints: function (intakeNum) {
+    let params = {
+      url: 'project/intake/all_intakes'
+    };
+    if (intakeNum) {
+      params.data = {
+        intakeNum: intakeNum
+      };
+    }
+    get(params)
+      .then((data) => {
+        this.setData({
+          isRefreshing_all: false
+        });
+        if (data.success && data.code === "0001") {
+          this.setData({
+            allWaterPoints: data.content.obj
+          });
+        } else {
+          wx.showToast({
+            title: data.msg,
+          })
+        }
+        console.log('Failed to add item:');
+      })
+      .catch((error) => {
+        this.setData({
+          isRefreshing_all: false
+        });
+        console.error('Failed to add item:', error);
+      });
+  },
+  //鑾峰彇甯哥敤鍙栨按鍙�
+  getcommonWaterPoints() {
+    get({
+        url: 'project/intake/used_intakes',
+        data: {
+          operator: getApp().globalData.sessionId
+        }
+      })
+      .then((data) => {
+        this.setData({
+          isRefreshing_common: false
+        });
+        if (data.success && data.code === "0001") {
+          this.setData({
+            commonWaterPoints: data.content
+          });
+        } else {
+          wx.showToast({
+            title: data.msg,
+          })
+        }
+        console.log('Failed to add item:');
+      })
+      .catch((error) => {
+        this.setData({
+          isRefreshing_common: false
+        });
+        wx.showToast({
+          title: error.code,
+          icon: 'error',
+          duration: 3000 // 鎻愮ず鐨勬寔缁椂闂达紝鍗曚綅姣
+        })
+        console.error('Failed to add item:', error);
+      });
+  },
+  /**
+   * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔
+   */
+  onPullDownRefresh_all() {
+    this.getallWaterPoints();
+  },
+  onPullDownRefresh_common() {
+    this.getcommonWaterPoints();
+  },
+  confirmDialog() {
+    this.setData({
+      showConfirm:false
+    })
+    this.postOpenValva(this.data.choseItem.intakeId);
+  },
+  closeDialog() {
+    this.setData({
+      showConfirm: false
+    })
   }
+
 })
\ No newline at end of file

--
Gitblit v1.8.0