consumer模块完成度95%,检查消费者前端bug并修复
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!-- pages/mall/consumer/orders.uvue -->
|
||||
<!-- pages/mall/consumer/orders.uvue -->
|
||||
<template>
|
||||
<view class="orders-page">
|
||||
<!-- 顶部标题栏 -->
|
||||
@@ -88,12 +88,12 @@
|
||||
v-for="product in order.products"
|
||||
:key="product.id"
|
||||
class="order-product"
|
||||
@click="navigateToProduct(product)"
|
||||
>
|
||||
<image
|
||||
class="product-image"
|
||||
:src="product.image"
|
||||
mode="aspectFill"
|
||||
@click.stop="navigateToProduct(product)"
|
||||
/>
|
||||
<view class="product-info">
|
||||
<view class="product-top-info">
|
||||
@@ -117,6 +117,14 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分享免单入口 (已付款订单显示: 待发货、待收货、已完成,且商家开启了分享免单) -->
|
||||
<view v-if="order.status >= 2 && order.status <= 4 && merchantShareFreeEnabled[order.merchant_id]" class="share-free-row" @click.stop="shareForFree(order)">
|
||||
<text class="share-free-icon">🎁</text>
|
||||
<text class="share-free-text">分享免单</text>
|
||||
<text class="share-free-tip">分享给好友,{{ merchantRequiredCount[order.merchant_id] != null ? merchantRequiredCount[order.merchant_id] : 4 }}人购买即可免单</text>
|
||||
<text class="share-free-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<!-- 订单操作 -->
|
||||
<view class="order-actions" @click.stop="">
|
||||
<view v-if="order.status === 1" class="action-buttons">
|
||||
@@ -226,6 +234,10 @@ const activeTab = ref<string>('all')
|
||||
const statusBarHeight = ref<number>(0)
|
||||
const searchKeyword = ref<string>('')
|
||||
|
||||
// 商家推销配置缓存
|
||||
const merchantShareFreeEnabled = ref<Record<string, boolean>>({})
|
||||
const merchantRequiredCount = ref<Record<string, number>>({})
|
||||
|
||||
// 订单标签页 - 使用 ref 以便整体替换
|
||||
const orderTabs = ref<OrderTabItem[]>([
|
||||
{ id: 'all', name: '全部', count: 0 },
|
||||
@@ -496,6 +508,9 @@ const loadOrders = async () => {
|
||||
// Apply current tab filter
|
||||
filterOrdersByTab()
|
||||
|
||||
// 加载商家推销配置
|
||||
loadMerchantPromotionConfigs(mappedOrders)
|
||||
|
||||
} catch (err) {
|
||||
console.error('加载订单异常:', err)
|
||||
uni.showToast({ title: '加载订单失败', icon: 'none' })
|
||||
@@ -532,6 +547,39 @@ onShow(() => {
|
||||
loadOrders()
|
||||
})
|
||||
|
||||
// 加载商家推销配置
|
||||
const loadMerchantPromotionConfigs = async (orderList: OrderItem[]) => {
|
||||
// 收集所有唯一的商家ID
|
||||
const merchantIds = new Set<string>()
|
||||
for (let i = 0; i < orderList.length; i++) {
|
||||
const merchantId = orderList[i].merchant_id
|
||||
if (merchantId != null && merchantId !== '' && !merchantShareFreeEnabled.value.hasOwnProperty(merchantId)) {
|
||||
merchantIds.add(merchantId)
|
||||
}
|
||||
}
|
||||
|
||||
// 批量加载商家配置
|
||||
const merchantIdArray = Array.from(merchantIds)
|
||||
for (let i = 0; i < merchantIdArray.length; i++) {
|
||||
const merchantId = merchantIdArray[i]
|
||||
try {
|
||||
const config = await supabaseService.getMerchantPromotionConfig(merchantId)
|
||||
const promotionEnabled = config.get('promotion_enabled')
|
||||
const shareFreeEnabled = config.get('share_free_enabled')
|
||||
const requiredCount = config.get('required_count')
|
||||
|
||||
merchantShareFreeEnabled.value[merchantId] =
|
||||
(promotionEnabled === true || promotionEnabled === 'true') &&
|
||||
(shareFreeEnabled === true || shareFreeEnabled === 'true')
|
||||
merchantRequiredCount.value[merchantId] = (requiredCount as number) ?? 4
|
||||
} catch (e) {
|
||||
console.error('加载商家推销配置失败:', merchantId, e)
|
||||
merchantShareFreeEnabled.value[merchantId] = false
|
||||
merchantRequiredCount.value[merchantId] = 4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const formatDate = (isoString: string): string => {
|
||||
if (isoString == '') return ''
|
||||
const date = new Date(isoString)
|
||||
@@ -799,16 +847,22 @@ const doConfirmReceipt = async (orderId: string) => {
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 更新本地状态
|
||||
const index = orders.value.findIndex((o: OrderItem): boolean => o.id === orderId)
|
||||
if (index !== -1) {
|
||||
orders.value[index].status = 4
|
||||
orders.value = [...orders.value]
|
||||
// 更新 allOrdersList 中的订单状态
|
||||
const allIndex = allOrdersList.value.findIndex((o: OrderItem): boolean => o.id === orderId)
|
||||
if (allIndex !== -1) {
|
||||
allOrdersList.value[allIndex].status = 4
|
||||
allOrdersList.value = [...allOrdersList.value]
|
||||
}
|
||||
|
||||
// 更新标签计数
|
||||
updateTabsCounts(allOrdersList.value)
|
||||
|
||||
// 重新应用当前标签筛选
|
||||
filterOrdersByTab()
|
||||
|
||||
// 跳转到评价页面
|
||||
setTimeout(() => {
|
||||
const order = orders.value.find((o: OrderItem): boolean => o.id === orderId)
|
||||
const order = allOrdersList.value.find((o: OrderItem): boolean => o.id === orderId)
|
||||
if (order != null) {
|
||||
goReview(order)
|
||||
}
|
||||
@@ -1030,6 +1084,53 @@ const navigateToProduct = (product: OrderProduct) => {
|
||||
const goShopping = () => {
|
||||
uni.switchTab({ url: '/pages/main/index' })
|
||||
}
|
||||
|
||||
const shareForFree = async (order: OrderItem) => {
|
||||
if (order.products.length === 0) {
|
||||
uni.showToast({ title: '没有可分享的商品', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const firstProduct = order.products[0]
|
||||
|
||||
try {
|
||||
uni.showLoading({ title: '创建分享...' })
|
||||
const result = await supabaseService.createShareRecord(
|
||||
firstProduct.id,
|
||||
order.id,
|
||||
'',
|
||||
firstProduct.name,
|
||||
firstProduct.image,
|
||||
firstProduct.price
|
||||
)
|
||||
uni.hideLoading()
|
||||
|
||||
const shareIdRaw = result.get('id')
|
||||
const shareCodeRaw = result.get('share_code')
|
||||
|
||||
if (shareIdRaw != null && shareCodeRaw != null) {
|
||||
const shareId = shareIdRaw as string
|
||||
const shareCode = shareCodeRaw as string
|
||||
|
||||
uni.showModal({
|
||||
title: '分享成功',
|
||||
content: `您的分享码: ${shareCode}\n分享给好友,当有4人购买后即可免单!`,
|
||||
confirmText: '查看详情',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.navigateTo({ url: `/pages/mall/consumer/share/detail?id=${shareId}` })
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.showToast({ title: '分享创建失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
console.error('[shareForFree] 创建分享失败:', e)
|
||||
uni.showToast({ title: '分享失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -1081,7 +1182,7 @@ const goShopping = () => {
|
||||
.search-input {
|
||||
flex: 1;
|
||||
height: 36px;
|
||||
line-height: normal;
|
||||
line-height: 36px;
|
||||
border: 1px solid #dddddd;
|
||||
border-radius: 18px;
|
||||
padding: 0 40px 0 16px;
|
||||
@@ -1677,6 +1778,41 @@ const goShopping = () => {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* 分享免单入口样式 */
|
||||
.share-free-row {
|
||||
margin: 0 15px;
|
||||
padding: 12px 15px;
|
||||
background: linear-gradient(135deg, #fff5f0 0%, #ffecd2 100%);
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.share-free-icon {
|
||||
font-size: 20px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.share-free-text {
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
color: #ff6b35;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.share-free-tip {
|
||||
flex: 1;
|
||||
font-size: 12px;
|
||||
color: #ff8c42;
|
||||
}
|
||||
|
||||
.share-free-arrow {
|
||||
font-size: 16px;
|
||||
color: #ff8c42;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 320px) {
|
||||
.tab-item {
|
||||
padding: 0 10px;
|
||||
|
||||
Reference in New Issue
Block a user