index.vue 14 KB

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