@{
    ViewBag.Title = "客户商品库存量";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content form-inline ">
            <div class="row">
                <div class="form-group col-lg-4 col-md-4 col-sm-4 ">
                </div>
                <div class="form-group col-lg-3 col-md-3 col-sm-3">
                </div>
                <div class="form-group col-lg-3 col-md-3 col-sm-3">
                </div>
                <div class="form-group col-lg-1 col-md-1 col-sm-1 pull-left">
                </div>
            </div>
        </div>
        <div class="ibox-content">
            <div id="toolbar" class="row">
                &nbsp;&nbsp;&nbsp;
                <button id="btnNew" class="btn btn-info btn-xs">新增</button>&nbsp;
                <button id="btnDel" class="btn btn-warning btn-xs">删除</button>&nbsp;
                <button id="btnBack" class="btn btn-default btn-xs">后退</button>
            </div>
            <table id="businessTable"></table>
        </div>
    </div>
</div>
<script type="text/javascript">
    function edit() {
        layer.open({
            type: 2,
            title: '@ViewBag.Title 新增页面',
            shadeClose: false,
            shade: 0.5,
            area: ['60%', '70%'],
            content: '../Users/AdminEdit'
        });
    }
    $(function () {
        $('#businessTable').bootstrapTable({
            url: '../Users/GetUserList?type=alltype',         //请求后台的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: "100%",               //行高，如果没有设置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: true,                   //是否显示父子表
            queryParams: function (params) {
                return {
                    pagesize: params.limit,//页面大小
                    page: params.offset, //页码
                };
            },//传递参数（*）
            columns: [{ checkbox: true },
                {
                    field: "index", title: "序号", align: "center", width: 50, edit: false, formatter: function (value, row, index) {
                        return row.index = index + 1; //返回行号
                    }
                },
                { field: 'btypeid', title: 'btypeid' },
                { field: 'bname', title: 'bname', class: "hidden-sm hidden-xs" },
                { field: 'bfullname', title: 'bfullname' },
                { field: 'bsonnum', title: 'bsonnum', class: "hidden-sm hidden-xs" },
                { field: 'busercode', title: 'busercode', class: "hidden-sm hidden-xs" },
                { field: 'leveal', title: 'leveal', class: "hidden-sm hidden-xs" },
                {
                    field: "edit", title: "编辑", align: "center", formatter: function (value, row, index) {
                        if (row["bsonnum"] == 0) {
                            var strHtml = '<a href="javascript:void(0);" onclick="edit()"><li class="glyphicon glyphicon-pencil"></li></a>';
                            return strHtml;
                        } else {
                            var strHtml = '<a href="javascript:void(0);" onclick="edit()" readonly="true"><li class="glyphicon glyphicon-pencil"></li></a>';
                            return strHtml;
                        }
                    }
                }]
            ,
            onClickRow: function (data) {
                if (data["bsonnum"] != 0) {
                    $("#businessTable").bootstrapTable('refresh', {
                        url: '../Users/GetUserList?btypeid=' + data["btypeid"] + '&parid=' + data["parid"]
                    });
                }
            }
        });
        //新增客户信息
        $("#btnNew").on("click", function () {
            layer.open({
                type: 2,
                title: '@ViewBag.Title 新增页面',
                shadeClose: false,
                shade: 0.5,
                area: ['60%', '70%'],
                content: '../Users/AdminEdit'
            });
        });
        //删除客户
        $("#btnDel").on("click", function () {
            var selectRows = $('#businessTable').bootstrapTable('getSelections');
            if (selectRows.length <= 0) {
                layer.alert("请勾选要删除的客户！"); return false;
            }
            else {
                layer.confirm("确认删除？", function (enter) {
                    if (enter) {
                        var btypeid = "";
                        for (var i = 0; i < selectRows.length; i++) {
                            if (i == selectRows.length - 1)
                            { btypeid += "'" + selectRows[i]["btypeid"] + "'"; }
                            else
                            { btypeid += "'" + selectRows[i]["btypeid"] + "'" + ","; }
                        }
                        var url = "../Users/DelUsers";
                        var params = { btypeid: btypeid, selectRows: selectRows }
                        $.ajax({
                            url: url,
                            type: "post",
                            data: params,
                            success: function (data) {
                                var selects = selectRows.length;
                                layer.alert("删除完成，删除成功:" + parseInt(data) + "条&nbsp;失败:" + (selects - parseInt(data)) + "条");
                                $('#businessTable').bootstrapTable("refresh");
                            },
                            error: function () {
                                layer.alert("删除失败！");
                            }
                        })
                    }
                });
            }
        });
        //后退功能
        $("#btnBack").on("click", function () {
            var leveal = $("#businessTable").bootstrapTable("getData")[0]["leveal"];
            $("#businessTable").bootstrapTable('refresh', {
                url: '../Users/GetUserList?back=' + leveal
            });
        });
    });
</script>