提交昨晚至今早的修改

This commit is contained in:
2026-01-28 10:46:54 +08:00
parent 4ab722a118
commit af316e6d94
13 changed files with 6635 additions and 196 deletions

View File

@@ -82,6 +82,32 @@
</view>
</view>
<!-- 购物车操作栏 (移至推荐商品上方) -->
<view v-if="cartItems.length > 0" class="cart-action-bar">
<view class="action-bar-content">
<view class="action-left">
<view class="select-all" @click="toggleSelectAll">
<text v-if="allSelected" class="selected-icon">✓</text>
<text v-else class="unselected-icon"></text>
<text class="select-all-text">全选</text>
</view>
</view>
<view class="action-right">
<view v-if="!isManageMode" class="total-info">
<text class="total-text">合计:</text>
<text class="total-price">¥{{ totalPrice }}</text>
</view>
<button v-if="!isManageMode" class="checkout-btn" @click="goToCheckout">
去结算({{ selectedCount }})
</button>
<button v-else class="delete-btn" @click="deleteSelectedItems">
删除({{ selectedCount }})
</button>
</view>
</view>
</view>
<!-- 推荐商品 -->
<view v-if="recommendProducts.length > 0" class="recommend-section">
<view class="section-header">
@@ -111,8 +137,8 @@
</view>
</scroll-view>
<!-- 底部结算栏 -->
<view v-if="cartItems.length > 0" class="cart-footer">
<!-- 底部结算栏 - 已移除,移动到内容区域 -->
<!-- <view v-if="cartItems.length > 0" class="cart-footer">
<view class="footer-content">
<view class="footer-left">
<view class="select-all" @click="toggleSelectAll">
@@ -127,8 +153,6 @@
<text class="total-text">合计:</text>
<text class="total-price">¥{{ totalPrice }}</text>
</view>
<!-- 结算按钮:即使在管理模式下,如果用户想结算也可以(或者在管理模式下隐藏结算,只显示删除) -->
<!-- 需求加购商品前面的按钮时cart购物车页面顶部的管理点击能对加购商品进行批量删除 -->
<button v-if="!isManageMode" class="checkout-btn" @click="goToCheckout">
去结算({{ selectedCount }})
</button>
@@ -137,7 +161,7 @@
</button>
</view>
</view>
</view>
</view> -->
</view>
</template>
@@ -415,15 +439,18 @@ const addToCart = (product: any) => {
}
}
// 检查商品是否已存在
const existingItem = currentItems.find((item: any) => item.id === product.id)
// 检查商品是否已存在 (使用商品ID匹配因为推荐商品没有SKU)
const existingItem = currentItems.find((item: any) =>
item.productId === product.id || item.id === product.id
)
if (existingItem) {
existingItem.quantity++
} else {
// 添加新商品
currentItems.push({
id: product.id,
id: product.id, // 商品ID因为没有SKU
productId: product.id, // 同样存储商品ID
shopId: product.shopId || 'shop_recommend',
shopName: product.shopName || '推荐好物',
name: product.name,
@@ -453,7 +480,11 @@ const goShopping = () => {
}
const navigateToProduct = (product: any) => {
uni.navigateTo({ url: `/pages/mall/consumer/product-detail?id=${product.id}` })
// 使用productId如果存在作为跳转的商品ID否则使用id
const productId = product.productId || product.id
uni.navigateTo({
url: `/pages/mall/consumer/product-detail?id=${productId}&name=${encodeURIComponent(product.name)}&price=${product.price}&image=${encodeURIComponent(product.image)}`
})
}
const goToCheckout = () => {
@@ -465,7 +496,10 @@ const goToCheckout = () => {
return
}
// 获取选中的商品
// 确保最新状态已保存到本地存储
saveCartData()
// 获取选中的商品 (直接过滤cartItems不依赖cartGroups)
const selectedItems = cartItems.value
.filter(item => item.selected)
.map(item => ({
@@ -475,10 +509,14 @@ const goToCheckout = () => {
product_name: item.name,
product_image: item.image,
sku_specifications: item.spec,
price: item.price,
quantity: item.quantity
price: Number(item.price), // 确保是数字
quantity: Number(item.quantity) // 确保是数字
}))
// 关键修复:将结算数据写入 Storage确保 checkout 页面能稳定获取
uni.setStorageSync('checkout_type', 'cart')
uni.setStorageSync('checkout_items', JSON.stringify(selectedItems))
// 跳转到结算页面并传递数据
uni.navigateTo({
url: '/pages/mall/consumer/checkout',
@@ -1059,83 +1097,171 @@ const goToCheckout = () => {
}
}
/* 底部结算栏 */
.cart-footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 60px;
background-color: white;
border-top: 1px solid #eee;
display: flex;
align-items: center;
justify-content: center; /* 居中内容 */
padding: 0 15px;
z-index: 900;
padding-bottom: env(safe-area-inset-bottom);
}
/* 购物车操作栏样式 - 自适应横向排列 */
.cart-action-bar {
background-color: white;
margin: 10px;
border-radius: 12px;
padding: 15px;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.footer-content {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.action-bar-content {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.footer-left {
display: flex;
align-items: center;
}
.action-left, .action-right {
display: flex;
align-items: center;
flex-wrap: nowrap;
}
.select-all {
display: flex;
align-items: center;
}
.select-all-text {
margin-left: 8px;
font-size: 14px;
color: #333;
}
.footer-right {
display: flex;
align-items: center;
}
.total-info {
margin-right: 15px;
text-align: right;
}
.total-text {
font-size: 14px;
color: #333;
margin-right: 5px;
}
.total-price {
font-size: 18px;
color: #ff5000;
font-weight: bold;
}
.checkout-btn {
background-color: #ff5000;
color: white;
border: none;
border-radius: 25px;
padding: 8px 20px;
font-size: 14px;
}
.delete-btn {
background-color: #ff3b30; /* 红色删除按钮 */
color: white;
border: none;
border-radius: 25px;
padding: 8px 25px;
font-size: 14px;
}
.action-right {
justify-content: flex-end;
flex: 1;
min-width: 0; /* 防止溢出 */
}
/* 合计信息区域 - 自适应横向排列 */
.total-info {
display: flex;
align-items: center;
margin-right: 12px;
flex-shrink: 0;
}
.total-text {
font-size: 14px;
color: #333;
margin-right: 5px;
white-space: nowrap;
}
.total-price {
font-size: 18px;
color: #ff5000;
font-weight: bold;
white-space: nowrap;
}
/* 结算按钮 */
.checkout-btn, .delete-btn {
background-color: #ff5000;
color: white;
border: none;
border-radius: 25px;
padding: 8px 20px;
font-size: 14px;
white-space: nowrap;
flex-shrink: 0;
}
.delete-btn {
background-color: #ff3b30; /* 红色删除按钮 */
padding: 8px 25px;
}
/* 全选区域 */
.select-all {
display: flex;
align-items: center;
}
.select-all-text {
margin-left: 8px;
font-size: 14px;
color: #333;
white-space: nowrap;
}
/* 响应式调整 */
/* 手机端小屏幕优化 */
@media screen and (max-width: 375px) {
.action-bar-content {
gap: 8px;
}
.total-text {
font-size: 13px;
}
.total-price {
font-size: 16px;
}
.checkout-btn, .delete-btn {
padding: 8px 15px;
font-size: 13px;
}
.select-all-text {
font-size: 13px;
}
}
/* 平板端优化 */
@media screen and (min-width: 768px) {
.cart-action-bar {
margin: 20px auto;
max-width: 95%;
padding: 20px;
}
.action-bar-content {
gap: 20px;
}
.total-price {
font-size: 20px;
}
.checkout-btn, .delete-btn {
padding: 10px 30px;
font-size: 16px;
}
}
/* 桌面端优化 */
@media screen and (min-width: 1024px) {
.cart-action-bar {
max-width: 1200px;
padding: 20px 30px;
}
.action-bar-content {
justify-content: space-between;
}
.total-info {
margin-right: 30px;
}
.total-text {
font-size: 16px;
}
.total-price {
font-size: 22px;
}
.checkout-btn, .delete-btn {
padding: 12px 40px;
font-size: 16px;
}
.select-all-text {
font-size: 16px;
}
}
/* 大屏幕优化 */
@media screen and (min-width: 1400px) {
.cart-action-bar {
max-width: 1400px;
}
}
</style>