@{
    ViewBag.Title = "";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<div class="topdiv">
    <div class="ibox-content">
        <table class="table table-bordered table-striped table-hover" style="margin: 0px;">
            <tr>
                <td>日期：</td>
                <td>
                    <input type="text" style="width: 110px" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmStartDate" value="@ViewBag.pmStartDate" />
                </td>
                <td>
                    <input type="text" style="width: 110px" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmEndDate" value="@ViewBag.pmEndDate" />
                </td>
                <td>客户名称：</td>
                <td>
                    <input id="uploadliginid" type="hidden" />
                    <input type="text" id="rsNum" readonly="true" />
                </td>
                <td>
                    <button onclick="ClientName()" class="glyphicon glyphicon-plus btn btn-default"></button>
                    <button onclick="ClearClient()" class="glyphicon glyphicon-minus btn btn-default"></button>
                </td>
                <td>制单人：</td>
                <td>
                    <input id="salesmanBtypeid" type="hidden" />
                    <input type="text" id="salesmanFullName" readonly="true" />
                </td>
                <td>
                    <button onclick="LoginName()" class="glyphicon glyphicon-plus btn btn-default"></button>
                    <button onclick="ClearLogin()" class="glyphicon glyphicon-minus btn btn-default"></button>
                </td>
                <td>
                    <button class="btn btn-default" onclick="search()"><i class="glyphicon glyphicon-zoom-in"></i> 查询</button>&nbsp;&nbsp;
                    <button class="btn btn-default" id="btnExcel"><i class="glyphicon glyphicon-download-alt"></i> 导 出</button>
                    <button class="btn btn-default" id="btnStat"><i class="glyphicon glyphicon-align-left"></i> 统计</button>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="centerdiv">
    <div class="wrapper wrapper-content">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <table id="businessTable"></table>
                <input type="hidden" id="billnumberid" />
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $('#businessTable').bootstrapTable({
            url: '../DataQuery/GetCustomerCard',         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: true,                   //是否显示分页（*）
            sortOrder: "asc",                   //排序方式
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 15,                       //每页的记录行数（*）
            pageList: [15, 30, 50],        //可供选择的每页的行数（*）
            minimumCountColumns: 2,  //最少允许的列数
            height: $(".centerdiv").height()-40,               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "btypeid",            //每一行的唯一标识，一般为主键列
            clickToSelect: true,              //是否启用点击选中行
            sortable: true,                     //是否启用排序
            silentSort: true,
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: false,
            paginationFirstText: '首页',
            paginationLastText: '末页',
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            showColumns: false,            //是否显示所有的列
            showRefresh: false,              //是否显示刷新按钮
            showToggle: false,                     //是否显示详细视图和列表视图的切换按钮
             cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            queryParams: function (params) {
                return {
                    pagesize: params.limit,//页面大小
                    page: params.offset, //页码
                    begindate: $("#pmStartDate").val(),
                    enddate: $("#pmEndDate").val(),
                };
            },//传递参数（*）
            columns: [
                {
                     title: "序号", align: "center", width: 50,
                    formatter: function (value, row, index) {
                        var pageNumber = $('#businessTable').bootstrapTable('getOptions').pageNumber;
                        var pageSize = $('#businessTable').bootstrapTable('getOptions').pageSize;
                        return (pageNumber - 1) * pageSize + index + 1;
                    }
                },
                { field: 'date', title: '日期' },
                { field: 'UserCode', title: '客户编号', class: "hidden-sm hidden-xs" },
                { field: 'bfullname', title: '客户名' },
                { field: 'efullname', title: '业务员', class: "hidden-sm hidden-xs" },
                { field: 'loginname', title: '制单人', class: "hidden-sm hidden-xs" },
                { field: 'comment', title: '备注', class: "hidden-sm hidden-xs" },
                {
                    field: "edit", title: "详情", align: "center", formatter: function (value, row, index) {
                        return '<span class="btn  btn-w-s"><i class="glyphicon glyphicon-list-alt"></i> 详情</span>';
                    }
                }
            ],
            onClickCell: function (field, value, row) {
                if (field == 'edit') {
                    $("#billnumberid").val(row["billnumberid"]);
                    layer.open({
                        type: 2,
                        title: "客户卡单详情",
                        shadeClose: false,
                        shade: 0.5,
                        area: ['80%', '70%'],
                        content: '../DataQuery/CustomerCardDetails'
                    })
                }
            }
        });
        $(window).resize(function () {
            $('#businessTable').bootstrapTable('resetView');
        });
    });
    //客户名称
    function ClientName() {
        layer.open({
            type: 2,
            title: '客户信息',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '70%'],
            content: '../CommonSelector/ClientSelector'
        });
    }
    function LoginName() {
        layer.open({
            type: 2,
            title: '制单人信息',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '70%'],
            content: '../CommonSelector/SalesmanSelector'
        });
    }
    //查询
    function search() {
        var begindate = $("#pmStartDate").val();
        var enddate = $("#pmEndDate").val();
        var btypeid = $('#uploadliginid').val(); //客户iD
        var loginid = $('#salesmanBtypeid').val(); //选中的值
        $('#businessTable').bootstrapTable("refresh", {
            url: '../DataQuery/GetCustomerCard?begindate=' + begindate + "&enddate=" + enddate + "&btypeid=" + btypeid + "&loginid=" + loginid
        })
    }

    //Excel导出
    $("#btnExcel").on("click", function () {
        var begindate = $("#pmStartDate").val();
        var enddate = $("#pmEndDate").val();
        var btypeid = $('#uploadliginid').val(); //客户iD
        var loginid = $('#salesmanBtypeid').val(); //选中的值
        window.location.href = '../DataQuery/GetExcelCustomerCard?begindate=' + begindate + "&enddate=" + enddate + "&btypeid=" + btypeid + "&loginid=" + loginid
    });

    //统计
    $("#btnStat").on("click", function () {
        layer.open({
            type: 2,
            title: '客户卡单统计',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '70%'],
            content: '../DataQuery/CustomerCardStat'
        });
    });

    //清除
    function ClearClient() {
        $("#uploadliginid").val("");
        $("#rsNum").val("");
    }
    function ClearLogin() {
        $("#salesmanFullName").val("");
        $("#salesmanBtypeid").val("");
    }
</script>
