From 032f821c77485c1178de18f78092ddedd25d2fb2 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期三, 09 四月 2025 15:26:58 +0800
Subject: [PATCH] 添加删除功能到灌溉计划页面,用户可通过点击删除按钮确认删除相应的轮灌计划;更新样式以增强用户体验。
---
pages/irrigation/irrigation.js | 147 +++++++++++++++++++++++++++++++++++++++---------
1 files changed, 119 insertions(+), 28 deletions(-)
diff --git a/pages/irrigation/irrigation.js b/pages/irrigation/irrigation.js
index 248efcc..e4adbc2 100644
--- a/pages/irrigation/irrigation.js
+++ b/pages/irrigation/irrigation.js
@@ -46,16 +46,20 @@
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
- }));
+ 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
+ };
+ });
console.log('杞亴璁″垝鏁版嵁锛�', activeList);
@@ -91,16 +95,20 @@
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
- }));
+ 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);
@@ -153,9 +161,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`
});
},
@@ -213,19 +234,89 @@
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
+ }).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'
+ });
+ });
+ },
+
+ /**
* 鐐瑰嚮绔嬪嵆鎵ц鎸夐挳
*/
onExecute: function (e) {
--
Gitblit v1.8.0