From 50433e86b718fab0d94ea1410724b29b5f53fa0a Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期三, 09 四月 2025 15:11:26 +0800 Subject: [PATCH] 更新SVG图标样式,优化灌溉计划和取水口页面逻辑,添加状态处理和信息提示功能;调整界面样式,提升用户体验。 --- pages/createIrrigation/createIrrigation.js | 944 ++++++++++++++++++++++++++-------------------------------- 1 files changed, 428 insertions(+), 516 deletions(-) diff --git a/pages/createIrrigation/createIrrigation.js b/pages/createIrrigation/createIrrigation.js index c7e8053..6a77e38 100644 --- a/pages/createIrrigation/createIrrigation.js +++ b/pages/createIrrigation/createIrrigation.js @@ -1,538 +1,450 @@ const app = getApp(); +const { get, post } = require('../../api/request'); +const dayjs = require('dayjs'); Page({ - /** - * 椤甸潰鐨勫垵濮嬫暟鎹� - */ - data: { - // 琛ㄥ崟鏁版嵁 - planCode: '', // 璁″垝缂栧彿 - 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 } - ] - } - ] - }, + /** + * 椤甸潰鐨勫垵濮嬫暟鎹� + */ + data: { + // 琛ㄥ崟鏁版嵁 + planCode: '', // 璁″垝缂栧彿 + startTime: '', // 鐏屾簤寮�濮嬫椂闂� + pickerValue: '', // 鏃堕棿閫夋嫨鍣ㄧ殑鍊� + timePickerVisible: false, // 鏃堕棿閫夋嫨鍣ㄦ槸鍚﹀彲瑙� + timeInfoVisible: false, // 鏃堕棿鎻愮ず寮圭獥鏄惁鍙 + // 椤圭洰閫夋嫨鍣ㄧ浉鍏� + projectPickerVisible: false, + projectPickerValue: [], + selectedProject: null, + projectOptions: [], + totalDuration: 0, // 娣诲姞鎬荤亴婧夋椂闂� + // 椤圭洰鍒楄〃 + projectList: [], + // 鏃堕棿閫夋嫨鍣ㄩ�夐」 + timeOptions: [], + // 杞亴缁勫垪琛ㄥ埛鏂扮姸鎬� + isRefreshing: false + }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 - */ - onLoad: function (options) { - // 椤甸潰鍔犺浇鏃跺彲浠ヤ粠API鑾峰彇椤圭洰鍜岃疆鐏岀粍鏁版嵁 - // this.fetchProjectsAndGroups(); - }, + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 + */ + onLoad: function (options) { + // 鐢熸垚璁″垝缂栧彿 + this.generatePlanCode(); + // 璁剧疆鏃堕棿閫夋嫨鍣ㄧ殑鍒濆鍊� + const now = dayjs(); + this.setData({ + pickerValue: now.add(8.5, 'hour').format('YYYY-MM-DD HH:mm') + }); + // 鑾峰彇椤圭洰鍒楄〃 + this.fetchProjects(); + }, - /** - * 鑾峰彇椤圭洰鍜岃疆鐏岀粍鏁版嵁 - */ - fetchProjectsAndGroups: function () { - // 杩欓噷鍙互娣诲姞API璇锋眰閫昏緫锛岃幏鍙栫湡瀹炴暟鎹� - // wx.request({ - // url: 'your-api-url', - // success: (res) => { - // this.setData({ - // projectList: res.data - // }); - // } - // }); - }, + /** + * 鐢熸垚璁″垝缂栧彿 + */ + 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 }); + }, - /** - * 澶勭悊璁″垝缂栧彿杈撳叆 - */ - onPlanCodeInput: function (e) { - this.setData({ - planCode: e.detail.value - }); - }, + /** + * 鑾峰彇椤圭洰鍒楄〃 + */ + 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: [] + })); - /** - * 鏄剧ず鏃堕棿閫夋嫨鍣� - */ - showTimePicker: function () { - this.setData({ - timePickerVisible: true - }); - }, + const projectOptions = projectList.map(project => ({ + label: project.name, + value: project.id + })); - /** - * 鏃堕棿閫夋嫨鍣ㄧ‘璁ゅ洖璋� - */ - onTimePickerConfirm: function (e) { - this.setData({ - startTime: e.detail.formatValue, - pickerValue: e.detail.value, - timePickerVisible: false - }); - }, + 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); + }); + }, - /** - * 鏃堕棿閫夋嫨鍣ㄥ彇娑堝洖璋� - */ - onTimePickerCancel: function () { - this.setData({ - timePickerVisible: false - }); - }, + /** + * 鑾峰彇杞亴缁勫垪琛� + */ + fetchGroups: function (projectId) { + return get({ + url: '/wx/irrigation/getSimpleGroups', + data: { + projectId: projectId, + }, + isShowLoding: true + }).then(res => { + if (res.success) { + console.log('杞亴缁勬暟鎹細', res.content.obj); - /** - * 鍒囨崲椤圭洰灞曞紑/鎶樺彔鐘舵�� - */ - 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 - }); - }, + // 鏇存柊閫変腑椤圭洰鐨勮疆鐏岀粍淇℃伅 + 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; + }); - /** - * 鍒囨崲杞亴缁勯�変腑鐘舵�� - */ - 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); - }, + // 鏇存柊閫変腑鐨勯」鐩� + const selectedProject = projectList.find(project => project.id === projectId); + console.log('鏇存柊鍚庣殑閫変腑椤圭洰锛�', selectedProject); - /** - * 澶勭悊鏃堕暱杈撳叆 - */ - 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`; - this.setData({ - [durationKey]: value - }); - - // 鑷姩閫変腑璇ヨ疆鐏岀粍 - const selectedKey = `projectList[${projectIndex}].groups[${groupIndex}].selected`; - if (value > 0 && !this.data.projectList[projectIndex].groups[groupIndex].selected) { - this.setData({ - [selectedKey]: true - }); - } - - // 璁$畻骞舵洿鏂伴」鐩�绘椂闀� - this.updateProjectTotalDuration(projectIndex); - }, + 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); + }); + }, - /** - * 璁$畻骞舵洿鏂伴」鐩�绘椂闀� - */ - 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 - }); - }, + /** + * 鏄剧ず鏃堕棿閫夋嫨鍣� + */ + showTimePicker: function () { + // 濡傛灉娌℃湁閫夋嫨鏃堕棿锛屼娇鐢ㄥ綋鍓嶆椂闂� + if (!this.data.pickerValue) { + const now = dayjs(); + this.setData({ + pickerValue: now.format('YYYY-MM-DD HH:mm') + }); + } - /** - * 闃绘浜嬩欢鍐掓场 - */ - stopPropagation: function (e) { - // 闃绘浜嬩欢鍐掓场锛岄槻姝㈢偣鍑昏緭鍏ユ鏃惰Е鍙戠埗鍏冪礌鐨勭偣鍑讳簨浠� - }, + this.setData({ + timePickerVisible: true + }); + }, - /** - * 璺宠浆鍒拌疆鐏岀粍璇︽儏椤� - */ - 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]; - - wx.navigateTo({ - url: `/pages/groupDetail/groupDetail?projectId=${project.id}&projectName=${project.name}&groupId=${group.id}&groupName=${group.name}` - }); - }, + /** + * 鏃堕棿閫夋嫨鍣ㄧ‘璁ゅ洖璋� + */ + onTimePickerConfirm: function (e) { + const { value } = e.detail; + this.setData({ + timePickerVisible: false, + startTime: value + }); + }, - /** - * 纭鎸夐挳鐐瑰嚮浜嬩欢 - */ - 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); - }, + /** + * 鏃堕棿閫夋嫨鍣ㄥ彇娑堝洖璋� + */ + onTimePickerCancel: function () { + this.setData({ + timePickerVisible: false + }); + }, - /** - * 楠岃瘉琛ㄥ崟 - */ - validateForm: function () { - if (!this.data.planCode) { - wx.showToast({ - title: '璇疯緭鍏ヨ鍒掔紪鍙�', - icon: 'none' - }); - return false; - } - - 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; - }, + /** + * 鍒囨崲椤圭洰灞曞紑/鎶樺彔鐘舵�� + */ + toggleProject: function (e) { + const index = e.currentTarget.dataset.index; + const currentValue = this.data.projectList[index].expanded; - /** - * 鑾峰彇閫変腑鐨勮疆鐏岀粍 - */ - getSelectedGroups: function () { - const selectedGroups = []; - - this.data.projectList.forEach(project => { - project.groups.forEach(group => { - if (group.selected) { - selectedGroups.push({ - projectId: project.id, - projectName: project.name, + // 鍒涘缓鏂扮殑椤圭洰鍒楄〃锛屽厛灏嗘墍鏈夐」鐩涓烘姌鍙犵姸鎬� + 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, - groupName: group.name, - duration: group.duration - }); - } - }); - }); - - return selectedGroups; - }, + duration: parseInt(group.duration) || 0 + })); - /** - * 鎻愪氦琛ㄥ崟鏁版嵁 - */ - submitForm: function (formData) { - // 杩欓噷鍙互娣诲姞API璇锋眰閫昏緫锛屾彁浜よ〃鍗曟暟鎹� - console.log('鎻愪氦鐨勮〃鍗曟暟鎹�:', formData); - - // 妯℃嫙API璇锋眰 - wx.showLoading({ - title: '鎻愪氦涓�...', - }); - - setTimeout(() => { - wx.hideLoading(); - - wx.showToast({ - title: '鍒涘缓鎴愬姛', - icon: 'success', - duration: 2000, - success: () => { - // 寤惰繜杩斿洖涓婁竴椤� - setTimeout(() => { - wx.navigateBack(); - }, 2000); + const requestData = { + projectId: selectedProject.id, + planName: planCode, + startupMode: startTime ? 2 : 1, + operatorId: app.globalData.clientId, + schedules: schedules + }; + + // 濡傛灉鏈夊紑濮嬫椂闂达紝娣诲姞鍒拌姹傛暟鎹腑 + if (startTime) { + requestData.planStartTime = startTime; } - }); - }, 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' - // }); - // } - // }); - } + + // 鍙戦�佽姹� + 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({ + 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 + }); + }, + + /** + * 鍏抽棴鏃堕棿鎻愮ず寮圭獥 + */ + onTimeInfoConfirm: function () { + this.setData({ + timeInfoVisible: false + }); + }, }); \ No newline at end of file -- Gitblit v1.8.0