orders.vue 8.3 KB

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