zoukankan      html  css  js  c++  java
  • pigcms 微外卖下单加数量bug

    bug:加数量的时候结算金钱出现NAN  

    先给一个简单粗暴的解决办法。

    找到/tpl/static/dishout/js/main.js   

    把  65行

    disPrice = parseFloat(sign + 1) * parseFloat($(this).parents('li').find('.tureunit_price').val()),

    换成

    disPrice = parseFloat(sign + 1) * parseFloat($(this).parents('.li').find('.unit_price').text()),

    main.js的源码全部在这里  

    var yTotalPrice=0;
    $.fn.amount = function(num, callback){
        var num = typeof num === 'undefined' ? 0 : num,
            callback = callback || $.noop,
            isShow = num > 0 ? '' : ' style="display:none;"',
            activeClass = 'active';
    
        function add(){
            var obj = $(this).prev(),
                _num = obj.find('.num'),
                curNum = parseInt(_num.text(), 10);
            
            var data_obj = obj.parent();
            var max = data_obj.attr("max");/**控制每个菜最多可点多少份**/
            if(null != max && max != "" && max != "-1" && curNum >= max)
            {
                return false;
            }
            
            _num.text(++curNum);
            
            data_obj.next(".number").val(curNum);
            if(curNum > 0){
                obj.show();
                $(this).addClass(activeClass);
            }
            return callback.call(this, '+');
        }
    
        function del(){
            var obj = $(this).parent(),
                _num = obj.find('.num'),
                _add = obj.next(),
                curNum = parseInt(_num.text(), 10);
    
            _num.text(--curNum);
            obj.parent().next(".number").val(curNum);
            if(curNum < 1){
                obj.hide();
                _add.removeClass(activeClass);
            }else{
                _add.addClass(activeClass);
            }
            return callback.call(this, '-');
        }
    
        return this.each(function(){
            $(this).before('<span'+ isShow +'><a href="javascript:void(0);" class="btn del '+ activeClass +'"></a><span class="num">'+ num +'</span></span>').bind('click', add);
            
            $(this).prev().find('.del').bind('click', del);
    
            if(num > 0){
                $(this).addClass(activeClass);
            }
        });
    }
    
    $.amountCb = function(){
        var _condition = $('#sendCondition'),
            _total = $('#totalPrice'),
            _cartNum = $('#cartNum'),
            sendCondition = parseFloat(_condition.text()).toFixed(2);
        return function(sign){
            var totalPrice = parseFloat(_total.text()) || 0,
                disPrice = parseFloat(sign + 1) * parseFloat($(this).parents('li').find('.unit_price').text()),
                price = totalPrice + disPrice,
                number = _cartNum.text() == '' ? 0 : parseInt(_cartNum.text()),
                disNumber = number + parseInt(sign + 1);
                yTotalPrice=yTotalPrice+disPrice;
                price = parseFloat((yTotalPrice).toFixed(2));
                //alert( parseFloat(sign + 1))
            _total.text(price);
            
            _condition.text(parseFloat((sendCondition - price).toFixed(2)));
            _cartNum.text(disNumber);
            
            if(sendCondition - price <= 0){
                _condition.parent().hide().next().show();
            }else{
                _condition.parent().show().next().hide();
            }
            if(price<=0){
               _condition.text(Pricing);
               _condition.parent().show().next().hide();
            }
            if(disNumber > 0){
                _cartNum.addClass('has_num');
            }else{
                _cartNum.removeClass('has_num').text('0');
            }
            return false;
        }
    }
    
    $(function(){
        if($('#swipeNum').length){
            new Swipe($('#imgSwipe')[0], {
                speed: 500, 
                auto: 5000, 
                callback: function(index){
                    $('#swipeNum li').eq(index).addClass("on").siblings().removeClass("on");
                }
            });
        }
    
        $('#storeList li').click(function(e){
            if(e.target.tagName != 'A'){
                location.href = $(this).attr('href');
            }
        });
    });

    ok! 其实看代码就能知道问题的关键应该是它原来的tureunit_price这个类的标签页面上没有了。所以就无法获得参数进行计算

    所以对应的解决办法是不改js加html代码。

    在选商品和结算的这两个页面上每个循环价钱标签旁加下面这段

    <input type="hidden" class="tureunit_price" value="{pigcms:$dditem['price']}"/>

  • 相关阅读:
    深度分析HTML5在移动开发方面的发展状况
    腾讯实习生笔试题
    更简洁的 CSS 清理浮动方式
    图片垂直居中的使用技巧
    Css Reset(复位)整理
    70565 Pro: Designing and Developing Enterprise Applications Using the Microsoft .NET Framework 3.5 考试感言
    Android SDK 有bug
    70540 TS: Microsoft Windows Mobile 5.0 Application Development 考试感言
    70565 Pro: Designing and Developing Enterprise Applications Using the Microsoft .NET Framework 3.5 考试感言
    TS:70503 Windows Communication Foundation TS: 70505 Windows Form Application Dev 考试感言
  • 原文地址:https://www.cnblogs.com/yzycoder/p/5626526.html
Copyright © 2011-2022 走看看