index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. uni.setStorageSync('senderAddress',{
  102. id: '20',
  103. name: '姓名',
  104. phone: '13000000000',
  105. address: '编辑一下地址',
  106. provinceName: '天津市',
  107. cityName: '天津市',
  108. countyName: '和平区',
  109. isDefault: false
  110. })
  111. uni.setStorageSync('receiverAddress',{
  112. id: '30',
  113. name: '姓名',
  114. phone: '13000000000',
  115. address: '编辑一下地址',
  116. provinceName: '天津市',
  117. cityName: '天津市',
  118. countyName: '和平区',
  119. isDefault: false
  120. })
  121. // 可以在这里初始化数据
  122. getOrderList(false)
  123. })
  124. // Tab切换事件
  125. const switchTab = (index) => {
  126. currentTab.value = index
  127. getOrderList(false)
  128. }
  129. const loadMore = () => {
  130. pageNum.value++
  131. getOrderList(true)
  132. }
  133. const handleSearch = () => {
  134. getOrderList(false)
  135. }
  136. // 获取收益明细列表
  137. const getOrderList = async (isLoadMore = false) => {
  138. if (loadState.value) return
  139. if (!isLoadMore) {
  140. pageNum.value = 1
  141. loadFinished.value = false
  142. ordersList.value = []
  143. }
  144. loadState.value = true
  145. //orderType: 订单类型(1-全部订单, 2-待确认, 4-已完成, 5-申请退款)
  146. try {
  147. uni.showLoading({
  148. mask: true
  149. })
  150. const orderType = orderTypeMap[currentTab.value]
  151. const params = {
  152. pageNum: pageNum.value,
  153. pageSize: pageSize.value,
  154. orderType: orderType,
  155. keyword: searchKeyword.value
  156. }
  157. var res = await getOrderListApi(params)
  158. if (res.code === 200) {
  159. const list = res.rows || []
  160. const total = res.total || 0
  161. if (isLoadMore) {
  162. ordersList.value = [...ordersList.value, ...list]
  163. } else {
  164. ordersList.value = list
  165. }
  166. recordTotal.value = total
  167. // 判断是否还有更多数据
  168. if (list.length < pageSize.value) {
  169. loadFinished.value = true
  170. }
  171. }
  172. } catch (error) {
  173. } finally {
  174. loadState.value = false
  175. uni.hideLoading()
  176. }
  177. }
  178. // 查看订单详情
  179. const viewOrderDetail = (order) => {
  180. uni.showToast({
  181. title: `查看订单详情 - ${order.orderNumber}`,
  182. icon: 'none'
  183. })
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .container {
  188. display: flex;
  189. flex-direction: column;
  190. height: 100vh;
  191. background-color: #F5F7FA;
  192. }
  193. .search-section {
  194. background-color: #fff;
  195. padding: 16rpx;
  196. margin-left: 14rpx;
  197. :deep .u-search__content {
  198. border-radius: 36rpx !important;
  199. }
  200. }
  201. .page-title {
  202. font-size: 36rpx;
  203. font-weight: bold;
  204. text-align: center;
  205. margin-bottom: 30rpx;
  206. color: #333333;
  207. }
  208. .tabs-section {
  209. height: 88rpx;
  210. background-color: #ffffff;
  211. }
  212. .custom-tabs {
  213. display: flex;
  214. width: 100%;
  215. }
  216. .tab-item {
  217. flex: 1;
  218. text-align: center;
  219. padding: 30rpx 0;
  220. font-size: 28rpx;
  221. color: #333333;
  222. position: relative;
  223. transition: all 0.3s;
  224. }
  225. .tab-item.active {
  226. color: #0089FF;
  227. }
  228. .tab-item.active::after {
  229. content: '';
  230. position: absolute;
  231. bottom: 0;
  232. left: 50%;
  233. transform: translateX(-50%);
  234. width: 40rpx;
  235. height: 6rpx;
  236. background-color: #2979ff;
  237. border-radius: 4rpx;
  238. }
  239. .order-list {
  240. flex: 1;
  241. padding: 20rpx;
  242. min-height: 500rpx;
  243. background-color: #F5F7FA;
  244. box-sizing: border-box;
  245. }
  246. .order-card {
  247. background-color: #ffffff;
  248. border-radius: 16rpx;
  249. padding: 16rpx;
  250. margin-bottom: 16rpx;
  251. position: relative;
  252. }
  253. .order-header {
  254. display: flex;
  255. justify-content: space-between;
  256. align-items: center;
  257. margin-bottom: 20rpx;
  258. }
  259. .order-title {
  260. font-size: 32rpx;
  261. font-weight: bold;
  262. color: #333333;
  263. }
  264. .order-status {
  265. width: 136rpx;
  266. height: 54rpx;
  267. line-height: 54rpx;
  268. color: #fff;
  269. font-size: 24rpx;
  270. border-radius: 0rpx 16rpx 0rpx 16rpx;
  271. position: absolute;
  272. right: 0px;
  273. top: 0px;
  274. text-align: center;
  275. }
  276. .status-pending {
  277. background: linear-gradient(270deg, #49ABFF 0%, #0089FF 100%);
  278. }
  279. .status-assigned {
  280. background: linear-gradient(134deg, #5ED89B 0%, #36B475 99%);
  281. }
  282. .status-completed {
  283. background: linear-gradient(134deg, #5ED89B 0%, #36B475 99%);
  284. }
  285. .status-market {
  286. background: linear-gradient(90deg, #FF9F23 0%, #FD5F3C 100%);
  287. }
  288. .price-section {
  289. display: flex;
  290. justify-content: space-between;
  291. align-items: center;
  292. margin-bottom: 16rpx;
  293. }
  294. .order-price {
  295. font-size: 32rpx;
  296. font-weight: bold;
  297. color: #FD5F3C;
  298. }
  299. .countdown {
  300. font-size: 24rpx;
  301. color: #F52929;
  302. }
  303. .order-details {
  304. margin-bottom: 16rpx;
  305. padding: 16rpx;
  306. background: #F5F7FA;
  307. border-radius: 16rpx;
  308. .customer-info {
  309. display: flex;
  310. align-items: center;
  311. margin-bottom: 16rpx;
  312. }
  313. .customer-photo {
  314. width: 48rpx;
  315. height: 48rpx;
  316. border-radius: 48rpx;
  317. margin-right: 16rpx;
  318. }
  319. .customer-name {
  320. font-size: 24rpx;
  321. color: #333333;
  322. font-weight: bold;
  323. }
  324. }
  325. .load-more-status {
  326. text-align: center;
  327. padding: 20rpx;
  328. font-size: 24rpx;
  329. color: #999;
  330. position: fixed;
  331. width: 100%;
  332. height: 100%;
  333. }
  334. .empty-state {
  335. display: flex;
  336. flex-direction: column;
  337. align-items: center;
  338. justify-content: center;
  339. padding: 120rpx 40rpx;
  340. color: #999999;
  341. }
  342. .empty-text {
  343. margin-top: 20rpx;
  344. font-size: 28rpx;
  345. }
  346. </style>