@{
    ViewBag.Title = "查看拜访";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<body>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="col-lg-4 col-md-4 col-sm-12" style="margin-top:5px">
                <table class="table table-bordered table-striped table-hover">
                    <tr>
                        <td style="height:55px">
                            <select data-placeholder="请选择业务员" class="chosen-select" id="ddlSalesman">
                                <option value=""></option>
                                @{
                                    if (@ViewBag.ulist != null && @ViewBag.ulist.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < @ViewBag.ulist.Rows.Count; i++)
                                        {
                                            <option @(@ViewBag.ulist.Rows[i]["TypeID_"].ToString() == @ViewBag.ETypeId ? "selected" : "") value=@ViewBag.ulist.Rows[i]["TypeID_"].ToString()>@ViewBag.ulist.Rows[i]["FullName"].ToString()</option>
                                        }
                                    }
                                }
                            </select>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="col-lg-4 col-md-4 col-sm-12" style="margin-top:5px">
                <table class="table table-bordered table-striped table-hover">
                    <tr>
                        <td style="height:55px">时间段：</td>
                        <td style="height:55px">
                            <input type="text" class="form-control" onFocus="WdatePicker({isShowClear:false,readOnly:true})" id="txtBeginDate" value="@ViewBag.pmStartDate" />
                        </td>
                        <td style="height:55px">
                            <input type="text" class="form-control" onFocus="WdatePicker({isShowClear:false,readOnly:true})" id="txtEndDate" value="@ViewBag.pmEndDate" />
                        </td>
                    </tr>
                </table>
            </div>
            <div class="col-lg-4 col-md-4 col-sm-12" style="margin-top:5px">
                <table class="table table-bordered table-striped table-hover">
                    <tr>
                        <td style="text-align: right;height:55px">
                            <button id="btnSeach" onclick="Search()" class="btn btn-default"><i class="glyphicon glyphicon-zoom-in"></i>查询</button>&nbsp;
                            <input id="hidBillid" type="hidden" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="col-lg-12 col-md-12 col-sm-12">
            <table id="ViewVisitTable" data-mobile-responsive="true"></table>
        </div>
    </div>
    <script type="text/javascript">
    function today() {//取当前时间
        var today = new Date();
        var h = today.getFullYear();
        var m = today.getMonth() + 1;
        var d = today.getDate();
        if (m<10) {
            m = "0" + m;
        }
        if (d < 10) {
            d = "0" + d;
        }
        return h + "-" + m + "-" + d;
    }
    function Search() {//查询
        $('#ViewVisitTable').bootstrapTable("refresh",
            {
                url: '../Shop/GetViewVisitList?userid=' + $("#ddlSalesman").val() + '&begindate=' + $("#txtBeginDate").val() + '&enddate=' + $("#txtEndDate").val()
            });
    }
    function ShowDetails(billid, billdate, enddate) {//查看详情
        $("#hidBillid").val(billid);
        layer.open({
            type: 2,
            title: '<i class="glyphicon glyphicon-list"></i> 拜访详情',
            shadeClose: false,
            shade: 0.5,
            area: ['90%', '95%'],
            content: '../Shop/V_CustomerVisitDetail?billid=' + billid + '&billdate=' + billdate + '&enddate=' + enddate,
            end: function () {//关闭弹窗后
            }
        });
    }
    $(function () {
        $("#txtBeginDate").val(today());
        $("#txtEndDate").val(today());
        $('#ViewVisitTable').bootstrapTable({
            url: '../Shop/GetViewVisitList',         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: true,                   //是否显示分页（*）
            sortOrder: "asc",                   //排序方式
            undefinedText: ' ',
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 30, 50],        //可供选择的每页的行数（*）
            minimumCountColumns: 2,  //最少允许的列数
            //height: $(".centerdiv").height()-40,               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "Num",            //每一行的唯一标识，一般为主键列
            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: $("#txtBeginDate").val(),
                    enddate: $("#txtEndDate").val(),
                };
            },//传递参数（*）
            columns: [
                { field: "SORT", title: "SORT" },
                {
                    title: '序号', width: '5%', align: 'center',
                    formatter: function (value, row, index) {
                        var pageNumber = $('#ViewVisitTable').bootstrapTable('getOptions').pageNumber;
                        var pageSize = $('#ViewVisitTable').bootstrapTable('getOptions').pageSize;
                        return (pageNumber - 1) * pageSize + index + 1;
                    }
                },
                { field: 'XIWAMAXTIME', title: '创建时间' },
                { field: 'ETYPENAME', title: '业务员' },
                { field: 'BILLDATE', title: 'BILLDATE' },
                { field: 'ENDDATE', title: 'ENDDATE' },
                {
                    field: 'TimeSlot', title: '时间段', formatter: function (value, row, index) {
                        return row.BILLDATE + " - " + row.ENDDATE;
                    }
                },
                {
                    field: 'CUSCOUNT', title: '客户数', formatter: function (value, row, index) {
                        if (value == null || value == "") {
                            return "0";
                        } else {
                            return value;
                        }
                    }
                },
                {
                    field: 'COUNT', title: '完成数', formatter: function (value, row, index) {
                        if (value == null || value == "") {
                            return "0";
                        } else {
                            return value;
                        }
                    }
                },
                {
                    field: 'RATE', title: '完成率', formatter: function (value, row, index) {
                        if (value == null || value == "") {
                            return "0%";
                        } else {
                            return value;
                        }
                    }
                },
                { field: 'BILLID', title: 'BILLID' },
                {
                    field: 'details', title: '详情', formatter: function (value, row, index) {
                        var strHtml = '<button id="btnDetail" class="btn btn-default" onclick="ShowDetails(\'' + row.BILLID + '\',\'' + row.BILLDATE + '\',\'' + row.ENDDATE + '\')"><i class="glyphicon glyphicon-list"></i> 拜访详情</button>';
                        return strHtml;
                    }
                }]
        });
        $(window).resize(function () {
            $('#ViewVisitTable').bootstrapTable('resetView');
        });
        //隐藏列
        $('#ViewVisitTable').bootstrapTable('hideColumn', 'BILLDATE');
        $('#ViewVisitTable').bootstrapTable('hideColumn', 'BILLID');
        $('#ViewVisitTable').bootstrapTable('hideColumn', 'ENDDATE');
        $('#ViewVisitTable').bootstrapTable('hideColumn', 'SORT');
    });
    </script>
</body>
