index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <view class="fee-statistics-page">
  3. <NavBar title="费用统计" bgColor="#ffffff" color="#000"></NavBar>
  4. <!-- 顶部背景 -->
  5. <view class="header-bg">
  6. <view class="total-title">总服务费 (元)</view>
  7. <view class="total-amount">{{ totalFee }}</view>
  8. <view class="date-picker-wrap">
  9. <picker mode="date" fields="month" @change="onDateChange">
  10. <view class="date-range">
  11. <text>{{ currentDateText }}</text>
  12. <uni-icons type="bottom" size="14" color="#fff"></uni-icons>
  13. </view>
  14. </picker>
  15. </view>
  16. </view>
  17. <!-- 统计卡片 -->
  18. <view class="stats-card">
  19. <view class="stats-item">
  20. <text class="stats-value">{{ totalCount }}</text>
  21. <text class="stats-label">单数</text>
  22. </view>
  23. <view class="stats-divider"></view>
  24. <view class="stats-item">
  25. <text class="stats-value">{{ maxFee }}</text>
  26. <text class="stats-label">最高单笔</text>
  27. </view>
  28. <view class="stats-divider"></view>
  29. <view class="stats-item">
  30. <text class="stats-value">{{ avgFee }}</text>
  31. <text class="stats-label">平均单笔</text>
  32. </view>
  33. </view>
  34. <!-- 订单明细 -->
  35. <view class="detail-section">
  36. <view class="section-header">
  37. <view class="header-line"></view>
  38. <text class="header-text">订单明细</text>
  39. </view>
  40. <view class="detail-list">
  41. <view class="detail-item" v-for="(item, index) in orderDetails" :key="index">
  42. <view class="detail-info">
  43. <view class="detail-title">{{ item.title }}</view>
  44. <view class="detail-time">{{ item.time }}</view>
  45. </view>
  46. <view class="detail-amount-wrap">
  47. <view class="detail-amount">+{{ item.amount }}</view>
  48. <view class="detail-no">{{ item.orderNo }}</view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script setup>
  56. import { ref, computed } from 'vue'
  57. import { onLoad } from '@dcloudio/uni-app'
  58. import NavBar from '@/components/nav-bar/index.vue'
  59. import { listOnFeeStatistic } from '@/api/order/subOrder'
  60. import { listAll } from '@/api/service/list'
  61. const orderDetails = ref([])
  62. const totalFee = ref('0.00')
  63. const totalCount = ref(0)
  64. const maxFee = ref('0.00')
  65. const avgFee = ref('0.00')
  66. const serviceMap = ref({})
  67. const currentDateText = ref('本月')
  68. const queryParams = ref({
  69. pageNum: 1,
  70. pageSize: 9999,
  71. 'params[beginTime]': '',
  72. 'params[endTime]': ''
  73. })
  74. const getList = async () => {
  75. try {
  76. uni.showLoading({ title: '加载中' })
  77. const res = await listOnFeeStatistic(queryParams.value)
  78. const list = res.rows || []
  79. let sum = 0
  80. let max = 0
  81. orderDetails.value = list.map(item => {
  82. // 后端金额是分,转化为元
  83. const amount = (item.orderCommission || 0) / 100
  84. sum += amount
  85. if (amount > max) {
  86. max = amount
  87. }
  88. // 组装标题 (优先团购套餐,否则通过serviceId获取服务名称)
  89. let finalTitle = item.groupPurchasePackageName || ''
  90. if (!finalTitle) {
  91. const sId = (item.service || item.serviceId || '').toString().trim()
  92. if (sId) {
  93. finalTitle = serviceMap.value[sId] || '未知服务'
  94. }
  95. }
  96. return {
  97. title: finalTitle || '基础服务',
  98. time: item.createTime || '',
  99. amount: amount.toFixed(2),
  100. orderNo: item.code || ''
  101. }
  102. })
  103. totalCount.value = list.length
  104. totalFee.value = sum.toFixed(2)
  105. maxFee.value = max.toFixed(2)
  106. avgFee.value = list.length > 0 ? (sum / list.length).toFixed(2) : '0.00'
  107. } catch (e) {
  108. console.error(e)
  109. } finally {
  110. uni.hideLoading()
  111. }
  112. }
  113. const onDateChange = (e) => {
  114. const val = e.detail.value // "YYYY-MM"
  115. currentDateText.value = val
  116. // 简单的处理将月份转为当月起始和结束时间
  117. const date = new Date(val + '-01')
  118. const year = date.getFullYear()
  119. const month = date.getMonth()
  120. const lastDay = new Date(year, month + 1, 0).getDate()
  121. queryParams.value['params[beginTime]'] = `${val}-01 00:00:00`
  122. queryParams.value['params[endTime]'] = `${val}-${lastDay} 23:59:59`
  123. getList()
  124. }
  125. const getServices = async () => {
  126. try {
  127. const res = await listAll()
  128. const dataList = res.data || res.rows || (Array.isArray(res) ? res : [])
  129. if (Array.isArray(dataList)) {
  130. const tempMap = {}
  131. dataList.forEach(s => {
  132. if (s.id) {
  133. tempMap[String(s.id).trim()] = s.name
  134. }
  135. })
  136. serviceMap.value = tempMap
  137. }
  138. } catch (e) {
  139. console.error('获取服务类型失败', e)
  140. }
  141. }
  142. onLoad(async () => {
  143. // 默认本月
  144. const now = new Date()
  145. const year = now.getFullYear()
  146. let month = now.getMonth() + 1
  147. if (month < 10) month = '0' + month
  148. const val = `${year}-${month}`
  149. currentDateText.value = val
  150. const lastDay = new Date(year, month, 0).getDate()
  151. queryParams.value['params[beginTime]'] = `${val}-01 00:00:00`
  152. queryParams.value['params[endTime]'] = `${val}-${lastDay} 23:59:59`
  153. uni.showLoading({ title: '加载中' })
  154. await getServices()
  155. getList()
  156. })
  157. </script>
  158. <style lang="scss" scoped>
  159. .fee-statistics-page {
  160. min-height: 100vh;
  161. background-color: #f8f9fb;
  162. }
  163. .header-bg {
  164. background: linear-gradient(180deg, #ff7b00 0%, #ff9500 100%);
  165. padding: 60rpx 40rpx 140rpx;
  166. text-align: center;
  167. color: #fff;
  168. }
  169. .total-title {
  170. font-size: 28rpx;
  171. opacity: 0.9;
  172. margin-bottom: 20rpx;
  173. }
  174. .total-amount {
  175. font-size: 80rpx;
  176. font-weight: 900;
  177. margin-bottom: 40rpx;
  178. }
  179. .date-picker-wrap {
  180. display: inline-block;
  181. }
  182. .date-range {
  183. background: rgba(255, 255, 255, 0.2);
  184. padding: 12rpx 32rpx;
  185. border-radius: 40rpx;
  186. font-size: 24rpx;
  187. display: flex;
  188. align-items: center;
  189. gap: 8rpx;
  190. }
  191. .stats-card {
  192. background: #fff;
  193. margin: -80rpx 32rpx 40rpx;
  194. padding: 40rpx 0;
  195. border-radius: 32rpx;
  196. display: flex;
  197. align-items: center;
  198. box-shadow: 0 12rpx 32rpx rgba(0, 0, 0, 0.05);
  199. position: relative;
  200. z-index: 2;
  201. }
  202. .stats-item {
  203. flex: 1;
  204. text-align: center;
  205. display: flex;
  206. flex-direction: column;
  207. gap: 12rpx;
  208. }
  209. .stats-value {
  210. font-size: 36rpx;
  211. font-weight: 800;
  212. color: #1a1a1a;
  213. }
  214. .stats-label {
  215. font-size: 22rpx;
  216. color: #999;
  217. }
  218. .stats-divider {
  219. width: 2rpx;
  220. height: 60rpx;
  221. background: #f0f0f0;
  222. }
  223. .detail-section {
  224. padding: 0 32rpx;
  225. }
  226. .section-header {
  227. display: flex;
  228. align-items: center;
  229. gap: 12rpx;
  230. margin-bottom: 24rpx;
  231. }
  232. .header-line {
  233. width: 8rpx;
  234. height: 32rpx;
  235. background: #ff7b00;
  236. border-radius: 4rpx;
  237. }
  238. .header-text {
  239. font-size: 32rpx;
  240. font-weight: bold;
  241. color: #333;
  242. }
  243. .detail-list {
  244. display: flex;
  245. flex-direction: column;
  246. gap: 20rpx;
  247. }
  248. .detail-item {
  249. background: #fff;
  250. padding: 32rpx;
  251. border-radius: 24rpx;
  252. display: flex;
  253. justify-content: space-between;
  254. align-items: center;
  255. }
  256. .detail-info {
  257. display: flex;
  258. flex-direction: column;
  259. gap: 12rpx;
  260. }
  261. .detail-title {
  262. font-size: 28rpx;
  263. font-weight: bold;
  264. color: #333;
  265. }
  266. .detail-time {
  267. font-size: 24rpx;
  268. color: #999;
  269. }
  270. .detail-amount-wrap {
  271. text-align: right;
  272. display: flex;
  273. flex-direction: column;
  274. gap: 8rpx;
  275. }
  276. .detail-amount {
  277. font-size: 32rpx;
  278. font-weight: bold;
  279. color: #ff5252;
  280. }
  281. .detail-no {
  282. font-size: 22rpx;
  283. color: #ccc;
  284. }
  285. </style>