index.vue 15 KB

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