order-stats.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <view class="container">
  3. <!-- 统计banner:圆角浮动卡,左右30rpx边距 -->
  4. <view class="stats-banner">
  5. <view class="banner-item">
  6. <text class="banner-num">{{ stats.total }}</text>
  7. <text class="banner-label">累计接单</text>
  8. </view>
  9. <view class="banner-item">
  10. <text class="banner-num">{{ stats.reject }}</text>
  11. <text class="banner-label">累计拒单</text>
  12. </view>
  13. <view class="banner-item">
  14. <text class="banner-num">{{ stats.reward }}</text>
  15. <text class="banner-label">奖励单量</text>
  16. </view>
  17. <view class="banner-item">
  18. <text class="banner-num">{{ stats.punish }}</text>
  19. <text class="banner-label">惩罚单量</text>
  20. </view>
  21. </view>
  22. <!-- 标签页(全宽,无圆角,紧贴屏幕宽度) -->
  23. <view class="tab-bar">
  24. <view
  25. class="tab-item"
  26. v-for="(tab, idx) in tabs"
  27. :key="idx"
  28. :class="{ active: activeTab === idx }"
  29. @click="switchTab(idx)"
  30. >
  31. <text>{{ tab }}</text>
  32. <view class="tab-line" v-if="activeTab === idx"></view>
  33. </view>
  34. </view>
  35. <!-- 订单列表:每张卡片用margin左右各30rpx,与banner宽度对齐 -->
  36. <scroll-view scroll-y class="order-scroll" @scrolltolower="onReachBottom">
  37. <view style="height: 16rpx;"></view>
  38. <view
  39. class="order-card"
  40. v-for="(order, idx) in filteredOrders"
  41. :key="idx"
  42. >
  43. <!-- 卡片头部:类型图标 + 类型名 | 状态 + 时间 -->
  44. <view class="card-header">
  45. <view class="type-badge">
  46. <image class="type-icon" :src="order.typeIcon"></image>
  47. <text class="type-text">{{ order.typeName }}</text>
  48. </view>
  49. <text class="status-text" :style="{ color: order.statusColor }">
  50. {{ order.statusLabel }}
  51. </text>
  52. </view>
  53. <!-- 服务时间 -->
  54. <text class="service-time">服务时间:{{ order.serviceTime }}</text>
  55. <!-- 宠物信息卡(灰底)+ 右侧价格 -->
  56. <view class="pet-card">
  57. <image class="pet-avatar" :src="order.petAvatar" mode="aspectFill"></image>
  58. <view class="pet-info">
  59. <text class="pet-name">{{ order.petName }}</text>
  60. <text class="pet-breed">品种: {{ order.petBreed }}</text>
  61. </view>
  62. <text class="pet-price">¥{{ order.price }}</text>
  63. </view>
  64. <!-- 路线信息 -->
  65. <view class="route-info">
  66. <!-- 接送:取 → 送 -->
  67. <template v-if="order.orderType === 1">
  68. <view class="route-item">
  69. <view class="icon-circle pickup">取</view>
  70. <view class="route-connector"></view>
  71. <view class="address-box">
  72. <text class="addr-title">{{ order.startName }}</text>
  73. <text class="addr-desc">{{ order.startAddr }}</text>
  74. </view>
  75. </view>
  76. <view class="route-item">
  77. <view class="icon-circle deliver">送</view>
  78. <view class="address-box">
  79. <text class="addr-title">{{ order.endName }}</text>
  80. <text class="addr-desc">{{ order.endAddr }}</text>
  81. </view>
  82. </view>
  83. </template>
  84. <!-- 喂遛/洗护:服 -->
  85. <template v-else>
  86. <view class="route-item">
  87. <view class="icon-circle service">服</view>
  88. <view class="address-box">
  89. <text class="addr-title">{{ order.endName }}</text>
  90. <text class="addr-desc">{{ order.endAddr }}</text>
  91. </view>
  92. </view>
  93. <view class="service-note-row" v-if="order.serviceNote">
  94. <text class="service-note-text">服务内容:{{ order.serviceNote }}</text>
  95. </view>
  96. </template>
  97. </view>
  98. </view>
  99. <!-- 空状态 -->
  100. <view class="empty-state" v-if="filteredOrders.length === 0 && !loading">
  101. <text class="empty-text">暂无相关订单</text>
  102. </view>
  103. <view class="loading-more" v-if="loading">
  104. <text>加载中...</text>
  105. </view>
  106. <view style="height: 40rpx;"></view>
  107. </scroll-view>
  108. </view>
  109. </template>
  110. <script>
  111. import { getOrderStats, getStatisticOrders } from '@/api/fulfiller';
  112. import { listAllService } from '@/api/service/list/index';
  113. export default {
  114. data() {
  115. return {
  116. tabs: ['全部', '已完成', '已拒绝'],
  117. activeTab: 0,
  118. stats: {
  119. total: 0,
  120. reject: 0,
  121. reward: 0,
  122. punish: 0
  123. },
  124. orders: [],
  125. serviceList: [],
  126. pageNum: 1,
  127. pageSize: 10,
  128. total: 0,
  129. loading: false
  130. };
  131. },
  132. computed: {
  133. filteredOrders() {
  134. return this.orders;
  135. }
  136. },
  137. async onLoad() {
  138. await this.loadServiceList();
  139. this.fetchStats();
  140. this.fetchOrders(true);
  141. },
  142. methods: {
  143. async loadServiceList() {
  144. try {
  145. const res = await listAllService();
  146. this.serviceList = res.data || [];
  147. } catch (err) {
  148. console.error('获取服务类型失败:', err);
  149. }
  150. },
  151. async fetchStats() {
  152. try {
  153. const res = await getOrderStats();
  154. if (res.code === 200 && res.data) {
  155. this.stats = {
  156. ...this.stats,
  157. ...res.data
  158. };
  159. }
  160. } catch (err) {
  161. console.error('获取统计值失败:', err);
  162. }
  163. },
  164. async fetchOrders(reset = false) {
  165. if (reset) {
  166. this.pageNum = 1;
  167. this.orders = [];
  168. }
  169. if (this.loading) return;
  170. if (!reset && this.orders.length >= this.total && this.total !== 0) return;
  171. this.loading = true;
  172. try {
  173. const statusMap = { 0: undefined, 1: 4, 2: 5 };
  174. const params = {
  175. status: statusMap[this.activeTab],
  176. pageNum: this.pageNum,
  177. pageSize: this.pageSize
  178. };
  179. const res = await getStatisticOrders(params);
  180. if (res.code === 200) {
  181. this.total = res.total || 0;
  182. const rows = res.rows || [];
  183. const mapped = rows.map(item => this.transformOrder(item));
  184. this.orders = this.orders.concat(mapped);
  185. this.pageNum++;
  186. }
  187. } catch (err) {
  188. console.error('获取订单列表失败:', err);
  189. } finally {
  190. this.loading = false;
  191. }
  192. },
  193. transformOrder(order) {
  194. const service = this.serviceList.find(s => s.id === order.service);
  195. const mode = service?.mode || 0;
  196. const isRoundTrip = mode === 1;
  197. // 状态枚举映射
  198. const statusMap = {
  199. 0: { label: '待派单', color: '#f56c6c' },
  200. 1: { label: '待接单', color: '#e6a23c' },
  201. 2: { label: '待服务', color: '#49a3ff' },
  202. 3: { label: '服务中', color: '#49a3ff' },
  203. 4: { label: '已完成', color: '#67c23a' },
  204. 5: { label: '已取消', color: '#909399' }
  205. };
  206. const statusInfo = statusMap[order.status] || { label: '未知', color: '#999' };
  207. return {
  208. id: order.id,
  209. orderType: isRoundTrip ? 1 : 2,
  210. typeName: service?.name || '未知',
  211. typeIcon: service?.iconUrl || '',
  212. statusLabel: statusInfo.label,
  213. statusColor: statusInfo.color,
  214. finishTime: order.serviceTime || '',
  215. serviceTime: order.serviceTime || '',
  216. petName: order.petName || '未知',
  217. petBreed: order.breed || '未知',
  218. petAvatar: order.petAvatarUrl || '/static/dog.png',
  219. price: (order.price / 100).toFixed(2),
  220. startName: order.fromAddress || '',
  221. startAddr: order.fromAddress || '',
  222. endName: (order.customerName || '') + ' ' + (order.customerPhone || ''),
  223. endAddr: order.toAddress || '',
  224. serviceNote: order.remark || ''
  225. };
  226. },
  227. switchTab(idx) {
  228. this.activeTab = idx;
  229. this.fetchOrders(true);
  230. },
  231. onReachBottom() {
  232. this.fetchOrders();
  233. },
  234. navBack() {
  235. uni.navigateBack();
  236. }
  237. }
  238. };
  239. </script>
  240. <style>
  241. page { background-color: #F7F8FA; }
  242. .container { min-height: 100vh; background-color: #F7F8FA; padding: 20rpx 0 0; display: flex; flex-direction: column; }
  243. /* ===== 统计banner:圆角浮动卡,左右30rpx边距 ===== */
  244. .stats-banner {
  245. background: linear-gradient(135deg, #FF9800 0%, #FF5722 100%);
  246. padding: 28rpx 16rpx;
  247. display: flex;
  248. justify-content: space-around;
  249. margin: 0 30rpx 20rpx;
  250. border-radius: 20rpx;
  251. box-shadow: 0 6rpx 20rpx rgba(255, 87, 34, 0.25);
  252. flex-shrink: 0;
  253. }
  254. .banner-item { display: flex; flex-direction: column; align-items: center; }
  255. .banner-num { font-size: 34rpx; font-weight: bold; color: #fff; margin-bottom: 4rpx; }
  256. .banner-unit { font-size: 22rpx; font-weight: normal; }
  257. .banner-label { font-size: 20rpx; color: rgba(255,255,255,0.85); }
  258. /* ===== 标签页:全宽平铺,无圆角,无side margin ===== */
  259. .tab-bar {
  260. background-color: #fff;
  261. display: flex;
  262. padding: 0 30rpx;
  263. border-bottom: 1rpx solid #f0f0f0;
  264. margin-bottom: 0;
  265. flex-shrink: 0;
  266. }
  267. .tab-item {
  268. padding: 20rpx 24rpx;
  269. font-size: 28rpx;
  270. color: #999;
  271. position: relative;
  272. display: flex;
  273. flex-direction: column;
  274. align-items: center;
  275. }
  276. .tab-item.active { color: #FF9800; font-weight: bold; }
  277. .tab-line {
  278. position: absolute;
  279. bottom: 0;
  280. left: 50%;
  281. transform: translateX(-50%);
  282. width: 36rpx;
  283. height: 4rpx;
  284. background-color: #FF9800;
  285. border-radius: 2rpx;
  286. }
  287. /* ===== 订单列表:scroll-view 全宽,每张card用margin左右30rpx ===== */
  288. .order-scroll { flex: 1; height: 0; width: 100%; }
  289. .order-card {
  290. background-color: #fff;
  291. border-radius: 16rpx;
  292. padding: 24rpx;
  293. margin: 0 30rpx 16rpx;
  294. box-sizing: border-box;
  295. }
  296. /* 卡片头部 */
  297. .card-header {
  298. display: flex;
  299. align-items: center;
  300. justify-content: space-between;
  301. margin-bottom: 10rpx;
  302. }
  303. .type-badge { display: flex; align-items: center; }
  304. .type-icon {
  305. width: 44rpx;
  306. height: 44rpx;
  307. margin-right: 12rpx;
  308. }
  309. .type-text { font-size: 30rpx; font-weight: bold; color: #333; }
  310. .status-text { font-size: 24rpx; }
  311. .status-text.green { color: #4CAF50; }
  312. .status-text.red { color: #F44336; }
  313. /* 服务时间 */
  314. .service-time {
  315. font-size: 24rpx;
  316. color: #999;
  317. margin-bottom: 16rpx;
  318. display: block;
  319. }
  320. /* 宠物信息卡(灰底背景,右侧显示价格) */
  321. .pet-card {
  322. background-color: #F7F8FA;
  323. border-radius: 10rpx;
  324. padding: 16rpx 20rpx;
  325. display: flex;
  326. align-items: center;
  327. margin-bottom: 16rpx;
  328. }
  329. .pet-avatar { width: 70rpx; height: 70rpx; border-radius: 50%; margin-right: 16rpx; flex-shrink: 0; }
  330. .pet-info { flex: 1; display: flex; flex-direction: column; }
  331. .pet-name { font-size: 28rpx; font-weight: bold; color: #333; margin-bottom: 4rpx; }
  332. .pet-breed { font-size: 24rpx; color: #999; }
  333. /* 价格在宠物卡右侧 */
  334. .pet-price { font-size: 34rpx; font-weight: bold; color: #FF5722; flex-shrink: 0; }
  335. /* 路线信息 */
  336. .route-info { display: flex; flex-direction: column; }
  337. .route-item {
  338. display: flex;
  339. align-items: flex-start;
  340. position: relative;
  341. padding-bottom: 8rpx;
  342. }
  343. .icon-circle {
  344. width: 44rpx;
  345. height: 44rpx;
  346. border-radius: 50%;
  347. display: flex;
  348. align-items: center;
  349. justify-content: center;
  350. font-size: 22rpx;
  351. font-weight: bold;
  352. color: #fff;
  353. flex-shrink: 0;
  354. margin-right: 16rpx;
  355. margin-top: 2rpx;
  356. }
  357. .icon-circle.pickup { background: linear-gradient(135deg, #FF9800, #FF6D00); }
  358. .icon-circle.deliver { background: linear-gradient(135deg, #4CAF50, #2E7D32); }
  359. .icon-circle.service { background: linear-gradient(135deg, #4CAF50, #1B5E20); }
  360. /* 取→送之间的虚线连接 */
  361. .route-connector {
  362. position: absolute;
  363. left: 21rpx;
  364. top: 46rpx;
  365. width: 2rpx;
  366. height: 30rpx;
  367. background-color: #e0e0e0;
  368. }
  369. .address-box { flex: 1; padding-bottom: 14rpx; }
  370. .addr-title { font-size: 26rpx; color: #333; display: block; margin-bottom: 4rpx; }
  371. .addr-desc { font-size: 24rpx; color: #999; display: block; }
  372. /* 服务内容说明(喂遛/洗护) */
  373. .service-note-row { padding: 4rpx 0 0 60rpx; }
  374. .service-note-text { font-size: 24rpx; color: #999; }
  375. /* 空状态 */
  376. .empty-state { text-align: center; padding: 80rpx 0; }
  377. .empty-text { font-size: 28rpx; color: #ccc; }
  378. .loading-more { text-align: center; padding: 20rpx; font-size: 24rpx; color: #999; }
  379. </style>