| // pages/valveList/valveList.js 开关阀记录 | 
| const { | 
|   get, | 
|   post | 
| } = require('../../api/request.js'); | 
|   | 
| Page({ | 
|   | 
|   /** | 
|    * 页面的初始数据 | 
|    */ | 
|   data: { | 
|     listVirtualData: [], | 
|     listPhysicalData: [], | 
|     currentTab: 0, | 
|     isVirtualRefreshing: false, //虚拟卡刷新中 | 
|     isPhysicalRefreshing: false, //实体卡刷新中 | 
|     physicalPageCurr: 1, //实体卡当前页数 | 
|     pageSize: 20, | 
|     virtualPageCurr: 1, //虚拟卡当前页数 | 
|     virtualhasMore: true, | 
|     physicalHasMore: true, | 
|     virtualIsLoding: false, | 
|     physicalIsLoding: false, | 
|     useTestData: false, // 添加测试数据标志 | 
|   }, | 
|   | 
|   /** | 
|    * 生命周期函数--监听页面加载 | 
|    */ | 
|   onLoad(options) { | 
|   | 
|   }, | 
|   | 
|   /** | 
|    * 生命周期函数--监听页面初次渲染完成 | 
|    */ | 
|   onReady() { | 
|     this.getPhysicalListData(); | 
|     this.getVirtualListData(); | 
|   }, | 
|   | 
|   /** | 
|    * 生命周期函数--监听页面显示 | 
|    */ | 
|   onShow() { | 
|   | 
|   }, | 
|   | 
|   /** | 
|    * 生命周期函数--监听页面隐藏 | 
|    */ | 
|   onHide() { | 
|   | 
|   }, | 
|   | 
|   /** | 
|    * 生命周期函数--监听页面卸载 | 
|    */ | 
|   onUnload() { | 
|   | 
|   }, | 
|   | 
|   /** | 
|    * 页面相关事件处理函数--监听用户下拉动作 | 
|    */ | 
|   onPullDownRefresh() { | 
|   | 
|   }, | 
|   | 
|   /** | 
|    * 页面上拉触底事件的处理函数 | 
|    */ | 
|   onReachBottom() { | 
|   | 
|   }, | 
|   | 
|   /** | 
|    * 用户点击右上角分享 | 
|    */ | 
|   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(); | 
|     } | 
|   | 
|   } | 
|   | 
| }) |