{% block addCustomer %}
<div class="modal fade" id="addCustomer" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <div class="row">
                    <div class="col-md-6">
                        <input type="text" placeholder="客户编号/姓名/手机号搜索" id="addCustomer_searchtext" class="form-control">
                    </div>
                    <div class="col-md-2">
                        <button type="button" class="btn btn-success" id="addCustomer_search">搜索</button>
                    </div>
                </div>
            </div>
            <div class="modal-body " style="height: 500px;overflow: auto;">
                <ul id="addCustomer_list">
                </ul>
            </div>
        </div>
    </div>
</div>
<script>
    function close_modal_addCustomer(){
        $("#addCustomer").modal('hide');
    }

    function init_modal_addCustomer(callback,customerDemand){
        $("#addCustomer").on("shown.bs.modal",function(){

        });

        $("#addCustomer_search").click(function(){
            searchCustomer(customerDemand);
        });

        $("#addCustomer_list").on("click",".row",function(){
            callback($(this).data());
        });

        searchCustomer(customerDemand);
    }

    function searchCustomer(customerDemand){
        var params = {
            action:"searchCustomerByNameOrPhone",
            search:$("#addCustomer_searchtext").val(),
            customerDemand:customerDemand
        };
        $.ajax({
            type: "post",
            url: "admin-ajax.php",
            data: params,
            success:function(json){
                $("#addCustomer_list").find(".row").remove();
                console.log(json);
                if(json){
                    for(var i = 0; i <json.length; i++){
                        var item = json[i];
                        var name = item["name"];
                        var id = item['id'];
                        var phone = item['phone'];
                        var idDiv = $("<label>").append(id);
                        var phoneDiv = $("<label>").append(phone);
                        var nameDiv = $("<label>").append(name);
                        var row = $("<div>").addClass("row").css("margin-bottom","10px");
                        var left = $("<div>").addClass("col-md-1");
                        var middle = $("<div>").addClass("col-md-3");
                        var right = $("<div>").addClass("col-md-3");
                        left.append(idDiv);
                        middle.append(nameDiv);
                        right.append(phoneDiv);
                        row.append(left).append(middle).append(right).data(item);
                        $("#addCustomer_list").append(row);
                    }
                }
            }
        });
    }
</script>
{% endblock %}