From 90612989855f6849fd94b0665168c3bb7619ff32 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期一, 07 四月 2025 18:08:01 +0800
Subject: [PATCH] 更新项目配置,添加多个项目的专有设置,包括登录需求和统一ID;优化用户数据获取逻辑,确保根据项目需求进行登录状态检查;调整界面显示项目名称和提示信息,增强用户体验。
---
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