From fe3ce21a469f7e2584dbcb85cb75022d149f436c Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期二, 25 三月 2025 19:28:56 +0800 Subject: [PATCH] 更新灌溉计划页面,添加项目选择器和总灌溉时间计算功能;优化界面样式,增加SVG图标;修复项目列表和轮灌组显示逻辑;调整配置文件,添加libVersion字段。 --- pages/createIrrigation/createIrrigation.js | 472 ++++++++++++++++------------------------------------------ 1 files changed, 134 insertions(+), 338 deletions(-) diff --git a/pages/createIrrigation/createIrrigation.js b/pages/createIrrigation/createIrrigation.js index c7e8053..ce7e83b 100644 --- a/pages/createIrrigation/createIrrigation.js +++ b/pages/createIrrigation/createIrrigation.js @@ -10,213 +10,78 @@ startTime: '', // 鐏屾簤寮�濮嬫椂闂� pickerValue: '', // 鏃堕棿閫夋嫨鍣ㄧ殑鍊� timePickerVisible: false, // 鏃堕棿閫夋嫨鍣ㄦ槸鍚﹀彲瑙� - - // 椤圭洰鍜岃疆鐏岀粍鏁版嵁 + // 椤圭洰閫夋嫨鍣ㄧ浉鍏� + projectPickerVisible: false, + projectPickerValue: [], + selectedProject: null, + projectOptions: [], + totalDuration: 0, // 娣诲姞鎬荤亴婧夋椂闂� + // 娴嬭瘯鏁版嵁 projectList: [ { - id: '1', - name: '椤圭洰涓�', - expanded: false, // 鏄惁灞曞紑 - totalDuration: 0, // 鎬绘椂闀� + id: 1, + name: '娴嬭瘯椤圭洰涓�', 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: 101, + name: '杞亴缁凙', + duration: 30, + selected: false + }, + { + id: 102, + name: '杞亴缁凚', + duration: 45, + selected: false + }, + { + id: 103, + name: '杞亴缁凜', + duration: 60, + selected: false + } ] }, { - id: '2', - name: '椤圭洰浜�', - expanded: false, - totalDuration: 0, + id: 2, + name: '娴嬭瘯椤圭洰浜�', groups: [ - { id: '2-1', name: '杞亴缁凙', selected: false, duration: 0 }, - { id: '2-2', name: '杞亴缁凚', selected: false, duration: 0 } + { + id: 201, + name: '杞亴缁�1', + duration: 40, + selected: false + }, + { + id: 202, + name: '杞亴缁�2', + duration: 50, + selected: false + } ] }, { - id: '4', - name: '椤圭洰涓�', - expanded: false, // 鏄惁灞曞紑 - totalDuration: 0, // 鎬绘椂闀� + id: 3, + name: '娴嬭瘯椤圭洰涓�', 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 } + { + id: 301, + name: '涓滃尯杞亴缁�', + duration: 35, + selected: false + }, + { + id: 302, + name: '瑗垮尯杞亴缁�', + duration: 55, + selected: false + }, + { + id: 303, + name: '鍗楀尯杞亴缁�', + duration: 25, + selected: false + } ] } ] @@ -226,8 +91,15 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad: function (options) { - // 椤甸潰鍔犺浇鏃跺彲浠ヤ粠API鑾峰彇椤圭洰鍜岃疆鐏岀粍鏁版嵁 - // this.fetchProjectsAndGroups(); + // 鍒濆鍖栭」鐩�夋嫨鍣ㄩ�夐」 + const projectOptions = this.data.projectList.map(project => ({ + label: project.name, + value: project.id + })); + + this.setData({ + projectOptions: projectOptions // 鐩存帴浣跨敤涓�缁存暟缁勶紝涓嶉渶瑕佸寘瑁呮垚浜岀淮鏁扮粍 + }); }, /** @@ -267,10 +139,10 @@ * 鏃堕棿閫夋嫨鍣ㄧ‘璁ゅ洖璋� */ onTimePickerConfirm: function (e) { + const { value } = e.detail; this.setData({ - startTime: e.detail.formatValue, - pickerValue: e.detail.value, - timePickerVisible: false + timePickerVisible: false, + startTime: value }); }, @@ -330,26 +202,18 @@ * 澶勭悊鏃堕暱杈撳叆 */ onDurationInput: function (e) { - const projectIndex = e.currentTarget.dataset.projectIndex; - const groupIndex = e.currentTarget.dataset.groupIndex; - const value = parseInt(e.detail.value) || 0; + const { groupIndex } = e.currentTarget.dataset; + const duration = parseInt(e.detail.value) || 0; - // 鏇存柊杞亴缁勬椂闀� - const durationKey = `projectList[${projectIndex}].groups[${groupIndex}].duration`; + 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); }, /** @@ -376,7 +240,7 @@ /** * 闃绘浜嬩欢鍐掓场 */ - stopPropagation: function (e) { + stopPropagation: function () { // 闃绘浜嬩欢鍐掓场锛岄槻姝㈢偣鍑昏緭鍏ユ鏃惰Е鍙戠埗鍏冪礌鐨勭偣鍑讳簨浠� }, @@ -384,155 +248,87 @@ * 璺宠浆鍒拌疆鐏岀粍璇︽儏椤� */ 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}` - }); + const { groupIndex } = e.currentTarget.dataset; + // TODO: 瀹炵幇璺宠浆閫昏緫 }, /** * 纭鎸夐挳鐐瑰嚮浜嬩欢 */ onConfirm: function () { - // 楠岃瘉琛ㄥ崟 - if (!this.validateForm()) { - return; - } + const { planCode, startTime, selectedProject } = this.data; - // 鏀堕泦閫変腑鐨勮疆鐏岀粍 - const selectedGroups = this.getSelectedGroups(); - - // 鏋勫缓鎻愪氦鏁版嵁 - const formData = { - planCode: this.data.planCode, - startTime: this.data.startTime, - groups: selectedGroups - }; - - // 鎻愪氦鏁版嵁 - this.submitForm(formData); - }, - - /** - * 楠岃瘉琛ㄥ崟 - */ - validateForm: function () { - if (!this.data.planCode) { + if (!planCode) { wx.showToast({ title: '璇疯緭鍏ヨ鍒掔紪鍙�', icon: 'none' }); - return false; + return; } - if (!this.data.startTime) { + if (!startTime) { wx.showToast({ title: '璇烽�夋嫨鐏屾簤寮�濮嬫椂闂�', icon: 'none' }); - return false; + return; } - const selectedGroups = this.getSelectedGroups(); - if (selectedGroups.length === 0) { + if (!selectedProject) { wx.showToast({ - title: '璇疯嚦灏戦�夋嫨涓�涓疆鐏岀粍', + title: '璇烽�夋嫨椤圭洰', icon: 'none' }); - return false; + return; } - - // 妫�鏌ラ�変腑鐨勮疆鐏岀粍鏄惁閮借缃簡鏃堕暱 - const invalidGroups = selectedGroups.filter(group => !group.duration); - if (invalidGroups.length > 0) { - wx.showToast({ - title: '璇蜂负鎵�鏈夐�変腑鐨勮疆鐏岀粍璁剧疆鏃堕暱', - icon: 'none' - }); - return false; - } - - return true; + + // TODO: 瀹炵幇纭閫昏緫 + console.log('鎻愪氦鏁版嵁锛�', { + planCode, + startTime, + project: selectedProject + }); }, - /** - * 鑾峰彇閫変腑鐨勮疆鐏岀粍 - */ - 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 - }); - } - }); + // 鏄剧ず椤圭洰閫夋嫨鍣� + showProjectPicker() { + this.setData({ + projectPickerVisible: true }); - - return selectedGroups; }, - /** - * 鎻愪氦琛ㄥ崟鏁版嵁 - */ - submitForm: function (formData) { - // 杩欓噷鍙互娣诲姞API璇锋眰閫昏緫锛屾彁浜よ〃鍗曟暟鎹� - console.log('鎻愪氦鐨勮〃鍗曟暟鎹�:', formData); + // 椤圭洰閫夋嫨鍣ㄧ‘璁� + onProjectPickerConfirm(e) { + const { value } = e.detail; + const selectedProject = this.data.projectList.find(project => project.id === value[0]); - // 妯℃嫙API璇锋眰 - wx.showLoading({ - title: '鎻愪氦涓�...', + this.setData({ + projectPickerVisible: false, + selectedProject: selectedProject, + projectPickerValue: value + }, () => { + // 閫夋嫨椤圭洰鍚庤绠楁�绘椂闂� + this.calculateTotalDuration(); }); + }, + + // 椤圭洰閫夋嫨鍣ㄥ彇娑� + onProjectPickerCancel() { + this.setData({ + projectPickerVisible: false + }); + }, + + // 璁$畻鎬荤亴婧夋椂闂� + calculateTotalDuration() { + if (!this.data.selectedProject) return; - setTimeout(() => { - wx.hideLoading(); - - wx.showToast({ - title: '鍒涘缓鎴愬姛', - icon: 'success', - duration: 2000, - success: () => { - // 寤惰繜杩斿洖涓婁竴椤� - setTimeout(() => { - wx.navigateBack(); - }, 2000); - } - }); - }, 1500); + const totalDuration = this.data.selectedProject.groups.reduce((sum, group) => { + return sum + (parseInt(group.duration) || 0); + }, 0); - // 瀹為檯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' - // }); - // } - // }); - } + this.setData({ + totalDuration + }); + }, }); \ No newline at end of file -- Gitblit v1.8.0