套餐选择和优惠券

来源:互联网 发布:java 存在 编辑:程序博客网 时间:2024/04/29 03:03






像如此的购物车页面,依赖于JQuery WeUI的部分组件事件

1.head部分

      <link rel="stylesheet" href="css/jquery-weui.min.css">
     <link rel="stylesheet" href="css/weui.css">
     <link rel="stylesheet" href="css/index.css"> //自己的页面样式
     <script src="js/jquery.min.js"></script>
     <script src="js/jquery-weui.min.js"></script>
     <script src="js/jweixin-1.0.0.js"></script>
     <script src="js/auto-size.js"></script>


2.JS部分

toFixed () 是截取小数点后面的多少位

$(function(){ 
        //icon背景图片更改 [套餐选择] 固定单选
        var productRmb, remCardNum,//声明优惠券、套餐
        productId= $('.left-icon-change').parent().attr('data-id'),//声明套餐、优惠券id
        couponId = "", 
        lastCouponId = '',
        numRmb =  $('.left-icon-change').parent().find("p[class]").text().split("¥")[1],
        numPage = '0'  
    if(!numRmb){
    $('.total').text('0元') 
    }else{
    $('.total').text(numRmb + '元') 
    }           
        $('.cardPage').text(numPage + '张')  
        var moneryArr = $('.five')
        for(var i =0; i <moneryArr.length; i++){
            var n = moneryArr[i].innerHTML.split("¥")[1];
            console.log(n)
            if( n.length > 4){               
                moneryArr.css({'fontSize':'.42rem'})
            }
        }
        $('.firstCard').on('click',changeicon)       
        function changeicon(){
                $(".firstCard i").each(function(){
                    $(this).removeClass('left-icon-change').addClass( ' left-icon');
                })
                $(this).find('.left-icon').removeClass(' left-icon').addClass( ' left-icon-change');
                productRmb = parseFloat( $(this).find("p[class]").text().split("¥")[1] )
                numRmb = productRmb
                lastCouponId = ''
                $(".cardId i").each(function(){
                    $(this).removeClass('rigeht-cardId-icon-change').addClass( ' rigeht-cardId-icon');
                })
                $('.total').text(numRmb + '元')
                $('.cardPage').text(numPage + '张')
                productId = $(this).attr('data-id')
        }           
        //优惠券展示
        $('.cardList').on('click',function(){
                $('.weui-mengban').show()
                $('.weui-actionsheet').slideDown("fast").show()
        })
        //关闭优惠券展示
        $('.closeCard').on('click',function(){
        setTimeout(function(){
        $('.weui-mengban').hide()
                $('.weui-actionsheet').slideUp("slow").hide()
            },10)
                couponId = '';                                       
        })
        //确定选取优惠券
        $('.ascertain').on('click',function(){  
                lastCouponId = couponId ? couponId : lastCouponId;                               
                setTimeout(function(){
                    $('.weui-mengban').hide()
                    $('.weui-actionsheet').slideUp("slow").hide()
                },10)                            
                var nowN = parseFloat ( numRmb - remCardNum );                            
                if( !remCardNum ){
                    $('.total').text(numRmb + '元')
                    $('.cardPage').text(  numPage + '张')            
                }else if (nowN < 0){
                    $('.total').text( numPage + '元')
                    $('.cardPage').text(  '1张')
                }else{    
                    $('.total').text(nowN.toFixed(2) + '元')
                    $('.cardPage').text(  '1张')  
                }          
        })       
        //新手优惠劵
        $('.cardId').on('click',function(){
        $(".cardId i").each(function(){
            $(this).removeClass('rigeht-cardId-icon-change').addClass( ' rigeht-cardId-icon');
        })
            $(this).find('.rigeht-cardId-icon').removeClass(' rigeht-cardId-icon').addClass( ' rigeht-cardId-icon-change');
                remCardNum = parseFloat( $(this).find("p[id]").text().split("¥")[1] )
                couponId = $(this).attr('data-id');
        })
        $('#btnClick').on('click',function(){
        var token = $("#token").val();
            var url = $(this).attr('href')
            url += 'productId=' + productId  + '&token=' + token + '&couponId=' + lastCouponId;
            $("#btnClick").attr("href",url);                 
        })        
 })

       

原创粉丝点击