From aec1b6ec73897b5e5f3a85f2985447726a399ed0 Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期六, 19 四月 2025 15:56:48 +0800 Subject: [PATCH] 更新灌溉计划页面,添加灌溉计划列表刷新标记,优化项目选择器和时间选择器的逻辑;更新样式以提升用户体验,确保在切换标签时只加载必要的数据。 --- pages/valveList/valveList.js | 210 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 198 insertions(+), 12 deletions(-) diff --git a/pages/valveList/valveList.js b/pages/valveList/valveList.js index 78d4eb5..1aee367 100644 --- a/pages/valveList/valveList.js +++ b/pages/valveList/valveList.js @@ -1,21 +1,28 @@ // pages/valveList/valveList.js 寮�鍏抽榾璁板綍 +const { + get, + post +} = require('../../api/request.js'); + Page({ /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ data: { - listData: [{ - intakeNum: "1023356646612" - }, { - intakeNum: "1023356646612" - }, { - intakeNum: "1023356646612" - }, { - intakeNum: "1023356646612" - }, { - intakeNum: "1023356646612" - }] + listVirtualData: [], + listPhysicalData: [], + currentTab: 0, + isVirtualRefreshing: false, //铏氭嫙鍗″埛鏂颁腑 + isPhysicalRefreshing: false, //瀹炰綋鍗″埛鏂颁腑 + physicalPageCurr: 1, //瀹炰綋鍗″綋鍓嶉〉鏁� + pageSize: 20, + virtualPageCurr: 1, //铏氭嫙鍗″綋鍓嶉〉鏁� + virtualhasMore: true, + physicalHasMore: true, + virtualIsLoding: false, + physicalIsLoding: false, + useTestData: false, // 娣诲姞娴嬭瘯鏁版嵁鏍囧織 }, /** @@ -29,7 +36,8 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ onReady() { - + this.getPhysicalListData(); + this.getVirtualListData(); }, /** @@ -72,5 +80,183 @@ */ onShareAppMessage() { + }, + switchTab(e) { + const tab = parseInt(e.currentTarget.dataset.tab); + this.setData({ + currentTab: tab + }); + }, + //铏氭嫙鍗″埛鏂� + onPullVirtualDownRefresh() { + this.setData({ + isVirtualRefreshing: true, + }) + this.getVirtualListData(true); + }, + //瀹炰綋鍗″埛鏂� + onPullPhysicalDownRefresh() { + this.setData({ + isPhysicalRefreshing: true, + }) + this.getPhysicalListData(true); + }, + // 鐢熸垚铏氭嫙鍗℃祴璇曟暟鎹� + generateVirtualTestData() { + return Array(10).fill().map((_, index) => ({ + expense: (Math.random() * 100).toFixed(2), + cardNum: `VC${Math.floor(Math.random() * 10000).toString().padStart(4, '0')}`, + intakeNum: `IN${Math.floor(Math.random() * 1000).toString().padStart(3, '0')}`, + openType: ['鎵嬪姩寮�闃�', '鑷姩寮�闃�', '璁″垝寮�闃�'][Math.floor(Math.random() * 3)], + openTime: this.generateRandomTime(), + closeTime: this.generateRandomTime(), + duration: Math.floor(Math.random() * 120), + amount: (Math.random() * 50).toFixed(2) + })); + }, + + // 鐢熸垚瀹炰綋鍗℃祴璇曟暟鎹� + generatePhysicalTestData() { + return Array(10).fill().map((_, index) => ({ + expense: (Math.random() * 100).toFixed(2), + cardNum: `PC${Math.floor(Math.random() * 10000).toString().padStart(4, '0')}`, + intakeNum: `IN${Math.floor(Math.random() * 1000).toString().padStart(3, '0')}`, + openType: ['鎵嬪姩寮�闃�', '鑷姩寮�闃�', '璁″垝寮�闃�'][Math.floor(Math.random() * 3)], + openTime: this.generateRandomTime(), + closeTime: this.generateRandomTime(), + duration: Math.floor(Math.random() * 120), + amount: (Math.random() * 50).toFixed(2) + })); + }, + + // 鐢熸垚闅忔満鏃堕棿 + generateRandomTime() { + const now = new Date(); + const randomHours = Math.floor(Math.random() * 24); + const randomMinutes = Math.floor(Math.random() * 60); + const randomSeconds = Math.floor(Math.random() * 60); + + const date = new Date(now); + date.setHours(randomHours); + date.setMinutes(randomMinutes); + date.setSeconds(randomSeconds); + + return date.toLocaleString(); + }, + + //鑾峰彇瀹炰綋鍗″垪琛� + getPhysicalListData(isRefresh) { + if (this.data.useTestData) { + // 浣跨敤娴嬭瘯鏁版嵁 + const testData = this.generatePhysicalTestData(); + this.setData({ + listPhysicalData: isRefresh ? testData : this.data.listPhysicalData.concat(testData), + isPhysicalRefreshing: false, + physicalIsLoding: false, + physicalHasMore: this.data.physicalPageCurr < 3 // 妯℃嫙3椤垫暟鎹� + }); + return; + } + + get({ + url: 'wx/intake/getCardOpenClose', + data: { + clientId: getApp().globalData.clientId, + pageCurr: this.data.physicalPageCurr, + pageSize: this.data.pageSize + } + }) + .then((data) => { + this.setData({ + isPhysicalRefreshing: false, + physicalIsLoding: false + }); + if (data.success && data.code === "0001") { + const filteredData = data.content.obj.filter(item => item.openTime !== null && item.closeTime !== null); + this.setData({ + listPhysicalData: isRefresh ? filteredData : this.data.listPhysicalData.concat(filteredData), + physicalHasMore: this.data.physicalPageCurr < data.content.pageTotal, + }); + } else { + wx.showToast({ + title: data.msg, + }) + } + }) + .catch((error) => { + this.setData({ + isPhysicalRefreshing: false + }); + console.error('Failed to add item:', error); + }); + }, + + //鑾峰彇铏氭嫙鍗″紑鍏抽榾璁板綍 + getVirtualListData(isRefresh) { + if (this.data.useTestData) { + // 浣跨敤娴嬭瘯鏁版嵁 + const testData = this.generateVirtualTestData(); + this.setData({ + listVirtualData: isRefresh ? testData : this.data.listVirtualData.concat(testData), + isVirtualRefreshing: false, + virtualIsLoding: false, + virtualhasMore: this.data.virtualPageCurr < 3 // 妯℃嫙3椤垫暟鎹� + }); + return; + } + + get({ + url: 'wx/intake/getVcCardOpenClose', + data: { + clientId: getApp().globalData.clientId, + pageCurr: this.data.physicalPageCurr, + pageSize: this.data.pageSize + } + }) + .then((data) => { + this.setData({ + isVirtualRefreshing: false, + virtualIsLoding: false + }); + if (data.success && data.code === "0001") { + const filteredData = data.content.obj.filter(item => item.openTime !== null && item.closeTime !== null); + this.setData({ + listVirtualData: isRefresh ? filteredData : this.data.listVirtualData.concat(filteredData), + virtualhasMore: this.data.virtualPageCurr < data.content.pageTotal, + }); + } else { + wx.showToast({ + title: data.msg, + }) + } + }) + .catch((error) => { + this.setData({ + isVirtualRefreshing: false + }); + console.error('Failed to add item:', error); + }); + }, + //鍔犺浇鏇村鐨勫疄浣撳崱 + loadPhysicalMore() { + if (this.data.physicalHasMore) { + this.setData({ + physicalIsLoding: true, + physicalPageCurr: this.data.physicalPageCurr + 1 + }) + this.getPhysicalListData(); + } + }, + //鍔犺浇鏇村鐨勮櫄鎷熷崱 + loadVirtualMore() { + if (this.data.virtualhasMore) { + this.setData({ + virtualIsLoding: true, + virtualPageCurr: this.data.virtualPageCurr + 1 + }) + this.getVirtualListData(); + } + } + }) \ No newline at end of file -- Gitblit v1.8.0