index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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: 30rpx;
  171. opacity: 0.9;
  172. margin-bottom: 20rpx;
  173. font-weight: 600;
  174. }
  175. .total-amount {
  176. font-size: 80rpx;
  177. font-weight: 900;
  178. margin-bottom: 40rpx;
  179. }
  180. .date-picker-wrap {
  181. display: inline-block;
  182. }
  183. .date-range {
  184. background: rgba(255, 255, 255, 0.2);
  185. padding: 12rpx 32rpx;
  186. border-radius: 40rpx;
  187. font-size: 26rpx;
  188. display: flex;
  189. align-items: center;
  190. gap: 8rpx;
  191. }
  192. .stats-card {
  193. background: #fff;
  194. margin: -80rpx 32rpx 40rpx;
  195. padding: 40rpx 0;
  196. border-radius: 32rpx;
  197. display: flex;
  198. align-items: center;
  199. box-shadow: 0 12rpx 32rpx rgba(0, 0, 0, 0.05);
  200. position: relative;
  201. z-index: 2;
  202. }
  203. .stats-item {
  204. flex: 1;
  205. text-align: center;
  206. display: flex;
  207. flex-direction: column;
  208. gap: 12rpx;
  209. }
  210. .stats-value {
  211. font-size: 34rpx;
  212. font-weight: 800;
  213. color: #1a1a1a;
  214. }
  215. .stats-label {
  216. font-size: 26rpx;
  217. color: #999;
  218. }
  219. .stats-divider {
  220. width: 2rpx;
  221. height: 60rpx;
  222. background: #EEEEEE;
  223. }
  224. .detail-section {
  225. padding: 0 32rpx;
  226. }
  227. .section-header {
  228. display: flex;
  229. align-items: center;
  230. gap: 12rpx;
  231. margin-bottom: 24rpx;
  232. }
  233. .header-line {
  234. width: 8rpx;
  235. height: 32rpx;
  236. background: #ff7b00;
  237. border-radius: 4rpx;
  238. }
  239. .header-text {
  240. font-size: 30rpx;
  241. font-weight: bold;
  242. color: #333;
  243. }
  244. .detail-list {
  245. display: flex;
  246. flex-direction: column;
  247. gap: 20rpx;
  248. }
  249. .detail-item {
  250. background: #fff;
  251. padding: 32rpx;
  252. border-radius: 24rpx;
  253. display: flex;
  254. justify-content: space-between;
  255. align-items: center;
  256. }
  257. .detail-info {
  258. display: flex;
  259. flex-direction: column;
  260. gap: 12rpx;
  261. }
  262. .detail-title {
  263. font-size: 30rpx;
  264. font-weight: bold;
  265. color: #333;
  266. }
  267. .detail-time {
  268. font-size: 24rpx;
  269. color: #999;
  270. }
  271. .detail-amount-wrap {
  272. text-align: right;
  273. display: flex;
  274. flex-direction: column;
  275. gap: 8rpx;
  276. }
  277. .detail-amount {
  278. font-size: 34rpx;
  279. font-weight: bold;
  280. color: #ff5252;
  281. }
  282. .detail-no {
  283. font-size: 24rpx;
  284. color: #ccc;
  285. }
  286. </style>