From 50433e86b718fab0d94ea1410724b29b5f53fa0a Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期三, 09 四月 2025 15:11:26 +0800 Subject: [PATCH] 更新SVG图标样式,优化灌溉计划和取水口页面逻辑,添加状态处理和信息提示功能;调整界面样式,提升用户体验。 --- pages/irrigationDetail/irrigationDetail.js | 353 +++++++++++++++++++++------------------------------------- 1 files changed, 131 insertions(+), 222 deletions(-) diff --git a/pages/irrigationDetail/irrigationDetail.js b/pages/irrigationDetail/irrigationDetail.js index 5b4907b..597a4c7 100644 --- a/pages/irrigationDetail/irrigationDetail.js +++ b/pages/irrigationDetail/irrigationDetail.js @@ -4,249 +4,144 @@ */ data: { planCode: '', + projectName: '', startTime: '', - projects: [], - isRefreshing: false, // 涓嬫媺鍒锋柊鐘舵�� - planId: '' // 淇濆瓨璁″垝ID + stopTime: '', + isRefreshing: false, + groupList: [], + planId: '', + planStatusText: '', + planStatusClass: '' }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad: function (options) { - if (options.id) { + if (options.planId) { this.setData({ - planId: options.id + planId: options.planId }); - // 浠庡垪琛ㄩ〉闈㈣繘鍏ユ椂锛屾墍鏈夐」鐩粯璁ゆ敹璧� - const fromListPage = options.fromList === 'true'; - this.loadIrrigationDetail(options.id, !fromListPage); + this.fetchIrrigationData(options.planId); + } else { + wx.showToast({ + title: '缂哄皯璁″垝ID', + icon: 'none' + }); + setTimeout(() => { + wx.navigateBack(); + }, 1500); } }, /** - * 鍔犺浇鐏屾簤璁″垝璇︽儏 - * @param {string} id 鐏屾簤璁″垝ID - * @param {boolean} isFirstLoad 鏄惁棣栨鍔犺浇 + * 鑾峰彇鐏屾簤璁″垝鏁版嵁 */ - loadIrrigationDetail: function (id, isFirstLoad = false) { - // 寮�濮嬪姞杞斤紝璁剧疆鍒锋柊鐘舵�� - this.setData({ - isRefreshing: true - }); - - // 淇濆瓨褰撳墠椤圭洰鐨勫睍寮�鐘舵�� - const currentExpandStates = {}; - if (!isFirstLoad && this.data.projects.length > 0) { - this.data.projects.forEach((project, index) => { - currentExpandStates[project.id] = project.expanded; + fetchIrrigationData: function(planId) { + const { get } = require('../../api/request'); + + const data = { + planId: planId || this.data.planId, + }; + + get({ + url: 'wx/plan/getPublishResults', + isShowLoding: true, + useParams: true, + data: data + }).then(res => { + if (res.success) { + this.processIrrigationData(res.content); + } else { + wx.showToast({ + title: res.msg || '鑾峰彇鏁版嵁澶辫触', + icon: 'none' + }); + } + }).catch(err => { + console.error('璇锋眰澶辫触锛�', err); + wx.showToast({ + title: '璇锋眰澶辫触', + icon: 'none' }); - } + }); + }, - // 杩欓噷搴旇鏄粠API鑾峰彇鏁版嵁 - // 浠ヤ笅鏄ā鎷熸暟鎹� - const mockData = { - planCode: 'IRG20240317001', - startTime: '2024-03-17 08:00', - projects: [ - { - id: 1, - name: '椤圭洰A', - expanded: isFirstLoad ? true : false, // 浠呭湪闈炲垪琛ㄩ〉杩涘叆涓旈娆″姞杞芥椂灞曞紑绗竴涓」鐩� - groups: [ - { - id: 1, - name: '杞亴缁凙-1', - status: 'irrigated', // 宸茬亴婧� - statusText: '宸茬亴婧�', - startTime: '2024-03-17 08:00', - endTime: '2024-03-17 09:30', - duration: 90 - }, - { - id: 2, - name: '杞亴缁凙-2', - status: 'irrigating', // 姝e湪鐏屾簤 - statusText: '姝e湪鐏屾簤', - startTime: '2024-03-17 09:30', - endTime: '2024-03-17 11:00', - duration: 90 - } - ] - }, - { - id: 2, - name: '椤圭洰B', - expanded: false, - groups: [ - { - id: 3, - name: '杞亴缁凚-1', - status: 'waiting', // 鏈亴婧� - statusText: '鏈亴婧�', - startTime: '2024-03-17 11:00', - endTime: '2024-03-17 12:30', - duration: 90 - }, - { - id: 4, - name: '杞亴缁凚-2', - status: 'waiting', // 鏈亴婧� - statusText: '鏈亴婧�', - startTime: '2024-03-17 12:30', - endTime: '2024-03-17 14:00', - duration: 90 - } - ] - }, - { - id: 3, - name: '椤圭洰C', - expanded: false, - groups: [ - { - id: 5, - name: '杞亴缁凜-1', - status: 'waiting', // 鏈亴婧� - statusText: '鏈亴婧�', - startTime: '2024-03-17 14:00', - endTime: '2024-03-17 15:30', - duration: 90 - } - ] - } - ] + /** + * 澶勭悊鎺ュ彛杩斿洖鐨勬暟鎹� + */ + processIrrigationData: function(data) { + console.log('鐏屾簤璁″垝璇︽儏鏁版嵁锛�', data); + + // 澶勭悊杞亴缁勭姸鎬� + const statusMap = { + 2: {status: 'pending', statusText: '鏈紑濮�'}, + 3: {status: 'in_progress', statusText: '鐏屾簤涓�'}, + 4: {status: 'completed', statusText: '宸茬粨鏉�'} }; - // 璁$畻姣忎釜椤圭洰鐨勬�荤亴婧夋椂闀� - mockData.projects = this.calculateProjectTotalDuration(mockData.projects); - - // 濡傛灉涓嶆槸棣栨鍔犺浇锛屾仮澶嶉」鐩殑灞曞紑鐘舵�� - if (!isFirstLoad) { - mockData.projects.forEach(project => { - if (currentExpandStates[project.id] !== undefined) { - project.expanded = currentExpandStates[project.id]; - } - }); + // 澶勭悊璁″垝鐘舵�� + let planStatusText = ''; + let planStatusClass = ''; + + // 鏍规嵁璁″垝鐨勭姸鎬佽缃笉鍚岀殑鏂囨湰鍜屾牱寮� + // 娉ㄦ剰锛氭帴鍙h繑鍥炵殑鏄痵tate鑰屼笉鏄痯lanState + console.log('璁″垝鐘舵�佸�硷細', data.state, '绫诲瀷锛�', typeof data.state); + + // 纭繚state鏄暟瀛楃被鍨� + const planState = parseInt(data.state); + + switch(planState) { + case 1: + planStatusText = '鑽夌'; + planStatusClass = 'draft'; + break; + case 2: + planStatusText = '鏈墽琛�'; + planStatusClass = 'published'; + break; + case 3: + planStatusText = '鎵ц涓�'; + planStatusClass = 'executing'; + break; + case 4: + planStatusText = '宸插畬鎴�'; + planStatusClass = 'completed'; + break; + case 5: + planStatusText = '宸茬粓姝�'; + planStatusClass = 'terminated'; + break; + default: + planStatusText = '鏈煡鐘舵��'; + planStatusClass = 'draft'; + console.log('鏈瘑鍒殑璁″垝鐘舵�佸�硷細', planState); } - // 妯℃嫙缃戠粶璇锋眰寤惰繜 - setTimeout(() => { - // 璁剧疆椤甸潰鏁版嵁 - this.setData({ - planCode: mockData.planCode, - startTime: mockData.startTime, - projects: mockData.projects, - isRefreshing: false // 缁撴潫鍒锋柊鐘舵�� - }); - }, 1000); - - // 瀹為檯椤圭洰涓簲璇ヤ娇鐢╳x.request鑾峰彇鏁版嵁 - // wx.request({ - // url: 'https://your-api-url/irrigation/' + id, - // method: 'GET', - // success: (res) => { - // if (res.data && res.data.code === 0) { - // // 鑾峰彇鏂版暟鎹� - // let projects = res.data.data.projects; - // - // // 濡傛灉鏄娆″姞杞斤紝璁剧疆榛樿灞曞紑鐘舵�� - // if (isFirstLoad) { - // projects = projects.map((project, index) => { - // return { - // ...project, - // expanded: index === 0 // 榛樿鍙睍寮�绗竴涓」鐩� - // }; - // }); - // } else { - // // 濡傛灉涓嶆槸棣栨鍔犺浇锛屾仮澶嶉」鐩殑灞曞紑鐘舵�� - // projects = projects.map(project => { - // return { - // ...project, - // expanded: currentExpandStates[project.id] !== undefined - // ? currentExpandStates[project.id] - // : false - // }; - // }); - // } - // - // // 璁$畻姣忎釜椤圭洰鐨勬�荤亴婧夋椂闀� - // projects = this.calculateProjectTotalDuration(projects); - // - // this.setData({ - // planCode: res.data.data.planCode, - // startTime: res.data.data.startTime, - // projects: projects, - // isRefreshing: false // 缁撴潫鍒锋柊鐘舵�� - // }); - // } else { - // wx.showToast({ - // title: '鑾峰彇鏁版嵁澶辫触', - // icon: 'none' - // }); - // this.setData({ - // isRefreshing: false // 缁撴潫鍒锋柊鐘舵�� - // }); - // } - // }, - // fail: () => { - // wx.showToast({ - // title: '缃戠粶閿欒', - // icon: 'none' - // }); - // this.setData({ - // isRefreshing: false // 缁撴潫鍒锋柊鐘舵�� - // }); - // } - // }); - }, - - /** - * 璁$畻姣忎釜椤圭洰鐨勬�荤亴婧夋椂闀� - */ - calculateProjectTotalDuration: function(projects) { - return projects.map(project => { - // 璁$畻椤圭洰涓嬫墍鏈夎疆鐏岀粍鐨勬�绘椂闀� - const totalDuration = project.groups.reduce((total, group) => { - return total + (group.duration || 0); - }, 0); + // 杞崲鏁版嵁鏍煎紡 + const groupList = data.groups.map(group => { + const statusInfo = statusMap[group.state] || {status: 'unknown', statusText: '鏈煡鐘舵��'}; return { - ...project, - totalDuration: totalDuration + id: group.groupId, + name: group.groupCode, + status: statusInfo.status, + statusText: statusInfo.statusText, + startTime: group.startTime, + endTime: group.stopTime, + duration: group.duration, + publishResult: group.publishResult || [] }; }); - }, - /** - * 鍒囨崲椤圭洰灞曞紑/鏀惰捣鐘舵�� - */ - toggleProject: function (e) { - const index = e.currentTarget.dataset.index; - const expanded = this.data.projects[index].expanded; - - // 鏇存柊椤圭洰鐨勫睍寮�鐘舵�� - const key = `projects[${index}].expanded`; this.setData({ - [key]: !expanded - }); - }, - - /** - * 瀵艰埅鍒拌疆鐏岀粍璇︽儏椤甸潰 - */ - navigateToGroupDetail: function (e) { - const projectName = e.currentTarget.dataset.projectName; - const groupName = e.currentTarget.dataset.groupName; - const groupId = e.currentTarget.dataset.groupId; - const status = e.currentTarget.dataset.status; - - console.log('璺宠浆鍒扮粍璇︽儏椤甸潰锛屽師濮嬬姸鎬�:', status); - - // 瀵艰埅鍒扮粍璇︽儏椤甸潰锛屽苟浼犻�掑弬鏁� - // 娉ㄦ剰锛氶渶瑕佸皢status杞崲涓篿sIrrigating鍙傛暟锛屼互渚垮湪缁勮鎯呴〉闈㈡纭樉绀哄懡浠ょ姸鎬� - wx.navigateTo({ - url: `/pages/groupDetail/groupDetail?projectName=${projectName}&groupName=${groupName}&groupId=${groupId}&status=${status}&isIrrigating=${status === 'irrigating' ? 'true' : 'false'}` + planCode: data.planName, + projectName: data.projectName, + startTime: data.planStartTime, + stopTime: data.planStopTime, + groupList: groupList, + planStatusText: planStatusText, + planStatusClass: planStatusClass }); }, @@ -282,14 +177,18 @@ * 涓嬫媺鍒锋柊澶勭悊鍑芥暟 */ onPullDownRefresh: function () { - // 閲嶆柊鍔犺浇鏁版嵁锛屼絾淇濇寔灞曞紑鐘舵�� - if (this.data.planId) { - this.loadIrrigationDetail(this.data.planId, false); - } else { + this.setData({ + isRefreshing: true + }); + + this.fetchIrrigationData(this.data.planId); + + // 瀹屾垚鍒锋柊 + setTimeout(() => { this.setData({ isRefreshing: false }); - } + }, 1000); }, /** @@ -304,5 +203,15 @@ */ onShareAppMessage: function () { + }, + + /** + * 瀵艰埅鍒拌疆鐏岀粍璇︽儏椤甸潰 + */ + navigateToGroupDetail: function (e) { + const { projectName, groupName, groupId, status } = e.currentTarget.dataset; + wx.navigateTo({ + url: `/pages/groupDetail/groupDetail?projectName=${projectName}&groupName=${groupName}&groupId=${groupId}&status=${status}` + }); } }) \ No newline at end of file -- Gitblit v1.8.0