@{
    ViewBag.Title = "客户商品库存量";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<div class="topdiv">
    <div class="ibox-content">
        <table class="table table-bordered table-striped table-hover">
            <tr>
                <td>日期:</td>
                <td>
                    <input type="text" class="form-control" style="width:100px" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmStartDate" value="@ViewBag.pmStartDate" />
                </td>
                <td>
                    <input type="text" class="form-control" style="width:100px" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmEndDate" value="@ViewBag.pmEndDate" />
                </td>
                <td>客户名称:</td>
                <td>
                    <input type="hidden" id="clientTypeID" />
                    <input type="text" class="form-control" id="rsNum" value="" readonly="true" />
                </td>
                <td>
                    <span onclick="ClientName()" class="glyphicon glyphicon-plus btn btn-default"></span>
                    <span class="glyphicon glyphicon-minus btn btn-default" onclick="Clear()"></span>
                </td>
                <td>业务员:</td>
                <td>
                    <input type="text" readonly="true" class="form-control" id="fullname" />
                    <input type="hidden" id="btypeid" />
                </td>
                <td><span onclick="Salesman()" class="glyphicon glyphicon-plus btn btn-default"></span><span class="glyphicon glyphicon-minus btn btn-default" onclick="ClearSalesman()"></span></td>
                <td>
                    <button class="btn btn-default" id="btnSearch" onclick="Search()"><i class="glyphicon glyphicon-zoom-in"></i>查询</button>
                     <input id="hidCount" type="hidden" />
                </td>
                <td>
                    <button class="btn btn-default" id="btnExcel"><i class="glyphicon glyphicon-download-alt"></i>导出</button>
                </td>
                <td>
                    <button class="btn btn-default" id="btnWarnSet"><i class="glyphicon glyphicon-warning-sign"></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>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $('#businessTable').bootstrapTable({
            url: '../DataQuery/GetPtypeStock',         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: true,                   //是否显示分页（*）
            sortOrder: "asc",                   //排序方式
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 15,                       //每页的记录行数（*）
            pageList: [15, 30, 50],        //可供选择的每页的行数（*）
            minimumCountColumns: 2,  //最少允许的列数
            height: $(".centerdiv").height() - 20,               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            clickToSelect: true,              //是否启用点击选中行
            undefinedText: " ",
            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, //页码
                    StartTime: $("#pmStartDate").val(),
                    EndTime: $("#pmEndDate").val(),
                };
            },//传递参数（*）
            columns: [
                {
                    field: "index", title: "序号", align: "center", width: 50, edit: false, formatter: function (value, row, index) {
                        return row.index = index + 1; //返回行号
                    }
                },
                { field: 'BillDate', title: '日期' },
                { field: 'LoginName', title: '业务员', },
                { field: 'Bfullname', title: '客户' },
                { field: 'usercode', title: '商品编号' },
                { field: 'pfullname', title: '商品名' },
                { field: 'unitname', title: '单位' },
                { field: 'qty', title: '库存量' },
                { field: 'maxlimit', title: '上限' },
                { field: 'minlimit', title: '下限' },
                { field: 'maxcha', title: '上限差额' },
                { field: 'MINcha', title: '下限差额' },
                { field: 'Comment', title: '备注' }
            ], onLoadSuccess: function (data) {
                $("#hidCount").val(data.total);
            }
        });
        $(window).resize(function () {
            $('#businessTable').bootstrapTable('resetView');
        });
    });
    //查询
    function Search() {
        var StartTime = $("#pmStartDate").val();
        var EndTime = $("#pmEndDate").val();
        var empid = $("#clientTypeID").val();
        var cusid = $("#btypeid").val();
        $('#businessTable').bootstrapTable("refresh", {
            url: '../DataQuery/GetPtypeStock?StartTime=' + StartTime + '&EndTime=' + EndTime + '&cusid=' + cusid + '&empid=' + empid
        })
    }
    //Excel导出
    $("#btnExcel").on("click", function () {
        var StartTime = $("#pmStartDate").val();
        var EndTime = $("#pmEndDate").val();
        var empid = $("#clientTypeID").val();
        var cusid = $("#btypeid").val();
        window.location.href = '../DataQuery/GetExcelPtypeStock?StartTime=' + StartTime + '&EndTime=' + EndTime + '&cusid=' + cusid + '&empid=' + empid + "&pagesize=" + parseInt($("#hidCount").val()) + "&page=0"
    });
    //警报设置
    $("#btnWarnSet").on("click", function () {
        layer.open({
            type: 2,
            title: '警报设置',
            shadeClose: false,
            shade: 0.5,
            area: ['90%', '90%'],
            content: '../DataQuery/CusPtypeAlarmSet'
        });
    });
    //选择客户
    function ClientName() {
        layer.open({
            type: 2,
            title: '客户信息',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '70%'],
            content: '../CommonSelector/ClientSelector'
        });
    }
    //选择业务员
    function Salesman() {
        layer.open({
            type: 2,
            title: '业务员信息',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '90%'],
            content: '../CommonSelector/EmployeeSelector'
        });
    }
    function Clear() {
        $("#rsNum").val("");
        $("#clientTypeID").val("");
    }
    function ClearSalesman() {
        $("#btypeid").val("");
        $("#fullname").val("");
    }
</script>
