index.vue 7.2 KB

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