orders.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view class="container">
  3. <view class="status-tabs">
  4. <view
  5. v-for="item in statusList"
  6. :key="item.value"
  7. :class="['tab', currentStatus === item.value ? 'active' : '']"
  8. @click="onStatusChange(item.value)"
  9. >
  10. {{ item.label }}
  11. </view>
  12. </view>
  13. <scroll-view scroll-y class="order-list" @scrolltolower="onLoadMore" refresher-enabled :refresher-triggered="refreshing" @refresherrefresh="onRefresh">
  14. <view v-if="loading && orders.length === 0" class="loading-wrap">
  15. <text class="loading-text">加载中...</text>
  16. </view>
  17. <view v-else-if="orders.length === 0" class="empty-wrap">
  18. <text class="empty-icon">📋</text>
  19. <text class="empty-text">暂无订单</text>
  20. </view>
  21. <view v-else>
  22. <view
  23. v-for="item in orders"
  24. :key="item.id"
  25. class="order-card"
  26. @click="goDetail(item.orderNo)"
  27. >
  28. <view class="order-header">
  29. <text class="order-no">{{ item.orderNo }}</text>
  30. <text :class="['status-badge', 'status-' + item.status]">{{ statusLabel(item.status) }}</text>
  31. </view>
  32. <view class="order-body">
  33. <view class="product-info">
  34. <text class="product-name">{{ item.productName }}</text>
  35. <text class="order-meta">买家ID: {{ item.buyerId }}</text>
  36. </view>
  37. <view class="order-amount-section">
  38. <text class="order-amount">{{ formatPriceWithSymbol(item.totalAmount) }}</text>
  39. <text class="order-qty">x{{ item.quantity }}</text>
  40. </view>
  41. </view>
  42. <view class="order-footer">
  43. <text class="order-time">{{ formatTime(item.createdAt) }}</text>
  44. <view class="order-actions">
  45. <button
  46. v-if="item.status === 'paid'"
  47. class="btn-xs btn-confirm"
  48. @click.stop="onConfirm(item.orderNo)"
  49. >确认完成</button>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view v-if="noMore && orders.length > 0" class="no-more">
  55. <text class="no-more-text">— 没有更多了 —</text>
  56. </view>
  57. </scroll-view>
  58. </view>
  59. </template>
  60. <script>
  61. import { productOrderVendor, productOrderConfirm } from '@/utils/api.js'
  62. import { parseDate } from '@/utils/format.js'
  63. export default {
  64. data() {
  65. return {
  66. statusList: [
  67. { label: '全部', value: '' },
  68. { label: '待支付', value: 'pending' },
  69. { label: '已支付', value: 'paid' },
  70. { label: '已完成', value: 'completed' }
  71. ],
  72. currentStatus: '',
  73. orders: [],
  74. page: 1,
  75. size: 20,
  76. loading: false,
  77. refreshing: false,
  78. noMore: false
  79. }
  80. },
  81. onLoad() {
  82. this.loadOrders()
  83. },
  84. methods: {
  85. onStatusChange(value) {
  86. this.currentStatus = value
  87. this.page = 1
  88. this.orders = []
  89. this.noMore = false
  90. this.loadOrders()
  91. },
  92. loadOrders() {
  93. if (this.loading) return
  94. this.loading = true
  95. const params = { page: this.page, size: this.size }
  96. if (this.currentStatus) {
  97. params.status = this.currentStatus
  98. }
  99. productOrderVendor(params).then(res => {
  100. this.loading = false
  101. this.refreshing = false
  102. if (res.code === 200 && res.data) {
  103. const list = res.data.records || res.data || []
  104. if (this.page === 1) {
  105. this.orders = list
  106. } else {
  107. this.orders = this.orders.concat(list)
  108. }
  109. const total = res.data.total || 0
  110. this.noMore = this.products && this.products.length >= total
  111. }
  112. }).catch(() => {
  113. this.loading = false
  114. this.refreshing = false
  115. })
  116. },
  117. onRefresh() {
  118. this.refreshing = true
  119. this.page = 1
  120. this.noMore = false
  121. this.loadOrders()
  122. },
  123. onLoadMore() {
  124. if (this.noMore) return
  125. this.page = this.page + 1
  126. this.loadOrders()
  127. },
  128. goDetail(orderNo) {
  129. uni.navigateTo({ url: '/pages/shop/order-detail/order-detail?orderNo=' + orderNo })
  130. },
  131. onConfirm(orderNo) {
  132. productOrderConfirm({ orderNo }).then(res => {
  133. if (res.code === 200) {
  134. uni.showToast({ title: '订单已完成', icon: 'success' })
  135. this.onRefresh()
  136. } else {
  137. uni.showToast({ title: res.message || '操作失败', icon: 'none' })
  138. }
  139. })
  140. },
  141. statusLabel(status) {
  142. const map = {
  143. pending: '待支付',
  144. paid: '已支付',
  145. completed: '已完成',
  146. cancelled: '已取消'
  147. }
  148. return map[status] || status
  149. },
  150. formatTime(time) {
  151. if (!time) return ''
  152. const d = parseDate(time)
  153. if (!d) return ''
  154. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
  155. }
  156. }
  157. }
  158. </script>
  159. <style scoped>
  160. .container {
  161. display: flex;
  162. flex-direction: column;
  163. height: 100vh;
  164. background: #f5f5f5;
  165. }
  166. .status-tabs {
  167. display: flex;
  168. background: #fff;
  169. padding: 20rpx 0;
  170. border-bottom: 1rpx solid #eee;
  171. }
  172. .tab {
  173. flex: 1;
  174. text-align: center;
  175. font-size: 26rpx;
  176. color: #666;
  177. padding: 10rpx 0;
  178. }
  179. .tab.active {
  180. color: #F97316;
  181. font-weight: bold;
  182. border-bottom: 4rpx solid #F97316;
  183. }
  184. .order-list {
  185. flex: 1;
  186. height: calc(100vh - 100rpx);
  187. }
  188. .loading-wrap,
  189. .empty-wrap {
  190. display: flex;
  191. flex-direction: column;
  192. align-items: center;
  193. padding-top: 200rpx;
  194. }
  195. .loading-text {
  196. font-size: 26rpx;
  197. color: #999;
  198. }
  199. .empty-icon {
  200. font-size: 100rpx;
  201. margin-bottom: 30rpx;
  202. }
  203. .empty-text {
  204. font-size: 28rpx;
  205. color: #999;
  206. }
  207. .order-card {
  208. background: #fff;
  209. margin: 20rpx;
  210. border-radius: 16rpx;
  211. padding: 24rpx;
  212. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  213. }
  214. .order-header {
  215. display: flex;
  216. justify-content: space-between;
  217. align-items: center;
  218. margin-bottom: 16rpx;
  219. }
  220. .order-no {
  221. font-size: 24rpx;
  222. color: #999;
  223. }
  224. .status-badge {
  225. font-size: 22rpx;
  226. padding: 4rpx 16rpx;
  227. border-radius: 20rpx;
  228. }
  229. .status-pending { background: #fff7e6; color: #fa8c16; }
  230. .status-paid { background: #e6f7ff; color: #1890ff; }
  231. .status-completed { background: #f6ffed; color: #52c41a; }
  232. .order-body {
  233. display: flex;
  234. justify-content: space-between;
  235. margin-bottom: 16rpx;
  236. }
  237. .product-info {
  238. flex: 1;
  239. }
  240. .product-name {
  241. display: block;
  242. font-size: 28rpx;
  243. color: #333;
  244. margin-bottom: 6rpx;
  245. }
  246. .order-meta {
  247. font-size: 22rpx;
  248. color: #999;
  249. }
  250. .order-amount-section {
  251. text-align: right;
  252. }
  253. .order-amount {
  254. display: block;
  255. font-size: 30rpx;
  256. color: #F97316;
  257. font-weight: bold;
  258. }
  259. .order-qty {
  260. font-size: 22rpx;
  261. color: #999;
  262. }
  263. .order-footer {
  264. display: flex;
  265. justify-content: space-between;
  266. align-items: center;
  267. border-top: 1rpx solid #f5f5f5;
  268. padding-top: 16rpx;
  269. }
  270. .order-time {
  271. font-size: 22rpx;
  272. color: #999;
  273. }
  274. .order-actions {
  275. display: flex;
  276. gap: 12rpx;
  277. }
  278. .btn-xs {
  279. font-size: 22rpx;
  280. padding: 8rpx 24rpx;
  281. border-radius: 30rpx;
  282. border: none;
  283. line-height: 1.5;
  284. }
  285. .btn-confirm {
  286. background: #e6f7ff;
  287. color: #1890ff;
  288. }
  289. .btn-xs::after {
  290. border: none;
  291. }
  292. .no-more {
  293. text-align: center;
  294. padding: 30rpx;
  295. }
  296. .no-more-text {
  297. font-size: 24rpx;
  298. color: #ccc;
  299. }
  300. </style>