From ada0bc5ee523c4b45645fa8d984364561fcc2063 Mon Sep 17 00:00:00 2001 From: DU Date: Wed, 21 Jan 2026 23:24:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=99=E9=A2=9D=E9=87=8D=E7=BD=AE=E3=80=81?= =?UTF-8?q?=20=E5=85=85=E5=80=BC=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pagesOrder/rechargeDetail/index.tsx | 224 ++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 src/pagesOrder/rechargeDetail/index.tsx diff --git a/src/pagesOrder/rechargeDetail/index.tsx b/src/pagesOrder/rechargeDetail/index.tsx new file mode 100644 index 0000000..b61eb36 --- /dev/null +++ b/src/pagesOrder/rechargeDetail/index.tsx @@ -0,0 +1,224 @@ +/** + * 充值明细页面 + */ +import { View, Text, Image } from '@tarojs/components' +import { useState } from 'react' +import { ArrowDown } from '@taroify/icons' +import { Popup, DatetimePicker } from '@taroify/core' +import Taro, { useLoad } from '@tarojs/taro' +import './index.scss' + +const noDataImg = require('../../assets/big/noData.png') + +interface RechargeRecordItem { + id: string + storeName: string + rechargeTime: string + rechargeType: string + amount: number + status: string +} + +const RechargeDetail = () => { + const [selectedMonth, setSelectedMonth] = useState('2025-03') + const [datePickerOpen, setDatePickerOpen] = useState(false) + const [pickerValue, setPickerValue] = useState(new Date()) + + // 模拟充值记录数据 + const [dataList, setDataList] = useState([ + { + id: '2025-03-1', + storeName: '北京球场风云店', + rechargeTime: '2025-03-09 00:00:00', + rechargeType: '账户充值', + amount: 100.00, + status: '充值完成' + }, + { + id: '2025-03-2', + storeName: '北京球场风云店', + rechargeTime: '2025-03-06 00:00:00', + rechargeType: '账户充值', + amount: 100.00, + status: '充值完成' + } + ]) + + useLoad(() => { + console.log('充值明细页面加载') + }) + + // 模拟接口请求充值记录数据 + const fetchRechargeRecords = async (yearMonth: string) => { + Taro.showLoading({ + title: '加载中...', + mask: true + }) + + // 模拟接口请求 + return new Promise((resolve) => { + setTimeout(() => { + // 模拟返回数据 + const mockData: RechargeRecordItem[] = [ + { + id: `${yearMonth}-1`, + storeName: '北京球场风云店', + rechargeTime: `${yearMonth}-15 14:30:00`, + rechargeType: '账户充值', + amount: 100, + status: '充值完成' + }, + { + id: `${yearMonth}-2`, + storeName: '北京球场风云店', + rechargeTime: `${yearMonth}-10 10:20:00`, + rechargeType: '账户充值', + amount: 200, + status: '充值完成' + } + ] + + setDataList(mockData) + Taro.hideLoading() + resolve(mockData) + }, 1000) // 模拟 1 秒的网络延迟 + }) + } + + // 按月份分组记录 + const groupByMonth = (records: RechargeRecordItem[]) => { + const groups: Record = {} + records.forEach(record => { + const month = record.rechargeTime.substring(0, 7) // 提取 YYYY-MM + if (!groups[month]) { + groups[month] = [] + } + groups[month].push(record) + }) + return groups + } + + const groupedRecords = groupByMonth(dataList) + + // 计算当月总充值金额 + const calculateMonthTotal = (records: RechargeRecordItem[]) => { + return records.reduce((sum, record) => sum + record.amount, 0) + } + + // 打开月份选择器 + const handleSelectMonth = () => { + setDatePickerOpen(true) + } + + // 确认选择月份 + const handleDateConfirm = async (value: Date) => { + const year = value.getFullYear() + const month = String(value.getMonth() + 1).padStart(2, '0') + const formattedMonth = `${year}-${month}` + + setSelectedMonth(formattedMonth) + setPickerValue(value) + setDatePickerOpen(false) + + // 调用接口请求该月份的数据 + await fetchRechargeRecords(formattedMonth) + } + + // 取消选择 + const handleDateCancel = () => { + setDatePickerOpen(false) + } + + return ( + + {dataList.length === 0 ? ( + + + + ) : ( + <> + {Object.keys(groupedRecords).map(month => { + const monthRecords = groupedRecords[month] + const monthTotal = calculateMonthTotal(monthRecords) + + return ( + + {/* 月份标题和充值统计 */} + + + {month} + + + + 充值 + + {monthTotal.toFixed(2)} + + + + {/* 分割线 */} + + + {/* 记录列表 */} + + {monthRecords.map((item, index) => ( + + + {/* 第一行:店铺名称 + 状态 */} + + {item.storeName} + {item.status} + + + {/* 第二行:充值类型 */} + + {item.rechargeType} + + + {/* 第三行:充值时间 + 实付金额 */} + + 充值时间:{item.rechargeTime} + + 实付 ¥ + {item.amount.toFixed(2)} + + + + + {/* item 之间的分割线 */} + {index < monthRecords.length - 1 && ( + + )} + + ))} + + + ) + })} + + {/* 到底了提示 */} + + 到底了~ + + + )} + + {/* 年月选择器 */} + setDatePickerOpen(false)} + > + + + + ) +} + +export default RechargeDetail