@{
    ViewBag.Title = "";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<body style="background-color:white">
    <div class="wrapper wrapper-content">
        <input type="hidden" id="ClientBtypeid"   />@*存储设置用户*@
        <input type="hidden" id="btypeid"   />@*存储经手人id*@
        <input type="hidden" id="fullname"   />@*存储经手人姓名*@
        <input type="hidden" id="salesmanBtypeid"   />@*存储制单人id*@
        <input type="hidden" id="salesmanFullName"   />@*存储制单人id*@
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <button id="btnSetUser" class="btn btn-default"><i class="glyphicon glyphicon-user"></i> 设置用户</button>
                <button id="btnSetbrokerage" class="btn btn-default"><i class="glyphicon glyphicon-user"></i> 设置经手人</button>
                <button id="btnSetProducer" class="btn btn-default"><i class="glyphicon glyphicon-file"></i> 设置制单人</button>
                <table id="businessTable" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript">
    function OnlineVerificationAndRevOrStop(loginsetOrIsStop, LoginID, OperationType) {//在线验证/启动停用设置
        $.ajax({
            url: "../DealerEdition/LoginSetAndIsStop",
            dataType: "text",
            data: { loginsetorisstop: loginsetOrIsStop, loginid: LoginID, operation: OperationType },
            type: "post",
            success: function (data) {//操作成功后刷新table
                layer.msg(data, {time: 2000 });
                $('#businessTable').bootstrapTable("refresh");
            },
            error: function (data) {
                layer.msg(data, {time: 2000 });
            }
        })
    }
    function Del(num, loginid, systype) {//删除
        layer.confirm("确认删除？", function (enter) {//删除前提示
            if (enter) {
                if (systype == 1) {
                    layer.msg("超级用户不可以删除", { icon: 0, time: 2000 });
                    return;
                }
                $.ajax({
                    url: "../DealerEdition/DelDealerEdition",
                    dataType: "text",
                    data: { num: num, loginid: loginid },
                    type: "post",
                    success: function (data) {//删除成功后刷新table
                        layer.msg(data, { time: 2000 });
                        $('#businessTable').bootstrapTable("refresh");
                    },
                    error: function (data) {
                        layer.msg(data, { icon: 5, time: 2000 });
                    },
                })
            }
        })
    }
    function editRightsUser(LoginName, LoginID, loginusername, loginuserid, FullName, TypeID_, Btypename, Btypeid, PassWord, Comment) {//修改
        layer.open({
            btnClose: 2,
            type: 2,
            title: '<i class="glyphicon glyphicon-user"></i> 修改权限',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '90%'],
            content: '../DealerEdition/UpdateDealerUserRights?loginname=' + LoginName + '&LoginID=' + LoginID + '&loginusername=' + loginusername + '&loginuserid=' + loginuserid + '&fullname=' + FullName + '&TypeID_=' + TypeID_ + '&Btypename=' + Btypename + '&Btypeid=' + Btypeid + '&PassWord=' + PassWord + '&Comment=' + Comment,
            end: function () {

            }
        });
    }
    function Rights(LoginID) {//设置
        layer.open({
            btnClose: 2,
            type: 2,
            title: '<i class="glyphicon glyphicon-user"></i> 设置权限',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '90%'],
            content: '../DealerEdition/DealerRightsSetting?LoginID=' + LoginID,
            end: function () {
            }
        });
    }
    function MessageRights(LoginID) {//信息授权
        layer.open({
            btnClose: 2,
            type: 2,
            title: '<i class="glyphicon glyphicon-user"></i> 信息授权',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '90%'],
            content: '../DealerEdition/DealerMessageRights?LoginID=' + LoginID,
            end: function () {
            }
        });
    }
    function CopyRights(LoginID, LoginName) {//复制权限
        layer.open({
            btnClose: 2,
            type: 2,
            title: '<i class="glyphicon glyphicon-user"></i> 复制权限',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '90%'],
            content: '../DealerEdition/CopyDealerRights?LoginID=' + LoginID + '&LoginName=' + LoginName,
            end: function () {
            }
        });
    }
    $(function () {
        $('#businessTable').bootstrapTable({
            url: '../DealerEdition/GetDealerTableList',         //请求后台的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:$(window).height()-50,               //行高，如果没有设置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, //页码
                };
            },//传递参数（*）
            columns: [
                {
                    field: "index", title: "序号", align: "center",
                    formatter: function (value, row, index) {
                        var pageNumber = $('#businessTable').bootstrapTable('getOptions').pageNumber;
                        var pageSize = $('#businessTable').bootstrapTable('getOptions').pageSize;
                        return (pageNumber - 1) * pageSize + index + 1;
                    }
                },
                { field: 'LoginID', align: "center", title: '登录编号' },
                { field: 'Num', title: 'Num' },
                { field: 'LoginName', align: "center", title: '登录人员' },
                { field: 'loginusername', align: "center", title: '经手人' },
                { field: 'loginuserid', title: 'loginuserid' },
                {
                    field: 'FullName', align: "center", title: '对应制单人', formatter: function (value, row, index) {
                        if (value == null) {
                            return "";
                        } else {
                            return value;
                        }
                    }
                },
                {
                    field: 'TypeID_', title: 'TypeID_', formatter: function (value, row, index) {
                        if (value == null) {
                            return "";
                        } else {
                            return value;
                        }
                    }
                },
                { field: 'Btypename', align: "center", title: '往来单位' },
                { field: 'Btypeid', title: 'Btypeid' },
               {
                   field: "loginset", title: "在线验证", align: "center", formatter: function (value, row, index) {//在线验证
                       if (row["loginset"] == 1) {
                           var strHtml = '<a href="javascript:void(0);" onclick="OnlineVerificationAndRevOrStop(\'' + row.loginset + '\',\'' + row.LoginID + '\',\'verification\')"><li class="glyphicon glyphicon-ok"></li></a>';
                           return strHtml;
                       } else {
                           var strHtml = '<a href="javascript:void(0);" onclick="OnlineVerificationAndRevOrStop(\'' + row.loginset + '\',\'' + row.LoginID + '\',\'verification\')"><li class="glyphicon glyphicon-remove"></li></a>';
                           return strHtml;
                       }
                   }
               },
                {
                    field: "IsStop", title: "启/停用", align: "center", formatter: function (value, row, index) {//启/停用
                        if (row["IsStop"] == 0) {
                            var strHtml = '<a href="javascript:void(0);" onclick="OnlineVerificationAndRevOrStop(\'' + row.IsStop + '\',\'' + row.LoginID + '\',\'enableordisable\')"><li class="glyphicon glyphicon-ok"></li></a>';
                            return strHtml;
                        } else {
                            var strHtml = '<a href="javascript:void(0);" onclick="OnlineVerificationAndRevOrStop(\'' + row.IsStop + '\',\'' + row.LoginID + '\',\'enableordisable\')"><li class="glyphicon glyphicon-remove"></li></a>';
                            return strHtml;
                        }
                    }
                },
                {
                    field: 'PassWord', align: "center", title: '密码', formatter: function (value, row, index) {
                        if (value == "") {
                            return value;
                        } else {
                            return '******';
                        }
                    }
                },
                { field: 'Comment', align: "center", width: "150px", title: '备注' },
                 {
                     field: 'Edit', title: '修改', align: "center", width: "80px", formatter: function (value, row, index) {//修改
                         var strHtml = '<button id="btnEdit" class="btn btn-default" onclick="editRightsUser(\'' + row.LoginName + '\',\'' + row.LoginID + '\',\'' + row.loginusername + '\',\'' + row.loginuserid + '\',\'' + row.FullName + '\',\'' + row.TypeID_ + '\',\'' + row.Btypename + '\',\'' + row.Btypeid + '\',\'' + row.PassWord + '\',\'' + row.Comment + '\')"><i class="glyphicon glyphicon-edit"></i> 修改</button>';
                         return strHtml;
                     }
                 },
                {
                    field: 'Rights', width: "80px", title: '权限', align: "center", formatter: function (value, row, index) {//设置权限
                        var strHtml = '<button id="btnRights" class="btn btn-default" onclick="Rights(\'' + row.LoginID + '\')"><i class="glyphicon glyphicon-cog"></i> 设置</button>';
                        return strHtml;
                    }
                },
                {
                    field: 'MessagesRights', width: "80px", title: '信息授权', align: "center", formatter: function (value, row, index) {//信息授权
                        var strHtml = '<button id="btnMessageRights" class="btn btn-default" onclick="MessageRights(\'' + row.LoginID + '\')"><i class="glyphicon glyphicon-comment"></i> 设置</button>';
                        return strHtml;
                    }
                },
                 {
                     field: 'copyRights', width: "80px", title: '复制权限', align: "center", formatter: function (value, row, index) {//复制权限
                         var strHtml = '<button id="btnCopyRights" class="btn btn-default" onclick="CopyRights(\'' + row.LoginID + '\',\'' + row.LoginName + '\')"><i class="glyphicon glyphicon-file"></i> 复制权限</button>';
                         return strHtml;
                     }
                 },
                {
                    field: 'Del', title: '删除', width: "80px", align: "center", formatter: function (value, row, index) {//删除
                        var strHtml = '<button id="btnDel" class="btn btn-default" onclick="Del(\'' + row.Num + '\',\'' + row.LoginID + '\',\'' + row.SysType + '\')"><i class="glyphicon glyphicon-trash"></i> 删除</button>';
                        return strHtml;
                    }
                }
            ], onLoadSuccess: function () {
                var flag = '@ViewBag.isUserPower';
                if (flag == "true") {
                    $('#businessTable').bootstrapTable('showColumn', 'MessagesRights');
                }
                else {
                    $('#businessTable').bootstrapTable('hideColumn', 'MessagesRights');
                }
            }
        });
        $('#businessTable').bootstrapTable('hideColumn', 'Num');
        $('#businessTable').bootstrapTable('hideColumn', 'loginuserid');
        $('#businessTable').bootstrapTable('hideColumn', 'TypeID_');
        $('#businessTable').bootstrapTable('hideColumn', 'Btypeid');
        $(window).resize(function () {
            $('#businessTable').bootstrapTable('resetView');
        });
        //设置用户
        $("#btnSetUser").on("click", function () {
            $("#ClientBtypeid").val("");//清空设置用户
            layer.open({
                btnClose: 2,
                type: 2,
                title: '<i class="glyphicon glyphicon-user"></i> 设置用户',
                shadeClose: false,
                shade: 0.5,
                area: ['80%', '90%'],
                content: '../CommonSelector/ClientSelectorMore',
                end: function () {
                    if ($("#ClientBtypeid").val() != "") {
                        var btypeid = $("#ClientBtypeid").val();
                        $.ajax({
                            url: "../DealerEdition/SetDealerUsers",
                            dataType: "text",
                            data: { btypeid: btypeid },
                            type: "post",
                            success: function (data) {//删除成功后刷新table
                                layer.msg(data, { time: 2000 });
                                $('#businessTable').bootstrapTable("refresh");
                            },
                            error: function (data) {
                                layer.msg(data, { icon: 5, time: 2000 });
                            },
                        })
                    }
                }
            });
        });
        //设置经手人
        $("#btnSetbrokerage").on("click", function () {
            $("#btypeid").val("");
            $("#fullname").val("");
            layer.open({
                btnClose: 2,
                type: 2,
                title: '<i class="glyphicon glyphicon-user"></i> 设置经手人',
                shadeClose: false,
                shade: 0.5,
                area: ['80%', '90%'],
                content: '../CommonSelector/EmployeeSelector?operation=next',
                end: function () {
                    if ($("#btypeid").val() != "") {
                        var btypeid = $("#btypeid").val();
                        var fullname = $("#fullname").val();
                        $.ajax({
                            url: "../DealerEdition/SetNextDealerUsers",
                            dataType: "text",
                            data: { btypeid: btypeid, fullname: fullname },
                            type: "post",
                            success: function (data) {//删除成功后刷新table
                                layer.msg(data, { time: 2000 });
                                $('#businessTable').bootstrapTable("refresh");
                            },
                            error: function (data) {
                                layer.msg(data, { icon: 5, time: 2000 });
                            },
                        })
                    }
                }
            });
        });
        //设置制单人
        $("#btnSetProducer").on("click", function () {
            $("#salesmanBtypeid").val("");
            $("#salesmanFullName").val("");
            layer.open({
                btnClose: 2,
                type: 2,
                title: '<i class="glyphicon glyphicon-user"></i> 设置制单人',
                shadeClose: false,
                shade: 0.5,
                area: ['80%', '90%'],
                content: '../CommonSelector/OriginatorSelector?',
                end: function () {
                    if ($("#salesmanBtypeid").val() != "" && $("#salesmanFullName").val() != "") {
                        var btypeid = $("#salesmanBtypeid").val();
                        var fullname = $("#salesmanFullName").val();
                        $.ajax({
                            url: "../DealerEdition/SetProducer",
                            dataType: "text",
                            data: { btypeid: btypeid, fullname: fullname },
                            type: "post",
                            success: function (data) {//
                                layer.msg(data, { time: 2000 });
                                $('#businessTable').bootstrapTable("refresh");
                            },
                            error: function (data) {
                                layer.msg(data, { icon: 5, time: 2000 });
                            },
                        })
                    }
                }
            });
        });
    });
</script>