From 5d3ed12a593020ec7fd9b5af50991f68b191e649 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期一, 07 四月 2025 17:17:20 +0800
Subject: [PATCH] 调整参数

---
 pages/irrigation/irrigation.js |  220 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 126 insertions(+), 94 deletions(-)

diff --git a/pages/irrigation/irrigation.js b/pages/irrigation/irrigation.js
index e906d7e..248efcc 100644
--- a/pages/irrigation/irrigation.js
+++ b/pages/irrigation/irrigation.js
@@ -1,4 +1,7 @@
 // pages/irrigation/irrigation.js
+const { get, post } = require('../../api/request');
+const app = getApp();
+
 Page({
   /**
    * 椤甸潰鐨勫垵濮嬫暟鎹�
@@ -9,14 +12,22 @@
     completedList: [], // 宸插畬鎴愮殑杞亴鍒楄〃
     currentList: [], // 褰撳墠鏄剧ず鐨勫垪琛�
     isRefreshing: false, // 鏄惁姝e湪鍒锋柊
-    isWXRefreshing: false // 寰俊鍘熺敓涓嬫媺鍒锋柊鐘舵��
+    isWXRefreshing: false, // 寰俊鍘熺敓涓嬫媺鍒锋柊鐘舵��
+    projectId: null // Added to store projectId
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad: function (options) {
+    // 鑾峰彇椤圭洰ID
+    if (options.projectId) {
+      this.setData({
+        projectId: options.projectId
+      });
+    }
     this.loadIrrigationData();
+    this.loadCompletedIrrigationData();
   },
 
   /**
@@ -24,100 +35,97 @@
    */
   onShow: function () {
     this.loadIrrigationData();
+    this.loadCompletedIrrigationData();
   },
 
   /**
    * 鍔犺浇杞亴鏁版嵁
    */
   loadIrrigationData: function () {
-    // 杩欓噷搴旇璋冪敤API鑾峰彇鏁版嵁
-    // 妯℃嫙鏁版嵁
-    const mockData = {
-      activeList: [
-        {
-          id: '1',
-          title: 'LG-2023-001',
-          status: '鏈彂甯�',
-          irrigationTime: '2023-05-20 08:00 - 17:00'
-        },
-        {
-          id: '2',
-          title: 'LG-2023-002',
-          status: '宸插彂甯�',
-          irrigationTime: '2023-05-22 09:00 - 18:00'
-        },
-        {
-          id: '2',
-          title: 'LG-2023-002',
-          status: '宸插彂甯�',
-          irrigationTime: '2023-05-22 09:00 - 18:00'
-        },  {
-          id: '2',
-          title: 'LG-2023-002',
-          status: '宸插彂甯�',
-          irrigationTime: '2023-05-22 09:00 - 18:00'
-        },  {
-          id: '2',
-          title: 'LG-2023-002',
-          status: '宸插彂甯�',
-          irrigationTime: '2023-05-22 09:00 - 18:00'
-        },
-        {
-          id: '3',
-          title: 'LG-2023-003',
-          status: '鎵ц涓�',
-          irrigationTime: '2023-05-18 07:30 - 16:30',
-          irrigatedTime: '3灏忔椂25鍒嗛挓',
-          irrigatedGroups: '1缁勩��2缁勩��3缁�'
-        },   {
-          id: '2',
-          title: 'LG-2023-002',
-          status: '宸插彂甯�',
-          irrigationTime: '2023-05-22 09:00 - 18:00'
-        },
-        {
-          id: '3',
-          title: 'LG-2023-003',
-          status: '鎵ц涓�',
-          irrigationTime: '2023-05-18 07:30 - 16:30',
-          irrigatedTime: '3灏忔椂25鍒嗛挓',
-          irrigatedGroups: '1缁勩��2缁勩��3缁�'
-        },   {
-          id: '2',
-          title: 'LG-2023-002',
-          status: '宸插彂甯�',
-          irrigationTime: '2023-05-22 09:00 - 18:00'
-        },
-        {
-          id: '3',
-          title: 'LG-2023-003',
-          status: '鎵ц涓�',
-          irrigationTime: '2023-05-18 07:30 - 16:30',
-          irrigatedTime: '3灏忔椂25鍒嗛挓',
-          irrigatedGroups: '1缁勩��2缁勩��3缁�'
-        }
-        
-      ]
-      // completedList: [
-      //   {
-      //     id: '4',
-      //     title: 'LG-2023-004',
-      //     status: '宸插畬鎴�',
-      //     irrigationTime: '2023-05-10 10:00 - 19:00'
-      //   }
-      // ]
-    };
+    get({
+      url: '/wx/plan/getNotCompletePlans'
+    }).then(res => {
+      if (res.success) {
+        const activeList = res.content.map(item => ({
+          id: item.planId,
+          title: item.planName,
+          projectName: item.projectName || '鏈垎閰嶉」鐩�',
+          status: item.planState,
+          planStartTime: item.planStartTime,
+          planStopTime: item.planStopTime,
+          duration: item.duration,
+          startupMode: item.startupMode
+        }));
 
-    // 妯℃嫙缃戠粶璇锋眰寤惰繜
-    setTimeout(() => {
-      this.setData({
-        activeList: mockData.activeList || [],
-        completedList: mockData.completedList || [],
-        currentList: this.data.currentTab === 0 ? mockData.activeList || [] : mockData.completedList || [],
-        isRefreshing: false, // 缁撴潫鍒锋柊鐘舵��
-        isWXRefreshing: false // 缁撴潫寰俊鍘熺敓涓嬫媺鍒锋柊鐘舵��
+        console.log('杞亴璁″垝鏁版嵁锛�', activeList);
+
+        this.setData({
+          activeList: activeList,
+          currentList: this.data.currentTab === 0 ? activeList : this.data.completedList,
+          isRefreshing: false,
+          isWXRefreshing: false
+        });
+      } else {
+        wx.showToast({
+          title: res.msg || '鍔犺浇澶辫触',
+          icon: 'none'
+        });
+      }
+    }).catch(err => {
+      wx.showToast({
+        title: '鍔犺浇澶辫触',
+        icon: 'none'
       });
-    }, 1000);
+      this.setData({
+        isRefreshing: false,
+        isWXRefreshing: false
+      });
+    });
+  },
+
+  /**
+   * 鍔犺浇宸插畬鎴愮殑杞亴鏁版嵁
+   */
+  loadCompletedIrrigationData: function () {
+    get({
+      url: '/wx/plan/getCompletedPlans'
+    }).then(res => {
+      if (res.success) {
+        const completedList = res.content.map(item => ({
+          id: item.planId,
+          title: item.planName,
+          projectName: item.projectName || '鏈垎閰嶉」鐩�',
+          status: item.planState,
+          planStartTime: item.planStartTime,
+          planStopTime: item.planStopTime,
+          duration: item.duration,
+          startupMode: item.startupMode
+        }));
+
+        console.log('宸插畬鎴愯疆鐏岃鍒掓暟鎹細', completedList);
+
+        this.setData({
+          completedList: completedList,
+          currentList: this.data.currentTab === 1 ? completedList : this.data.activeList,
+          isRefreshing: false,
+          isWXRefreshing: false
+        });
+      } else {
+        wx.showToast({
+          title: res.msg || '鍔犺浇澶辫触',
+          icon: 'none'
+        });
+      }
+    }).catch(err => {
+      wx.showToast({
+        title: '鍔犺浇澶辫触',
+        icon: 'none'
+      });
+      this.setData({
+        isRefreshing: false,
+        isWXRefreshing: false
+      });
+    });
   },
 
   /**
@@ -161,13 +169,35 @@
       content: '纭畾瑕佸彂甯冭杞亴璁″垝鍚楋紵',
       success: (res) => {
         if (res.confirm) {
-          // 杩欓噷搴旇璋冪敤API鍙戝竷杞亴璁″垝
-          wx.showToast({
-            title: '鍙戝竷鎴愬姛',
-            icon: 'success'
+          // 璋冪敤鍙戝竷鎺ュ彛
+          post({
+            url: '/wx/plan/publishPlan',
+            data: {
+              planId: id,
+              operatorId: app.globalData.clientId
+            },
+            isShowLoding: true
+          }).then(res => {
+            if (res.success) {
+              wx.showToast({
+                title: '鍙戝竷鎴愬姛',
+                icon: 'success'
+              });
+              // 鍒锋柊鏁版嵁
+              this.loadIrrigationData();
+            } else {
+              wx.showToast({
+                title: res.msg || '鍙戝竷澶辫触',
+                icon: 'none'
+              });
+            }
+          }).catch(err => {
+            console.error('鍙戝竷澶辫触锛�', err);
+            wx.showToast({
+              title: '鍙戝竷澶辫触',
+              icon: 'none'
+            });
           });
-          // 鍒锋柊鏁版嵁
-          this.loadIrrigationData();
         }
       }
     });
@@ -222,7 +252,7 @@
    */
   onAddIrrigation: function () {
     wx.navigateTo({
-      url: '/pages/createIrrigation/createIrrigation'
+      url: '/pages/createIrrigation/createIrrigation?projectId=' + this.data.projectId
     });
   },
 
@@ -243,6 +273,7 @@
         isRefreshing: true
       });
       this.loadIrrigationData();
+      this.loadCompletedIrrigationData();
     }
   },
 
@@ -254,5 +285,6 @@
       isWXRefreshing: true
     });
     this.loadIrrigationData();
+    this.loadCompletedIrrigationData();
   }
 }) 
\ No newline at end of file

--
Gitblit v1.8.0