| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- <template>
- <view class="container">
- <view class="status-tabs">
- <view
- v-for="item in statusList"
- :key="item.value"
- :class="['tab', currentStatus === item.value ? 'active' : '']"
- @click="onStatusChange(item.value)"
- >
- {{ item.label }}
- </view>
- </view>
- <scroll-view scroll-y class="order-list" @scrolltolower="onLoadMore" refresher-enabled :refresher-triggered="refreshing" @refresherrefresh="onRefresh">
- <view v-if="loading && orders.length === 0" class="loading-wrap">
- <text class="loading-text">加载中...</text>
- </view>
- <view v-else-if="orders.length === 0" class="empty-wrap">
- <text class="empty-icon">📋</text>
- <text class="empty-text">暂无订单</text>
- </view>
- <view v-else>
- <view
- v-for="item in orders"
- :key="item.id"
- class="order-card"
- @click="goDetail(item.orderNo)"
- >
- <view class="order-header">
- <text class="order-no">{{ item.orderNo }}</text>
- <text :class="['status-badge', 'status-' + item.status]">{{ statusLabel(item.status) }}</text>
- </view>
- <view class="order-body">
- <view class="product-info">
- <text class="product-name">{{ item.productName }}</text>
- <text class="order-meta">买家ID: {{ item.buyerId }}</text>
- </view>
- <view class="order-amount-section">
- <text class="order-amount">{{ formatPriceWithSymbol(item.totalAmount) }}</text>
- <text class="order-qty">x{{ item.quantity }}</text>
- </view>
- </view>
- <view class="order-footer">
- <text class="order-time">{{ formatTime(item.createdAt) }}</text>
- <view class="order-actions">
- <button
- v-if="item.status === 'paid'"
- class="btn-xs btn-confirm"
- @click.stop="onConfirm(item.orderNo)"
- >确认完成</button>
- </view>
- </view>
- </view>
- </view>
- <view v-if="noMore && orders.length > 0" class="no-more">
- <text class="no-more-text">— 没有更多了 —</text>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import { productOrderVendor, productOrderConfirm } from '@/utils/api.js'
- import { parseDate } from '@/utils/format.js'
- export default {
- data() {
- return {
- statusList: [
- { label: '全部', value: '' },
- { label: '待支付', value: 'pending' },
- { label: '已支付', value: 'paid' },
- { label: '已完成', value: 'completed' }
- ],
- currentStatus: '',
- orders: [],
- page: 1,
- size: 20,
- loading: false,
- refreshing: false,
- noMore: false
- }
- },
- onLoad() {
- this.loadOrders()
- },
- methods: {
- onStatusChange(value) {
- this.currentStatus = value
- this.page = 1
- this.orders = []
- this.noMore = false
- this.loadOrders()
- },
- loadOrders() {
- if (this.loading) return
- this.loading = true
- const params = { page: this.page, size: this.size }
- if (this.currentStatus) {
- params.status = this.currentStatus
- }
- productOrderVendor(params).then(res => {
- this.loading = false
- this.refreshing = false
- if (res.code === 200 && res.data) {
- const list = res.data.records || res.data || []
- if (this.page === 1) {
- this.orders = list
- } else {
- this.orders = this.orders.concat(list)
- }
- const total = res.data.total || 0
- this.noMore = this.products && this.products.length >= total
- }
- }).catch(() => {
- this.loading = false
- this.refreshing = false
- })
- },
- onRefresh() {
- this.refreshing = true
- this.page = 1
- this.noMore = false
- this.loadOrders()
- },
- onLoadMore() {
- if (this.noMore) return
- this.page = this.page + 1
- this.loadOrders()
- },
- goDetail(orderNo) {
- uni.navigateTo({ url: '/pages/shop/order-detail/order-detail?orderNo=' + orderNo })
- },
- onConfirm(orderNo) {
- productOrderConfirm({ orderNo }).then(res => {
- if (res.code === 200) {
- uni.showToast({ title: '订单已完成', icon: 'success' })
- this.onRefresh()
- } else {
- uni.showToast({ title: res.message || '操作失败', icon: 'none' })
- }
- })
- },
- statusLabel(status) {
- const map = {
- pending: '待支付',
- paid: '已支付',
- completed: '已完成',
- cancelled: '已取消'
- }
- return map[status] || status
- },
- formatTime(time) {
- if (!time) return ''
- const d = parseDate(time)
- if (!d) return ''
- return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
- }
- }
- }
- </script>
- <style scoped>
- .container {
- display: flex;
- flex-direction: column;
- height: 100vh;
- background: #f5f5f5;
- }
- .status-tabs {
- display: flex;
- background: #fff;
- padding: 20rpx 0;
- border-bottom: 1rpx solid #eee;
- }
- .tab {
- flex: 1;
- text-align: center;
- font-size: 26rpx;
- color: #666;
- padding: 10rpx 0;
- }
- .tab.active {
- color: #F97316;
- font-weight: bold;
- border-bottom: 4rpx solid #F97316;
- }
- .order-list {
- flex: 1;
- height: calc(100vh - 100rpx);
- }
- .loading-wrap,
- .empty-wrap {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding-top: 200rpx;
- }
- .loading-text {
- font-size: 26rpx;
- color: #999;
- }
- .empty-icon {
- font-size: 100rpx;
- margin-bottom: 30rpx;
- }
- .empty-text {
- font-size: 28rpx;
- color: #999;
- }
- .order-card {
- background: #fff;
- margin: 20rpx;
- border-radius: 16rpx;
- padding: 24rpx;
- box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
- }
- .order-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 16rpx;
- }
- .order-no {
- font-size: 24rpx;
- color: #999;
- }
- .status-badge {
- font-size: 22rpx;
- padding: 4rpx 16rpx;
- border-radius: 20rpx;
- }
- .status-pending { background: #fff7e6; color: #fa8c16; }
- .status-paid { background: #e6f7ff; color: #1890ff; }
- .status-completed { background: #f6ffed; color: #52c41a; }
- .order-body {
- display: flex;
- justify-content: space-between;
- margin-bottom: 16rpx;
- }
- .product-info {
- flex: 1;
- }
- .product-name {
- display: block;
- font-size: 28rpx;
- color: #333;
- margin-bottom: 6rpx;
- }
- .order-meta {
- font-size: 22rpx;
- color: #999;
- }
- .order-amount-section {
- text-align: right;
- }
- .order-amount {
- display: block;
- font-size: 30rpx;
- color: #F97316;
- font-weight: bold;
- }
- .order-qty {
- font-size: 22rpx;
- color: #999;
- }
- .order-footer {
- display: flex;
- justify-content: space-between;
- align-items: center;
- border-top: 1rpx solid #f5f5f5;
- padding-top: 16rpx;
- }
- .order-time {
- font-size: 22rpx;
- color: #999;
- }
- .order-actions {
- display: flex;
- gap: 12rpx;
- }
- .btn-xs {
- font-size: 22rpx;
- padding: 8rpx 24rpx;
- border-radius: 30rpx;
- border: none;
- line-height: 1.5;
- }
- .btn-confirm {
- background: #e6f7ff;
- color: #1890ff;
- }
- .btn-xs::after {
- border: none;
- }
- .no-more {
- text-align: center;
- padding: 30rpx;
- }
- .no-more-text {
- font-size: 24rpx;
- color: #ccc;
- }
- </style>
|