index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. <template>
  2. <view class="statistics-container">
  3. <!-- 日/月切换 -->
  4. <view class="segment-section">
  5. <view class="segmented-control">
  6. <view
  7. v-for="(option, index) in tabOptions"
  8. :key="index"
  9. class="segment-item"
  10. :class="{ active: activeTab === index }"
  11. @click="handleTabChange(index)">
  12. <text>{{ option }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. <!-- 筛选栏 -->
  17. <view class="filter-section">
  18. <view class="filter-row">
  19. <view class="filter-item">
  20. <text class="filter-label">站点</text>
  21. <picker mode="selector" :range="stationList" range-key="stationName" @change="handleStationChange">
  22. <view class="picker-value">
  23. <text :class="{ placeholder: !selectedStationName }">{{ selectedStationName || '全部站点' }}</text>
  24. <AppIcon name="chevron-down" :size="20" color="#999999" class="picker-arrow" />
  25. </view>
  26. </picker>
  27. </view>
  28. <view class="filter-item">
  29. <text class="filter-label">{{ activeTab === 0 ? '日期' : '月份' }}</text>
  30. <input
  31. type="text"
  32. :placeholder="activeTab === 0 ? '如 2026-06-10' : '如 2026-06'"
  33. v-model="filterKey"
  34. @confirm="handleSearch" />
  35. </view>
  36. </view>
  37. <button class="search-btn" @click="handleSearch">查询</button>
  38. </view>
  39. <!-- 汇总卡片(仅日统计) -->
  40. <view class="summary-range" v-if="activeTab === 0 && list.length > 0">
  41. <text class="range-text">统计范围:{{ summaryDateRange }}</text>
  42. </view>
  43. <view class="summary-section" v-if="activeTab === 0 && list.length > 0">
  44. <view class="summary-card">
  45. <text class="summary-label">总收入</text>
  46. <text class="summary-value highlight">¥{{ formatAmount(summary.totalIncome) }}</text>
  47. </view>
  48. <view class="summary-card">
  49. <text class="summary-label">订单数</text>
  50. <text class="summary-value">{{ summary.totalOrders }}</text>
  51. </view>
  52. <view class="summary-card">
  53. <text class="summary-label">注册用户</text>
  54. <text class="summary-value">{{ summary.totalRegistrations }}</text>
  55. </view>
  56. <view class="summary-card">
  57. <text class="summary-label">活跃用户</text>
  58. <text class="summary-value">{{ summary.totalActiveUsers }}</text>
  59. </view>
  60. <view class="summary-card">
  61. <text class="summary-label">充值笔数</text>
  62. <text class="summary-value">{{ summary.totalRechargeCount }}</text>
  63. </view>
  64. <view class="summary-card">
  65. <text class="summary-label">退款笔数</text>
  66. <text class="summary-value">{{ summary.totalRefundCount }}</text>
  67. </view>
  68. </view>
  69. <!-- 数据列表 -->
  70. <view class="stats-list" v-if="list.length > 0">
  71. <view
  72. class="stats-item"
  73. v-for="(item, index) in list"
  74. :key="index"
  75. @click="viewDetail(item)">
  76. <view class="item-header">
  77. <text class="item-period">{{ activeTab === 0 ? item.statDate : item.statMonth }}</text>
  78. <text class="item-station">{{ item.stationName || '-' }}</text>
  79. <AppIcon name="chevron-right" :size="24" color="#B0B0B0" class="item-header-arrow" />
  80. </view>
  81. <view class="item-content">
  82. <view class="info-grid">
  83. <view class="info-item">
  84. <text class="info-label">总收入</text>
  85. <text class="info-value highlight">¥{{ formatAmount(item.totalIncome) }}</text>
  86. </view>
  87. <view class="info-item">
  88. <text class="info-label">消费金额</text>
  89. <text class="info-value">¥{{ formatAmount(item.consumption) }}</text>
  90. </view>
  91. <view class="info-item">
  92. <text class="info-label">退款金额</text>
  93. <text class="info-value">¥{{ formatAmount(item.totalRefund) }}</text>
  94. </view>
  95. <view class="info-item">
  96. <text class="info-label">订单数</text>
  97. <text class="info-value">{{ item.ordersCount || 0 }}</text>
  98. </view>
  99. <view class="info-item">
  100. <text class="info-label">注册用户</text>
  101. <text class="info-value">{{ item.registrations || 0 }}</text>
  102. </view>
  103. <view class="info-item">
  104. <text class="info-label">活跃用户</text>
  105. <text class="info-value">{{ item.activeUserCount || 0 }}</text>
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. <!-- 加载更多 -->
  112. <view class="load-more" v-if="list.length > 0">
  113. <text class="load-more-text" v-if="loadMoreStatus === 'more'">上拉加载更多</text>
  114. <text class="load-more-text" v-else-if="loadMoreStatus === 'loading'">正在加载...</text>
  115. <text class="load-more-text" v-else>没有更多数据了</text>
  116. </view>
  117. <!-- 空状态 -->
  118. <view class="empty-state" v-if="list.length === 0 && !loading">
  119. <view class="empty-icon-wrapper">
  120. <AppIcon name="bar-chart" :size="80" color="#999999" />
  121. </view>
  122. <text class="empty-text">暂无统计数据</text>
  123. </view>
  124. <!-- 加载状态 -->
  125. <view class="loading-state" v-if="loading && list.length === 0">
  126. <view class="loading-spinner"></view>
  127. <text class="loading-text">加载中...</text>
  128. </view>
  129. <!-- 详情弹窗 -->
  130. <view class="detail-overlay" v-if="showDetail" @click="closeDetail">
  131. <view class="detail-card" @click.stop>
  132. <view class="detail-header">
  133. <text class="detail-title">{{ activeTab === 0 ? '日统计详情' : '月统计详情' }}</text>
  134. <view class="detail-close" @click="closeDetail">
  135. <AppIcon name="x" :size="32" color="#999999" />
  136. </view>
  137. </view>
  138. <view class="detail-content" v-if="detailItem">
  139. <view class="detail-grid">
  140. <view class="detail-cell">
  141. <text class="d-label">{{ activeTab === 0 ? '日期' : '月份' }}</text>
  142. <text class="d-value">{{ activeTab === 0 ? detailItem.statDate : detailItem.statMonth }}</text>
  143. </view>
  144. <view class="detail-cell">
  145. <text class="d-label">站点名称</text>
  146. <text class="d-value">{{ detailItem.stationName || '-' }}</text>
  147. </view>
  148. <view class="detail-cell">
  149. <text class="d-label">总收入</text>
  150. <text class="d-value amount">¥{{ formatAmount(detailItem.totalIncome) }}</text>
  151. </view>
  152. <view class="detail-cell">
  153. <text class="d-label">退款金额</text>
  154. <text class="d-value">¥{{ formatAmount(detailItem.totalRefund) }}</text>
  155. </view>
  156. <view class="detail-cell">
  157. <text class="d-label">跨店收入</text>
  158. <text class="d-value">¥{{ formatAmount(detailItem.crossIncome) }}</text>
  159. </view>
  160. <view class="detail-cell">
  161. <text class="d-label">跨店支出</text>
  162. <text class="d-value">¥{{ formatAmount(detailItem.crossExpend) }}</text>
  163. </view>
  164. <view class="detail-cell">
  165. <text class="d-label">消费金额</text>
  166. <text class="d-value">¥{{ formatAmount(detailItem.consumption) }}</text>
  167. </view>
  168. <view class="detail-cell" v-if="activeTab === 1 && detailItem.platformFee !== undefined">
  169. <text class="d-label">平台服务费</text>
  170. <text class="d-value">¥{{ formatAmount(detailItem.platformFee) }}</text>
  171. </view>
  172. <view class="detail-cell">
  173. <text class="d-label">充值笔数</text>
  174. <text class="d-value">{{ detailItem.rechargeCount || 0 }}</text>
  175. </view>
  176. <view class="detail-cell">
  177. <text class="d-label">退款笔数</text>
  178. <text class="d-value">{{ detailItem.refundCount || 0 }}</text>
  179. </view>
  180. <view class="detail-cell">
  181. <text class="d-label">注册人数</text>
  182. <text class="d-value">{{ detailItem.registrations || 0 }}</text>
  183. </view>
  184. <view class="detail-cell">
  185. <text class="d-label">活跃用户数</text>
  186. <text class="d-value">{{ detailItem.activeUserCount || 0 }}</text>
  187. </view>
  188. <view class="detail-cell">
  189. <text class="d-label">订单数量</text>
  190. <text class="d-value">{{ detailItem.ordersCount || 0 }}</text>
  191. </view>
  192. <view class="detail-cell" v-if="detailItem.createTime">
  193. <text class="d-label">创建时间</text>
  194. <text class="d-value">{{ formatTime(detailItem.createTime) }}</text>
  195. </view>
  196. </view>
  197. </view>
  198. </view>
  199. </view>
  200. </view>
  201. </template>
  202. <script setup>
  203. import { ref, computed, onMounted } from 'vue'
  204. import { onReachBottom } from '@dcloudio/uni-app'
  205. import { getDailyStatList, getMonthlyStatList, getDailyStatAggregate } from '../../api/stat.js'
  206. import { getStationList } from '../../api/station.js'
  207. import { formatTime, showToast, formatAmount } from '../../utils/index.js'
  208. import { loadDicts } from '../../utils/dict.js'
  209. const activeTab = ref(0)
  210. const tabOptions = ['日统计', '月统计']
  211. const list = ref([])
  212. const loading = ref(true)
  213. const page = ref(1)
  214. const pageSize = ref(10)
  215. const hasMore = ref(true)
  216. const loadMoreStatus = ref('more')
  217. const filterKey = ref('')
  218. const stationList = ref([])
  219. const selectedStationId = ref('')
  220. const selectedStationName = ref('')
  221. const showDetail = ref(false)
  222. const detailItem = ref(null)
  223. const summary = ref({
  224. totalIncome: 0,
  225. totalConsumption: 0,
  226. totalOrders: 0,
  227. totalRegistrations: 0,
  228. totalActiveUsers: 0,
  229. totalRechargeCount: 0,
  230. totalRefundCount: 0
  231. })
  232. const summaryLoading = ref(false)
  233. const summaryDateRange = computed(() => {
  234. if (filterKey.value) {
  235. return activeTab.value === 0 ? filterKey.value : filterKey.value
  236. }
  237. return '全部日期'
  238. })
  239. const emptySummary = () => ({
  240. totalIncome: 0, totalConsumption: 0, totalOrders: 0,
  241. totalRegistrations: 0, totalActiveUsers: 0,
  242. totalRechargeCount: 0, totalRefundCount: 0
  243. })
  244. const loadSummary = async () => {
  245. if (activeTab.value !== 0) {
  246. summary.value = emptySummary()
  247. return
  248. }
  249. summaryLoading.value = true
  250. try {
  251. const params = {}
  252. if (selectedStationId.value) params.stationId = selectedStationId.value
  253. if (filterKey.value) {
  254. params.startDate = filterKey.value
  255. params.endDate = filterKey.value
  256. }
  257. const res = await getDailyStatAggregate(params)
  258. if (res && res.code === 200 && res.data) {
  259. summary.value = {
  260. totalIncome: res.data.totalIncome || 0,
  261. totalConsumption: res.data.totalConsumption || 0,
  262. totalOrders: res.data.ordersCount || 0,
  263. totalRegistrations: res.data.registrations || 0,
  264. totalActiveUsers: res.data.activeUserCount || 0,
  265. totalRechargeCount: res.data.rechargeCount || 0,
  266. totalRefundCount: res.data.refundCount || 0
  267. }
  268. }
  269. } catch (e) {
  270. console.error('加载汇总数据失败:', e)
  271. } finally {
  272. summaryLoading.value = false
  273. }
  274. }
  275. const loadStations = async () => {
  276. try {
  277. const res = await getStationList({ pageSize: 1024 })
  278. if (res && res.code === 200) {
  279. const data = res.data
  280. stationList.value = data.records || data.list || data || []
  281. stationList.value.unshift({ stationId: '', stationName: '全部站点' })
  282. }
  283. } catch (error) {
  284. showToast('加载站点列表失败')
  285. }
  286. }
  287. const handleStationChange = (e) => {
  288. const index = e.detail.value
  289. const selected = stationList.value[index]
  290. if (selected) {
  291. selectedStationId.value = selected.stationId || ''
  292. selectedStationName.value = selected.stationName || ''
  293. }
  294. }
  295. const handleTabChange = (index) => {
  296. activeTab.value = index
  297. filterKey.value = ''
  298. loadData()
  299. }
  300. const loadData = async (isLoadMore = false) => {
  301. if (!isLoadMore) {
  302. page.value = 1
  303. list.value = []
  304. hasMore.value = true
  305. loadMoreStatus.value = 'more'
  306. } else {
  307. loadMoreStatus.value = 'loading'
  308. }
  309. loading.value = true
  310. try {
  311. const params = {
  312. pageNum: page.value,
  313. pageSize: pageSize.value
  314. }
  315. if (selectedStationId.value) params.stationId = selectedStationId.value
  316. const fetcher = activeTab.value === 0 ? getDailyStatList : getMonthlyStatList
  317. // 日期筛选
  318. if (filterKey.value) {
  319. if (activeTab.value === 0) {
  320. params.startDate = filterKey.value
  321. params.endDate = filterKey.value
  322. } else {
  323. params.statMonth = filterKey.value
  324. }
  325. }
  326. const res = await fetcher(params)
  327. if (res && res.code === 200) {
  328. const data = res.data
  329. const records = data.records || data.list || data
  330. const total = data.total || 0
  331. const totalPages = Math.ceil(total / pageSize.value)
  332. hasMore.value = page.value < totalPages
  333. loadMoreStatus.value = hasMore.value ? 'more' : 'noMore'
  334. if (isLoadMore) {
  335. list.value = [...list.value, ...records]
  336. page.value++
  337. } else {
  338. list.value = records
  339. page.value = 2
  340. loadSummary()
  341. }
  342. }
  343. } catch (error) {
  344. showToast('加载统计数据失败')
  345. } finally {
  346. loading.value = false
  347. }
  348. }
  349. const loadMore = () => {
  350. if (hasMore.value && !loading.value && loadMoreStatus.value !== 'loading') {
  351. loadData(true)
  352. }
  353. }
  354. onReachBottom(() => {
  355. loadMore()
  356. })
  357. const handleSearch = () => {
  358. loadData()
  359. }
  360. const viewDetail = (item) => {
  361. detailItem.value = item
  362. showDetail.value = true
  363. }
  364. const closeDetail = () => {
  365. showDetail.value = false
  366. detailItem.value = null
  367. }
  368. onMounted(async () => {
  369. await loadDicts()
  370. loadStations()
  371. loadData()
  372. })
  373. </script>
  374. <style scoped>
  375. .statistics-container {
  376. min-height: 100vh;
  377. background-color: #F5F7FA;
  378. padding-bottom: 60rpx;
  379. }
  380. .segment-section {
  381. background-color: #FFFFFF;
  382. padding: 20rpx 30rpx;
  383. }
  384. .segmented-control {
  385. display: flex;
  386. width: 100%;
  387. border-radius: 16rpx;
  388. overflow: hidden;
  389. background-color: #F5F5F5;
  390. padding: 6rpx;
  391. gap: 6rpx;
  392. }
  393. .segment-item {
  394. flex: 1;
  395. text-align: center;
  396. padding: 16rpx 0;
  397. font-size: 26rpx;
  398. color: #666666;
  399. transition: all 0.3s;
  400. border-radius: 12rpx;
  401. font-weight: 500;
  402. }
  403. .segment-item.active {
  404. color: #FFFFFF;
  405. font-weight: 600;
  406. background: #C6171E;
  407. box-shadow: 0 4rpx 12rpx rgba(198, 23, 30, 0.3);
  408. }
  409. .filter-section {
  410. background-color: #FFFFFF;
  411. padding: 0 20rpx 20rpx;
  412. margin-bottom: 16rpx;
  413. }
  414. .filter-row {
  415. display: flex;
  416. gap: 16rpx;
  417. margin-bottom: 12rpx;
  418. }
  419. .filter-item {
  420. flex: 1;
  421. }
  422. .filter-label {
  423. font-size: 24rpx;
  424. color: #999999;
  425. margin-bottom: 8rpx;
  426. display: block;
  427. }
  428. .picker-value {
  429. display: flex;
  430. justify-content: space-between;
  431. align-items: center;
  432. background-color: #F5F5F5;
  433. border-radius: 16rpx;
  434. padding: 0 20rpx;
  435. font-size: 26rpx;
  436. height: 56rpx;
  437. box-sizing: border-box;
  438. }
  439. .picker-value .placeholder {
  440. color: #B0B0B0;
  441. }
  442. .picker-arrow {
  443. flex-shrink: 0;
  444. }
  445. .filter-item input {
  446. background-color: #F5F5F5;
  447. border-radius: 16rpx;
  448. padding: 0 20rpx;
  449. font-size: 26rpx;
  450. height: 56rpx;
  451. box-sizing: border-box;
  452. }
  453. .search-btn {
  454. width: 100%;
  455. padding: 16rpx 0;
  456. background: #C6171E;
  457. color: #FFFFFF;
  458. border-radius: 16rpx;
  459. font-size: 28rpx;
  460. border: none;
  461. }
  462. .summary-range {
  463. padding: 8rpx 20rpx 12rpx;
  464. text-align: center;
  465. }
  466. .range-text {
  467. font-size: 22rpx;
  468. color: #999999;
  469. }
  470. .summary-section {
  471. display: grid;
  472. grid-template-columns: repeat(3, 1fr);
  473. gap: 16rpx;
  474. padding: 0 20rpx 16rpx;
  475. }
  476. .summary-card {
  477. background-color: #FFFFFF;
  478. padding: 24rpx;
  479. border-radius: 16rpx;
  480. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  481. text-align: center;
  482. }
  483. .summary-label {
  484. font-size: 24rpx;
  485. color: #999999;
  486. display: block;
  487. margin-bottom: 8rpx;
  488. }
  489. .summary-value {
  490. font-size: 34rpx;
  491. font-weight: 700;
  492. color: #1A1A1A;
  493. display: block;
  494. }
  495. .summary-value.highlight {
  496. color: #C6171E;
  497. }
  498. .stats-list {
  499. padding: 0 20rpx;
  500. }
  501. .stats-item {
  502. background-color: #FFFFFF;
  503. border-radius: 24rpx;
  504. padding: 24rpx;
  505. margin-bottom: 16rpx;
  506. box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  507. }
  508. .stats-item:active {
  509. transform: translateY(-4rpx);
  510. box-shadow: 0 2px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.08);
  511. }
  512. .item-header {
  513. display: flex;
  514. flex-direction: column;
  515. align-items: center;
  516. padding-bottom: 16rpx;
  517. border-bottom: 1rpx solid #F0F0F0;
  518. margin-bottom: 16rpx;
  519. position: relative;
  520. }
  521. .item-period {
  522. font-size: 28rpx;
  523. font-weight: 600;
  524. color: #1A1A1A;
  525. text-align: center;
  526. }
  527. .item-station {
  528. font-size: 24rpx;
  529. color: #999999;
  530. margin-top: 4rpx;
  531. text-align: center;
  532. }
  533. .item-header-arrow {
  534. position: absolute;
  535. right: 0;
  536. top: 50%;
  537. transform: translateY(-50%);
  538. }
  539. .info-grid {
  540. display: grid;
  541. grid-template-columns: repeat(3, 1fr);
  542. gap: 12rpx;
  543. }
  544. .info-item {
  545. padding: 8rpx 0;
  546. text-align: center;
  547. }
  548. .info-label {
  549. font-size: 24rpx;
  550. color: #999999;
  551. display: block;
  552. margin-bottom: 4rpx;
  553. }
  554. .info-value {
  555. font-size: 26rpx;
  556. color: #1A1A1A;
  557. font-weight: 500;
  558. }
  559. .info-value.highlight {
  560. color: #C6171E;
  561. font-size: 28rpx;
  562. }
  563. .load-more {
  564. display: flex;
  565. justify-content: center;
  566. padding: 24rpx 0;
  567. }
  568. .load-more-text {
  569. font-size: 24rpx;
  570. color: #999999;
  571. }
  572. .empty-state {
  573. display: flex;
  574. flex-direction: column;
  575. align-items: center;
  576. padding: 80rpx 0;
  577. }
  578. .empty-text {
  579. font-size: 28rpx;
  580. color: #999999;
  581. margin-top: 20rpx;
  582. }
  583. .loading-state {
  584. display: flex;
  585. flex-direction: column;
  586. align-items: center;
  587. padding: 80rpx 0;
  588. }
  589. .loading-text {
  590. font-size: 28rpx;
  591. color: #999999;
  592. margin-top: 16rpx;
  593. }
  594. .loading-spinner {
  595. width: 60rpx;
  596. height: 60rpx;
  597. border: 4rpx solid rgba(198, 23, 30, 0.2);
  598. border-top-color: #C6171E;
  599. border-radius: 50%;
  600. animation: spin 0.8s linear infinite;
  601. }
  602. @keyframes spin {
  603. to { transform: rotate(360deg); }
  604. }
  605. /* 详情弹窗 */
  606. .detail-overlay {
  607. position: fixed;
  608. top: 0;
  609. left: 0;
  610. right: 0;
  611. bottom: 0;
  612. background-color: rgba(0, 0, 0, 0.5);
  613. display: flex;
  614. align-items: flex-end;
  615. z-index: 1000;
  616. }
  617. .detail-card {
  618. width: 100%;
  619. max-height: 80vh;
  620. background-color: #FFFFFF;
  621. border-radius: 32rpx 32rpx 0 0;
  622. padding: 30rpx;
  623. overflow-y: auto;
  624. }
  625. .detail-header {
  626. display: flex;
  627. justify-content: space-between;
  628. align-items: center;
  629. margin-bottom: 30rpx;
  630. }
  631. .detail-title {
  632. font-size: 32rpx;
  633. font-weight: 600;
  634. color: #1A1A1A;
  635. }
  636. .detail-close {
  637. padding: 10rpx;
  638. }
  639. .detail-grid {
  640. display: grid;
  641. grid-template-columns: repeat(3, 1fr);
  642. gap: 16rpx 12rpx;
  643. }
  644. .detail-cell {
  645. text-align: center;
  646. padding: 12rpx 0;
  647. border-bottom: 1rpx solid #F5F5F5;
  648. }
  649. .d-label {
  650. font-size: 24rpx;
  651. color: #999999;
  652. display: block;
  653. margin-bottom: 4rpx;
  654. }
  655. .d-value {
  656. font-size: 26rpx;
  657. color: #1A1A1A;
  658. font-weight: 500;
  659. display: block;
  660. }
  661. .d-value.amount {
  662. color: #C6171E;
  663. }
  664. </style>