orders.vue 7.5 KB

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