index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <view class="order-list-page">
  3. <nav-bar title="订单列表" :showBack="false"></nav-bar>
  4. <!-- 顶部状态栏 -->
  5. <view class="sticky-header">
  6. <scroll-view scroll-x class="tabs-scroll" :show-scrollbar="false">
  7. <view class="tabs-row">
  8. <view v-for="tab in tabList" :key="tab.value"
  9. :class="['tab-item', { active: activeStatus === tab.value }]" @click="onTabClick(tab.value)">
  10. <text>{{ tab.title }}</text>
  11. </view>
  12. </view>
  13. </scroll-view>
  14. <!-- 搜索和过滤 -->
  15. <view class="filter-row">
  16. <picker :range="typeOptions" range-key="text" @change="onTypeChange">
  17. <view class="dropdown-btn">
  18. <text>{{ currentTypeName }}</text>
  19. <uni-icons type="bottom" size="12" color="#333"></uni-icons>
  20. </view>
  21. </picker>
  22. <view class="search-wrap">
  23. <uni-icons type="search" size="14" color="#999"></uni-icons>
  24. <input class="search-input" v-model="searchValue" placeholder="订单号/商户/宠主/手机号"
  25. placeholder-class="placeholder-style" />
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 订单列表内容 -->
  30. <view class="list-container">
  31. <view class="order-card" v-for="order in filteredOrders" :key="order.id" @click="goToDetail(order)">
  32. <!-- 头部:订单号与状态 -->
  33. <view class="order-head">
  34. <text class="order-no">{{ order.id }}</text>
  35. <text :class="['status-text', order.statusClass]">{{ order.statusText }}</text>
  36. </view>
  37. <!-- 主体信息 -->
  38. <view class="order-body">
  39. <view class="service-row">
  40. <text class="service-name">{{ order.serviceType }}</text>
  41. <text class="service-tag tag-orange" v-if="order.serviceTags[0]">{{ order.serviceTags[0]
  42. }}</text>
  43. <text class="service-tag tag-blue" v-if="order.serviceTags[1] === '接'">接</text>
  44. <text class="service-tag tag-green" v-if="order.serviceTags[1] === '送'">送</text>
  45. </view>
  46. <view class="pet-row">
  47. <view class="pet-avatar-text">
  48. <text>{{ order.petName.substring(0, 1).toUpperCase() }}</text>
  49. </view>
  50. <view class="pet-desc">
  51. <text class="bold">{{ order.petName }}</text>
  52. <text class="sub">{{ order.petBreed }}</text>
  53. </view>
  54. <text class="user-desc">{{ order.userName }}</text>
  55. </view>
  56. <view class="info-list">
  57. <view class="info-item">
  58. <uni-icons type="location" size="14" color="#999"></uni-icons>
  59. <text>{{ order.address }}</text>
  60. </view>
  61. <view class="info-item">
  62. <uni-icons type="shop" size="14" color="#999"></uni-icons>
  63. <text>{{ order.shopName }} {{ order.userPhone }}</text>
  64. </view>
  65. <view class="info-item">
  66. <uni-icons type="calendar" size="14" color="#999"></uni-icons>
  67. <text>预约: {{ order.bookTime }}</text>
  68. </view>
  69. </view>
  70. </view>
  71. <!-- 履约与操作栏 -->
  72. <view class="order-foot">
  73. <view class="foot-left">
  74. <text class="create-time">下单: {{ order.createTime }}</text>
  75. <view class="assign-info">
  76. <text class="assign-label">履约信息:</text>
  77. <text class="assign-none" v-if="order.statusText === '待派单'">暂未派单</text>
  78. <text class="assign-none" v-else-if="order.statusText === '已取消'">订单已关闭</text>
  79. <text class="assign-name" v-else>{{ order.assigneeName }}</text>
  80. </view>
  81. <text class="cancel-time" v-if="order.statusText === '已取消' && order.cancelTime">取消: {{
  82. order.cancelTime }}</text>
  83. </view>
  84. <view class="actions">
  85. <template v-if="order.statusText === '待派单' || order.statusText === '待接单'">
  86. <button size="mini" class="action-btn btn-cancel"
  87. @click.stop="onCancelOrder(order)">取消</button>
  88. <button size="mini" class="action-btn btn-primary"
  89. @click.stop="goToDetail(order)">详情</button>
  90. </template>
  91. <template v-else-if="['服务中', '待商家确认', '已完成'].includes(order.statusText)">
  92. <button v-if="['服务中', '已完成'].includes(order.statusText)" size="mini"
  93. class="action-btn btn-cancel" @click.stop="onComplaint(order)">投诉</button>
  94. <button size="mini" class="action-btn btn-primary"
  95. @click.stop="goToDetail(order)">详情</button>
  96. </template>
  97. <template v-else>
  98. <button size="mini" class="action-btn btn-primary"
  99. @click.stop="goToDetail(order)">详情</button>
  100. </template>
  101. </view>
  102. </view>
  103. </view>
  104. <!-- 空状态 -->
  105. <view class="empty-state" v-if="filteredOrders.length === 0">
  106. <text class="empty-text">暂无相关订单</text>
  107. </view>
  108. </view>
  109. <custom-tabbar></custom-tabbar>
  110. </view>
  111. </template>
  112. <script setup>
  113. import { ref, computed } from 'vue'
  114. import { onLoad } from '@dcloudio/uni-app'
  115. import navBar from '@/components/nav-bar/index.vue'
  116. import customTabbar from '@/components/custom-tabbar/index.vue'
  117. import orderMockData from '@/mock/order.json'
  118. import orderStatusData from '@/json/orderStatus.json'
  119. // 筛选与搜索
  120. const activeStatus = ref(-1) // -1 表示全部,其他值为枚举值
  121. const filterType = ref(0)
  122. const searchValue = ref('')
  123. // 从 orderStatus.json 生成 tabList
  124. const tabList = ref([
  125. { title: '全部订单', value: -1 },
  126. ...orderStatusData.map(item => ({
  127. title: item.label,
  128. value: item.value,
  129. color: item.color
  130. }))
  131. ])
  132. const typeOptions = [
  133. { text: '全部类型', value: 0 },
  134. { text: '宠物接送', value: 1 },
  135. { text: '上门喂遛', value: 2 },
  136. { text: '上门洗护', value: 3 }
  137. ]
  138. const currentTypeName = computed(() => {
  139. return typeOptions[filterType.value].text
  140. })
  141. // 从 URL 参数初始化状态
  142. onLoad((options) => {
  143. if (options.status !== undefined) {
  144. const statusValue = parseInt(options.status)
  145. if (!isNaN(statusValue)) {
  146. activeStatus.value = statusValue
  147. }
  148. }
  149. })
  150. // 根据枚举值获取状态信息
  151. const getStatusInfo = (value) => {
  152. return orderStatusData.find(item => item.value === value)
  153. }
  154. const onTabClick = (value) => {
  155. activeStatus.value = value
  156. }
  157. const onTypeChange = (e) => {
  158. filterType.value = Number(e.detail.value)
  159. }
  160. // 搜索与过滤后的订单列表
  161. const filteredOrders = computed(() => {
  162. return orders.value.filter(order => {
  163. let statusMatch = true
  164. if (activeStatus.value !== -1) {
  165. const statusInfo = getStatusInfo(activeStatus.value)
  166. statusMatch = statusInfo && order.statusText === statusInfo.label
  167. }
  168. const typeMap = { 1: '宠物接送', 2: '上门喂遛', 3: '上门洗护' }
  169. const typeMatch = filterType.value === 0 || order.serviceType === typeMap[filterType.value]
  170. const searchLower = searchValue.value.toLowerCase()
  171. const searchMatch = !searchValue.value ||
  172. order.id.toLowerCase().includes(searchLower) ||
  173. order.userName.toLowerCase().includes(searchLower) ||
  174. order.petName.toLowerCase().includes(searchLower) ||
  175. order.userPhone.includes(searchLower)
  176. return statusMatch && typeMatch && searchMatch
  177. })
  178. })
  179. const orders = ref(orderMockData)
  180. const onCancelOrder = (order) => {
  181. uni.showModal({
  182. title: '提示',
  183. content: `确定要取消订单 [${order.id}] 吗?`,
  184. success: (res) => {
  185. if (res.confirm) {
  186. uni.showToast({ title: '订单已取消', icon: 'success' })
  187. order.statusText = '已取消'
  188. order.statusClass = 'text-gray'
  189. activeStatus.value = 5
  190. }
  191. }
  192. })
  193. }
  194. const goToDetail = (order) => {
  195. const serviceKey = order.serviceType === '宠物接送' ? 'transport' : (order.serviceType === '上门喂遛' ? 'feed' : 'wash')
  196. // 根据 statusText 查找对应的枚举值
  197. const statusInfo = orderStatusData.find(item => item.label === order.statusText)
  198. const statusValue = statusInfo ? statusInfo.value : 3
  199. const cancelTime = order.cancelTime ? encodeURIComponent(order.cancelTime) : ''
  200. uni.navigateTo({
  201. url: `/pages/order/detail/index?service=${serviceKey}&status=${statusValue}${cancelTime ? '&cancelTime=' + cancelTime : ''}`
  202. })
  203. }
  204. const onComplaint = (order) => {
  205. uni.navigateTo({
  206. url: `/pages/my/complaint-submit/index?orderId=${order.id}`
  207. })
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .order-list-page {
  212. background-color: #f2f2f2;
  213. min-height: 100vh;
  214. padding-bottom: 120rpx;
  215. }
  216. .sticky-header {
  217. position: sticky;
  218. top: calc(44px + var(--status-bar-height, 44px));
  219. z-index: 99;
  220. background-color: #fff;
  221. }
  222. .tabs-scroll {
  223. white-space: nowrap;
  224. border-bottom: 1rpx solid #f5f5f5;
  225. }
  226. .tabs-row {
  227. display: flex;
  228. padding: 0 16rpx;
  229. }
  230. .tab-item {
  231. padding: 24rpx 24rpx;
  232. font-size: 28rpx;
  233. color: #666;
  234. position: relative;
  235. flex-shrink: 0;
  236. }
  237. .tab-item.active {
  238. color: #333;
  239. font-weight: bold;
  240. }
  241. .tab-item.active::after {
  242. content: '';
  243. position: absolute;
  244. bottom: 0;
  245. left: 50%;
  246. transform: translateX(-50%);
  247. width: 48rpx;
  248. height: 6rpx;
  249. background-color: #f7ca3e;
  250. border-radius: 6rpx;
  251. }
  252. .filter-row {
  253. display: flex;
  254. align-items: center;
  255. padding: 12rpx 16rpx;
  256. background-color: #fff;
  257. border-top: 1rpx solid #f9f9f9;
  258. gap: 16rpx;
  259. }
  260. .dropdown-btn {
  261. display: flex;
  262. align-items: center;
  263. gap: 8rpx;
  264. background: #f5f5f5;
  265. border-radius: 34rpx;
  266. padding: 12rpx 24rpx;
  267. font-size: 26rpx;
  268. color: #333;
  269. }
  270. .search-wrap {
  271. flex: 1;
  272. display: flex;
  273. align-items: center;
  274. background: #f5f5f5;
  275. border-radius: 34rpx;
  276. padding: 12rpx 20rpx;
  277. gap: 12rpx;
  278. }
  279. .search-input {
  280. flex: 1;
  281. font-size: 24rpx;
  282. }
  283. .placeholder-style {
  284. color: #999;
  285. font-size: 24rpx;
  286. }
  287. .list-container {
  288. padding: 24rpx;
  289. }
  290. .order-card {
  291. padding: 28rpx;
  292. margin-bottom: 24rpx;
  293. background: #fff;
  294. border-radius: 24rpx;
  295. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  296. }
  297. .order-head {
  298. display: flex;
  299. justify-content: space-between;
  300. align-items: center;
  301. border-bottom: 1rpx solid #f5f5f5;
  302. padding-bottom: 20rpx;
  303. margin-bottom: 20rpx;
  304. }
  305. .order-no {
  306. font-size: 26rpx;
  307. color: #666;
  308. }
  309. .status-text {
  310. font-size: 26rpx;
  311. font-weight: bold;
  312. }
  313. .text-red {
  314. color: #f44336;
  315. }
  316. .text-orange {
  317. color: #ff9800;
  318. }
  319. .text-blue {
  320. color: #2196f3;
  321. }
  322. .text-green {
  323. color: #4caf50;
  324. }
  325. .text-gray {
  326. color: #999;
  327. }
  328. .service-row {
  329. display: flex;
  330. align-items: center;
  331. margin-bottom: 20rpx;
  332. gap: 12rpx;
  333. }
  334. .service-name {
  335. font-size: 30rpx;
  336. font-weight: bold;
  337. color: #333;
  338. }
  339. .service-tag {
  340. font-size: 20rpx;
  341. padding: 2rpx 8rpx;
  342. border-radius: 8rpx;
  343. border: 1rpx solid;
  344. }
  345. .tag-orange {
  346. color: #ff9800;
  347. border-color: #ff9800;
  348. background: #fff3e0;
  349. }
  350. .tag-blue {
  351. color: #2196f3;
  352. border-color: #2196f3;
  353. background: #e3f2fd;
  354. }
  355. .tag-green {
  356. color: #4caf50;
  357. border-color: #4caf50;
  358. background: #e8f5e9;
  359. }
  360. .pet-row {
  361. display: flex;
  362. align-items: center;
  363. margin-bottom: 20rpx;
  364. background: #f7f8fa;
  365. padding: 16rpx 20rpx;
  366. border-radius: 16rpx;
  367. }
  368. .pet-avatar-text {
  369. width: 64rpx;
  370. height: 64rpx;
  371. border-radius: 50%;
  372. background-color: #e3f2fd;
  373. color: #2196f3;
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. font-weight: bold;
  378. font-size: 32rpx;
  379. margin-right: 20rpx;
  380. }
  381. .pet-desc {
  382. display: flex;
  383. align-items: baseline;
  384. gap: 12rpx;
  385. flex: 1;
  386. }
  387. .pet-desc .bold {
  388. font-size: 28rpx;
  389. font-weight: bold;
  390. color: #333;
  391. }
  392. .pet-desc .sub {
  393. font-size: 24rpx;
  394. color: #666;
  395. }
  396. .user-desc {
  397. font-size: 26rpx;
  398. color: #333;
  399. }
  400. .info-list {
  401. display: flex;
  402. flex-direction: column;
  403. gap: 12rpx;
  404. }
  405. .info-item {
  406. display: flex;
  407. align-items: center;
  408. font-size: 24rpx;
  409. color: #666;
  410. gap: 12rpx;
  411. }
  412. .order-foot {
  413. display: flex;
  414. justify-content: space-between;
  415. align-items: flex-end;
  416. margin-top: 24rpx;
  417. padding-top: 20rpx;
  418. border-top: 1rpx solid #f5f5f5;
  419. }
  420. .foot-left {
  421. display: flex;
  422. flex-direction: column;
  423. gap: 12rpx;
  424. }
  425. .create-time,
  426. .cancel-time {
  427. font-size: 22rpx;
  428. color: #999;
  429. }
  430. .assign-info {
  431. display: flex;
  432. align-items: center;
  433. font-size: 24rpx;
  434. gap: 12rpx;
  435. }
  436. .assign-label {
  437. color: #999;
  438. }
  439. .assign-none {
  440. color: #ccc;
  441. }
  442. .assign-name {
  443. color: #333;
  444. font-weight: bold;
  445. }
  446. .actions {
  447. display: flex;
  448. gap: 16rpx;
  449. }
  450. .action-btn {
  451. height: 56rpx;
  452. line-height: 56rpx;
  453. min-width: 120rpx;
  454. font-size: 24rpx;
  455. font-weight: 600;
  456. padding: 0 28rpx;
  457. border-radius: 28rpx;
  458. display: inline-flex;
  459. align-items: center;
  460. justify-content: center;
  461. }
  462. .btn-cancel {
  463. border: 1rpx solid #ddd;
  464. color: #666;
  465. background: transparent;
  466. }
  467. .btn-primary {
  468. background: linear-gradient(90deg, #ffd53f, #ff9500);
  469. border: none;
  470. color: #fff;
  471. box-shadow: 0 6rpx 16rpx rgba(255, 149, 0, 0.3);
  472. }
  473. .empty-state {
  474. text-align: center;
  475. padding: 100rpx 0;
  476. }
  477. .empty-text {
  478. font-size: 28rpx;
  479. color: #999;
  480. }
  481. </style>