From dc49b96b835326a64056da9da0b43eabd2d96e32 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期五, 25 七月 2025 19:37:11 +0800
Subject: [PATCH] 常用取水口列表搜索接口兼容性
---
pages/irrigationDetail/irrigationDetail.js | 466 ++++++++++++++++++++++++++++++---------------------------
1 files changed, 244 insertions(+), 222 deletions(-)
diff --git a/pages/irrigationDetail/irrigationDetail.js b/pages/irrigationDetail/irrigationDetail.js
index 5b4907b..fff0558 100644
--- a/pages/irrigationDetail/irrigationDetail.js
+++ b/pages/irrigationDetail/irrigationDetail.js
@@ -4,249 +4,231 @@
*/
data: {
planCode: '',
+ projectName: '',
startTime: '',
- projects: [],
- isRefreshing: false, // 涓嬫媺鍒锋柊鐘舵��
- planId: '' // 淇濆瓨璁″垝ID
+ stopTime: '',
+ isRefreshing: false,
+ groupList: [],
+ planId: '',
+ planStatusText: '',
+ planStatusClass: '',
+ failureCount: 0,
+ realStopTime: '',
+ originalStatus: '',
+ currentStatus: null
},
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
*/
onLoad: function (options) {
- if (options.id) {
+ if (options.planId) {
this.setData({
- planId: options.id
+ planId: options.planId
});
- // 浠庡垪琛ㄩ〉闈㈣繘鍏ユ椂锛屾墍鏈夐」鐩粯璁ゆ敹璧�
- const fromListPage = options.fromList === 'true';
- this.loadIrrigationDetail(options.id, !fromListPage);
+
+ // 鑾峰彇鏈�鏂扮姸鎬�
+ this.fetchPlanLatestState(options.planId).then(res => {
+ if (res.success) {
+ const currentStatus = res.content;
+ this.setData({
+ currentStatus: currentStatus,
+ originalStatus: currentStatus
+ });
+
+ // 鏍规嵁鏈�鏂扮姸鎬佽皟鐢ㄧ浉搴旂殑鎺ュ彛
+ if (currentStatus === 5) {
+ this.fetchTerminatedIrrigationData(options.planId);
+ } else {
+ this.fetchNormalIrrigationData(options.planId);
+ }
+ } else {
+ wx.showToast({
+ title: res.msg || '鑾峰彇鐘舵�佸け璐�',
+ icon: 'none'
+ });
+ }
+ }).catch(err => {
+ console.error('鑾峰彇鐘舵�佸け璐ワ細', err);
+ wx.showToast({
+ title: '鑾峰彇鐘舵�佸け璐�',
+ icon: 'none'
+ });
+ });
+ } else {
+ wx.showToast({
+ title: '缂哄皯璁″垝ID',
+ icon: 'none'
+ });
+ setTimeout(() => {
+ wx.navigateBack();
+ }, 1500);
}
},
/**
- * 鍔犺浇鐏屾簤璁″垝璇︽儏
- * @param {string} id 鐏屾簤璁″垝ID
- * @param {boolean} isFirstLoad 鏄惁棣栨鍔犺浇
+ * 鑾峰彇甯歌鐏屾簤璁″垝璇︾粏鏁版嵁
*/
- loadIrrigationDetail: function (id, isFirstLoad = false) {
- // 寮�濮嬪姞杞斤紝璁剧疆鍒锋柊鐘舵��
- this.setData({
- isRefreshing: true
- });
-
- // 淇濆瓨褰撳墠椤圭洰鐨勫睍寮�鐘舵��
- const currentExpandStates = {};
- if (!isFirstLoad && this.data.projects.length > 0) {
- this.data.projects.forEach((project, index) => {
- currentExpandStates[project.id] = project.expanded;
+ fetchNormalIrrigationData: function(planId) {
+ const { get } = require('../../api/request');
+
+ const data = {
+ planId: planId || this.data.planId,
+ };
+
+ get({
+ url: 'wx/plan/getPublishResults',
+ isShowLoding: true,
+ useParams: true,
+ data: data
+ }).then(res => {
+ if (res.success) {
+ this.processIrrigationData(res.content);
+ } else {
+ wx.showToast({
+ title: res.msg || '鑾峰彇鏁版嵁澶辫触',
+ icon: 'none'
+ });
+ }
+ }).catch(err => {
+ console.error('璇锋眰澶辫触锛�', err);
+ wx.showToast({
+ title: '璇锋眰澶辫触',
+ icon: 'none'
});
- }
+ });
+ },
- // 杩欓噷搴旇鏄粠API鑾峰彇鏁版嵁
- // 浠ヤ笅鏄ā鎷熸暟鎹�
- const mockData = {
- planCode: 'IRG20240317001',
- startTime: '2024-03-17 08:00',
- projects: [
- {
- id: 1,
- name: '椤圭洰A',
- expanded: isFirstLoad ? true : false, // 浠呭湪闈炲垪琛ㄩ〉杩涘叆涓旈娆″姞杞芥椂灞曞紑绗竴涓」鐩�
- groups: [
- {
- id: 1,
- name: '杞亴缁凙-1',
- status: 'irrigated', // 宸茬亴婧�
- statusText: '宸茬亴婧�',
- startTime: '2024-03-17 08:00',
- endTime: '2024-03-17 09:30',
- duration: 90
- },
- {
- id: 2,
- name: '杞亴缁凙-2',
- status: 'irrigating', // 姝e湪鐏屾簤
- statusText: '姝e湪鐏屾簤',
- startTime: '2024-03-17 09:30',
- endTime: '2024-03-17 11:00',
- duration: 90
- }
- ]
- },
- {
- id: 2,
- name: '椤圭洰B',
- expanded: false,
- groups: [
- {
- id: 3,
- name: '杞亴缁凚-1',
- status: 'waiting', // 鏈亴婧�
- statusText: '鏈亴婧�',
- startTime: '2024-03-17 11:00',
- endTime: '2024-03-17 12:30',
- duration: 90
- },
- {
- id: 4,
- name: '杞亴缁凚-2',
- status: 'waiting', // 鏈亴婧�
- statusText: '鏈亴婧�',
- startTime: '2024-03-17 12:30',
- endTime: '2024-03-17 14:00',
- duration: 90
- }
- ]
- },
- {
- id: 3,
- name: '椤圭洰C',
- expanded: false,
- groups: [
- {
- id: 5,
- name: '杞亴缁凜-1',
- status: 'waiting', // 鏈亴婧�
- statusText: '鏈亴婧�',
- startTime: '2024-03-17 14:00',
- endTime: '2024-03-17 15:30',
- duration: 90
- }
- ]
- }
- ]
+ /**
+ * 鑾峰彇宸茬粓姝㈢亴婧夎鍒掕缁嗘暟鎹�
+ */
+ fetchTerminatedIrrigationData: function(planId) {
+ const { get } = require('../../api/request');
+
+ const data = {
+ planId: planId || this.data.planId,
+ };
+
+ get({
+ url: 'wx/plan/getTerminateResults',
+ isShowLoding: true,
+ useParams: true,
+ data: data
+ }).then(res => {
+ if (res.success) {
+ this.processIrrigationData(res.content);
+ } else {
+ wx.showToast({
+ title: res.msg || '鑾峰彇鏁版嵁澶辫触',
+ icon: 'none'
+ });
+ }
+ }).catch(err => {
+ console.error('璇锋眰澶辫触锛�', err);
+ wx.showToast({
+ title: '璇锋眰澶辫触',
+ icon: 'none'
+ });
+ });
+ },
+
+ /**
+ * 鑾峰彇璁″垝鏈�鏂扮姸鎬�
+ */
+ fetchPlanLatestState: function(planId) {
+ const { get } = require('../../api/request');
+
+ const data = {
+ planId: planId || this.data.planId,
+ };
+
+ return get({
+ url: 'wx/plan/getPlanLatestState',
+ isShowLoding: true,
+ useParams: true,
+ data: data
+ });
+ },
+
+ /**
+ * 澶勭悊鎺ュ彛杩斿洖鐨勬暟鎹�
+ */
+ processIrrigationData: function(data) {
+ console.log('鐏屾簤璁″垝璇︽儏鏁版嵁锛�', data);
+
+ // 澶勭悊杞亴缁勭姸鎬�
+ const statusMap = {
+ 2: {status: 'pending', statusText: '鏈紑濮�'},
+ 3: {status: 'in_progress', statusText: '鐏屾簤涓�'},
+ 4: {status: 'completed', statusText: '宸茬粨鏉�'},
+ 5: {status: 'terminated', statusText: '涓�斿叧闃�'},
+ 6: {status: 'canceled', statusText: '鍙栨秷寮�闃�'}
};
- // 璁$畻姣忎釜椤圭洰鐨勬�荤亴婧夋椂闀�
- mockData.projects = this.calculateProjectTotalDuration(mockData.projects);
-
- // 濡傛灉涓嶆槸棣栨鍔犺浇锛屾仮澶嶉」鐩殑灞曞紑鐘舵��
- if (!isFirstLoad) {
- mockData.projects.forEach(project => {
- if (currentExpandStates[project.id] !== undefined) {
- project.expanded = currentExpandStates[project.id];
- }
- });
+ // 澶勭悊璁″垝鐘舵��
+ let planStatusText = '';
+ let planStatusClass = '';
+
+ // 鏍规嵁璁″垝鐨勭姸鎬佽缃笉鍚岀殑鏂囨湰鍜屾牱寮�
+ // 娉ㄦ剰锛氭帴鍙h繑鍥炵殑鏄痵tate鑰屼笉鏄痯lanState
+ console.log('璁″垝鐘舵�佸�硷細', data.state, '绫诲瀷锛�', typeof data.state);
+
+ // 纭繚state鏄暟瀛楃被鍨�
+ const planState = parseInt(data.state);
+
+ switch(planState) {
+ case 1:
+ planStatusText = '鑽夌';
+ planStatusClass = 'draft';
+ break;
+ case 2:
+ planStatusText = '鏈墽琛�';
+ planStatusClass = 'published';
+ break;
+ case 3:
+ planStatusText = '鎵ц涓�';
+ planStatusClass = 'executing';
+ break;
+ case 4:
+ planStatusText = '宸插畬鎴�';
+ planStatusClass = 'completed';
+ break;
+ case 5:
+ planStatusText = '宸茬粓姝�';
+ planStatusClass = 'terminated';
+ break;
+ default:
+ planStatusText = '鏈煡鐘舵��';
+ planStatusClass = 'draft';
+ console.log('鏈瘑鍒殑璁″垝鐘舵�佸�硷細', planState);
}
- // 妯℃嫙缃戠粶璇锋眰寤惰繜
- setTimeout(() => {
- // 璁剧疆椤甸潰鏁版嵁
- this.setData({
- planCode: mockData.planCode,
- startTime: mockData.startTime,
- projects: mockData.projects,
- isRefreshing: false // 缁撴潫鍒锋柊鐘舵��
- });
- }, 1000);
-
- // 瀹為檯椤圭洰涓簲璇ヤ娇鐢╳x.request鑾峰彇鏁版嵁
- // wx.request({
- // url: 'https://your-api-url/irrigation/' + id,
- // method: 'GET',
- // success: (res) => {
- // if (res.data && res.data.code === 0) {
- // // 鑾峰彇鏂版暟鎹�
- // let projects = res.data.data.projects;
- //
- // // 濡傛灉鏄娆″姞杞斤紝璁剧疆榛樿灞曞紑鐘舵��
- // if (isFirstLoad) {
- // projects = projects.map((project, index) => {
- // return {
- // ...project,
- // expanded: index === 0 // 榛樿鍙睍寮�绗竴涓」鐩�
- // };
- // });
- // } else {
- // // 濡傛灉涓嶆槸棣栨鍔犺浇锛屾仮澶嶉」鐩殑灞曞紑鐘舵��
- // projects = projects.map(project => {
- // return {
- // ...project,
- // expanded: currentExpandStates[project.id] !== undefined
- // ? currentExpandStates[project.id]
- // : false
- // };
- // });
- // }
- //
- // // 璁$畻姣忎釜椤圭洰鐨勬�荤亴婧夋椂闀�
- // projects = this.calculateProjectTotalDuration(projects);
- //
- // this.setData({
- // planCode: res.data.data.planCode,
- // startTime: res.data.data.startTime,
- // projects: projects,
- // isRefreshing: false // 缁撴潫鍒锋柊鐘舵��
- // });
- // } else {
- // wx.showToast({
- // title: '鑾峰彇鏁版嵁澶辫触',
- // icon: 'none'
- // });
- // this.setData({
- // isRefreshing: false // 缁撴潫鍒锋柊鐘舵��
- // });
- // }
- // },
- // fail: () => {
- // wx.showToast({
- // title: '缃戠粶閿欒',
- // icon: 'none'
- // });
- // this.setData({
- // isRefreshing: false // 缁撴潫鍒锋柊鐘舵��
- // });
- // }
- // });
- },
-
- /**
- * 璁$畻姣忎釜椤圭洰鐨勬�荤亴婧夋椂闀�
- */
- calculateProjectTotalDuration: function(projects) {
- return projects.map(project => {
- // 璁$畻椤圭洰涓嬫墍鏈夎疆鐏岀粍鐨勬�绘椂闀�
- const totalDuration = project.groups.reduce((total, group) => {
- return total + (group.duration || 0);
- }, 0);
+ // 杞崲鏁版嵁鏍煎紡
+ const groupList = data.groups.map(group => {
+ const statusInfo = statusMap[group.state] || {status: 'unknown', statusText: '鏈煡鐘舵��'};
return {
- ...project,
- totalDuration: totalDuration
+ id: group.groupId,
+ name: group.groupCode,
+ status: statusInfo.status,
+ statusText: statusInfo.statusText,
+ startTime: group.startTime,
+ endTime: group.stopTime,
+ duration: group.duration,
+ publishResult: group.publishResult || []
};
});
- },
- /**
- * 鍒囨崲椤圭洰灞曞紑/鏀惰捣鐘舵��
- */
- toggleProject: function (e) {
- const index = e.currentTarget.dataset.index;
- const expanded = this.data.projects[index].expanded;
-
- // 鏇存柊椤圭洰鐨勫睍寮�鐘舵��
- const key = `projects[${index}].expanded`;
this.setData({
- [key]: !expanded
- });
- },
-
- /**
- * 瀵艰埅鍒拌疆鐏岀粍璇︽儏椤甸潰
- */
- navigateToGroupDetail: function (e) {
- const projectName = e.currentTarget.dataset.projectName;
- const groupName = e.currentTarget.dataset.groupName;
- const groupId = e.currentTarget.dataset.groupId;
- const status = e.currentTarget.dataset.status;
-
- console.log('璺宠浆鍒扮粍璇︽儏椤甸潰锛屽師濮嬬姸鎬�:', status);
-
- // 瀵艰埅鍒扮粍璇︽儏椤甸潰锛屽苟浼犻�掑弬鏁�
- // 娉ㄦ剰锛氶渶瑕佸皢status杞崲涓篿sIrrigating鍙傛暟锛屼互渚垮湪缁勮鎯呴〉闈㈡纭樉绀哄懡浠ょ姸鎬�
- wx.navigateTo({
- url: `/pages/groupDetail/groupDetail?projectName=${projectName}&groupName=${groupName}&groupId=${groupId}&status=${status}&isIrrigating=${status === 'irrigating' ? 'true' : 'false'}`
+ planCode: data.planName,
+ projectName: data.projectName,
+ startTime: data.planStartTime,
+ stopTime: data.planStopTime,
+ realStopTime: data.realStopTime || '',
+ groupList: groupList,
+ planStatusText: planStatusText,
+ planStatusClass: planStatusClass,
+ failureCount: data.failureCount || 0
});
},
@@ -282,14 +264,44 @@
* 涓嬫媺鍒锋柊澶勭悊鍑芥暟
*/
onPullDownRefresh: function () {
- // 閲嶆柊鍔犺浇鏁版嵁锛屼絾淇濇寔灞曞紑鐘舵��
- if (this.data.planId) {
- this.loadIrrigationDetail(this.data.planId, false);
- } else {
+ this.setData({
+ isRefreshing: true
+ });
+
+ // 鑾峰彇鏈�鏂扮姸鎬佸苟鍒锋柊鏁版嵁
+ this.fetchPlanLatestState(this.data.planId).then(res => {
+ if (res.success) {
+ const currentStatus = res.content;
+ this.setData({
+ currentStatus: currentStatus
+ });
+
+ if (currentStatus === 5) {
+ this.fetchTerminatedIrrigationData(this.data.planId);
+ } else {
+ this.fetchNormalIrrigationData(this.data.planId);
+ }
+ } else {
+ wx.showToast({
+ title: res.msg || '鑾峰彇鐘舵�佸け璐�',
+ icon: 'none'
+ });
+ }
+
+ // 瀹屾垚鍒锋柊
this.setData({
isRefreshing: false
});
- }
+ }).catch(err => {
+ console.error('鑾峰彇鐘舵�佸け璐ワ細', err);
+ wx.showToast({
+ title: '鑾峰彇鐘舵�佸け璐�',
+ icon: 'none'
+ });
+ this.setData({
+ isRefreshing: false
+ });
+ });
},
/**
@@ -304,5 +316,15 @@
*/
onShareAppMessage: function () {
+ },
+
+ /**
+ * 瀵艰埅鍒拌疆鐏岀粍璇︽儏椤甸潰
+ */
+ navigateToGroupDetail: function (e) {
+ const { projectName, groupName, groupId, status } = e.currentTarget.dataset;
+ wx.navigateTo({
+ url: `/pages/groupDetail/groupDetail?projectName=${projectName}&groupName=${groupName}&groupId=${groupId}&status=${status}`
+ });
}
})
\ No newline at end of file
--
Gitblit v1.8.0