var allCustomer = [];
var orderTemplate
$(function () {

    $("#Category").select2();
    TdRowOverOut("tOrder");

    $.ajax({
        url: "/Order/GetAutoCompleteCustomer",
        type: 'GET',
        cache: false,
        dataType: 'json',
        async: false,
        success: function (result) {
            for (var i in result.data) {
                allCustomer.push({ label: result.data[i].ItemText, value: result.data[i].ItemValue });
            }
        },
        error: function (e) {
        }
    });

    try {
        $('#txtCustomer').autocomplete({
            source: allCustomer,
            select: function (a, b, c) {
                $("#sCustomerNo").val(b.item.value);
             
            },
            close: function (envent, ui) {
                $('#txtCustomer').val("");
            }
        });
    }
    catch (e) {
    }

    orderTemplate = eval($("#OrderTemplate").val());

    $("#Category").append("<option value=''>请选择分类</option>");
    for (var i in orderTemplate) {
        $("#Category").append("<option value=\"" + orderTemplate[i].id + "\">" + orderTemplate[i].text + "</option>");
    }

    $('#Category').change(function () {
        CategoryChange();
    });

    $("#Category").val($('#sCategory').val());
});

function CategoryChange() {
    $("#sCategory").val($('#Category').val());
}