index.vue 6.8 KB

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