From aec1b6ec73897b5e5f3a85f2985447726a399ed0 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期六, 19 四月 2025 15:56:48 +0800
Subject: [PATCH] 更新灌溉计划页面,添加灌溉计划列表刷新标记,优化项目选择器和时间选择器的逻辑;更新样式以提升用户体验,确保在切换标签时只加载必要的数据。
---
pages/createIrrigation/createIrrigation.js | 906 +++++++++++++++++++++++++++++---------------------------
1 files changed, 472 insertions(+), 434 deletions(-)
diff --git a/pages/createIrrigation/createIrrigation.js b/pages/createIrrigation/createIrrigation.js
index 6a77e38..6915e8f 100644
--- a/pages/createIrrigation/createIrrigation.js
+++ b/pages/createIrrigation/createIrrigation.js
@@ -1,450 +1,488 @@
const app = getApp();
-const { get, post } = require('../../api/request');
+const {
+ get,
+ post
+} = require('../../api/request');
const dayjs = require('dayjs');
Page({
- /**
- * 椤甸潰鐨勫垵濮嬫暟鎹�
- */
- data: {
- // 琛ㄥ崟鏁版嵁
- planCode: '', // 璁″垝缂栧彿
- startTime: '', // 鐏屾簤寮�濮嬫椂闂�
- pickerValue: '', // 鏃堕棿閫夋嫨鍣ㄧ殑鍊�
- timePickerVisible: false, // 鏃堕棿閫夋嫨鍣ㄦ槸鍚﹀彲瑙�
- timeInfoVisible: false, // 鏃堕棿鎻愮ず寮圭獥鏄惁鍙
- // 椤圭洰閫夋嫨鍣ㄧ浉鍏�
- projectPickerVisible: false,
- projectPickerValue: [],
- selectedProject: null,
- projectOptions: [],
- totalDuration: 0, // 娣诲姞鎬荤亴婧夋椂闂�
- // 椤圭洰鍒楄〃
- projectList: [],
- // 鏃堕棿閫夋嫨鍣ㄩ�夐」
- timeOptions: [],
- // 杞亴缁勫垪琛ㄥ埛鏂扮姸鎬�
- isRefreshing: false
- },
+ /**
+ * 椤甸潰鐨勫垵濮嬫暟鎹�
+ */
+ data: {
+ // 琛ㄥ崟鏁版嵁
+ planCode: '', // 璁″垝缂栧彿
+ startTime: '', // 鐏屾簤寮�濮嬫椂闂�
+ pickerValue: '', // 鏃堕棿閫夋嫨鍣ㄧ殑鍊�
+ timePickerVisible: false, // 鏃堕棿閫夋嫨鍣ㄦ槸鍚﹀彲瑙�
+ timeInfoVisible: false, // 鏃堕棿鎻愮ず寮圭獥鏄惁鍙
+ // 椤圭洰閫夋嫨鍣ㄧ浉鍏�
+ projectPickerVisible: false,
+ projectPickerValue: [],
+ selectedProject: null,
+ projectOptions: [],
+ totalDuration: 0, // 娣诲姞鎬荤亴婧夋椂闂�
+ // 椤圭洰鍒楄〃
+ projectList: [],
+ // 鏃堕棿閫夋嫨鍣ㄩ�夐」
+ timeOptions: [],
+ // 杞亴缁勫垪琛ㄥ埛鏂扮姸鎬�
+ isRefreshing: false
+ },
- /**
- * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
- */
- onLoad: function (options) {
- // 鐢熸垚璁″垝缂栧彿
- this.generatePlanCode();
- // 璁剧疆鏃堕棿閫夋嫨鍣ㄧ殑鍒濆鍊�
- const now = dayjs();
- this.setData({
- pickerValue: now.add(8.5, 'hour').format('YYYY-MM-DD HH:mm')
- });
- // 鑾峰彇椤圭洰鍒楄〃
- this.fetchProjects();
- },
+ /**
+ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
+ */
+ onLoad: function (options) {
+ // 鐢熸垚璁″垝缂栧彿
+ this.generatePlanCode();
+ // 璁剧疆鏃堕棿閫夋嫨鍣ㄧ殑鍒濆鍊�
+ const now = dayjs();
+ this.setData({
+ pickerValue: now.add(8.5, 'hour').format('YYYY-MM-DD HH:mm')
+ });
+ // 鑾峰彇椤圭洰鍒楄〃
+ this.fetchProjects();
+ },
- /**
- * 鐢熸垚璁″垝缂栧彿
- */
- generatePlanCode: function () {
- const now = dayjs();
- const dateStr = now.format('YYYYMMDD');
- const randomNum = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
- const planCode = `${dateStr}${randomNum}`;
- this.setData({ planCode });
- },
+ /**
+ * 鐢熸垚璁″垝缂栧彿
+ */
+ generatePlanCode: function () {
+ const now = dayjs();
+ const dateStr = now.format('YYYY-MM-DD');
+ const randomNum = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
+ const planCode = `${dateStr}${-randomNum}`;
+ this.setData({
+ planCode
+ });
+ },
- /**
- * 鑾峰彇椤圭洰鍒楄〃
- */
- fetchProjects: function () {
- return get({
- url: '/wx/irrigation/getSimpleProjects',
- isShowLoding: true
- }).then(res => {
- if (res.success) {
- const projectList = res.content.map(project => ({
- id: project.projectId,
- name: project.projectName,
- groupCount: project.groupCount,
- groups: []
- }));
-
- const projectOptions = projectList.map(project => ({
- label: project.name,
- value: project.id
- }));
-
- this.setData({
- projectList,
- projectOptions
- });
- } else {
- wx.showToast({
- title: res.msg || '鑾峰彇椤圭洰鍒楄〃澶辫触',
- icon: 'none'
- });
- return Promise.reject(new Error(res.msg || '鑾峰彇椤圭洰鍒楄〃澶辫触'));
- }
- }).catch(err => {
- console.error('鑾峰彇椤圭洰鍒楄〃澶辫触锛�', err);
- wx.showToast({
- title: '鑾峰彇椤圭洰鍒楄〃澶辫触',
- icon: 'none'
- });
- return Promise.reject(err);
- });
- },
-
- /**
- * 鑾峰彇杞亴缁勫垪琛�
- */
- fetchGroups: function (projectId) {
- return get({
- url: '/wx/irrigation/getSimpleGroups',
- data: {
- projectId: projectId,
- },
- isShowLoding: true
- }).then(res => {
- if (res.success) {
- console.log('杞亴缁勬暟鎹細', res.content.obj);
-
- // 鏇存柊閫変腑椤圭洰鐨勮疆鐏岀粍淇℃伅
- const projectList = this.data.projectList.map(project => {
- if (project.id === projectId) {
- return {
- ...project,
- groups: res.content.obj.map(group => ({
- id: group.groupId,
- name: group.groupCode,
- duration: group.defaultDuration || 0,
- selected: false,
- intakeCount: group.intakeCount
- }))
- };
- }
- return project;
- });
-
- // 鏇存柊閫変腑鐨勯」鐩�
- const selectedProject = projectList.find(project => project.id === projectId);
- console.log('鏇存柊鍚庣殑閫変腑椤圭洰锛�', selectedProject);
-
- this.setData({
- projectList,
- selectedProject
- }, () => {
- // 璁$畻鎬绘椂闂�
- this.calculateTotalDuration();
- });
- } else {
- wx.showToast({
- title: res.msg || '鑾峰彇杞亴缁勫垪琛ㄥけ璐�',
- icon: 'none'
- });
- return Promise.reject(new Error(res.msg || '鑾峰彇杞亴缁勫垪琛ㄥけ璐�'));
- }
- }).catch(err => {
- console.error('鑾峰彇杞亴缁勫垪琛ㄥけ璐ワ細', err);
- wx.showToast({
- title: '鑾峰彇杞亴缁勫垪琛ㄥけ璐�',
- icon: 'none'
- });
- return Promise.reject(err);
- });
- },
-
- /**
- * 鏄剧ず鏃堕棿閫夋嫨鍣�
- */
- showTimePicker: function () {
- // 濡傛灉娌℃湁閫夋嫨鏃堕棿锛屼娇鐢ㄥ綋鍓嶆椂闂�
- if (!this.data.pickerValue) {
- const now = dayjs();
- this.setData({
- pickerValue: now.format('YYYY-MM-DD HH:mm')
- });
- }
-
- this.setData({
- timePickerVisible: true
- });
- },
-
- /**
- * 鏃堕棿閫夋嫨鍣ㄧ‘璁ゅ洖璋�
- */
- onTimePickerConfirm: function (e) {
- const { value } = e.detail;
- this.setData({
- timePickerVisible: false,
- startTime: value
- });
- },
-
- /**
- * 鏃堕棿閫夋嫨鍣ㄥ彇娑堝洖璋�
- */
- onTimePickerCancel: function () {
- this.setData({
- timePickerVisible: false
- });
- },
-
- /**
- * 鍒囨崲椤圭洰灞曞紑/鎶樺彔鐘舵��
- */
- toggleProject: function (e) {
- const index = e.currentTarget.dataset.index;
- const currentValue = this.data.projectList[index].expanded;
-
- // 鍒涘缓鏂扮殑椤圭洰鍒楄〃锛屽厛灏嗘墍鏈夐」鐩涓烘姌鍙犵姸鎬�
- const newProjectList = this.data.projectList.map((item, idx) => {
- return {
- ...item,
- expanded: false
- };
- });
-
- // 濡傛灉褰撳墠鐐瑰嚮鐨勯」鐩凡缁忔槸灞曞紑鐘舵�侊紝鍒欎繚鎸佹墍鏈夐」鐩姌鍙�
- // 鍚﹀垯锛屽皢褰撳墠鐐瑰嚮鐨勯」鐩涓哄睍寮�鐘舵��
- if (!currentValue) {
- newProjectList[index].expanded = true;
- }
-
- this.setData({
- projectList: newProjectList
- });
- },
-
- /**
- * 鍒囨崲杞亴缁勯�変腑鐘舵��
- */
- toggleGroupSelection: function (e) {
- const projectIndex = e.currentTarget.dataset.projectIndex;
- const groupIndex = e.currentTarget.dataset.groupIndex;
- const key = `projectList[${projectIndex}].groups[${groupIndex}].selected`;
- const currentValue = this.data.projectList[projectIndex].groups[groupIndex].selected;
-
- this.setData({
- [key]: !currentValue
- });
-
- // 鏇存柊椤圭洰鎬绘椂闀�
- this.updateProjectTotalDuration(projectIndex);
- },
-
- /**
- * 澶勭悊鏃堕暱杈撳叆
- */
- onDurationInput: function (e) {
- const { groupIndex } = e.currentTarget.dataset;
- const duration = parseInt(e.detail.value) || 0;
-
- const selectedProject = { ...this.data.selectedProject };
- selectedProject.groups[groupIndex].duration = duration;
-
- this.setData({
- selectedProject
- }, () => {
- // 杈撳叆鏃堕暱鍚庨噸鏂拌绠楁�绘椂闂�
- this.calculateTotalDuration();
- });
- },
-
- /**
- * 璁$畻骞舵洿鏂伴」鐩�绘椂闀�
- */
- updateProjectTotalDuration: function (projectIndex) {
- const project = this.data.projectList[projectIndex];
- let totalDuration = 0;
-
- // 璁$畻鎵�鏈夐�変腑鐨勮疆鐏岀粍鐨勬椂闀挎�诲拰
- project.groups.forEach(group => {
- if (group.selected) {
- totalDuration += parseInt(group.duration) || 0;
- }
- });
-
- // 鏇存柊椤圭洰鎬绘椂闀�
- const totalDurationKey = `projectList[${projectIndex}].totalDuration`;
- this.setData({
- [totalDurationKey]: totalDuration
- });
- },
-
- /**
- * 闃绘浜嬩欢鍐掓场
- */
- stopPropagation: function (e) {
- if (e && e.stopPropagation) {
- e.stopPropagation();
- }
- return false;
- },
-
- /**
- * 璺宠浆鍒拌疆鐏岀粍璇︽儏椤�
- */
- navigateToGroupDetail: function (e) {
- const { groupIndex } = e.currentTarget.dataset;
- // TODO: 瀹炵幇璺宠浆閫昏緫
- },
-
- /**
- * 纭鎸夐挳鐐瑰嚮浜嬩欢
- */
- onConfirm: function () {
- const { planCode, startTime, selectedProject } = this.data;
-
- if (!planCode) {
- wx.showToast({
- title: '璇疯緭鍏ヨ鍒掔紪鍙�',
- icon: 'none'
- });
- return;
- }
-
- if (!selectedProject) {
- wx.showToast({
- title: '璇烽�夋嫨椤圭洰',
- icon: 'none'
- });
- return;
- }
-
- // 鏋勫缓涓婃姤鏁版嵁
- const schedules = selectedProject.groups.map(group => ({
- groupId: group.id,
- duration: parseInt(group.duration) || 0
+ /**
+ * 鑾峰彇椤圭洰鍒楄〃
+ */
+ fetchProjects: function (isShowDiaolog) {
+ return get({
+ url: '/wx/irrigation/getSimpleProjects',
+ isShowLoding: true
+ }).then(res => {
+ if (res.success) {
+ const projectList = res.content.map(project => ({
+ id: project.projectId,
+ name: project.projectName,
+ groupCount: project.groupCount,
+ groups: []
}));
- const requestData = {
- projectId: selectedProject.id,
- planName: planCode,
- startupMode: startTime ? 2 : 1,
- operatorId: app.globalData.clientId,
- schedules: schedules
- };
+ const projectOptions = projectList.map(project => ({
+ label: project.name,
+ value: project.id
+ }));
- // 濡傛灉鏈夊紑濮嬫椂闂达紝娣诲姞鍒拌姹傛暟鎹腑
- if (startTime) {
- requestData.planStartTime = startTime;
- }
-
- // 鍙戦�佽姹�
- post({
- url: '/wx/plan/createPlan',
- data: requestData,
- isShowLoding: true
- }).then(res => {
- if (res.success) {
- wx.showToast({
- title: '鍒涘缓鎴愬姛',
- icon: 'success'
- });
- // 杩斿洖涓婁竴椤�
- setTimeout(() => {
- wx.navigateBack();
- }, 1500);
- } else {
- wx.showToast({
- title: res.msg || '鍒涘缓澶辫触',
- icon: 'none'
- });
- }
- }).catch(err => {
- console.error('鍒涘缓璁″垝澶辫触锛�', err);
- wx.showToast({
- title: '鍒涘缓澶辫触',
- icon: 'none'
- });
- });
- },
-
- // 鏄剧ず椤圭洰閫夋嫨鍣�
- showProjectPicker() {
this.setData({
+ projectList,
+ projectOptions
+ });
+ if (isShowDiaolog) {
+ this.setData({
projectPickerVisible: true
- });
- },
-
- // 椤圭洰閫夋嫨鍣ㄧ‘璁�
- onProjectPickerConfirm(e) {
- const { value } = e.detail;
- console.log('閫夋嫨鐨勯」鐩甀D锛�', value[0]); // 娣诲姞鏃ュ織鏌ョ湅鏁版嵁
- const selectedProject = this.data.projectList.find(project => project.id === value[0]);
- console.log('鎵惧埌鐨勯」鐩細', selectedProject); // 娣诲姞鏃ュ織鏌ョ湅鏁版嵁
-
- this.setData({
- projectPickerVisible: false,
- selectedProject: selectedProject,
- projectPickerValue: value
- }, () => {
- // 閫夋嫨椤圭洰鍚庤幏鍙栬疆鐏岀粍鍒楄〃
- if (selectedProject) {
- this.fetchGroups(selectedProject.id);
- }
- });
- },
-
- // 椤圭洰閫夋嫨鍣ㄥ彇娑�
- onProjectPickerCancel() {
- this.setData({
- projectPickerVisible: false
- });
- },
-
- /**
- * 璁$畻鎬荤亴婧夋椂闂�
- */
- calculateTotalDuration: function () {
- if (!this.data.selectedProject) return;
-
- const totalDuration = this.data.selectedProject.groups.reduce((sum, group) => {
- return sum + (parseInt(group.duration) || 0);
- }, 0);
-
- this.setData({
- totalDuration
- });
- },
-
- /**
- * 杞亴缁勫垪琛ㄤ笅鎷夊埛鏂�
- */
- onGroupListRefresh: function () {
- if (!this.data.selectedProject) {
- this.setData({ isRefreshing: false });
- return;
+ });
}
-
- this.setData({ isRefreshing: true });
-
- this.fetchGroups(this.data.selectedProject.id)
- .then(() => {
- this.setData({ isRefreshing: false });
- })
- .catch(() => {
- this.setData({ isRefreshing: false });
- });
- },
-
- /**
- * 鏄剧ず鏃堕棿鎻愮ず寮圭獥
- */
- showTimeInfo: function () {
- this.setData({
- timeInfoVisible: true
+ } else {
+ wx.showToast({
+ title: res.msg || '鑾峰彇椤圭洰鍒楄〃澶辫触',
+ icon: 'none'
});
- },
+ return Promise.reject(new Error(res.msg || '鑾峰彇椤圭洰鍒楄〃澶辫触'));
+ }
+ }).catch(err => {
+ console.error('鑾峰彇椤圭洰鍒楄〃澶辫触锛�', err);
+ wx.showToast({
+ title: '鑾峰彇椤圭洰鍒楄〃澶辫触',
+ icon: 'none'
+ });
+ return Promise.reject(err);
+ });
+ },
- /**
- * 鍏抽棴鏃堕棿鎻愮ず寮圭獥
- */
- onTimeInfoConfirm: function () {
- this.setData({
- timeInfoVisible: false
+ /**
+ * 鑾峰彇杞亴缁勫垪琛�
+ */
+ fetchGroups: function (projectId) {
+ return get({
+ url: '/wx/irrigation/getSimpleGroups',
+ data: {
+ projectId: projectId,
+ },
+ isShowLoding: true
+ }).then(res => {
+ if (res.success) {
+ console.log('杞亴缁勬暟鎹細', res.content);
+
+ // 鏇存柊閫変腑椤圭洰鐨勮疆鐏岀粍淇℃伅
+ const projectList = this.data.projectList.map(project => {
+ if (project.id === projectId) {
+ return {
+ ...project,
+ groups: res.content.map(group => ({
+ id: group.groupId,
+ name: group.groupCode,
+ duration: group.defaultDuration || 0,
+ selected: false,
+ intakeCount: group.intakeCount
+ }))
+ };
+ }
+ return project;
});
- },
-});
\ No newline at end of file
+
+ // 鏇存柊閫変腑鐨勯」鐩�
+ const selectedProject = projectList.find(project => project.id === projectId);
+ console.log('鏇存柊鍚庣殑閫変腑椤圭洰锛�', selectedProject);
+
+ this.setData({
+ projectList,
+ selectedProject
+ }, () => {
+ // 璁$畻鎬绘椂闂�
+ this.calculateTotalDuration();
+ });
+ } else {
+ wx.showToast({
+ title: res.msg || '鑾峰彇杞亴缁勫垪琛ㄥけ璐�',
+ icon: 'none'
+ });
+ return Promise.reject(new Error(res.msg || '鑾峰彇杞亴缁勫垪琛ㄥけ璐�'));
+ }
+ }).catch(err => {
+ console.error('鑾峰彇杞亴缁勫垪琛ㄥけ璐ワ細', err);
+ wx.showToast({
+ title: '鑾峰彇杞亴缁勫垪琛ㄥけ璐�',
+ icon: 'none'
+ });
+ return Promise.reject(err);
+ });
+ },
+
+ /**
+ * 鏄剧ず鏃堕棿閫夋嫨鍣�
+ */
+ showTimePicker: function () {
+ // 濡傛灉娌℃湁閫夋嫨鏃堕棿锛屼娇鐢ㄥ綋鍓嶆椂闂�
+ if (!this.data.pickerValue) {
+ const now = dayjs();
+ this.setData({
+ pickerValue: now.format('YYYY-MM-DD HH:mm')
+ });
+ }
+
+ this.setData({
+ timePickerVisible: true
+ });
+ },
+
+ /**
+ * 鏃堕棿閫夋嫨鍣ㄧ‘璁ゅ洖璋�
+ */
+ onTimePickerConfirm: function (e) {
+ const {
+ value
+ } = e.detail;
+ this.setData({
+ timePickerVisible: false,
+ startTime: value
+ });
+ },
+
+ /**
+ * 鏃堕棿閫夋嫨鍣ㄥ彇娑堝洖璋�
+ */
+ onTimePickerCancel: function () {
+ this.setData({
+ timePickerVisible: false
+ });
+ },
+
+ /**
+ * 鍒囨崲椤圭洰灞曞紑/鎶樺彔鐘舵��
+ */
+ toggleProject: function (e) {
+ const index = e.currentTarget.dataset.index;
+ const currentValue = this.data.projectList[index].expanded;
+
+ // 鍒涘缓鏂扮殑椤圭洰鍒楄〃锛屽厛灏嗘墍鏈夐」鐩涓烘姌鍙犵姸鎬�
+ const newProjectList = this.data.projectList.map((item, idx) => {
+ return {
+ ...item,
+ expanded: false
+ };
+ });
+
+ // 濡傛灉褰撳墠鐐瑰嚮鐨勯」鐩凡缁忔槸灞曞紑鐘舵�侊紝鍒欎繚鎸佹墍鏈夐」鐩姌鍙�
+ // 鍚﹀垯锛屽皢褰撳墠鐐瑰嚮鐨勯」鐩涓哄睍寮�鐘舵��
+ if (!currentValue) {
+ newProjectList[index].expanded = true;
+ }
+
+ this.setData({
+ projectList: newProjectList
+ });
+ },
+
+ /**
+ * 鍒囨崲杞亴缁勯�変腑鐘舵��
+ */
+ toggleGroupSelection: function (e) {
+ const projectIndex = e.currentTarget.dataset.projectIndex;
+ const groupIndex = e.currentTarget.dataset.groupIndex;
+ const key = `projectList[${projectIndex}].groups[${groupIndex}].selected`;
+ const currentValue = this.data.projectList[projectIndex].groups[groupIndex].selected;
+
+ this.setData({
+ [key]: !currentValue
+ });
+
+ // 鏇存柊椤圭洰鎬绘椂闀�
+ this.updateProjectTotalDuration(projectIndex);
+ },
+
+ /**
+ * 澶勭悊鏃堕暱杈撳叆
+ */
+ onDurationInput: function (e) {
+ const {
+ groupIndex
+ } = e.currentTarget.dataset;
+ const duration = parseInt(e.detail.value) || 0;
+
+ const selectedProject = {
+ ...this.data.selectedProject
+ };
+ selectedProject.groups[groupIndex].duration = duration;
+
+ this.setData({
+ selectedProject
+ }, () => {
+ // 杈撳叆鏃堕暱鍚庨噸鏂拌绠楁�绘椂闂�
+ this.calculateTotalDuration();
+ });
+ },
+
+ /**
+ * 璁$畻骞舵洿鏂伴」鐩�绘椂闀�
+ */
+ updateProjectTotalDuration: function (projectIndex) {
+ const project = this.data.projectList[projectIndex];
+ let totalDuration = 0;
+
+ // 璁$畻鎵�鏈夐�変腑鐨勮疆鐏岀粍鐨勬椂闀挎�诲拰
+ project.groups.forEach(group => {
+ if (group.selected) {
+ totalDuration += parseInt(group.duration) || 0;
+ }
+ });
+
+ // 鏇存柊椤圭洰鎬绘椂闀�
+ const totalDurationKey = `projectList[${projectIndex}].totalDuration`;
+ this.setData({
+ [totalDurationKey]: totalDuration
+ });
+ },
+
+ /**
+ * 闃绘浜嬩欢鍐掓场
+ */
+ stopPropagation: function (e) {
+ if (e && e.stopPropagation) {
+ e.stopPropagation();
+ }
+ return false;
+ },
+
+ /**
+ * 璺宠浆鍒拌疆鐏岀粍璇︽儏椤�
+ */
+ navigateToGroupDetail: function (e) {
+ const {
+ groupIndex
+ } = e.currentTarget.dataset;
+ // TODO: 瀹炵幇璺宠浆閫昏緫
+ },
+
+ /**
+ * 纭鎸夐挳鐐瑰嚮浜嬩欢
+ */
+ onConfirm: function () {
+ const {
+ planCode,
+ startTime,
+ selectedProject
+ } = this.data;
+
+ if (!planCode) {
+ wx.showToast({
+ title: '璇疯緭鍏ヨ鍒掔紪鍙�',
+ icon: 'none'
+ });
+ return;
+ }
+
+ if (!selectedProject) {
+ wx.showToast({
+ title: '璇烽�夋嫨椤圭洰',
+ icon: 'none'
+ });
+ return;
+ }
+
+ // 鏋勫缓涓婃姤鏁版嵁
+ const schedules = selectedProject.groups.map(group => ({
+ groupId: group.id,
+ duration: parseInt(group.duration) || 0
+ }));
+
+ const requestData = {
+ projectId: selectedProject.id,
+ planName: planCode,
+ startupMode: startTime ? 2 : 1,
+ operatorId: app.globalData.clientId,
+ schedules: schedules
+ };
+
+ // 濡傛灉鏈夊紑濮嬫椂闂达紝娣诲姞鍒拌姹傛暟鎹腑
+ if (startTime) {
+ requestData.planStartTime = startTime;
+ }
+
+ // 鍙戦�佽姹�
+ post({
+ url: '/wx/plan/createPlan',
+ data: requestData,
+ isShowLoding: true
+ }).then(res => {
+ if (res.success) {
+ wx.showToast({
+ title: '鍒涘缓鎴愬姛',
+ icon: 'success'
+ });
+ // 杩斿洖涓婁竴椤碉紝骞朵紶閫掑弬鏁版寚绀洪渶瑕佸埛鏂板垪琛ㄥ苟鍒囨崲鍒板綋鍓嶈鍒掑垪琛�
+ setTimeout(() => {
+ // 浣跨敤鍏ㄥ眬鍙橀噺鏍囪闇�瑕佸埛鏂�
+ const app = getApp();
+ app.globalData.needRefreshIrrigationList = true;
+
+ // 鐩存帴杩斿洖涓婁竴椤�
+ wx.navigateBack({
+ delta: 1
+ });
+ }, 1500);
+ } else {
+ wx.showToast({
+ title: res.msg || '鍒涘缓澶辫触',
+ icon: 'none'
+ });
+ }
+ }).catch(err => {
+ console.error('鍒涘缓璁″垝澶辫触锛�', err);
+ wx.showToast({
+ title: '鍒涘缓澶辫触',
+ icon: 'none'
+ });
+ });
+ },
+
+ // 鏄剧ず椤圭洰閫夋嫨鍣�
+ showProjectPicker() {
+ this.fetchProjects(true)
+
+ },
+
+ // 椤圭洰閫夋嫨鍣ㄧ‘璁�
+ onProjectPickerConfirm(e) {
+ const {
+ value
+ } = e.detail;
+ console.log('閫夋嫨鐨勯」鐩甀D锛�', value[0]); // 娣诲姞鏃ュ織鏌ョ湅鏁版嵁
+ const selectedProject = this.data.projectList.find(project => project.id === value[0]);
+ console.log('鎵惧埌鐨勯」鐩細', selectedProject); // 娣诲姞鏃ュ織鏌ョ湅鏁版嵁
+
+ this.setData({
+ projectPickerVisible: false,
+ selectedProject: selectedProject,
+ projectPickerValue: value
+ }, () => {
+ // 閫夋嫨椤圭洰鍚庤幏鍙栬疆鐏岀粍鍒楄〃
+ if (selectedProject) {
+ this.fetchGroups(selectedProject.id);
+ }
+ });
+ },
+
+ // 椤圭洰閫夋嫨鍣ㄥ彇娑�
+ onProjectPickerCancel() {
+ this.setData({
+ projectPickerVisible: false
+ });
+ },
+
+ /**
+ * 璁$畻鎬荤亴婧夋椂闂�
+ */
+ calculateTotalDuration: function () {
+ if (!this.data.selectedProject) return;
+
+ const totalDuration = this.data.selectedProject.groups.reduce((sum, group) => {
+ return sum + (parseInt(group.duration) || 0);
+ }, 0);
+
+ this.setData({
+ totalDuration
+ });
+ },
+
+ /**
+ * 杞亴缁勫垪琛ㄤ笅鎷夊埛鏂�
+ */
+ onGroupListRefresh: function () {
+ if (!this.data.selectedProject) {
+ this.setData({
+ isRefreshing: false
+ });
+ return;
+ }
+
+ this.setData({
+ isRefreshing: true
+ });
+
+ this.fetchGroups(this.data.selectedProject.id)
+ .then(() => {
+ this.setData({
+ isRefreshing: false
+ });
+ })
+ .catch(() => {
+ this.setData({
+ isRefreshing: false
+ });
+ });
+ },
+
+ /**
+ * 鏄剧ず鏃堕棿鎻愮ず寮圭獥
+ */
+ showTimeInfo: function () {
+ this.setData({
+ timeInfoVisible: true
+ });
+ },
+
+ /**
+ * 鍏抽棴鏃堕棿鎻愮ず寮圭獥
+ */
+ onTimeInfoConfirm: function () {
+ this.setData({
+ timeInfoVisible: false
+ });
+ },
+});
\ No newline at end of file
--
Gitblit v1.8.0