From 50433e86b718fab0d94ea1410724b29b5f53fa0a Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期三, 09 四月 2025 15:11:26 +0800
Subject: [PATCH] 更新SVG图标样式,优化灌溉计划和取水口页面逻辑,添加状态处理和信息提示功能;调整界面样式,提升用户体验。

---
 pages/irrigation/irrigation.js |  301 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 200 insertions(+), 101 deletions(-)

diff --git a/pages/irrigation/irrigation.js b/pages/irrigation/irrigation.js
index 6ff0e20..61b0f3e 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,105 @@
    */
   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 => {
+          // 纭繚灏唒lanState杞崲涓哄瓧绗︿覆
+          const planState = String(item.planState);
+          return {
+            id: item.planId,
+            title: item.planName,
+            projectName: item.projectName || '鏈垎閰嶉」鐩�',
+            status: 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 => {
+          // 纭繚灏唒lanState杞崲涓哄瓧绗︿覆
+          const planState = String(item.planState);
+          return {
+            id: item.planId,
+            title: item.planName,
+            projectName: item.projectName || '鏈垎閰嶉」鐩�',
+            status: 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
+      });
+    });
   },
 
   /**
@@ -139,6 +155,32 @@
   },
 
   /**
+   * 鐐瑰嚮鍒楄〃椤�
+   */
+  onItemTap: function (e) {
+    const id = e.currentTarget.dataset.id;
+    const status = e.currentTarget.dataset.status;
+    
+    console.log('鐐瑰嚮椤圭洰鐘舵��:', status, '绫诲瀷:', typeof status);
+    
+    // 鍒ゆ柇璁″垝鐘舵�侊紝濡傛灉鏄�1(鏈彂甯�)锛屽垯鎻愮ず鐢ㄦ埛
+    if (status === '1' || status === 1) {
+      wx.showModal({
+        title: '鎻愮ず',
+        content: '褰撳墠璁″垝鏈彂甯冿紝璇峰彂甯冨悗鏌ョ湅',
+        showCancel: false,
+        confirmText: '纭'
+      });
+      return;
+    }
+    
+    // 瀵艰埅鍒扮亴婧夎鎯呴〉闈紝骞朵紶閫掑弬鏁�
+    wx.navigateTo({
+      url: `/pages/irrigationDetail/irrigationDetail?planId=${id}&fromList=true`
+    });
+  },
+
+  /**
    * 鐐瑰嚮鍙戝竷鎸夐挳
    */
   onPublish: function (e) {
@@ -148,13 +190,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();
         }
       }
     });
@@ -170,17 +234,42 @@
       content: '纭畾瑕佺粓姝㈣杞亴璁″垝鍚楋紵',
       success: (res) => {
         if (res.confirm) {
-          // 杩欓噷搴旇璋冪敤API缁堟杞亴璁″垝
-          wx.showToast({
-            title: '宸茬粓姝�',
-            icon: 'success'
-          });
-          // 鍒锋柊鏁版嵁
-          this.loadIrrigationData();
+            this.postStop(id)
         }
       }
     });
   },
+  //缁堟杞亴璁″垝
+   postStop(planID){
+    post({
+        url: '/wx/plan/terminatePlan',
+        data: {
+          planId: planID,
+          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'
+        });
+      });
+   },
 
   /**
    * 鐐瑰嚮绔嬪嵆鎵ц鎸夐挳
@@ -209,8 +298,16 @@
    */
   onAddIrrigation: function () {
     wx.navigateTo({
-      url: '/pages/createIrrigation/createIrrigation'
+      url: '/pages/createIrrigation/createIrrigation?projectId=' + this.data.projectId
     });
+  },
+
+  /**
+   * 闃绘浜嬩欢鍐掓场
+   */
+  stopPropagation: function (e) {
+    // 闃绘浜嬩欢鍐掓场
+    return false;
   },
 
   /**
@@ -222,6 +319,7 @@
         isRefreshing: true
       });
       this.loadIrrigationData();
+      this.loadCompletedIrrigationData();
     }
   },
 
@@ -233,5 +331,6 @@
       isWXRefreshing: true
     });
     this.loadIrrigationData();
+    this.loadCompletedIrrigationData();
   }
 }) 
\ No newline at end of file

--
Gitblit v1.8.0