index.vue 14 KB

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