| 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="product-list" @scrolltolower="onLoadMore" refresher-enabled :refresher-triggered="refreshing" @refresherrefresh="onRefresh">
- <view v-if="loading && products.length === 0" class="loading-wrap">
- <text class="loading-text">加载中...</text>
- </view>
- <view v-else-if="products.length === 0" class="empty-wrap">
- <text class="empty-icon">📦</text>
- <text class="empty-text">暂无商品</text>
- <button class="btn-add" @click="goCreate">发布商品</button>
- </view>
- <view v-else>
- <view
- v-for="item in products"
- :key="item.id"
- class="product-card"
- >
- <view class="card-top">
- <image class="cover" :src="getImageUrl(item.coverImage) || '/static/default-product.png'" mode="aspectFill" />
- <view class="card-info">
- <text class="product-name">{{ item.name }}</text>
- <text class="product-price">{{ formatPriceWithSymbol(item.price) }}</text>
- <text class="product-stock">库存 {{ item.stock || 0 }}</text>
- </view>
- </view>
- <view class="card-bottom">
- <text :class="['status-badge', 'status-' + item.status]">{{ statusLabel(item.status) }}</text>
- <view class="card-actions">
- <button v-if="item.status === 'approved'" class="btn-xs" @click="onShelve(item.id, item.status === 'on_shelf' ? 'unshelve' : 'shelve')">
- {{ item.status === 'on_shelf' ? '下架' : '上架' }}
- </button>
- <button class="btn-xs btn-edit" @click="goEdit(item.id)">编辑</button>
- </view>
- </view>
- </view>
- </view>
- <view v-if="noMore && products.length > 0" class="no-more">
- <text class="no-more-text">— 没有更多了 —</text>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import { productMy, productShelve } from '@/utils/api.js'
- import config from '@/config.js'
- export default {
- data() {
- return {
- statusList: [
- { label: '全部', value: '' },
- { label: '待审核', value: 'pending' },
- { label: '已通过', value: 'approved' },
- { label: '已拒绝', value: 'rejected' },
- { label: '已上架', value: 'on_shelf' }
- ],
- currentStatus: '',
- products: [],
- page: 1,
- size: 20,
- loading: false,
- refreshing: false,
- noMore: false
- }
- },
- onLoad() {
- this.loadProducts()
- },
- methods: {
- onStatusChange(value) {
- this.currentStatus = value
- this.page = 1
- this.products = []
- this.noMore = false
- this.loadProducts()
- },
- loadProducts() {
- if (this.loading) return
- this.loading = true
- productMy({ page: this.page, size: this.size, status: this.currentStatus }).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.products = list
- } else {
- this.products = this.products.concat(list)
- }
- const total = res.data.total || 0
- this.noMore = this.products.length >= total
- }
- }).catch(() => {
- this.loading = false
- this.refreshing = false
- })
- },
- onRefresh() {
- this.refreshing = true
- this.page = 1
- this.noMore = false
- this.loadProducts()
- },
- onLoadMore() {
- if (this.noMore) return
- this.page = this.page + 1
- this.loadProducts()
- },
- onShelve(id, action) {
- productShelve({ productId: id, action }).then(res => {
- if (res.code === 200) {
- uni.showToast({ title: action === 'shelve' ? '上架成功' : '下架成功', icon: 'success' })
- this.onRefresh()
- } else {
- uni.showToast({ title: res.message || '操作失败', icon: 'none' })
- }
- })
- },
- goCreate() {
- uni.navigateTo({ url: '/pages/vendor/product-edit/product-edit' })
- },
- goEdit(id) {
- uni.navigateTo({ url: '/pages/vendor/product-edit/product-edit?id=' + id })
- },
- statusLabel(status) {
- const map = {
- draft: '草稿',
- pending: '待审核',
- approved: '已通过',
- rejected: '已拒绝',
- on_shelf: '已上架',
- off_shelf: '已下架'
- }
- return map[status] || status
- },
- getImageUrl: function(path) {
- return config.API_BASE_URL + path
- }
- }
- }
- </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;
- }
- .product-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;
- margin-bottom: 40rpx;
- }
- .btn-add {
- background: linear-gradient(135deg, #F97316, #FB923C);
- color: #fff;
- font-size: 28rpx;
- padding: 0 60rpx;
- height: 72rpx;
- line-height: 72rpx;
- border-radius: 36rpx;
- border: none;
- }
- .btn-add::after {
- border: none;
- }
- .product-card {
- background: #fff;
- margin: 20rpx;
- border-radius: 16rpx;
- padding: 24rpx;
- box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
- }
- .card-top {
- display: flex;
- margin-bottom: 16rpx;
- }
- .cover {
- width: 160rpx;
- height: 160rpx;
- border-radius: 12rpx;
- background: #f0f0f0;
- flex-shrink: 0;
- }
- .card-info {
- flex: 1;
- margin-left: 20rpx;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- }
- .product-name {
- font-size: 28rpx;
- color: #333;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .product-price {
- font-size: 30rpx;
- color: #F97316;
- font-weight: bold;
- }
- .product-stock {
- font-size: 22rpx;
- color: #999;
- }
- .card-bottom {
- display: flex;
- justify-content: space-between;
- align-items: center;
- border-top: 1rpx solid #f5f5f5;
- padding-top: 16rpx;
- }
- .status-badge {
- font-size: 22rpx;
- padding: 4rpx 16rpx;
- border-radius: 20rpx;
- }
- .status-draft { background: #f5f5f5; color: #999; }
- .status-pending { background: #fff7e6; color: #fa8c16; }
- .status-approved { background: #f6ffed; color: #52c41a; }
- .status-rejected { background: #fff2f0; color: #ff4d4f; }
- .status-on_shelf { background: #e6f7ff; color: #1890ff; }
- .status-off_shelf { background: #f5f5f5; color: #999; }
- .card-actions {
- display: flex;
- gap: 12rpx;
- }
- .btn-xs {
- font-size: 22rpx;
- padding: 8rpx 24rpx;
- border-radius: 30rpx;
- border: 1rpx solid #F97316;
- color: #F97316;
- background: #fff;
- line-height: 1.5;
- }
- .btn-edit {
- border-color: #1890ff;
- color: #1890ff;
- }
- .btn-xs::after {
- border: none;
- }
- .no-more {
- text-align: center;
- padding: 30rpx;
- }
- .no-more-text {
- font-size: 24rpx;
- color: #ccc;
- }
- </style>
|