index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. uni.showToast({ title: typeof e === 'string' ? e : '加载费用统计失败', icon: 'none' })
  110. } finally {
  111. uni.hideLoading()
  112. }
  113. }
  114. const onDateChange = (e) => {
  115. const val = e.detail.value // "YYYY-MM"
  116. currentDateText.value = val
  117. // 简单的处理将月份转为当月起始和结束时间
  118. const date = new Date(val + '-01')
  119. const year = date.getFullYear()
  120. const month = date.getMonth()
  121. const lastDay = new Date(year, month + 1, 0).getDate()
  122. queryParams.value['params[beginTime]'] = `${val}-01 00:00:00`
  123. queryParams.value['params[endTime]'] = `${val}-${lastDay} 23:59:59`
  124. getList()
  125. }
  126. const getServices = async () => {
  127. try {
  128. const res = await listAll()
  129. const dataList = res.data || res.rows || (Array.isArray(res) ? res : [])
  130. if (Array.isArray(dataList)) {
  131. const tempMap = {}
  132. dataList.forEach(s => {
  133. if (s.id) {
  134. tempMap[String(s.id).trim()] = s.name
  135. }
  136. })
  137. serviceMap.value = tempMap
  138. }
  139. } catch (e) {
  140. console.error('获取服务类型失败', e)
  141. uni.showToast({ title: typeof e === 'string' ? e : '获取服务类型失败', icon: 'none' })
  142. }
  143. }
  144. onLoad(async () => {
  145. // 默认本月
  146. const now = new Date()
  147. const year = now.getFullYear()
  148. let month = now.getMonth() + 1
  149. if (month < 10) month = '0' + month
  150. const val = `${year}-${month}`
  151. currentDateText.value = val
  152. const lastDay = new Date(year, month, 0).getDate()
  153. queryParams.value['params[beginTime]'] = `${val}-01 00:00:00`
  154. queryParams.value['params[endTime]'] = `${val}-${lastDay} 23:59:59`
  155. uni.showLoading({ title: '加载中' })
  156. await getServices()
  157. getList()
  158. })
  159. </script>
  160. <style lang="scss" scoped>
  161. .fee-statistics-page {
  162. min-height: 100vh;
  163. background-color: #f8f9fb;
  164. }
  165. .header-bg {
  166. background: linear-gradient(180deg, #ff7b00 0%, #ff9500 100%);
  167. padding: 60rpx 40rpx 140rpx;
  168. text-align: center;
  169. color: #fff;
  170. }
  171. .total-title {
  172. font-size: 30rpx;
  173. opacity: 0.9;
  174. margin-bottom: 20rpx;
  175. font-weight: 600;
  176. }
  177. .total-amount {
  178. font-size: 80rpx;
  179. font-weight: 900;
  180. margin-bottom: 40rpx;
  181. }
  182. .date-picker-wrap {
  183. display: inline-block;
  184. }
  185. .date-range {
  186. background: rgba(255, 255, 255, 0.2);
  187. padding: 12rpx 32rpx;
  188. border-radius: 40rpx;
  189. font-size: 26rpx;
  190. display: flex;
  191. align-items: center;
  192. gap: 8rpx;
  193. }
  194. .stats-card {
  195. background: #fff;
  196. margin: -80rpx 32rpx 40rpx;
  197. padding: 40rpx 0;
  198. border-radius: 32rpx;
  199. display: flex;
  200. align-items: center;
  201. box-shadow: 0 12rpx 32rpx rgba(0, 0, 0, 0.05);
  202. position: relative;
  203. z-index: 2;
  204. }
  205. .stats-item {
  206. flex: 1;
  207. text-align: center;
  208. display: flex;
  209. flex-direction: column;
  210. gap: 12rpx;
  211. }
  212. .stats-value {
  213. font-size: 34rpx;
  214. font-weight: 800;
  215. color: #1a1a1a;
  216. }
  217. .stats-label {
  218. font-size: 26rpx;
  219. color: #999;
  220. }
  221. .stats-divider {
  222. width: 2rpx;
  223. height: 60rpx;
  224. background: #EEEEEE;
  225. }
  226. .detail-section {
  227. padding: 0 32rpx;
  228. }
  229. .section-header {
  230. display: flex;
  231. align-items: center;
  232. gap: 12rpx;
  233. margin-bottom: 24rpx;
  234. }
  235. .header-line {
  236. width: 8rpx;
  237. height: 32rpx;
  238. background: #ff7b00;
  239. border-radius: 4rpx;
  240. }
  241. .header-text {
  242. font-size: 30rpx;
  243. font-weight: bold;
  244. color: #333;
  245. }
  246. .detail-list {
  247. display: flex;
  248. flex-direction: column;
  249. gap: 20rpx;
  250. }
  251. .detail-item {
  252. background: #fff;
  253. padding: 32rpx;
  254. border-radius: 24rpx;
  255. display: flex;
  256. justify-content: space-between;
  257. align-items: center;
  258. }
  259. .detail-info {
  260. display: flex;
  261. flex-direction: column;
  262. gap: 12rpx;
  263. }
  264. .detail-title {
  265. font-size: 30rpx;
  266. font-weight: bold;
  267. color: #333;
  268. }
  269. .detail-time {
  270. font-size: 24rpx;
  271. color: #999;
  272. }
  273. .detail-amount-wrap {
  274. text-align: right;
  275. display: flex;
  276. flex-direction: column;
  277. gap: 8rpx;
  278. }
  279. .detail-amount {
  280. font-size: 34rpx;
  281. font-weight: bold;
  282. color: #ff5252;
  283. }
  284. .detail-no {
  285. font-size: 24rpx;
  286. color: #ccc;
  287. }
  288. </style>