|
|
|
@ -12,6 +12,9 @@ definePage({
|
|
|
|
// 初始化购物车状态
|
|
|
|
// 初始化购物车状态
|
|
|
|
const cartStore = useCartStore()
|
|
|
|
const cartStore = useCartStore()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 管理模式状态
|
|
|
|
|
|
|
|
const isManageMode = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
// 计算属性
|
|
|
|
// 计算属性
|
|
|
|
const storeGroups = computed(() => cartStore.groupedByStore)
|
|
|
|
const storeGroups = computed(() => cartStore.groupedByStore)
|
|
|
|
const totalPrice = computed(() => cartStore.totalPrice)
|
|
|
|
const totalPrice = computed(() => cartStore.totalPrice)
|
|
|
|
@ -38,6 +41,44 @@ function handleCheckout() {
|
|
|
|
console.log('跳转到结算页面', cartStore.selectedCartItems)
|
|
|
|
console.log('跳转到结算页面', cartStore.selectedCartItems)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 切换管理模式
|
|
|
|
|
|
|
|
function toggleManageMode() {
|
|
|
|
|
|
|
|
isManageMode.value = !isManageMode.value
|
|
|
|
|
|
|
|
// 退出管理模式时清空选择
|
|
|
|
|
|
|
|
if (!isManageMode.value) {
|
|
|
|
|
|
|
|
cartStore.clearSelection()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 批量删除
|
|
|
|
|
|
|
|
function handleBatchDelete() {
|
|
|
|
|
|
|
|
if (selectedCount.value === 0) {
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
|
|
title: '请选择要删除的商品',
|
|
|
|
|
|
|
|
icon: 'none',
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uni.showModal({
|
|
|
|
|
|
|
|
title: '确认删除',
|
|
|
|
|
|
|
|
content: `确定要删除选中的${selectedCount.value}个商品吗?`,
|
|
|
|
|
|
|
|
success: (res) => {
|
|
|
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
|
|
|
cartStore.removeSelectedItems()
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
|
|
title: '删除成功',
|
|
|
|
|
|
|
|
icon: 'success',
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
// 如果删除后购物车为空,退出管理模式
|
|
|
|
|
|
|
|
if (cartStore.isEmpty) {
|
|
|
|
|
|
|
|
isManageMode.value = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 模拟数据 - 用于开发测试
|
|
|
|
// 模拟数据 - 用于开发测试
|
|
|
|
onMounted(() => {
|
|
|
|
onMounted(() => {
|
|
|
|
// 如果购物车为空,添加一些模拟数据
|
|
|
|
// 如果购物车为空,添加一些模拟数据
|
|
|
|
@ -92,6 +133,12 @@ onMounted(() => {
|
|
|
|
<!-- 页面头部 -->
|
|
|
|
<!-- 页面头部 -->
|
|
|
|
<view class="cart-header">
|
|
|
|
<view class="cart-header">
|
|
|
|
<text class="cart-title">购物车</text>
|
|
|
|
<text class="cart-title">购物车</text>
|
|
|
|
|
|
|
|
<!-- 管理按钮 -->
|
|
|
|
|
|
|
|
<view v-if="!isEmpty" class="header-actions">
|
|
|
|
|
|
|
|
<text class="manage-btn" @click="toggleManageMode">
|
|
|
|
|
|
|
|
{{ isManageMode ? '完成' : '管理' }}
|
|
|
|
|
|
|
|
</text>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 购物车内容 -->
|
|
|
|
<!-- 购物车内容 -->
|
|
|
|
@ -110,7 +157,7 @@ onMounted(() => {
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 底部结算栏 -->
|
|
|
|
<!-- 底部操作栏 -->
|
|
|
|
<view v-if="!isEmpty" class="cart-footer">
|
|
|
|
<view v-if="!isEmpty" class="cart-footer">
|
|
|
|
<!-- 全选 -->
|
|
|
|
<!-- 全选 -->
|
|
|
|
<view class="select-all-section">
|
|
|
|
<view class="select-all-section">
|
|
|
|
@ -123,8 +170,25 @@ onMounted(() => {
|
|
|
|
<text class="select-all-text">全选</text>
|
|
|
|
<text class="select-all-text">全选</text>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 价格和结算 -->
|
|
|
|
<!-- 操作区域 -->
|
|
|
|
<view class="checkout-section">
|
|
|
|
<view class="action-section">
|
|
|
|
|
|
|
|
<!-- 管理模式 -->
|
|
|
|
|
|
|
|
<template v-if="isManageMode">
|
|
|
|
|
|
|
|
<view class="selected-info">
|
|
|
|
|
|
|
|
<text class="selected-text">已选择{{ selectedCount }}项</text>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
<wd-button
|
|
|
|
|
|
|
|
type="error"
|
|
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
|
|
class="batch-delete-btn"
|
|
|
|
|
|
|
|
@click="handleBatchDelete"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
删除
|
|
|
|
|
|
|
|
</wd-button>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 普通模式 -->
|
|
|
|
|
|
|
|
<template v-else>
|
|
|
|
<view class="price-section">
|
|
|
|
<view class="price-section">
|
|
|
|
<text class="price-label">合计:</text>
|
|
|
|
<text class="price-label">合计:</text>
|
|
|
|
<text class="price-value">¥{{ totalPrice.toFixed(2) }}</text>
|
|
|
|
<text class="price-value">¥{{ totalPrice.toFixed(2) }}</text>
|
|
|
|
@ -137,6 +201,7 @@ onMounted(() => {
|
|
|
|
>
|
|
|
|
>
|
|
|
|
结算({{ selectedCount }})
|
|
|
|
结算({{ selectedCount }})
|
|
|
|
</wd-button>
|
|
|
|
</wd-button>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
@ -149,13 +214,22 @@ onMounted(() => {
|
|
|
|
|
|
|
|
|
|
|
|
/* 页面头部 */
|
|
|
|
/* 页面头部 */
|
|
|
|
.cart-header {
|
|
|
|
.cart-header {
|
|
|
|
@apply bg-white py-[30rpx] px-[32rpx] border-b border-gray-100;
|
|
|
|
@apply bg-white py-[30rpx] px-[32rpx] border-b border-gray-100 flex items-center justify-between;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.cart-title {
|
|
|
|
.cart-title {
|
|
|
|
@apply text-[32rpx] font-bold text-gray-800;
|
|
|
|
@apply text-[32rpx] font-bold text-gray-800;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 头部操作区域 */
|
|
|
|
|
|
|
|
.header-actions {
|
|
|
|
|
|
|
|
@apply flex items-center;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.manage-btn {
|
|
|
|
|
|
|
|
@apply text-[28rpx] text-gray-600;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 购物车内容 */
|
|
|
|
/* 购物车内容 */
|
|
|
|
.cart-content {
|
|
|
|
.cart-content {
|
|
|
|
@apply flex-1 overflow-y-auto;
|
|
|
|
@apply flex-1 overflow-y-auto;
|
|
|
|
@ -181,11 +255,17 @@ onMounted(() => {
|
|
|
|
@apply ml-[12rpx] text-[28rpx] text-gray-700;
|
|
|
|
@apply ml-[12rpx] text-[28rpx] text-gray-700;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 操作区域 */
|
|
|
|
|
|
|
|
.action-section {
|
|
|
|
|
|
|
|
@apply flex items-center;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 结算部分 */
|
|
|
|
/* 结算部分 */
|
|
|
|
.checkout-section {
|
|
|
|
.checkout-section {
|
|
|
|
@apply flex items-center;
|
|
|
|
@apply flex items-center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 价格部分 */
|
|
|
|
.price-section {
|
|
|
|
.price-section {
|
|
|
|
@apply mr-[24rpx];
|
|
|
|
@apply mr-[24rpx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -198,18 +278,39 @@ onMounted(() => {
|
|
|
|
@apply text-[32rpx] font-bold text-red-500;
|
|
|
|
@apply text-[32rpx] font-bold text-red-500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 结算按钮 */
|
|
|
|
.checkout-btn {
|
|
|
|
.checkout-btn {
|
|
|
|
@apply min-w-[200rpx];
|
|
|
|
@apply min-w-[200rpx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 管理模式 - 已选择信息 */
|
|
|
|
|
|
|
|
.selected-info {
|
|
|
|
|
|
|
|
@apply mr-[24rpx];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.selected-text {
|
|
|
|
|
|
|
|
@apply text-[26rpx] text-gray-600;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 批量删除按钮 */
|
|
|
|
|
|
|
|
.batch-delete-btn {
|
|
|
|
|
|
|
|
@apply min-w-[200rpx];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 响应式设计 */
|
|
|
|
/* 响应式设计 */
|
|
|
|
@media screen and (max-width: 750rpx) {
|
|
|
|
@media screen and (max-width: 750rpx) {
|
|
|
|
.cart-footer {
|
|
|
|
.cart-footer {
|
|
|
|
@apply py-[16rpx] px-[24rpx];
|
|
|
|
@apply py-[16rpx] px-[24rpx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.checkout-btn {
|
|
|
|
.checkout-btn,
|
|
|
|
|
|
|
|
.batch-delete-btn {
|
|
|
|
@apply min-w-[180rpx];
|
|
|
|
@apply min-w-[180rpx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.price-section,
|
|
|
|
|
|
|
|
.selected-info {
|
|
|
|
|
|
|
|
@apply mr-[16rpx];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|
|