{% 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="button action" 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){
        $("#addCustomer").on("shown.bs.modal",function(){

        });

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

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

        searchCustomer();
    }

    function searchCustomer(){
        var params = {
            action:"searchCustomerByNameOrPhone",
            search:$("#addCustomer_searchtext").val()
        };
        $.ajax({
            type: "post",
            url: "admin-ajax.php",
            data: params,
            success:function(json){
                $("#addCustomer_list").find(".row").remove();
                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 row = $("<div>").addClass("row").css("margin-bottom","10px");
                        var left = $("<div>").addClass("col-md-3");
                        var phoneDiv = $("<label>").append(phone);
                        var right = $("<div>").addClass("col-md-3");
                        var nameDiv = $("<label>").append(name);
                        right.append(phoneDiv);
                        left.append(nameDiv);
                        row.append(left).append(right).data(item);
                        $("#addCustomer_list").append(row);
                    }
                }
            }
        });
    }
</script>
{% endblock %}