我是javascript / jquery的新手,你可以帮我解决这个问题。我有一个POS交易,当我输入11个订单时,它正确排队并正确。从2015101000000到2015101000010发票编号,但是当我输入另一个订单时,这里的错误是它没有继续排队,它从2015101000001开始重复。但正确的是2015101000011.这是代码。
io.on('listOrders', function(pr1) {
tmc = "";
if (pr1.length === 0) {
$("#ordersListContentContainer").html("<span>No Data to Display</span>")
$("#ordersListStatusCountMin, #ordersListStatusCountMax, #ordersListStatusCountCap").text(0)
}
else {
var tdn = 1;
for (var i=0; i<pr1.length; i++) {
var tdc = new Date(pr1[i].dateAdded);
var tdm = fp.pageDate.getDateFrag(tdc).monthname("2");
var tdt = fp.pageDate.getDateFrag(tdc).time();
var tdd = tdm + " " + tdc.getDate() + ", " + tdc.getFullYear() + " | " + tdt;
var tdp = 1;
var taa = (pr1[i].orderInvoiceHold);
var tbb = (parseFloat(pr1[i].transactionAmount).toFixed(2) == "NaN" ? "0.00" : parseFloat(pr1[i].transactionAmount).toFixed(2));
var tcc = (parseFloat(pr1[i].transactionTotal).toFixed(2) == "NaN" ? "0.00" : parseFloat(pr1[i].transactionTotal).toFixed(2));
var tbl = (pr1[i].tableID === 0 ? "Take Out" : "Table "+pr1[i].tableID);
tmc += "<span class='ordersListContentContainerItem' data-num="+(i+1)+" data-pgn="+tdn+" data-ictg='"+pr1[i].itemCategoryLabel+"' data-oorc="+pr1[i].orderCodeHold+" data-horc="+pr1[i].orderCodeHold+" data-oqty="+pr1[i].orderQuantity+" data-oprc="+pr1[i].orderTotalPrice+" data-mods='"+pr1[i].deliMods+"' data-disc='"+pr1[i].deliDiscounts+"' data-amnt='"+pr1[i].deliCharges+"' data-otra="+pr1[i].transactionAmount+" data-stff="+pr1[i].paymentStaff+" data-cust="+pr1[i].paymentCustomer+"> \
<span class='listItem l1'>"+tdd+"</span> \
<span class='listItem l2'>"+taa+"</span> \
<span class='listItem l3'>"+pr1[i].orderTransaction+"</span> \
<span class='listItem l4'>"+tbl+"</span> \
<span class='listItem l5'>"+pr1[i].orderStatus+"</span> \
<span class='listItem l6'>"+tbb+"</span> \
<span class='listItem l7'></span> \
<span class='listItem l8'>"+tcc+"</span> \
</span>"
if (tdp % parseInt($("#ordersSubOptsSelect").val()) === 0) {
tdn += 1;
}
}
$("#ordersListContentContainer").html(tmc);
$(".ordersListContentContainerItem").children("span").last().text(function() {
var aa = 0
$(".ordersListContentContainerItem").each(function() {
aa += $(this).data("oprc")*1;
});
});
$(".ordersListContentContainerItem").hide();
$(".ordersListContentContainerItem[data-pgn='1']").show();
$("#ordersListStatusCountMin").html($("#ordersListContentContainer").children(".ordersListContentContainerItem:visible").first().data("num"));
$("#ordersListStatusCountCap").html($("#ordersListContentContainer").children(".ordersListContentContainerItem").length);
$("#ordersListStatusCountMax").html($("#ordersListContentContainer").children(".ordersListContentContainerItem:visible").last().data("num"));
var os = function(a) {
var aa = "<div class='orderSummaryLabelContainer'> \
<span class='orderSummaryLabel1'>Item</span> \
<span class='orderSummaryLabel2'>Quantity</span> \
<span class='orderSummaryLabel3'>Price</span> \
</div><br><br>";
var ab = "";
var aba = 0;
var abb = 0;
var abc = 0;
$(".ordersListContentContainerItem[data-oorc='"+a+"']").each(function() {
var x = $(this);
abb = function(a) {
var b = "";
for (var i=0; i<a.length; i++) {
if (x.data("oprc") !== 0) {
io.emit('orderMods', {
hotelID: htld,
outletID: otld,
vr3: a[i].tid
}, true);
}
b += "<div class='ordersListContentContainerItemMods'> \
<span class='orderSummaryModItem' data-num="+x.data("num")+" data-mtid="+a[i].tid+" data-oqty="+a[i].tqt+" data-oprc='"+a[i].tpr+"'></span> \
<span class='orderSummaryModQty'>"+a[i].tqt+"</span> \
<span class='orderSummaryModPrc'>"+a[i].tpr+"</span> \
</div>";
abc += a[i].tpr*1;
}
return b;
}
ab += "<div class='orderSummaryItemContainer' data-oorc='"+x.data("horc")+"'> \
<span class='orderSummaryItem'>"+$(this).data("ictg")+"</span> \
<span class='orderSummaryQty'>"+$(this).data("oqty")+"</span> \
<span class='orderSummaryPrc'>"+parseFloat($(this).data("oprc")).toFixed(2)+"</span>"+abb($(this).data("mods"))+"</div>";
aba += $(this).data("oprc")*1;
});
var ac = "<br><br><div id='orderSummaryPriceContainer'> \
<span id='orderSummaryPrice1'>Sub Total:</span> \
<span id='orderSummaryPriceVal1'>"+parseFloat(aba+abc).toFixed(2)+"</span> \
<span id='orderSummaryPrice2'>Total:</span> \
<span id='orderSummaryPriceVal2'>0</span> \
<span id='orderSummaryPrice3'>Grand Total:</span> \
<span id='orderSummaryPriceVal3'>0</span> \
<span id='orderSummaryPrice4'>Amount Paid:</span> \
<span id='orderSummaryPriceVal4'>"+($(".ordersListContentContainerItem[data-oorc='"+a+"']").first().data("otra") === null ? "0.00" : parseFloat($(".ordersListContentContainerItem[data-oorc='"+a+"']").first().data("otra")).toFixed(2))+"</span> \
</div>";
return aa+ab+ac;
};
$(".ordersListContentContainerItem").on("click", function() {
var orc = $(this).data("oorc") || $(this).data("horc");
var onm = 0;
$("#orderReceiptCost_Total, #orderReceiptCost_TotalValue").hide();
$("#orderReceiptTableTitleContainer").find("#receiptTransaction").text("Trans #: "+$(this).find(".l3").text());
$("#orderReceiptTableTitleContainer").find("#receiptInvoice").text("Invoice #: "+$(this).find(".l2").text());
$("#orderReceiptTableTitleContainer").find("#receiptDate").html($(this).find(".l1").text());
$("#orderReceiptTableTitleContainer").find("#receiptTable").text($(this).find(".l4").text());
$("#orderReceiptTableTitleContainer").find("#receiptStaff").text("Staff: "+$(this).data("stff"));
$("#orderReceiptTableTitleContainer").find("#receiptCustomer").text("Customer: "+$(this).data("cust"));
fp.pageDialog.DialogDefault_Open("Order Summary - ("+orc+")", os($(this).data("oorc")), 3, function() {
});
$("#orderReceiptCost_GrandTotal, #orderReceiptCost_GrandTotalValue").css({"display": "none"});
$("#orderReceiptCost_GrandTotalValue").text("0.00");
$(".orderSummaryPriceCharge, .orderSummaryPriceChargeVal, .orderReceiptCost_Charge, .orderReceiptCost_ChargeAmount, .orderSummaryPriceDiscount, .orderSummaryPriceDiscountVal, .orderReceiptCost_Discount, .orderReceiptCost_DiscountValue").remove();
$("#orderSummaryPriceVal2, #orderSummaryPriceVal3, #orderReceiptCost_TotalValue, #orderReceiptCost_GrandTotalValue").text($("#orderSummaryPriceVal1").text());
$("#orderReceiptCost_SubTotalValue").text(parseFloat($("#orderSummaryPriceVal1").text()).toFixed(2))
$("#orderReceiptCost_AmountPaidValue").text(parseFloat($("#orderSummaryPriceVal4").text()).toFixed(2))
$("#orderReceiptCost_AmountChangeValue").text(parseFloat($("#orderSummaryPriceVal5").text()).toFixed(2))
if ($(this).data("amnt") !== "") {
var tma = $(this).data("amnt")+'';
getOCTotal(tma.split(" ||| "));
}
if ($(this).data("disc") !== "") {
var tmb = $(this).data("disc")+'';
getODTotal(tmb.split(" ||| "));
}
$("#orderReceiptItemContainer").empty();
$(".ordersListContentContainerItem[data-oorc='"+$(this).data("horc")+"']").each(function() {
var tgp = "";
$("#orderReceiptItemContainer").append("<div class='orderReceiptItem' data-num='"+$(this).data("num")+"' data-oorc='"+$(this).data("horc")+"'><div class='orderReceiptItemGroupMain'><span class='fs'></span><span class='sd'>"+$(this).data("ictg")+"</span><span class='tr'>"+$(this).data("oqty")+"</span><span class='ft'>"+parseFloat($(this).data("oprc")).toFixed(2)+"</span></div><div class='orderReceiptItemGroupMods'></div></div>");
});
$(".orderSummaryItemContainer[data-oorc='"+$(this).data("horc")+"']").each(function() {
onm += ($(this).find(".orderSummaryQty").text()*1);
$(this).find(".orderSummaryModItem").each(function() {
$(".orderReceiptItem[data-num='"+$(this).data("num")+"']").find(".orderReceiptItemGroupMods").show();
$(".orderReceiptItem[data-num='"+$(this).data("num")+"']").find(".orderReceiptItemGroupMods").append("<div class='orderReceiptMod'><span class='orderReceiptModDel'><i class='fa fa-times-circle'></i></span><span class='orderReceiptModLabel' data-mtid="+$(this).data("mtid")+"> </span><span class='orderReceiptModQuantity'>"+$(this).data("oqty")+"</span><span class='orderReceiptModPrice'>"+$(this).data("oprc")+"</span></div>");
io.emit('orderMods', {
hotelID: htld,
outletID: otld,
vr3: $(this).data("mtid")
}, false);
onm += ($(this).data("oqty")*1);
});
});
$("#orderReceiptCost_NumItemValue").text(onm);
});
}
});
答案 0 :(得分:0)
您的订单似乎是按字母顺序而非数字,这就是为什么它在10条记录后出错。
确保在应用排序之前将所有内容都转换为整数。
更改行:
$(&#34; #orderReceiptTableTitleContainer&#34;)。find(&#34; #recomeInvoice&#34;)。text(&#34; Invoice#:&#34; + $(this).find( &#34; .L2&#34;)文本());
类似于:
$(&#34; #orderReceiptTableTitleContainer&#34;)。find(&#34; #resentInvoice&#34;)。text(&#34; Invoice#:&#34; + parseFloat($(this)。找到(&#34; .L2&#34)。文本()));