From 1b944efc839c270699310def8d0781ce4497e43d Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期四, 07 八月 2025 10:10:05 +0800
Subject: [PATCH] Merge branch 'doing' of http://8.140.179.55:20000/r/wm/pipIrr into doing
---
pages/irrigation/irrigation.js | 594 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 484 insertions(+), 110 deletions(-)
diff --git a/pages/irrigation/irrigation.js b/pages/irrigation/irrigation.js
index e906d7e..1a6493f 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,115 +12,230 @@
completedList: [], // 宸插畬鎴愮殑杞亴鍒楄〃
currentList: [], // 褰撳墠鏄剧ず鐨勫垪琛�
isRefreshing: false, // 鏄惁姝e湪鍒锋柊
- isWXRefreshing: false // 寰俊鍘熺敓涓嬫媺鍒锋柊鐘舵��
+ isWXRefreshing: false, // 寰俊鍘熺敓涓嬫媺鍒锋柊鐘舵��
+ projectId: null, // Added to store projectId
+ // 娣诲姞鍒嗛〉鐩稿叧鏁版嵁
+ pageCurr: 1, // 褰撳墠椤电爜锛屼粠1寮�濮�
+ pageSize: 10, // 姣忛〉璁板綍鏁�
+ hasMoreData: true, // 鏄惁杩樻湁鏇村鏁版嵁
+ loadingMore: false // 鏄惁姝e湪鍔犺浇鏇村
},
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
*/
onLoad: function (options) {
- this.loadIrrigationData();
+ // 鑾峰彇椤圭洰ID
+ if (options.projectId) {
+ this.setData({
+ projectId: options.projectId
+ });
+ }
+
+ // 璁剧疆鍔犺浇鐘舵��
+ wx.showLoading({
+ title: '鍔犺浇涓�',
+ mask: true
+ });
+
+ // 榛樿鍏堝姞杞藉綋鍓嶇亴婧夎鍒�
+ this.loadIrrigationData()
+ .then(() => {
+ wx.hideLoading();
+ })
+ .catch(() => {
+ wx.hideLoading();
+ });
},
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
*/
onShow: function () {
- this.loadIrrigationData();
+ // 妫�鏌ュ叏灞�鍙橀噺锛屽垽鏂槸鍚﹂渶瑕佸埛鏂板垪琛ㄥ苟鍒囨崲鍒板綋鍓嶈鍒�
+ const app = getApp();
+
+ // 鍒锋柊鎵�鏈夋暟鎹紙褰撳墠璁″垝鍜屽巻鍙茶鍒掞級锛岀‘淇濇暟鎹渶鏂�
+ wx.showLoading({
+ title: '鍒锋柊鏁版嵁涓�',
+ mask: true
+ });
+
+ // 鍚屾椂鑾峰彇褰撳墠璁″垝鍜屽巻鍙茶鍒掓暟鎹�
+ Promise.all([
+ this.loadIrrigationData(),
+ this.loadCompletedIrrigationData(true) // 浼犲叆true琛ㄧず鏄噸鏂板姞杞界涓�椤�
+ ]).then(() => {
+ wx.hideLoading();
+
+ // 濡傛灉闇�瑕佸埛鏂板苟鍒囨崲鍒板綋鍓嶈鍒�
+ if (app.globalData.needRefreshIrrigationList) {
+ // 閲嶇疆鍏ㄥ眬鍙橀噺
+ app.globalData.needRefreshIrrigationList = false;
+
+ console.log('妫�娴嬪埌闇�瑕佸埛鏂扮亴婧夎鍒掑垪琛�');
+
+ // 鍒囨崲鍒板綋鍓嶇亴婧夎鍒掓爣绛鹃〉
+ if (this.data.currentTab !== 0) {
+ this.setData({
+ currentTab: 0,
+ currentList: this.data.activeList
+ });
+ }
+ }
+ }).catch(() => {
+ wx.hideLoading();
+ });
},
/**
* 鍔犺浇杞亴鏁版嵁
*/
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'
- // }
- // ]
- };
+ return new Promise((resolve, reject) => {
+ 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
+ });
+ resolve();
+ } else {
+ wx.showToast({
+ title: res.msg || '鍔犺浇澶辫触',
+ icon: 'none'
+ });
+ reject();
+ }
+ }).catch(err => {
+ console.error('鍔犺浇澶辫触:', err);
+ wx.showToast({
+ title: '鍔犺浇澶辫触',
+ icon: 'none'
+ });
+ this.setData({
+ isRefreshing: false,
+ isWXRefreshing: false
+ });
+ reject();
});
- }, 1000);
+ });
+ },
+
+ /**
+ * 鍔犺浇宸插畬鎴愮殑杞亴鏁版嵁
+ */
+ loadCompletedIrrigationData: function (isFirstPage) {
+ // 濡傛灉姝e湪鍔犺浇鎴栨病鏈夋洿澶氭暟鎹紝鍒欎笉鍐嶈姹�
+ if (this.data.loadingMore && !this.data.hasMoreData) {
+ return Promise.resolve();
+ }
+
+ // 濡傛灉鏄噸鏂板姞杞界涓�椤碉紝閲嶇疆椤电爜鍜岀姸鎬�
+ if (isFirstPage) {
+ this.setData({
+ pageCurr: 1,
+ hasMoreData: true
+ });
+ }
+
+ // 璁剧疆鍔犺浇鐘舵��
+ this.setData({
+ loadingMore: true
+ });
+
+ return new Promise((resolve, reject) => {
+ get({
+ url: '/wx/plan/getCompletedPlans',
+ data: {
+ pageCurr: this.data.pageCurr,
+ pageSize: this.data.pageSize
+ }
+ }).then(res => {
+ if (res.success) {
+ const newCompletedList = res.content.obj ? res.content.obj.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('宸插畬鎴愯疆鐏岃鍒掓暟鎹細', newCompletedList);
+
+ // 鑾峰彇鍒嗛〉淇℃伅
+ const pageInfo = {
+ itemTotal: res.content.itemTotal || 0, // 鎬昏褰曟暟
+ pageCurr: res.content.pageCurr || 1, // 褰撳墠椤电爜
+ pageSize: res.content.pageSize || 20, // 姣忛〉澶у皬
+ pageTotal: res.content.pageTotal || 1 // 鎬婚〉鏁�
+ };
+
+ console.log('鍒嗛〉淇℃伅锛�', pageInfo);
+
+ // 鍒ゆ柇鏄惁杩樻湁鏇村鏁版嵁 - 褰撳墠椤靛皬浜庢�婚〉鏁�
+ const hasMoreData = pageInfo.pageCurr < pageInfo.pageTotal;
+
+ // 鍚堝苟鏁版嵁锛岀涓�椤电洿鎺ユ浛鎹紝涔嬪悗鐨勯〉闈㈣拷鍔�
+ const completedList = this.data.pageCurr === 1 ?
+ newCompletedList : [...this.data.completedList, ...newCompletedList];
+
+ this.setData({
+ completedList: completedList,
+ currentList: this.data.currentTab === 1 ? completedList : this.data.activeList,
+ isRefreshing: false,
+ isWXRefreshing: false,
+ loadingMore: false,
+ hasMoreData: hasMoreData
+ });
+ resolve();
+ } else {
+ this.setData({
+ loadingMore: false
+ });
+ // 涓嶆樉绀烘彁绀猴紝鍥犱负鍙兘鏄湪鍚庡彴鍔犺浇
+ console.error('鍘嗗彶璁″垝鍔犺浇澶辫触:', res.msg);
+ reject();
+ }
+ }).catch(err => {
+ console.error('鍘嗗彶璁″垝鍔犺浇澶辫触:', err);
+ this.setData({
+ isRefreshing: false,
+ isWXRefreshing: false,
+ loadingMore: false
+ });
+ // 涓嶆樉绀烘彁绀猴紝鍥犱负鍙兘鏄湪鍚庡彴鍔犺浇
+ reject();
+ });
+ });
},
/**
@@ -132,10 +250,58 @@
const activeList = this.data.activeList || [];
const completedList = this.data.completedList || [];
- this.setData({
- currentTab: index,
- currentList: index === 0 ? activeList : completedList
- });
+ // 鍒囨崲鏍囩椤垫椂锛岀洿鎺ヤ娇鐢ㄥ凡鍔犺浇鐨勬暟鎹紝涓嶉噸鏂拌姹�
+ if (index === 1) {
+ // 鍒囨崲鍒板巻鍙茶鍒掓爣绛�
+ this.setData({
+ currentTab: index,
+ currentList: completedList
+ });
+
+ // 濡傛灉鍘嗗彶鍒楄〃涓虹┖锛屾墠杩涜鍔犺浇
+ if (completedList.length === 0) {
+ wx.showLoading({
+ title: '鍔犺浇涓�',
+ mask: true
+ });
+
+ this.setData({
+ pageCurr: 1,
+ hasMoreData: true,
+ loadingMore: true // 鏄剧ず鍔犺浇鎸囩ず鍣�
+ });
+
+ this.loadCompletedIrrigationData()
+ .then(() => {
+ wx.hideLoading();
+ })
+ .catch(() => {
+ wx.hideLoading();
+ });
+ }
+ } else {
+ // 鍒囨崲鍒板綋鍓嶇亴婧夎鍒掓爣绛�
+ this.setData({
+ currentTab: index,
+ currentList: activeList
+ });
+
+ // 濡傛灉褰撳墠鐏屾簤璁″垝鍒楄〃涓虹┖锛屾墠杩涜鍔犺浇
+ if (activeList.length === 0) {
+ wx.showLoading({
+ title: '鍔犺浇涓�',
+ mask: true
+ });
+
+ this.loadIrrigationData()
+ .then(() => {
+ wx.hideLoading();
+ })
+ .catch(() => {
+ wx.hideLoading();
+ });
+ }
+ }
},
/**
@@ -145,9 +311,22 @@
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?id=${id}&fromList=true`
+ url: `/pages/irrigationDetail/irrigationDetail?planId=${id}&fromList=true&status=${status}`
});
},
@@ -161,13 +340,43 @@
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,
+ timeout: 180000
+ }).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);
+ if(err.code==='1003'){
+ wx.showToast({
+ title: err.msg || '鍙戝竷澶辫触',
+ icon: 'none'
+ });
+ }else{
+ wx.showToast({
+ title: '鍙戝竷澶辫触',
+ icon: 'none'
+ });
+ }
});
- // 鍒锋柊鏁版嵁
- this.loadIrrigationData();
}
}
});
@@ -183,17 +392,93 @@
content: '纭畾瑕佺粓姝㈣杞亴璁″垝鍚楋紵',
success: (res) => {
if (res.confirm) {
- // 杩欓噷搴旇璋冪敤API缁堟杞亴璁″垝
- wx.showToast({
- title: '宸茬粓姝�',
- icon: 'success'
- });
- // 鍒锋柊鏁版嵁
- this.loadIrrigationData();
+ this.postStop(id)
}
}
});
},
+
+ /**
+ * 鐐瑰嚮鍒犻櫎鎸夐挳
+ */
+ onDelete: function (e) {
+ const id = e.currentTarget.dataset.id;
+ wx.showModal({
+ title: '纭鍒犻櫎',
+ content: '纭畾瑕佸垹闄よ杞亴璁″垝鍚楋紵',
+ success: (res) => {
+ if (res.confirm) {
+ // 璋冪敤鍒犻櫎鎺ュ彛
+ post({
+ url: '/wx/plan/deletePlan',
+ 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'
+ });
+ });
+ }
+ }
+ });
+ },
+
+ //缁堟杞亴璁″垝
+ postStop(planID){
+ post({
+ url: '/wx/plan/terminatePlan',
+ data: {
+ planId: planID,
+ operatorId: app.globalData.clientId
+ },
+ isShowLoding: true,
+ timeout: 180000
+ }).then(res => {
+ if (res.success) {
+ wx.showToast({
+ title: '缁堟鎴愬姛',
+ icon: 'success'
+ });
+ // 鍚屾椂鍒锋柊褰撳墠璁″垝鍒楄〃鍜屽巻鍙茶鍒掑垪琛�
+ Promise.all([
+ this.loadIrrigationData(),
+ this.loadCompletedIrrigationData(true) // 浼犲叆true琛ㄧず閲嶆柊鍔犺浇绗竴椤�
+ ]).catch(err => {
+ console.error('鍒锋柊鏁版嵁澶辫触:', err);
+ });
+ } else {
+ wx.showToast({
+ title: res.msg || '缁堟澶辫触',
+ icon: 'none'
+ });
+ }
+ }).catch(err => {
+ console.error('缁堟澶辫触锛�', err);
+ wx.showToast({
+ title: '缁堟澶辫触',
+ icon: 'none'
+ });
+ });
+ },
/**
* 鐐瑰嚮绔嬪嵆鎵ц鎸夐挳
@@ -222,7 +507,7 @@
*/
onAddIrrigation: function () {
wx.navigateTo({
- url: '/pages/createIrrigation/createIrrigation'
+ url: '/pages/createIrrigation/createIrrigation?projectId=' + this.data.projectId
});
},
@@ -242,7 +527,27 @@
this.setData({
isRefreshing: true
});
- this.loadIrrigationData();
+
+ // 鏍规嵁褰撳墠鏍囩椤靛彧鍒锋柊瀵瑰簲鐨勬暟鎹�
+ const currentTab = this.data.currentTab;
+ if (currentTab === 0) {
+ // 褰撳墠鏍囩鏄�"褰撳墠鐏屾簤璁″垝"锛屽彧鍒锋柊杩欎釜
+ this.loadIrrigationData()
+ .finally(() => {
+ this.setData({ isRefreshing: false });
+ });
+ } else {
+ // 褰撳墠鏍囩鏄�"鍘嗗彶璁″垝"锛屽皢鍒嗛〉閲嶇疆鍒扮涓�椤靛苟鍒锋柊
+ this.setData({
+ pageCurr: 1,
+ hasMoreData: true
+ });
+
+ this.loadCompletedIrrigationData()
+ .finally(() => {
+ this.setData({ isRefreshing: false });
+ });
+ }
}
},
@@ -253,6 +558,75 @@
this.setData({
isWXRefreshing: true
});
- this.loadIrrigationData();
+
+ // 鏍规嵁褰撳墠鏍囩椤靛彧鍒锋柊瀵瑰簲鐨勬暟鎹�
+ const currentTab = this.data.currentTab;
+ if (currentTab === 0) {
+ // 褰撳墠鏍囩鏄�"褰撳墠鐏屾簤璁″垝"锛屽彧鍒锋柊杩欎釜
+ this.loadIrrigationData()
+ .finally(() => {
+ this.setData({ isWXRefreshing: false });
+ });
+ } else {
+ // 褰撳墠鏍囩鏄�"鍘嗗彶璁″垝"锛屽皢鍒嗛〉閲嶇疆鍒扮涓�椤靛苟鍒锋柊
+ this.setData({
+ pageCurr: 1,
+ hasMoreData: true
+ });
+
+ this.loadCompletedIrrigationData()
+ .finally(() => {
+ this.setData({ isWXRefreshing: false });
+ });
+ }
+ },
+
+ /**
+ * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁�
+ */
+ onReachBottom: function() {
+ console.log('瑙﹀簳鍔犺浇鏇村, 褰撳墠鏍囩:', this.data.currentTab);
+ // 褰撳墠鏄凡瀹屾垚鍒楄〃涓旇繕鏈夋洿澶氭暟鎹椂鍔犺浇鏇村
+ if (this.data.currentTab === 1 && this.data.hasMoreData && !this.data.loadingMore) {
+ this.setData({
+ pageCurr: this.data.pageCurr + 1
+ });
+
+ // 鍔犺浇鏇村鍘嗗彶鏁版嵁
+ this.loadCompletedIrrigationData()
+ .catch(err => {
+ console.error('鍔犺浇鏇村鍘嗗彶鏁版嵁澶辫触:', err);
+ });
+ }
+ },
+
+ /**
+ * 浠庡垱寤虹亴婧夎鍒掗〉闈㈣繑鍥炴椂锛屽垏鎹㈠埌褰撳墠璁″垝鍒楄〃骞跺埛鏂版暟鎹�
+ */
+ switchToCurrentPlans: function() {
+ console.log('浠庡垱寤洪〉闈㈣繑鍥烇紝鍒囨崲鍒板綋鍓嶈鍒掑垪琛ㄥ苟鍒锋柊');
+
+ // 濡傛灉褰撳墠涓嶅湪 "褰撳墠鐏屾簤璁″垝" 鏍囩椤碉紝鍏堝垏鎹㈠埌璇ユ爣绛鹃〉
+ if (this.data.currentTab !== 0) {
+ this.setData({
+ currentTab: 0,
+ currentList: this.data.activeList
+ });
+ }
+
+ // 鏄剧ず鍔犺浇鎻愮ず
+ wx.showLoading({
+ title: '鍒锋柊鏁版嵁涓�',
+ mask: true
+ });
+
+ // 鍒锋柊褰撳墠鐏屾簤璁″垝鏁版嵁
+ this.loadIrrigationData()
+ .then(() => {
+ wx.hideLoading();
+ })
+ .catch(() => {
+ wx.hideLoading();
+ });
}
})
\ No newline at end of file
--
Gitblit v1.8.0