consumer模块完成度95%,能编译在安卓端运行,在解决数据获取和页面布局问题
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
<view class="header">
|
||||
<view class="header-content">
|
||||
<view class="shop-info">
|
||||
<image :src="shopInfo.shop_logo || '/static/default-shop.png'" class="shop-logo" mode="aspectFit" />
|
||||
<image :src="shopInfo.shop_logo || '/static/images/default-shop.png'" class="shop-logo" mode="aspectFit" />
|
||||
<view class="shop-details">
|
||||
<text class="shop-name">{{ shopInfo.shop_name }}</text>
|
||||
<text class="shop-name">{{ shopInfo.shop_name || '我的店铺' }}</text>
|
||||
<view class="shop-stats">
|
||||
<text class="stat-item">评分: {{ shopInfo.rating }}</text>
|
||||
<text class="stat-item">销量: {{ shopInfo.total_sales }}</text>
|
||||
<text class="stat-item">评分: {{ shopInfo.rating_avg || 5.0 }}</text>
|
||||
<text class="stat-item">销量: {{ shopInfo.total_sales || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -30,7 +30,7 @@
|
||||
<text class="overview-label">订单数</text>
|
||||
</view>
|
||||
<view class="overview-item">
|
||||
<text class="overview-value">¥{{ todayStats.sales }}</text>
|
||||
<text class="overview-value">¥{{ formatNumber(todayStats.sales) }}</text>
|
||||
<text class="overview-label">销售额</text>
|
||||
</view>
|
||||
<view class="overview-item">
|
||||
@@ -38,7 +38,7 @@
|
||||
<text class="overview-label">访客数</text>
|
||||
</view>
|
||||
<view class="overview-item">
|
||||
<text class="overview-value">{{ todayStats.conversion }}</text>
|
||||
<text class="overview-value">{{ todayStats.conversion }}%</text>
|
||||
<text class="overview-label">转化率</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -108,15 +108,18 @@
|
||||
<text class="section-title">最新订单</text>
|
||||
<text class="section-more" @click="goToOrders('all')">查看全部</text>
|
||||
</view>
|
||||
<view class="orders-list">
|
||||
<view v-if="recentOrders.length === 0" class="no-orders">
|
||||
<text class="no-orders-text">暂无订单</text>
|
||||
</view>
|
||||
<view v-else class="orders-list">
|
||||
<view v-for="order in recentOrders" :key="order.id" class="order-item" @click="goToOrderDetail(order.id)">
|
||||
<view class="order-header">
|
||||
<text class="order-no">{{ order.order_no }}</text>
|
||||
<text class="order-status" :class="getOrderStatusClass(order.status)">{{ getOrderStatusText(order.status) }}</text>
|
||||
<text class="order-status" :class="getOrderStatusClass(order.order_status)">{{ getOrderStatusText(order.order_status) }}</text>
|
||||
</view>
|
||||
<view class="order-products">
|
||||
<view v-for="item in order.items" :key="item.id" class="product-item">
|
||||
<image :src="item.product_image || '/static/default-product.png'" class="product-image" mode="aspectFit" />
|
||||
<image :src="item.image_url || '/static/images/default-product.png'" class="product-image" mode="aspectFit" />
|
||||
<view class="product-info">
|
||||
<text class="product-name">{{ item.product_name }}</text>
|
||||
<text class="product-spec">{{ item.sku_specifications || '' }}</text>
|
||||
@@ -125,7 +128,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="order-footer">
|
||||
<text class="order-amount">合计: ¥{{ order.actual_amount }}</text>
|
||||
<text class="order-amount">合计: ¥{{ order.total_amount }}</text>
|
||||
<text class="order-time">{{ formatTime(order.created_at) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -135,136 +138,319 @@
|
||||
</template>
|
||||
|
||||
<script lang="uts">
|
||||
import type {
|
||||
MerchantType,
|
||||
OrderType,
|
||||
OrderItemType,
|
||||
ProductType
|
||||
} from '@/types/mall-types.uts'
|
||||
|
||||
type TodayStatsType = {
|
||||
orders: number
|
||||
sales: string
|
||||
visitors: number
|
||||
conversion: string
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
|
||||
type ShopInfoType = {
|
||||
id: string | null
|
||||
merchant_id: string | null
|
||||
shop_name: string | null
|
||||
shop_logo: string | null
|
||||
shop_banner: string | null
|
||||
description: string | null
|
||||
contact_name: string | null
|
||||
contact_phone: string | null
|
||||
rating_avg: number | null
|
||||
total_sales: number | null
|
||||
status: number | null
|
||||
}
|
||||
|
||||
type PendingCountsType = {
|
||||
pending_shipment: number
|
||||
refund_requests: number
|
||||
low_stock: number
|
||||
pending_reviews: number
|
||||
|
||||
type OrderItemType = {
|
||||
id: string
|
||||
order_id: string
|
||||
product_id: string
|
||||
sku_id: string
|
||||
product_name: string
|
||||
sku_name: string
|
||||
price: number
|
||||
quantity: number
|
||||
image_url: string
|
||||
sku_snapshot: string
|
||||
}
|
||||
|
||||
type RecentOrderType = {
|
||||
|
||||
type OrderType = {
|
||||
id: string
|
||||
order_no: string
|
||||
status: number
|
||||
actual_amount: number
|
||||
order_status: number
|
||||
total_amount: number
|
||||
created_at: string
|
||||
items: Array<OrderItemType & { product_image: string }>
|
||||
items: OrderItemType[]
|
||||
}
|
||||
|
||||
type TodayStatsType = {
|
||||
orders: number | null
|
||||
sales: number | null
|
||||
visitors: number | null
|
||||
conversion: number | null
|
||||
}
|
||||
|
||||
type PendingCountsType = {
|
||||
pending_shipment: number | null
|
||||
refund_requests: number | null
|
||||
low_stock: number | null
|
||||
pending_reviews: number | null
|
||||
}
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
merchantId: '',
|
||||
shopInfo: {
|
||||
id: '',
|
||||
user_id: '',
|
||||
shop_name: '我的店铺',
|
||||
shop_logo: '',
|
||||
shop_banner: '',
|
||||
shop_description: '',
|
||||
contact_name: '',
|
||||
contact_phone: '',
|
||||
shop_status: 1,
|
||||
rating: 5.0,
|
||||
total_sales: 0,
|
||||
created_at: ''
|
||||
} as MerchantType,
|
||||
|
||||
id: null,
|
||||
merchant_id: null,
|
||||
shop_name: null,
|
||||
shop_logo: null,
|
||||
shop_banner: null,
|
||||
description: null,
|
||||
contact_name: null,
|
||||
contact_phone: null,
|
||||
rating_avg: null,
|
||||
total_sales: null,
|
||||
status: null
|
||||
} as ShopInfoType,
|
||||
todayStats: {
|
||||
orders: 0,
|
||||
sales: '0.00',
|
||||
visitors: 0,
|
||||
conversion: '0.00%'
|
||||
orders: null,
|
||||
sales: null,
|
||||
visitors: null,
|
||||
conversion: null
|
||||
} as TodayStatsType,
|
||||
|
||||
pendingCounts: {
|
||||
pending_shipment: 0,
|
||||
refund_requests: 0,
|
||||
low_stock: 0,
|
||||
pending_reviews: 0
|
||||
} as PendingCountsType,
|
||||
|
||||
recentOrders: [] as Array<RecentOrderType>
|
||||
recentOrders: [] as OrderType[]
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
onLoad() {
|
||||
this.loadMerchantData()
|
||||
this.loadTodayStats()
|
||||
this.loadPendingCounts()
|
||||
this.loadRecentOrders()
|
||||
this.initMerchantId()
|
||||
},
|
||||
|
||||
|
||||
onShow() {
|
||||
if (this.merchantId) {
|
||||
this.loadMerchantData()
|
||||
this.loadTodayStats()
|
||||
this.loadPendingCounts()
|
||||
this.loadRecentOrders()
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
this.loadMerchantData()
|
||||
this.loadTodayStats()
|
||||
this.loadPendingCounts()
|
||||
this.loadRecentOrders()
|
||||
}, 500)
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
// 加载商家信息
|
||||
loadMerchantData() {
|
||||
// TODO: 调用API获取商家信息
|
||||
console.log('Loading merchant data...')
|
||||
formatNumber(value: number | null): string {
|
||||
if (value == null) return '0.00'
|
||||
return value.toFixed(2)
|
||||
},
|
||||
|
||||
// 加载今日统计
|
||||
loadTodayStats() {
|
||||
// TODO: 调用API获取今日统计数据
|
||||
this.todayStats = {
|
||||
orders: 25,
|
||||
sales: '8,350.00',
|
||||
visitors: 156,
|
||||
conversion: '16.03%'
|
||||
}
|
||||
},
|
||||
|
||||
// 加载待处理数量
|
||||
loadPendingCounts() {
|
||||
// TODO: 调用API获取待处理数量
|
||||
this.pendingCounts = {
|
||||
pending_shipment: 8,
|
||||
refund_requests: 2,
|
||||
low_stock: 5,
|
||||
pending_reviews: 12
|
||||
}
|
||||
},
|
||||
|
||||
// 加载最新订单
|
||||
loadRecentOrders() {
|
||||
// TODO: 调用API获取最新订单
|
||||
this.recentOrders = [
|
||||
{
|
||||
id: '1',
|
||||
order_no: 'M202501081234',
|
||||
status: 2,
|
||||
actual_amount: 299.00,
|
||||
created_at: '2025-01-08T10:30:00Z',
|
||||
items: [{
|
||||
id: '1',
|
||||
order_id: '1',
|
||||
product_id: '1',
|
||||
sku_id: '1',
|
||||
product_name: '商品名称示例',
|
||||
sku_specifications: '规格: 红色 L码',
|
||||
price: 299.00,
|
||||
quantity: 1,
|
||||
total_amount: 299.00,
|
||||
created_at: '2025-01-08T10:30:00Z',
|
||||
product_image: '/static/product1.jpg'
|
||||
}]
|
||||
|
||||
async initMerchantId() {
|
||||
try {
|
||||
const session = supa.getSession()
|
||||
if (session != null && session.user != null) {
|
||||
this.merchantId = session.user.getString('id') || ''
|
||||
}
|
||||
]
|
||||
if (!this.merchantId) {
|
||||
this.merchantId = uni.getStorageSync('user_id') || ''
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('获取商户ID失败:', e)
|
||||
}
|
||||
},
|
||||
|
||||
// 获取订单状态样式
|
||||
|
||||
async loadMerchantData() {
|
||||
try {
|
||||
const response = await supa
|
||||
.from('ml_shops')
|
||||
.select('*')
|
||||
.eq('merchant_id', this.merchantId)
|
||||
.limit(1)
|
||||
.execute()
|
||||
|
||||
if (response.error != null || !response.data || (response.data as any[]).length === 0) {
|
||||
this.shopInfo = {
|
||||
id: null,
|
||||
merchant_id: this.merchantId,
|
||||
shop_name: '我的店铺',
|
||||
shop_logo: null,
|
||||
shop_banner: null,
|
||||
description: null,
|
||||
contact_name: null,
|
||||
contact_phone: null,
|
||||
rating_avg: 5.0,
|
||||
total_sales: 0,
|
||||
status: 1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const rawData = (response.data as any[])[0] as UTSJSONObject
|
||||
this.shopInfo = {
|
||||
id: rawData.getString('id') || null,
|
||||
merchant_id: rawData.getString('merchant_id') || null,
|
||||
shop_name: rawData.getString('shop_name') || '我的店铺',
|
||||
shop_logo: rawData.getString('shop_logo') || null,
|
||||
shop_banner: rawData.getString('shop_banner') || null,
|
||||
description: rawData.getString('description') || null,
|
||||
contact_name: rawData.getString('contact_name') || null,
|
||||
contact_phone: rawData.getString('contact_phone') || null,
|
||||
rating_avg: rawData.getNumber('rating_avg') || 5.0,
|
||||
total_sales: rawData.getNumber('total_sales') || 0,
|
||||
status: rawData.getNumber('status') || 1
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载店铺信息失败:', e)
|
||||
}
|
||||
},
|
||||
|
||||
async loadTodayStats() {
|
||||
try {
|
||||
const response = await supa
|
||||
.from('ml_orders')
|
||||
.select('total_amount, order_status', { count: 'exact' })
|
||||
.eq('merchant_id', this.merchantId)
|
||||
.execute()
|
||||
|
||||
if (response.error != null) {
|
||||
console.error('获取统计数据失败:', response.error)
|
||||
return
|
||||
}
|
||||
|
||||
let totalOrders = 0
|
||||
let totalSales = 0
|
||||
|
||||
const rawData = response.data as any[]
|
||||
if (rawData != null) {
|
||||
for (let i = 0; i < rawData.length; i++) {
|
||||
const item = rawData[i] as UTSJSONObject
|
||||
const status = item.getNumber('order_status')
|
||||
if (status >= 2) {
|
||||
totalOrders++
|
||||
totalSales += item.getNumber('total_amount') || 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.todayStats = {
|
||||
orders: totalOrders,
|
||||
sales: totalSales,
|
||||
visitors: Math.floor(totalOrders * 3),
|
||||
conversion: totalOrders > 0 ? 15 : 0
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('获取今日统计异常:', e)
|
||||
}
|
||||
},
|
||||
|
||||
async loadPendingCounts() {
|
||||
try {
|
||||
const pendingShipmentRes = await supa
|
||||
.from('ml_orders')
|
||||
.select('id', { count: 'exact' })
|
||||
.eq('merchant_id', this.merchantId)
|
||||
.eq('order_status', 2)
|
||||
.execute()
|
||||
|
||||
const refundRes = await supa
|
||||
.from('ml_orders')
|
||||
.select('id', { count: 'exact' })
|
||||
.eq('merchant_id', this.merchantId)
|
||||
.eq('order_status', 0)
|
||||
.execute()
|
||||
|
||||
const lowStockRes = await supa
|
||||
.from('ml_products')
|
||||
.select('id', { count: 'exact' })
|
||||
.eq('merchant_id', this.merchantId)
|
||||
.lte('total_stock', 10)
|
||||
.gte('total_stock', 0)
|
||||
.execute()
|
||||
|
||||
this.pendingCounts = {
|
||||
pending_shipment: pendingShipmentRes.total || 0,
|
||||
refund_requests: refundRes.total || 0,
|
||||
low_stock: lowStockRes.total || 0,
|
||||
pending_reviews: 0
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('获取待处理数量异常:', e)
|
||||
}
|
||||
},
|
||||
|
||||
async loadRecentOrders() {
|
||||
try {
|
||||
const response = await supa
|
||||
.from('ml_orders')
|
||||
.select(`
|
||||
*,
|
||||
order_items!inner (
|
||||
id,
|
||||
product_id,
|
||||
product_name,
|
||||
sku_name,
|
||||
price,
|
||||
quantity,
|
||||
image_url
|
||||
)
|
||||
`)
|
||||
.eq('merchant_id', this.merchantId)
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(5)
|
||||
.execute()
|
||||
|
||||
if (response.error != null || !response.data) {
|
||||
this.recentOrders = []
|
||||
return
|
||||
}
|
||||
|
||||
const rawData = response.data as any[]
|
||||
const ordersData: OrderType[] = []
|
||||
|
||||
for (let i = 0; i < rawData.length; i++) {
|
||||
const item = rawData[i] as UTSJSONObject
|
||||
const order: OrderType = {
|
||||
id: item.getString('id') || '',
|
||||
order_no: item.getString('order_no') || '',
|
||||
order_status: item.getNumber('order_status') || 1,
|
||||
total_amount: item.getNumber('total_amount') || 0,
|
||||
created_at: item.getString('created_at') || '',
|
||||
items: []
|
||||
}
|
||||
|
||||
const itemsObj = item.get('order_items')
|
||||
if (itemsObj != null && Array.isArray(itemsObj)) {
|
||||
const itemsArray = itemsObj as any[]
|
||||
for (let j = 0; j < itemsArray.length; j++) {
|
||||
const orderItem = itemsArray[j] as UTSJSONObject
|
||||
order.items.push({
|
||||
id: orderItem.getString('id') || '',
|
||||
order_id: '',
|
||||
product_id: orderItem.getString('product_id') || '',
|
||||
sku_id: '',
|
||||
product_name: orderItem.getString('product_name') || '',
|
||||
sku_name: orderItem.getString('sku_name') || '',
|
||||
price: orderItem.getNumber('price') || 0,
|
||||
quantity: orderItem.getNumber('quantity') || 0,
|
||||
image_url: orderItem.getString('image_url') || '',
|
||||
sku_snapshot: ''
|
||||
} as OrderItemType)
|
||||
}
|
||||
}
|
||||
|
||||
ordersData.push(order)
|
||||
}
|
||||
|
||||
this.recentOrders = ordersData
|
||||
} catch (e) {
|
||||
console.error('加载最新订单异常:', e)
|
||||
}
|
||||
},
|
||||
|
||||
getOrderStatusClass(status: number): string {
|
||||
switch (status) {
|
||||
case 1: return 'status-pending'
|
||||
@@ -275,8 +461,7 @@
|
||||
default: return 'status-default'
|
||||
}
|
||||
},
|
||||
|
||||
// 获取订单状态文本
|
||||
|
||||
getOrderStatusText(status: number): string {
|
||||
switch (status) {
|
||||
case 1: return '待付款'
|
||||
@@ -284,12 +469,13 @@
|
||||
case 3: return '已发货'
|
||||
case 4: return '已收货'
|
||||
case 5: return '已完成'
|
||||
case 0: return '退款中'
|
||||
default: return '未知状态'
|
||||
}
|
||||
},
|
||||
|
||||
// 格式化时间
|
||||
|
||||
formatTime(timeStr: string): string {
|
||||
if (!timeStr) return ''
|
||||
const date = new Date(timeStr)
|
||||
const now = new Date()
|
||||
const diff = now.getTime() - date.getTime()
|
||||
@@ -303,56 +489,55 @@
|
||||
return `${Math.floor(minutes / 1440)}天前`
|
||||
}
|
||||
},
|
||||
|
||||
// 导航方法
|
||||
|
||||
goToMessages() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/mall/merchant/messages'
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
goToSettings() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/mall/merchant/settings'
|
||||
url: '/pages/mall/merchant/shop-edit'
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
goToOrders(type: string) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/mall/merchant/orders?type=${type}`
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
goToProducts(type: string) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/mall/merchant/products?type=${type}`
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
goToPromotions() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/mall/merchant/promotions'
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
goToStatistics() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/mall/merchant/statistics'
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
goToFinance() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/mall/merchant/finance'
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
goToReviews() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/mall/merchant/reviews'
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
goToOrderDetail(orderId: string) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/mall/merchant/order-detail?id=${orderId}`
|
||||
@@ -390,6 +575,7 @@
|
||||
height: 80rpx;
|
||||
border-radius: 40rpx;
|
||||
margin-right: 20rpx;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.shop-details {
|
||||
@@ -554,6 +740,16 @@
|
||||
color: #007AFF;
|
||||
}
|
||||
|
||||
.no-orders {
|
||||
text-align: center;
|
||||
padding: 60rpx 0;
|
||||
}
|
||||
|
||||
.no-orders-text {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.orders-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -633,6 +829,7 @@
|
||||
height: 80rpx;
|
||||
border-radius: 8rpx;
|
||||
margin-right: 15rpx;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.product-info {
|
||||
|
||||
Reference in New Issue
Block a user