index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <view class="container">
  3. <!-- 搜索框 -->
  4. <view class="search-section">
  5. <u-search v-model="searchKeyword" placeholder="请输入订单编号或用户名称" :show-action="false" shape="square"
  6. bg-color="#F5F7FA" @search="handleSearch" @clear="handleSearch"></u-search>
  7. </view>
  8. <!-- Tab切换 -->
  9. <!-- <view class="tabs-section"> -->
  10. <!-- <view class="custom-tabs">
  11. <view class="tab-item" :class="{ active: currentTab == index }" v-for="(tab, index) in tabList"
  12. :key="index" @click="switchTab(index)">
  13. {{ tab.name }}
  14. </view>
  15. </view> -->
  16. <!-- </view> -->
  17. <!-- 订单列表 -->
  18. <view class="order-list" @scrolltolower="loadMore">
  19. <view v-if="ordersList.length" v-for="order in ordersList" :key="order.id">
  20. <OrderItem :order-detail="order" @success="getOrderList()"></OrderItem>
  21. </view>
  22. <view class="empty-state" v-else>
  23. <u-icon class="empty-icon" name="list" size="60" color="#ccc"></u-icon>
  24. <view class="empty-text">暂无相关订单</view>
  25. </view>
  26. <view class="load-more-status" v-if="loadFinished && ordersList.length !== 0">
  27. <text>没有更多数据了</text>
  28. </view>
  29. <!-- 加载状态提示 -->
  30. <view class="load-more-status" v-if="loadState">
  31. <text>加载中...</text>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script setup>
  37. import {
  38. ref,
  39. computed
  40. } from 'vue'
  41. import {
  42. onShow,
  43. onLoad,
  44. onReachBottom
  45. } from '@dcloudio/uni-app' // 导入 UniApp 的生命周期
  46. import OrderItem from './components/OrderItem.vue'
  47. import { getOrderListApi } from '../../api/order'
  48. // 搜索关键词
  49. const searchKeyword = ref('')
  50. const pageNum = ref(1)
  51. const pageSize = ref(10)
  52. const recordTotal = ref(0)
  53. const loadState = ref(false)
  54. const loadFinished = ref(false)
  55. // Tab数据
  56. const tabList = ref([{
  57. name: '全部订单'
  58. },
  59. {
  60. name: '待确认'
  61. },
  62. {
  63. name: '已完成'
  64. },
  65. {
  66. name: '申请退款'
  67. }
  68. ])
  69. // 1-全部订单, 2-待确认, 4-已完成, 5-申请退款
  70. //orderType: 订单类型(1-全部订单, 2-待确认, 3-待核销, 4-已完成, 5-申请退款, 6-服务中)
  71. const orderTypeMap = {
  72. 0: 1, // 全部订单
  73. 1: 2, // 待确认
  74. 2: 4, // 已完成
  75. 3: 5, // 申请退款
  76. }
  77. // 当前选中的Tab
  78. const currentTab = ref(0)
  79. // 订单数据
  80. const ordersList = ref([])
  81. // 获取状态类名
  82. const getStatusClass = (status) => {
  83. switch (status) {
  84. case 0:
  85. return 'status-pending' // 待派单
  86. case 1:
  87. return 'status-assigned' // 已派单
  88. case 2:
  89. return 'status-completed' // 已完成
  90. case 3:
  91. return 'status-market' // 抢单市场
  92. default:
  93. return 'status-pending'
  94. }
  95. }
  96. onLoad((option) => {
  97. if (option.orderStatusType) {
  98. currentTab.value = option.orderStatusType
  99. }
  100. })
  101. onShow(() => {
  102. // 可以在这里初始化数据
  103. getOrderList()
  104. })
  105. // Tab切换事件
  106. const switchTab = (index) => {
  107. currentTab.value = index
  108. getOrderList(false)
  109. }
  110. const handleSearch = () => {
  111. getOrderList()
  112. }
  113. // 获取收益明细列表
  114. const getOrderList = async () => {
  115. //orderType: 订单类型(1-全部订单, 2-待确认, 4-已完成, 5-申请退款)
  116. try {
  117. uni.showLoading({
  118. mask: true
  119. })
  120. const orderType = orderTypeMap[currentTab.value]
  121. const params = {
  122. pageNum: pageNum.value,
  123. pageSize: pageSize.value,
  124. // orderType: orderType,
  125. keyword: searchKeyword.value
  126. }
  127. var res = await getOrderListApi(params)
  128. if (res.code === 200) {
  129. const list = res.rows || []
  130. ordersList.value = pageNum.value == 1 ? list : [...ordersList.value, ...list]
  131. recordTotal.value = Math.ceil(res.total / pageSize.value) || 0
  132. }
  133. } catch (error) {
  134. } finally {
  135. uni.hideLoading()
  136. }
  137. }
  138. // 触底加载更多
  139. onReachBottom(() => {
  140. if (pageNum.value < recordTotal.value) {
  141. pageNum.value++;
  142. getOrderList()
  143. }
  144. })
  145. // 查看订单详情
  146. const viewOrderDetail = (order) => {
  147. uni.showToast({
  148. title: `查看订单详情 - ${order.orderNumber}`,
  149. icon: 'none'
  150. })
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .search-section {
  155. background-color: #fff;
  156. padding: 16rpx;
  157. margin-left: 14rpx;
  158. :deep .u-search__content {
  159. border-radius: 36rpx !important;
  160. }
  161. }
  162. .page-title {
  163. font-size: 36rpx;
  164. font-weight: bold;
  165. text-align: center;
  166. margin-bottom: 30rpx;
  167. color: #333333;
  168. }
  169. .tabs-section {
  170. height: 88rpx;
  171. background-color: #ffffff;
  172. }
  173. .custom-tabs {
  174. display: flex;
  175. width: 100%;
  176. }
  177. .tab-item {
  178. flex: 1;
  179. text-align: center;
  180. padding: 30rpx 0;
  181. font-size: 28rpx;
  182. color: #333333;
  183. position: relative;
  184. transition: all 0.3s;
  185. }
  186. .tab-item.active {
  187. color: #0089FF;
  188. }
  189. .tab-item.active::after {
  190. content: '';
  191. position: absolute;
  192. bottom: 0;
  193. left: 50%;
  194. transform: translateX(-50%);
  195. width: 40rpx;
  196. height: 6rpx;
  197. background-color: #2979ff;
  198. border-radius: 4rpx;
  199. }
  200. .order-list {
  201. padding: 20rpx;
  202. }
  203. .order-card {
  204. background-color: #ffffff;
  205. border-radius: 16rpx;
  206. padding: 16rpx;
  207. margin-bottom: 16rpx;
  208. position: relative;
  209. }
  210. .order-header {
  211. display: flex;
  212. justify-content: space-between;
  213. align-items: center;
  214. margin-bottom: 20rpx;
  215. }
  216. .order-title {
  217. font-size: 32rpx;
  218. font-weight: bold;
  219. color: #333333;
  220. }
  221. .order-status {
  222. width: 136rpx;
  223. height: 54rpx;
  224. line-height: 54rpx;
  225. color: #fff;
  226. font-size: 24rpx;
  227. border-radius: 0rpx 16rpx 0rpx 16rpx;
  228. position: absolute;
  229. right: 0px;
  230. top: 0px;
  231. text-align: center;
  232. }
  233. .status-pending {
  234. background: linear-gradient(270deg, #49ABFF 0%, #0089FF 100%);
  235. }
  236. .status-assigned {
  237. background: linear-gradient(134deg, #5ED89B 0%, #36B475 99%);
  238. }
  239. .status-completed {
  240. background: linear-gradient(134deg, #5ED89B 0%, #36B475 99%);
  241. }
  242. .status-market {
  243. background: linear-gradient(90deg, #FF9F23 0%, #FD5F3C 100%);
  244. }
  245. .price-section {
  246. display: flex;
  247. justify-content: space-between;
  248. align-items: center;
  249. margin-bottom: 16rpx;
  250. }
  251. .order-price {
  252. font-size: 32rpx;
  253. font-weight: bold;
  254. color: #FD5F3C;
  255. }
  256. .countdown {
  257. font-size: 24rpx;
  258. color: #F52929;
  259. }
  260. .order-details {
  261. margin-bottom: 16rpx;
  262. padding: 16rpx;
  263. background: #F5F7FA;
  264. border-radius: 16rpx;
  265. .customer-info {
  266. display: flex;
  267. align-items: center;
  268. margin-bottom: 16rpx;
  269. }
  270. .customer-photo {
  271. width: 48rpx;
  272. height: 48rpx;
  273. border-radius: 48rpx;
  274. margin-right: 16rpx;
  275. }
  276. .customer-name {
  277. font-size: 24rpx;
  278. color: #333333;
  279. font-weight: bold;
  280. }
  281. }
  282. .load-more-status {
  283. text-align: center;
  284. padding: 20rpx;
  285. font-size: 24rpx;
  286. color: #999;
  287. position: fixed;
  288. width: 100%;
  289. height: 100%;
  290. }
  291. .empty-state {
  292. display: flex;
  293. flex-direction: column;
  294. align-items: center;
  295. justify-content: center;
  296. padding: 120rpx 40rpx;
  297. color: #999999;
  298. }
  299. .empty-text {
  300. margin-top: 20rpx;
  301. font-size: 28rpx;
  302. }
  303. </style>