好库网
var idListValue = "", markListValue = "", CountListValue = "";
var id_list, name_list, count_list, price_list;
var value_list = new Array();
var p = 0;
var veg_list = new Array();

$(document).ready(function () {
    var tourl2 = appUrl + "/webpublic/veg/setveg.aspx?type=9&sid=" + sid + "&id=" + store_id;
    $.post(tourl2, { cache: false }, function (data) {
        if (data != ""){
            setTable();
        }
        else {
            window.location.href = "selVeg.aspx?sid=" + sid;
        }
    });
});

var vegcount;
function addveg(vegid) {

    if (isNaN($("#num_" + vegid).html())) {
        $("#num_" + vegid).html("1");
    }

    vegcount = parseInt($("#num_" + vegid).html()) + 1;
    $("#num_" + vegid).html(vegcount);

    $("#count" + vegid).val(vegcount);
    $("#count" + vegid).click();
    $("#plus_" + vegid).show();
    $("#num_" + vegid).show();

}
function plusveg(vegid) {

    vegcount = parseInt($("#num_" + vegid).html()) - 1;
    if (vegcount <= 0) {
        $("#num_" + vegid).html("0");
        $("#plus_" + vegid).hide();
        $("#num_" + vegid).hide();
        $("#div_veg_" + vegid).hide();
        //return;
    }

    $("#num_" + vegid).html(vegcount);
    $("#count" + vegid).val(vegcount);
    $("#count" + vegid).click();
}
function setTable() {

    if (vegmsg != '') {
        var list = vegmsg.split('-');
        for (var i = 0; i < list.length; i++) {
            var list2 = list[i].split('@');
            veg_list[list2[0]] = list2[1];

            var vid = list2[0].split('~')[0];
            $("#num_" + vid).html(list2[1]);
            $("#count" + vid).html(list2[1]);

            $("#plus_" + vid).show();
            $("#num_" + vid).show();
        }
        createTable("", "", "", "", "");
    }
}

function td_delete(obj) { veg_list[obj.id] = 0; createTable("", "", "", "", ""); }

function createTable(vegname, vegidlist, vegcount, vegprice, vegmark) {

    if (vegname != "") {
        var key = vegidlist + "~" + vegname + "~" + vegmark + "~" + vegprice;
        if (veg_list[key] != null)
            veg_list[key] = parseInt(vegcount);
        else
            veg_list[key] = vegcount;
    }
    var sumMoney = 0, sumCount = 0, sum = 0;

    idListValue = "";
    markListValue = "";
    CountListValue = "";

    var saveStr = "";
    for (var i in veg_list) {

        if (veg_list[i] == 0 || isNaN(veg_list[i])) {
            veg_list[i] = 0;
            continue;
        }
        var list = i.split('~');
        if (isNaN(list[3])) {
            continue;
        }

        saveStr += i.toString() + "@" + veg_list[i] + "-";

        sum = (list[3] * veg_list[i]).toFixed(2);

        sumMoney = (parseFloat(sumMoney) + parseFloat(sum)).toFixed(2);
        sumCount = parseFloat(sumCount) + parseFloat(veg_list[i]);
        idListValue = idListValue + "^" + list[0];
        CountListValue = CountListValue + "^" + veg_list[i];
        markListValue = markListValue + "^" + list[2];

    }
    $("#sp_sumMoney").html(sumMoney);
    $("#sp_sumCount").html(sumCount);

    var vegmsg2 = escape(idListValue + "~" + CountListValue + "~" + markListValue);
    var tourl = appUrl + "/webpublic/veg/setveg.aspx?vegmsg=" + escape(saveStr) + "&vegmsg2=" + vegmsg2 + "&id=" + store_id + "&sid=" + sid;
    $.post(tourl, function (data) {

        if (idListValue != "") {
            idListValue = idListValue.substring(1);
            markListValue = markListValue.substring(1);
            CountListValue = CountListValue.substring(1);
        }

    });

    if (sumCount == 0 || sumCount == 0) {
        alert("当前订餐车为空,请先选择菜品!");
        window.location.href = "selVeg.aspx?sid=" + sid;
    }
}

function tb_clear() {
    veg_list = new Array();
    createTable("", "", "", "", "");
}

function selCreate(obj) {
    var idlist = obj.lang.split("~");
    if (veg_list[obj.id] != null) {
        veg_list[obj.id] = parseInt(obj.value);
    }
    createTable(idlist[1], idlist[0], obj.value, idlist[3], idlist[2]);
}