index.html 11.0 KB
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>购物车</title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1, minimum-scale=1">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/base.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/swiper.min.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/common/buy_car.css">
    <script src="__TMPL__/public/assets/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__TMPL__/public/assets/js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__TMPL__/public/assets/js/base.js" type="text/javascript" charset="utf-8"></script>
    <style>
        .changeNone{
            display: none;
        }
        .show{
            display: block;
        }
    </style>
</head>

<body>
    <header class="mui_bar">
        <div class="delete_box">
            <img class="del_img" src="__TMPL__/public/assets/images/sdfadgas@2x.png" alt="">
            <p class="del_p">删除</p>
        </div>
        <h1 class="mui_title">购物车</h1>
    </header>
    <div class="container">
        <div class="con_warp">
            <ul class="con_list_ul first_ul">
                <volist name="cart" id="cart">
                <li class="con_list_li">
                    <div class="check_radio first_radio">
                        <!-- <input type="radio"> -->
                        <img class="sel_img changeNone"  src="__TMPL__/public/assets/images/sure.png" alt="">
                    </div>
                    <img class="con_list_img" src="{:cmf_get_image_url($cart.pic)}" alt="">
                    <div class="goods_box" index="{$cart.id}">
                        <p class="goods_title">{$cart.name}</p>
                        <span class="goods_content">{$cart.intro}</span>
                        <p class="goods_money"><span class="onlyMoney">{$cart.money}</span></p>
                        <div class="join">
                            <img class="subtract_img" src="__TMPL__/public/assets/images/item_reduce.png  " alt="">
                            <p class="number">{$cart.num} </p>
                            <img class="add_img" src="__TMPL__/public/assets/images/item_add.png" alt="">
                        </div>
                    </div>
                </li>
                </volist>
            </ul>
        </div>
    </div>
    <div class="zhifu">
        <div class="radio_box">
            <div class="all_ckeck ">
                <!-- <input type="radio"> -->
                <img class="all changeNone" src="__TMPL__/public/assets/images/sure.png" alt="">
            </div>
            <p>全选</p>
        </div>
        <div class="pay">
            <p class="to_pay">前往支付</p>
            <p class="all_price"> 合计:<span><span class="change_money">0.00</span></span></p>
        </div>
    </div>
    <footer class="footer">
        <ul class="bottom_list">
            <li id="index_bar" class="mainpage_botlist index_bar"><img src="__TMPL__/public/assets/images/index.png" alt=""><span>首页</span></li>
            <li id="buy_car" class="mainpage_botlist buy_car"><img src="__TMPL__/public/assets/images/cdvcd@1x_checked.png" alt=""><span>购物车</span></li>
            <li id="personal_center" class="mainpage_botlist personal_center"><img src="__TMPL__/public/assets/images/personal.png" alt=""><span>我的</span></li>
        </ul>
    </footer>
    </div>
    <script src="__TMPL__/public/assets/js/common.js"></script>
    <script>
        // 购物车数量  start
        var shopping_id = 0;
        var is_add = 0;
        // 购物车数量减少
        $('.subtract_img').click(function () {
            shopping_id = $(this).parent().parent().attr('index');
            is_add = 2;
            changenum($(this));
        });
        // 购物车数量增加
        $('.add_img').click(function () {
            shopping_id = $(this).parent().parent().attr('index');
            is_add = 1;
            changenum($(this));
        });
        function changenum(k) {
            $.ajax({
                type:"POST",
                url:"{:url('Shopping/changeShopping')}",
                data:{
                    "shopping_id":shopping_id,
                    "is_add":is_add,
                },
                success:function (data) {
                    var count_allFirst = 0;
                    if(data.code == '1'){
                        k.parent().find('.number').html(data.data.number);
                        var is_has = k.parent().parent().parent().find('.sel_img').hasClass('show');
                        if(is_has == true){
                            $('.show').map(function () {
                                var money = $(this).parent().parent().find('.onlyMoney').text();
                                var num = $(this).parent().parent().find('.number').text();
                                count_allFirst += parseFloat(money)*parseFloat(num);
                            })
                            // 更改总额
                            var final = count_allFirst.toFixed(2);
                            $('.change_money').text(final);
                        }
                    }else{
                        alert(data.message);
                    }
                },
                error:function () {
                }
            })
        }

        // end
        // 选中
        $('.first_radio').click(function () {
            // 增加样式
            var count_all = 0;
            if($(this).find('.sel_img').hasClass('show')){
                $(this).find('.sel_img').removeClass('show');
                $(this).find('.sel_img').addClass('changeNone');
            }else{
                $(this).find('.sel_img').removeClass('changeNone');
                $(this).find('.sel_img').addClass('show');

            }
            $('.first_radio .show').map(function () {
                var money = $(this).parent().parent().find('.onlyMoney').text();
                var num = $(this).parent().parent().find('.number').text();
                count_all += parseFloat(money)*parseFloat(num);
            })
            // 更改总额
            var final = count_all.toFixed(2);
            $('.change_money').text(final);
            // 全选
            var all_con = $(".first_ul .con_list_li").length;
            var choose_con = $(".first_ul .show").length;
            if(all_con == choose_con){
                $('.all_ckeck').find('.all').removeClass('changeNone');
                $('.all_ckeck').find('.all').addClass('show');
            }else{
                $('.all_ckeck').find('.all').removeClass('show');
                $('.all_ckeck').find('.all').addClass('changeNone');
            }
        });
        // 全选
        $('.all_ckeck').click(function () {
            if($('.all_ckeck').find('img').hasClass('show')){
                $('.first_ul li').find('.sel_img').removeClass('show');
                $('.first_ul li').find('.sel_img').addClass('changeNone');
                $('.all_ckeck').find('img').removeClass('show');
                $('.all_ckeck').find('img').addClass('changeNone');
            }else{
                $('.first_ul li').find('.sel_img').removeClass('changeNone');
                $('.first_ul li').find('.sel_img').addClass('show');
                $('.all_ckeck').find('img').removeClass('changeNone');
                $('.all_ckeck').find('img').addClass('show');
            }
            var count_all = 0;
            $('.first_radio .show').map(function () {
                var money = $(this).parent().parent().find('.onlyMoney').text();
                var num = $(this).parent().parent().find('.number').text();
                count_all += parseFloat(money)*parseFloat(num);
            })
            // 更改总额
            var final = count_all.toFixed(2);
            $('.change_money').text(final);
        })


        //删除
        $('.delete_box').on('click', function() {
            var del_arr = [];
            $('.first_ul').find('.show').map(function () {
                var del_id = $(this).parent().parent().find('.goods_box').attr('index');
                del_arr.push(del_id);
            })
            if(del_arr.length == 0){
                alert('请选择您要删除的物品!')
            }else{
                $.ajax({
                    type:"POST",
                    url:"{:url('Shopping/delShopping')}",
                    data:{
                        "shopping_id":del_arr,
                    },
                    success:function (data) {
                        alert(data.message);
                        if(data.code == 1){
                            window.location.reload();
                        }
                    },
                    error:function () {
                    }
                })
            }

        });




        // $(document).ready(function() {
        //     var $menu_box = $('.content_body .con_title>li');
        //     $menu_box.click(function() {
        //         $(this).addClass('con_curr').siblings().removeClass('con_curr');
        //         var index = $menu_box.index(this);
        //         $('.con_all .con_warp').eq(index).show().siblings().hide();
        //     });
        // })
    //勾选
    // $('.check_radio').on('click', function() {
    //
    //     if ($('.check_radio img').is(':hidden')) { //如果当前隐藏
    //         $('.check_radio img').show(); //那么就显示div
    //         $('.check_radio').css('border', '0.01rem solid #FFF');
    //
    //     } else { //否则
    //         $('.check_radio img').hide(); //就隐藏div
    //         $('.check_radio').css('border', '0.01rem solid rgba(0,0,0,0.4)');
    //     }
    //     if ($('.con_list_li').length == 1 && $('.check_radio img').is(':hidden') == false) {
    //         $('.all_ckeck img').show();
    //         $('.all_ckeck').css('border', '0.01rem solid #FFF');
    //     } else {
    //         $('.all_ckeck img').hide();
    //         $('.all_ckeck').css('border', '0.01rem solid rgba(0,0,0,0.4)');
    //
    //     }
    // })
    // //全部勾选
    // $('.all_ckeck').on('click', function() {
    //     if ($('.all_ckeck img').is(':hidden')) { //如果当前隐藏
    //         $('.all_ckeck img').show(); //那么就显示tupain
    //         $('.all_ckeck').css('border', '0.01rem solid #FFF');
    //         $('.check_radio img').show(); //那么就显示div
    //         $('.check_radio').css('border', '0.01rem solid #FFF');
    //     } else {
    //         $('.check_radio img').hide();
    //         $('.check_radio').css('border', 'none')
    //         $('.check_radio').css('border', '0.01em solid rgba(0,0,0,0.4)');
    //         $('.all_ckeck img').hide(); //那么就显示div
    //         $('.all_ckeck ').css('border', '0.01rem solid rgba(0,0,0,0.4)');
    //
    //     }
    //
    // })
    //导航栏跳转 
    $('#index_bar').on('click', function() { window.location.href = "{:url('Index/index')}" });
    $('#personal_center').on('click', function() { window.location.href = "{:url('User/index')}"})
    </script>
</body>

</html>