index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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()"/>
  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. .container {
  131. width: 100%;
  132. min-height: 100vh;
  133. background: linear-gradient( 135deg, #CFE9FF 0%, #F5F7FA 50.86%);
  134. display: flex;
  135. flex-direction: column;
  136. }
  137. .search-section {
  138. margin-left: 14rpx;
  139. margin-top: 96rpx;
  140. margin-right: 210rpx;
  141. }
  142. .search-box {
  143. display: flex;
  144. align-items: center;
  145. background-color: #F5F7FA;
  146. border-radius: 36rpx;
  147. padding: 0 20rpx;
  148. height: 72rpx; /* 与 u-search 高度一致 */
  149. }
  150. .search-icon {
  151. margin-right: 16rpx;
  152. display: flex;
  153. align-items: center;
  154. }
  155. .search-input {
  156. flex: 1;
  157. height: 100%;
  158. font-size: 28rpx;
  159. color: #333;
  160. background-color: transparent;
  161. border: none;
  162. outline: none;
  163. }
  164. .placeholder-style {
  165. color: #999;
  166. font-size: 28rpx;
  167. }
  168. .search-clear {
  169. display: flex;
  170. align-items: center;
  171. justify-content: center;
  172. margin-left: 16rpx;
  173. padding: 8rpx;
  174. &:active {
  175. opacity: 0.6;
  176. }
  177. }
  178. /* 以下样式与之前一致,无需改动 */
  179. .page-title {
  180. font-size: 36rpx;
  181. font-weight: bold;
  182. text-align: center;
  183. margin-bottom: 30rpx;
  184. color: #333333;
  185. }
  186. .tabs-section {
  187. height: 88rpx;
  188. background-color: #ffffff;
  189. }
  190. .custom-tabs {
  191. display: flex;
  192. width: 100%;
  193. }
  194. .tab-item {
  195. flex: 1;
  196. text-align: center;
  197. padding: 30rpx 0;
  198. font-size: 28rpx;
  199. color: #333333;
  200. position: relative;
  201. transition: all 0.3s;
  202. }
  203. .tab-item.active {
  204. color: #0089FF;
  205. }
  206. .tab-item.active::after {
  207. content: '';
  208. position: absolute;
  209. bottom: 0;
  210. left: 50%;
  211. transform: translateX(-50%);
  212. width: 40rpx;
  213. height: 6rpx;
  214. background-color: #2979ff;
  215. border-radius: 4rpx;
  216. }
  217. .order-list {
  218. padding: 20rpx;
  219. }
  220. .order-card {
  221. background-color: #ffffff;
  222. border-radius: 16rpx;
  223. padding: 16rpx;
  224. margin-bottom: 16rpx;
  225. position: relative;
  226. }
  227. .order-header {
  228. display: flex;
  229. justify-content: space-between;
  230. align-items: center;
  231. margin-bottom: 20rpx;
  232. }
  233. .order-title {
  234. font-size: 32rpx;
  235. font-weight: bold;
  236. color: #333333;
  237. }
  238. .order-status {
  239. width: 136rpx;
  240. height: 54rpx;
  241. line-height: 54rpx;
  242. color: #fff;
  243. font-size: 24rpx;
  244. border-radius: 0rpx 16rpx 0rpx 16rpx;
  245. position: absolute;
  246. right: 0px;
  247. top: 0px;
  248. text-align: center;
  249. }
  250. .status-pending {
  251. background: linear-gradient(270deg, #49ABFF 0%, #0089FF 100%);
  252. }
  253. .status-assigned {
  254. background: linear-gradient(134deg, #5ED89B 0%, #36B475 99%);
  255. }
  256. .status-completed {
  257. background: linear-gradient(134deg, #5ED89B 0%, #36B475 99%);
  258. }
  259. .status-market {
  260. background: linear-gradient(90deg, #FF9F23 0%, #FD5F3C 100%);
  261. }
  262. .price-section {
  263. display: flex;
  264. justify-content: space-between;
  265. align-items: center;
  266. margin-bottom: 16rpx;
  267. }
  268. .order-price {
  269. font-size: 32rpx;
  270. font-weight: bold;
  271. color: #FD5F3C;
  272. }
  273. .countdown {
  274. font-size: 24rpx;
  275. color: #F52929;
  276. }
  277. .order-details {
  278. margin-bottom: 16rpx;
  279. padding: 16rpx;
  280. background: #F5F7FA;
  281. border-radius: 16rpx;
  282. .customer-info {
  283. display: flex;
  284. align-items: center;
  285. margin-bottom: 16rpx;
  286. }
  287. .customer-photo {
  288. width: 48rpx;
  289. height: 48rpx;
  290. border-radius: 48rpx;
  291. margin-right: 16rpx;
  292. }
  293. .customer-name {
  294. font-size: 24rpx;
  295. color: #333333;
  296. font-weight: bold;
  297. }
  298. }
  299. .load-more-status {
  300. text-align: center;
  301. padding: 20rpx;
  302. font-size: 24rpx;
  303. color: #999;
  304. position: fixed;
  305. width: 100%;
  306. height: 100%;
  307. }
  308. .empty-state {
  309. display: flex;
  310. flex-direction: column;
  311. align-items: center;
  312. justify-content: center;
  313. padding: 120rpx 40rpx;
  314. color: #999999;
  315. }
  316. .empty-text {
  317. margin-top: 20rpx;
  318. font-size: 28rpx;
  319. }
  320. </style>