未显示总额和总金额、价格但在控制台中未显示任何错误什么是错误?

vwkv1x7d  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(183)

我想显示总金额和总金额、价格值的数据。此处显示数据价格值和产品表值。但代码没有正常工作,这是我想要的。但没有显示任何错误。你能帮你修一下吗?我使用了laravel 8和刀片模板。我认为这个错误出现在最后一个jquery代码中(addmoreproduct)
index.blade.php

@include("header")
@include('admin/nav')
<div class="card"  style="min-height:566px;">
<div class="card-header bg-dark">
    <h4 class="text-light">Ordered Products</h4>
</div>
<div style="height:20px;">
    @if ($errors->any())
        <div class="alert alert-danger">
            <strong>Error!</strong> 
            <ul>
                @foreach ($errors->all() as $error)
                    <li></li>
                @endforeach
            </ul>
        </div>
    @endif

    @if(Session::has('success'))

    <div class="alert alert-success">

    </div>

@endif
</div>
<div class="card-body"   style="min-height:520px;">
    <div class="row">
        <div class="col-sm-8">
            <div class="card">
            <table class="table table-bordered card-body">
            <thead class="col-sm-12">
                <tr>
                <th></th>
                <th>Product Name</th>
                <th>Quantity</th>
                <th>Price</th>
                <th>Discount(%)</th>
                <th>Total</th>
                <th><a href="#" class="btn btn-info btn-sm add_more"><i class="fa fa-plus"></i>+</a></th>
                </tr>
            </thead>
            <tbody class="addMoreProduct m-1">   
                <tr>
                    <td class="no">1</td>
                    <td>
                        <select name="product_id[]" id="product_id" class="form-control product_id">
                            <option value="">Select Item</option>
                            @foreach($products as $product)
                                <option data-price="{{$product->price}}" value="{{$product->id}}">{{$product->pname}}</option>
                            @endforeach
                        </select>        
                    </td>
                    <td><input type="number" name="quantity[]" id="quantity" class="form-control quantity"></td>
                    <td><input type="number" name="price[]" id="price" class="form-control price"></td>
                    <td><input type="number" name="discount[]" id="discount" class="form-control discount"></td>
                    <td><input type="number" name="total_amount[]" id="total_amount" class="form-control total_amount"></td> 
                    <td><a href="#" class="btn btn-warning btn-sm rounded-circle">Delete</a>
                    </td>                   
                </tr>
            </tbody>
            </table>
            </div>
        </div>
        <div class="col-sm-4  m-0">
            <div class="card">
                <span class="card-header h4 bg-success">Total :<b class="total"> 0.00</b></span>
                <div class="card-body h6 font-weight-bold alert-success">
                    <form action="" method="POST">
                    <div class="form-row">
                        <div class="form-group col-md row">
                            <label for="cashier" class="col-sm-5">User</label>
                            <input type="email" class="form-control col-sm-7" id="cashier" name="cashier">
                        </div>
                    </div>
                    <div class="form-row p-1">
                        <div class="custom-control custom-radio custom-control-inline">
                            <input type="radio" id="cash" class="custom-control-input">
                            <label class="custom-control-label" for="cash">Cash</label>
                        </div>
                        <div class="custom-control custom-radio custom-control-inline">
                            <input type="radio" id="transfer" class="custom-control-input">
                            <label class="custom-control-label" for="transfer">Bank Transfer</label>
                        </div>
                            <div class="custom-control custom-radio custom-control-inline">
                            <input type="radio" id="credit" class="custom-control-input">
                            <label class="custom-control-label" for="credit">Credit Card</label>
                        </div>
                    </div>
                    <br/>
                    <div class="form-row">
                        <div class="form-group col-md row">
                            <label class="col-sm-4" for="payment">Payment</label>
                            <input type="number" class="form-control col-sm-8" id="payment" name="payment">
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col-md row">
                            <label for="paid" class="col-sm-4">Paid Amount</label>
                            <input type="number" class="form-control col-sm-8" id="paid" name="paid">
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col-md row">
                            <label for="balance" class="col-sm-4">Balance</label>
                            <input type="number" class="form-control col-sm-8" id="balance" balance="balance">
                        </div>
                    </div>
                    <div class="form-group btn-group col-md-12">
                        <button type="submit" class="btn btn-md btn-success h6  font-weight-bold col-md-4">Save</button>
                        <button class="btn btn-md btn-danger h6  font-weight-bold col-md-4">Print</button>
                        <a class="btn btn-md  btn-secondary h6 font-weight-bold col-md-4">Calculator</a>
                    </div>        
                    </form>       
                </div>     
            </div>
        </div>
    </div>
</div>
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.10.2.js" type="text/javascript"></script>
<script>

    //add more row
    $('.add_more').on('click',function(){
        var product = $('.product_id').html();
        var numberofrow = ($('.addMoreProduct tr').length-0)+1;
        var tr = '<tr><td class"no"">'+ numberofrow + '</td>'+
        '<td><select class="form-control product_id" name="product_id[]">'+product+'</select></td>'+
        '<td><input type="number" name="quantity[]" class="form-control quantity"></td>'+
        '<td><input type="number" name="price[]" class="form-control price"></td>'+
        '<td><input type="number" name="discount[]" class="form-control discount"></td>'+
        '<td><input type="number" name="total_amount[]" class="form-control total_amount"></td>'+
        '<td><a class="btn btn-warning btn-sm delete rounded-circle">Delete</a></td>';
        $('.addMoreProduct').append(tr);

    });

    //delete a row
    $('.addMoreProduct').delegate('.delete','click',function(){
        $(this).parent().parent().remove();
    });

    function TotalAmount(){
        var total = 0;
        $('.total_amount').each(function(i,e){
            var amount = $(this).val() - 0;
            total += amount;
        });

        $('.total').html(total);

    }

    $('.addMoreProduct').delegate('.product_id','çhange',function(){
        var tr = $(this).parent().parent();
        var price = tr.find('.product_id option:selected').attr('data-price');
        tr.find('.price').val(price);
        var qty = tr.find('.quantity').val() - 0;
        var disc = tr.find('.discount').val() - 0;
        var total_amount =(qty * price)-((qty*price*disc)/100);
        tr.find('.total_amount').val(total_amount);
        TotalAmount();
    });

    $('.addMoreProduct').delegate('.quantity,.discount', 'keyup',function(){
        var tr=$(this).parent().parent();
        var qty = tr.find('.quantity').val() - 0;
        var disc = tr.find('.discount').val() - 0;
        var price = tr.find('.price').val() - 0;
        var total_amount =(qty * price)-((qty*price*disc)/100);
        tr.find('.total_amount').val(total_amount);
        TotalAmount();
    });

</script>

@include("footer")

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题