如何在每个部门中显示小计

时间:2016-03-28 01:00:48

标签: jquery

我有一个计算总计和总计的函数。我的问题是我想在每个分区上显示子总数,但它将是相同的输出。我想标题1子总数是37.00,标题2是99.00。这是屏幕截图。enter image description here

这是我的代码。

$('.pricing_level').on('change', function(e){
    var pricing_level_id = e.target.value;
    var customer_id = $('.customer ').val();

    $('tbody.subcontent tr').each(function(){
        var item_id =  $(this).closest('tr').find(".details_itemid").val();
        var category_id = $(this).closest('tr').find(".details_category_id").val();
        var subcategory_id = $(this).closest('tr').find(".details_subcategory_id").val();
        var that = this;

        $.get('/dev/api/itempricinglevel?item_id=' + item_id + '&pricinglevel_id=' + pricing_level_id, function(itempricinglevel){
            var std = parseFloat(itempricinglevel.std);
            var min = parseFloat(itempricinglevel.min);
            var max = parseFloat(itempricinglevel.max);

            $(that).closest('tr').find('.details_unitprice').val(std);

            //Here's the code to display the sub-total in every division
            var d_qty = $(that).closest('tr').find(".details_qty").val();
            var d_netprice  = $(that).closest('tr').find(".details_netunitprice").val();
            var total = d_qty * d_netprice;
            var totalAmt = total.toFixed(2);

            $(that).closest('tr').find(".details_total").val(totalAmt);
            grandtotal();
            var thisloc = $(that).parent().parent().parent().parent().find('.total');
            var inloc = $(that).parent().parent().parent().parent().find('.stotal');
            var eachloc =  $(that).parent().parent().parent().find('.details_total');
            subtotal(thisloc, eachloc, inloc);
            //------------------------------------------------------------ 
        })

    })
})

这是我的小计函数

function subtotal(thisloc, eachloc, inloc){ 
    var headertotal = 0;
    eachloc.each(function(){ 
        var price = $(this).val();
        headertotal += parseFloat(price);
        $(thisloc).text((headertotal).toFixed(2));
        $(inloc).val((headertotal).toFixed(2));
    });
}

这是小计的HTML代码。

$('tbody.content').prepend('<div class="groupborder" style="border-color:#333333;"><tr><td> \
            <table class="tables_details" style="width:100%;">\
              <th id="groups" data-id="'+headcount+'" style="background-color: #333333; width: 1250px;" > \
                <label style="display:inline-block;float:left; margin-left:900px; width:60px; font-weight: bold; color:#FFFFFF;">Sub-total: </label> \
                <label class="head" style="display: block; margin-left: -930px; float: left; font-weight: bold; color:#FFFFFF;">HEADER '+headcount+'</label> \
                <input type="text" name="header_name[]" class="edit-input" style="height: 20px; display: none; margin-left: -930px; float: left; padding-left:5px;" value="HEADER '+headcount+'"/> \
                <input name="header_id[]" type="hidden" value="'+headcount+'"> \
                <a href="" class="rm-header fa fa-times-circle fa-lg" style="float:right; margin-right:5px; margin-top:5px"></a> \
                <label style="display:inline-block; float:right; margin-right:18px; font-weight: bold; color:#FFFFFF;" class="total">0.00</label> \
                <input name="header_subtotal[]" class="stotal" type="hidden" value="0.00"> </th> \
              <tbody class="subcontent tbody"></tbody>\
            </table>\
         </td>\
       </tr></div>');

1 个答案:

答案 0 :(得分:0)

在api里面是。

var dataid = $(that).closest('tr').find('.details_total').data('total_id');
subtotal2(dataid);

你必须制作另一个小计函数。

function subtotal2(dataid){ 
    var headertotal = 0;
    $('.details_total_'+dataid+'').each(function(){ 
        var price = $(this).val();
        headertotal += parseFloat(price);
        $('#total_'+dataid+'').text((headertotal).toFixed(2));
        $('#total_'+dataid+'').val((headertotal).toFixed(2));

    });
}
相关问题