From 61e89d748cc7f5456c20866e672a4bde153534f1 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期一, 21 四月 2025 17:18:53 +0800
Subject: [PATCH] 优化项目配置,重构项目URL管理逻辑,改为使用动态配置;更新灌溉组详情页面,添加详细信息展示和请求逻辑,提升用户体验;更新首页项目选择器,支持动态项目列表展示。
---
pages/createIrrigation/createIrrigation.js | 745 +++++++++++++++++++++++++++------------------------------
1 files changed, 355 insertions(+), 390 deletions(-)
diff --git a/pages/createIrrigation/createIrrigation.js b/pages/createIrrigation/createIrrigation.js
index c7e8053..14c2a4c 100644
--- a/pages/createIrrigation/createIrrigation.js
+++ b/pages/createIrrigation/createIrrigation.js
@@ -1,4 +1,9 @@
const app = getApp();
+const {
+ get,
+ post
+} = require('../../api/request');
+const dayjs = require('dayjs');
Page({
/**
@@ -10,247 +15,152 @@
startTime: '', // 鐏屾簤寮�濮嬫椂闂�
pickerValue: '', // 鏃堕棿閫夋嫨鍣ㄧ殑鍊�
timePickerVisible: false, // 鏃堕棿閫夋嫨鍣ㄦ槸鍚﹀彲瑙�
-
- // 椤圭洰鍜岃疆鐏岀粍鏁版嵁
- projectList: [
- {
- id: '1',
- name: '椤圭洰涓�',
- expanded: false, // 鏄惁灞曞紑
- totalDuration: 0, // 鎬绘椂闀�
- groups: [
- { id: '1-1', name: '杞亴缁�1', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 }
- ]
- },
- {
- id: '2',
- name: '椤圭洰浜�',
- expanded: false,
- totalDuration: 0,
- groups: [
- { id: '2-1', name: '杞亴缁凙', selected: false, duration: 0 },
- { id: '2-2', name: '杞亴缁凚', selected: false, duration: 0 }
- ]
- },
- {
- id: '4',
- name: '椤圭洰涓�',
- expanded: false, // 鏄惁灞曞紑
- totalDuration: 0, // 鎬绘椂闀�
- groups: [
- { id: '1-1', name: '杞亴缁�1', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 }
- ]
- },
- {
- id: '5',
- name: '椤圭洰涓�',
- expanded: false, // 鏄惁灞曞紑
- totalDuration: 0, // 鎬绘椂闀�
- groups: [
- { id: '1-1', name: '杞亴缁�1', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 }
- ]
- },
- {
- id: '6',
- name: '椤圭洰涓�',
- expanded: false, // 鏄惁灞曞紑
- totalDuration: 0, // 鎬绘椂闀�
- groups: [
- { id: '1-1', name: '杞亴缁�1', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 }
- ]
- },
- {
- id: '7',
- name: '椤圭洰涓�',
- expanded: false, // 鏄惁灞曞紑
- totalDuration: 0, // 鎬绘椂闀�
- groups: [
- { id: '1-1', name: '杞亴缁�1', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 }
- ]
- },
- {
- id: '8',
- name: '椤圭洰8',
- expanded: false, // 鏄惁灞曞紑
- totalDuration: 0, // 鎬绘椂闀�
- groups: [
- { id: '1-1', name: '杞亴缁�1', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 },
- { id: '1-2', name: '杞亴缁�2', selected: false, duration: 0 },
- { id: '1-3', name: '杞亴缁�3', selected: false, duration: 0 }
- ]
- },
- {
- id: '3',
- name: '椤圭洰3',
- expanded: false,
- totalDuration: 0,
- groups: [
- { id: '3-1', name: '杞亴缁刋', selected: false, duration: 0 },
- { id: '3-2', name: '杞亴缁刌', selected: false, duration: 0 },
- { id: '3-3', name: '杞亴缁刏', selected: false, duration: 0 }
- ]
- },
- {
- id: '9',
- name: '椤圭洰9',
- expanded: false,
- totalDuration: 0,
- groups: [
- { id: '3-1', name: '杞亴缁刋', selected: false, duration: 0 },
- { id: '3-2', name: '杞亴缁刌', selected: false, duration: 0 },
- { id: '3-3', name: '杞亴缁刏', selected: false, duration: 0 }
- ]
- }
- ,
- {
- id: '10',
- name: '椤圭洰10',
- expanded: false,
- totalDuration: 0,
- groups: [
- { id: '3-1', name: '杞亴缁刋', selected: false, duration: 0 },
- { id: '3-2', name: '杞亴缁刌', selected: false, duration: 0 },
- { id: '3-3', name: '杞亴缁刏', selected: false, duration: 0 }
- ]
- }
- ,
- {
- id: '11',
- name: '椤圭洰11',
- expanded: false,
- totalDuration: 0,
- groups: [
- { id: '3-1', name: '杞亴缁刋', selected: false, duration: 0 },
- { id: '3-2', name: '杞亴缁刌', selected: false, duration: 0 },
- { id: '3-3', name: '杞亴缁刏', selected: false, duration: 0 }
- ]
- }
- ]
+ timeInfoVisible: false, // 鏃堕棿鎻愮ず寮圭獥鏄惁鍙
+ // 椤圭洰閫夋嫨鍣ㄧ浉鍏�
+ projectPickerVisible: false,
+ projectPickerValue: [],
+ selectedProject: null,
+ projectOptions: [],
+ totalDuration: 0, // 娣诲姞鎬荤亴婧夋椂闂�
+ // 椤圭洰鍒楄〃
+ projectList: [],
+ // 鏃堕棿閫夋嫨鍣ㄩ�夐」
+ timeOptions: [],
+ // 杞亴缁勫垪琛ㄥ埛鏂扮姸鎬�
+ isRefreshing: false
},
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
*/
onLoad: function (options) {
- // 椤甸潰鍔犺浇鏃跺彲浠ヤ粠API鑾峰彇椤圭洰鍜岃疆鐏岀粍鏁版嵁
- // this.fetchProjectsAndGroups();
- },
-
- /**
- * 鑾峰彇椤圭洰鍜岃疆鐏岀粍鏁版嵁
- */
- fetchProjectsAndGroups: function () {
- // 杩欓噷鍙互娣诲姞API璇锋眰閫昏緫锛岃幏鍙栫湡瀹炴暟鎹�
- // wx.request({
- // url: 'your-api-url',
- // success: (res) => {
- // this.setData({
- // projectList: res.data
- // });
- // }
- // });
- },
-
- /**
- * 澶勭悊璁″垝缂栧彿杈撳叆
- */
- onPlanCodeInput: function (e) {
+ // 鐢熸垚璁″垝缂栧彿
+ this.generatePlanCode();
+ // 璁剧疆鏃堕棿閫夋嫨鍣ㄧ殑鍒濆鍊�
+ const now = dayjs();
this.setData({
- planCode: e.detail.value
+ pickerValue: now.add(8.5, 'hour').format('YYYY-MM-DD HH:mm')
+ });
+ // 鑾峰彇椤圭洰鍒楄〃
+ this.fetchProjects();
+ },
+
+ /**
+ * 鐢熸垚璁″垝缂栧彿
+ */
+ 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 (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 projectOptions = projectList.map(project => ({
+ label: project.name,
+ value: project.id
+ }));
+
+ this.setData({
+ projectList,
+ projectOptions
+ });
+ if (isShowDiaolog) {
+ this.setData({
+ projectPickerVisible: 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);
+ });
+ },
+
+ /**
+ * 鑾峰彇杞亴缁勫垪琛�
+ */
+ 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;
+ });
+
+ // 鏇存柊閫変腑鐨勯」鐩�
+ 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);
});
},
@@ -258,6 +168,14 @@
* 鏄剧ず鏃堕棿閫夋嫨鍣�
*/
showTimePicker: function () {
+ // 濡傛灉娌℃湁閫夋嫨鏃堕棿锛屼娇鐢ㄥ綋鍓嶆椂闂�
+ if (!this.data.pickerValue) {
+ const now = dayjs();
+ this.setData({
+ pickerValue: now.format('YYYY-MM-DD HH:mm')
+ });
+ }
+
this.setData({
timePickerVisible: true
});
@@ -267,10 +185,12 @@
* 鏃堕棿閫夋嫨鍣ㄧ‘璁ゅ洖璋�
*/
onTimePickerConfirm: function (e) {
+ const {
+ value
+ } = e.detail;
this.setData({
- startTime: e.detail.formatValue,
- pickerValue: e.detail.value,
- timePickerVisible: false
+ timePickerVisible: false,
+ startTime: value
});
},
@@ -289,7 +209,7 @@
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 {
@@ -297,13 +217,13 @@
expanded: false
};
});
-
+
// 濡傛灉褰撳墠鐐瑰嚮鐨勯」鐩凡缁忔槸灞曞紑鐘舵�侊紝鍒欎繚鎸佹墍鏈夐」鐩姌鍙�
// 鍚﹀垯锛屽皢褰撳墠鐐瑰嚮鐨勯」鐩涓哄睍寮�鐘舵��
if (!currentValue) {
newProjectList[index].expanded = true;
}
-
+
this.setData({
projectList: newProjectList
});
@@ -317,11 +237,11 @@
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);
},
@@ -330,26 +250,22 @@
* 澶勭悊鏃堕暱杈撳叆
*/
onDurationInput: function (e) {
- const projectIndex = e.currentTarget.dataset.projectIndex;
- const groupIndex = e.currentTarget.dataset.groupIndex;
- const value = parseInt(e.detail.value) || 0;
-
- // 鏇存柊杞亴缁勬椂闀�
- const durationKey = `projectList[${projectIndex}].groups[${groupIndex}].duration`;
+ const {
+ groupIndex
+ } = e.currentTarget.dataset;
+ const duration = parseInt(e.detail.value) || 0;
+
+ const selectedProject = {
+ ...this.data.selectedProject
+ };
+ selectedProject.groups[groupIndex].duration = duration;
+
this.setData({
- [durationKey]: value
+ selectedProject
+ }, () => {
+ // 杈撳叆鏃堕暱鍚庨噸鏂拌绠楁�绘椂闂�
+ this.calculateTotalDuration();
});
-
- // 鑷姩閫変腑璇ヨ疆鐏岀粍
- const selectedKey = `projectList[${projectIndex}].groups[${groupIndex}].selected`;
- if (value > 0 && !this.data.projectList[projectIndex].groups[groupIndex].selected) {
- this.setData({
- [selectedKey]: true
- });
- }
-
- // 璁$畻骞舵洿鏂伴」鐩�绘椂闀�
- this.updateProjectTotalDuration(projectIndex);
},
/**
@@ -358,14 +274,14 @@
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({
@@ -377,20 +293,34 @@
* 闃绘浜嬩欢鍐掓场
*/
stopPropagation: function (e) {
- // 闃绘浜嬩欢鍐掓场锛岄槻姝㈢偣鍑昏緭鍏ユ鏃惰Е鍙戠埗鍏冪礌鐨勭偣鍑讳簨浠�
+ if (e && e.stopPropagation) {
+ e.stopPropagation();
+ }
+ return false;
},
/**
* 璺宠浆鍒拌疆鐏岀粍璇︽儏椤�
*/
navigateToGroupDetail: function (e) {
- const projectIndex = e.currentTarget.dataset.projectIndex;
- const groupIndex = e.currentTarget.dataset.groupIndex;
- const project = this.data.projectList[projectIndex];
- const group = project.groups[groupIndex];
+ const { groupIndex } = e.currentTarget.dataset;
+ const group = this.data.selectedProject.groups[groupIndex];
+ // 鏋勫缓URL鍙傛暟
+ const params = {
+ projectName: this.data.selectedProject.name,
+ groupName: group.name,
+ groupId: group.id
+ };
+
+ // 鏋勫缓URL鏌ヨ瀛楃涓�
+ const queryString = Object.keys(params)
+ .map(key => `${key}=${encodeURIComponent(params[key])}`)
+ .join('&');
+
+ // 璺宠浆鍒拌疆鐏岀粍璇︽儏椤�
wx.navigateTo({
- url: `/pages/groupDetail/groupDetail?projectId=${project.id}&projectName=${project.name}&groupId=${group.id}&groupName=${group.name}`
+ url: `/pages/groupDetail/groupDetail?${queryString}`
});
},
@@ -398,141 +328,176 @@
* 纭鎸夐挳鐐瑰嚮浜嬩欢
*/
onConfirm: function () {
- // 楠岃瘉琛ㄥ崟
- if (!this.validateForm()) {
- return;
- }
-
- // 鏀堕泦閫変腑鐨勮疆鐏岀粍
- const selectedGroups = this.getSelectedGroups();
-
- // 鏋勫缓鎻愪氦鏁版嵁
- const formData = {
- planCode: this.data.planCode,
- startTime: this.data.startTime,
- groups: selectedGroups
- };
-
- // 鎻愪氦鏁版嵁
- this.submitForm(formData);
- },
+ const {
+ planCode,
+ startTime,
+ selectedProject
+ } = this.data;
- /**
- * 楠岃瘉琛ㄥ崟
- */
- validateForm: function () {
- if (!this.data.planCode) {
+ if (!planCode) {
wx.showToast({
title: '璇疯緭鍏ヨ鍒掔紪鍙�',
icon: 'none'
});
- return false;
+ return;
}
-
- if (!this.data.startTime) {
- wx.showToast({
- title: '璇烽�夋嫨鐏屾簤寮�濮嬫椂闂�',
- icon: 'none'
- });
- return false;
- }
-
- const selectedGroups = this.getSelectedGroups();
- if (selectedGroups.length === 0) {
- wx.showToast({
- title: '璇疯嚦灏戦�夋嫨涓�涓疆鐏岀粍',
- icon: 'none'
- });
- return false;
- }
-
- // 妫�鏌ラ�変腑鐨勮疆鐏岀粍鏄惁閮借缃簡鏃堕暱
- const invalidGroups = selectedGroups.filter(group => !group.duration);
- if (invalidGroups.length > 0) {
- wx.showToast({
- title: '璇蜂负鎵�鏈夐�変腑鐨勮疆鐏岀粍璁剧疆鏃堕暱',
- icon: 'none'
- });
- return false;
- }
-
- return true;
- },
- /**
- * 鑾峰彇閫変腑鐨勮疆鐏岀粍
- */
- getSelectedGroups: function () {
- const selectedGroups = [];
-
- this.data.projectList.forEach(project => {
- project.groups.forEach(group => {
- if (group.selected) {
- selectedGroups.push({
- projectId: project.id,
- projectName: project.name,
- groupId: group.id,
- groupName: group.name,
- duration: group.duration
+ 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'
});
});
-
- return selectedGroups;
+ },
+
+ // 鏄剧ず椤圭洰閫夋嫨鍣�
+ 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
+ });
},
/**
- * 鎻愪氦琛ㄥ崟鏁版嵁
+ * 璁$畻鎬荤亴婧夋椂闂�
*/
- submitForm: function (formData) {
- // 杩欓噷鍙互娣诲姞API璇锋眰閫昏緫锛屾彁浜よ〃鍗曟暟鎹�
- console.log('鎻愪氦鐨勮〃鍗曟暟鎹�:', formData);
-
- // 妯℃嫙API璇锋眰
- wx.showLoading({
- title: '鎻愪氦涓�...',
+ 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
});
-
- setTimeout(() => {
- wx.hideLoading();
-
- wx.showToast({
- title: '鍒涘缓鎴愬姛',
- icon: 'success',
- duration: 2000,
- success: () => {
- // 寤惰繜杩斿洖涓婁竴椤�
- setTimeout(() => {
- wx.navigateBack();
- }, 2000);
- }
+ },
+
+ /**
+ * 杞亴缁勫垪琛ㄤ笅鎷夊埛鏂�
+ */
+ onGroupListRefresh: function () {
+ if (!this.data.selectedProject) {
+ this.setData({
+ isRefreshing: false
});
- }, 1500);
-
- // 瀹為檯API璇锋眰绀轰緥
- // wx.request({
- // url: 'your-api-url',
- // method: 'POST',
- // data: formData,
- // success: (res) => {
- // wx.showToast({
- // title: '鍒涘缓鎴愬姛',
- // icon: 'success',
- // duration: 2000,
- // success: () => {
- // setTimeout(() => {
- // wx.navigateBack();
- // }, 2000);
- // }
- // });
- // },
- // fail: (err) => {
- // wx.showToast({
- // title: '鍒涘缓澶辫触锛岃閲嶈瘯',
- // icon: 'none'
- // });
- // }
- // });
- }
-});
\ No newline at end of file
+ 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