diff --git a/beike/Shop/Http/Controllers/CartController.php b/beike/Shop/Http/Controllers/CartController.php index 109ca7ae..35852b68 100644 --- a/beike/Shop/Http/Controllers/CartController.php +++ b/beike/Shop/Http/Controllers/CartController.php @@ -106,7 +106,7 @@ class CartController extends Controller public function miniCart() { $carts = CartService::list(current_customer()); - $reloadData = CartService::reloadData($carts, true); + $reloadData = CartService::reloadData($carts); $data['html'] = view('cart/mini', $reloadData)->render(); $data['quantity'] = $reloadData['quantity']; diff --git a/resources/beike/admin/views/layouts/master.blade.php b/resources/beike/admin/views/layouts/master.blade.php index 94f7e940..b3b83223 100644 --- a/resources/beike/admin/views/layouts/master.blade.php +++ b/resources/beike/admin/views/layouts/master.blade.php @@ -8,7 +8,7 @@ - + diff --git a/resources/beike/shop/default/css/header.scss b/resources/beike/shop/default/css/header.scss index 27266917..07e314b9 100644 --- a/resources/beike/shop/default/css/header.scss +++ b/resources/beike/shop/default/css/header.scss @@ -255,11 +255,26 @@ header { } #offcanvas-right-cart { + .select-wrap { + flex: 1; + margin-right: 10px; + cursor: pointer; + + i { + font-size: 20px; + color: #aaa; + &.bi-check-circle-fill { + color: $primary; + } + } + } + .offcanvas-right-products { .product-list { padding: 1rem 0; border-top: 1px solid #eee; + .left { width: 80px; flex: 0 0 80px; @@ -281,6 +296,14 @@ header { -webkit-line-clamp: 2; } + .price { + input { + margin-left: 10px; + width: 50px; + height: 24px; + } + } + .offcanvas-products-delete { cursor: pointer; color: #999; @@ -288,6 +311,10 @@ header { } } } + + .offcanvas-footer { + + } } #offcanvas-mobile-menu { diff --git a/resources/beike/shop/default/js/header.js b/resources/beike/shop/default/js/header.js index 1fdd557d..c7433c4a 100644 --- a/resources/beike/shop/default/js/header.js +++ b/resources/beike/shop/default/js/header.js @@ -3,12 +3,12 @@ * @link https://beikeshop.com * @Author pu shuo * @Date 2022-08-16 18:47:18 - * @LastEditTime 2022-09-16 20:56:58 + * @LastEditTime 2022-11-04 14:18:43 */ -// offcanvas-search-top $(function () { - var myOffcanvas = document.getElementById("offcanvas-search-top"); + // 搜索弹出层交互 + const myOffcanvas = document.getElementById("offcanvas-search-top"); if (myOffcanvas) { myOffcanvas.addEventListener("shown.bs.offcanvas", function () { $("#offcanvas-search-top input").focus(); @@ -22,8 +22,50 @@ $(function () { }); } + // 响应式下弹窗菜单交互 $(document).on("click", ".mobile-open-menu", function () { const offcanvasMobileMenu = new bootstrap.Offcanvas('#offcanvas-mobile-menu') offcanvasMobileMenu.show() }); + + // 右侧购物车弹出层内交互 + $(document).on("click", "#offcanvas-right-cart .select-wrap", function () { + const [unchecked, checked] = ['bi bi-circle', 'bi bi-check-circle-fill']; + const productListAll = $('#offcanvas-right-cart .product-list').length; + + const isChecked = $(this).children('i').hasClass(unchecked); + $(this).children('i').prop('class', isChecked ? checked : unchecked); + + const checkedProduct = $('#offcanvas-right-cart .offcanvas-right-products i.bi-check-circle-fill').length; + + if ($(this).hasClass('all-select')) { + const isAll = $('.all-select i').hasClass(checked); + $('#offcanvas-right-cart .product-list').find('.select-wrap i').prop('class', isAll ? checked : unchecked) + } else { + $('.offcanvas-footer .all-select i').prop('class', productListAll == checkedProduct ? checked : unchecked); + } + + const checkedIds = $('#offcanvas-right-cart .product-list').map(function() { + return $(this).find('i.bi-check-circle-fill').data('id'); + }).get(); + + $http.post(`/carts/select`, {cart_ids: checkedIds}, {hload: true}).then((res) => { + updateMiniCartData(res); + }) + }); + + // 右侧购物车弹出层内交互 + $(document).on("change", "#offcanvas-right-cart .price input", function () { + const [id, sku_id, quantity] = [$(this).data('id'), $(this).data('sku'), $(this).val() * 1]; + if ($(this).val() === '') $(this).val(1); + + $http.put(`/carts/${id}`, {quantity: quantity, sku_id}, {hload: true}).then((res) => { + updateMiniCartData(res); + }) + }) + + function updateMiniCartData(res) { + $('.offcanvas-right-cart-count').text(res.data.quantity); + $('.offcanvas-right-cart-amount').text(res.data.amount_format); + } }); diff --git a/themes/default/account/address.blade.php b/themes/default/account/address.blade.php index d3e8172d..a953a3b3 100644 --- a/themes/default/account/address.blade.php +++ b/themes/default/account/address.blade.php @@ -3,7 +3,7 @@ @section('body-class', 'page-account-address') @push('header') - + @endpush diff --git a/themes/default/account/forgotten.blade.php b/themes/default/account/forgotten.blade.php index 4148f1ad..d6811197 100644 --- a/themes/default/account/forgotten.blade.php +++ b/themes/default/account/forgotten.blade.php @@ -3,7 +3,7 @@ @section('body-class', 'page-forgotten') @push('header') - + @endpush diff --git a/themes/default/account/login.blade.php b/themes/default/account/login.blade.php index d37cccbd..95d5e270 100644 --- a/themes/default/account/login.blade.php +++ b/themes/default/account/login.blade.php @@ -3,7 +3,7 @@ @section('body-class', 'page-login') @push('header') - + @endpush diff --git a/themes/default/account/rmas/form.blade.php b/themes/default/account/rmas/form.blade.php index 292ebffd..4e98620f 100644 --- a/themes/default/account/rmas/form.blade.php +++ b/themes/default/account/rmas/form.blade.php @@ -3,7 +3,7 @@ @section('body-class', 'page-account-rmas') @push('header') - {{-- --}} + {{-- --}} @endpush @section('content') diff --git a/themes/default/account/rmas/info.blade.php b/themes/default/account/rmas/info.blade.php index 8ef7a88d..e96c79a2 100644 --- a/themes/default/account/rmas/info.blade.php +++ b/themes/default/account/rmas/info.blade.php @@ -3,7 +3,7 @@ @section('body-class', 'page-account-rmas') @push('header') - {{-- --}} + {{-- --}} @endpush @section('content') diff --git a/themes/default/cart/cart.blade.php b/themes/default/cart/cart.blade.php index e9934c98..f6b48b80 100644 --- a/themes/default/cart/cart.blade.php +++ b/themes/default/cart/cart.blade.php @@ -3,7 +3,7 @@ @section('body-class', 'page-cart') @push('header') - + @endpush diff --git a/themes/default/cart/mini.blade.php b/themes/default/cart/mini.blade.php index ed200c6b..4eae410d 100644 --- a/themes/default/cart/mini.blade.php +++ b/themes/default/cart/mini.blade.php @@ -3,18 +3,29 @@ + @php $check = 0 @endphp + @if ($carts) @foreach ($carts as $cart) + @if ($cart['selected']) @php $check = $check + 1 @endphp @endif - - - {{ $cart['name'] }} - - {{ $cart['price_format'] }} x {{ $cart['quantity'] }} + + + + + + + {{ $cart['name'] }} + + + {{ $cart['price_format'] }} x + + + + {{ __('common.delete') }} - - {{ __('common.delete') }} @@ -40,9 +51,15 @@ @if ($carts)