@{
    ViewBag.Title = "用户权限";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<body style="background-color: white">
    <div class="container-fluid">
        <div class="row-fluid" id="toolbar">
            <button id="btnNew" data-ripple class="btn btn-default button-rounded"><i class="glyphicon glyphicon-plus-sign"></i>新增</button>
            <button id="btnRightsGroupSetting" data-ripple class="btn btn-default button-rounded"><i class="glyphicon glyphicon-cog"></i>权限组设置</button>
            <button id="btnCommodityGroupSetting" data-ripple class="btn btn-default button-rounded"><i class="glyphicon glyphicon-cog"></i>商品组设置</button>
            <button id="btnPLImport" data-ripple class="btn btn-defaultl button-rounded"><i class="glyphicon glyphicon-cog"></i>导入职员</button>
            <button id="btnSet" data-ripple class="btn btn-default button-rounded"><i class="glyphicon glyphicon-cog"></i>导入操作员</button>
            <input type="hidden" id="salesmanBtypeid" />@*存储制单人id*@
            <input type="hidden" id="salesmanFullName" />@*存储制单人id*@
            <input type="hidden" id="hidUserid" />@*用户id*@
            <input type="hidden" id="Employeebtypeid" />@*存储多选制单人id*@
        </div>
        <table id="RightsListTable" data-mobile-responsive="true"></table>
    </div>

    <script type="text/javascript">
        var $table = $('#RightsListTable');
        //设置制单人
        $("#btnSet").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: ['60%', '70%'],
                content: '../CommonSelector/OriginatorSelector?',
                end: function () {
                    if ($("#salesmanBtypeid").val() != "" && $("#salesmanFullName").val() != "") {
                        var btypeid = $("#salesmanBtypeid").val();
                        var fullname = $("#salesmanFullName").val();
                        $.ajax({
                            url: "../WLTManage/SetProducer",
                            dataType: "text",
                            data: { btypeid: btypeid, fullname: fullname },
                            type: "post",
                            success: function (data) {//
                                layer.msg(data, { time: 2000 });
                                $('#RightsListTable').bootstrapTable("refresh", {
                                    url: '../WLTManage/GetUserRightsList'
                                })
                            },
                            error: function (data) {
                                layer.msg(data, { time: 2000 });
                            },
                        })
                    }
                }
            });
        });



        function OnlineVerificationAndRevOrStop(loginsetOrIsStop, LoginID, OperationType, SysType) {//在线验证/启动停用设置
            if (SysType == 1 && OperationType == "RevOrStop") {
                layer.msg("超级用户不可以修改", {time: 2000 });
                return;
            }
            $.ajax({
                url: "../WLTManage/OnlineVerificationAndRevOrStop",
                dataType: "text",
                data: { loginsetOrIsStop: loginsetOrIsStop, LoginID: LoginID, OperationType: OperationType },
                type: "post",
                success: function (data) {//操作成功后刷新table
                    if (data == "操作成功！") {
                        if (loginsetOrIsStop == "0") {
                            layer.msg("已停用", { time: 2000 });
                            $('#RightsListTable').bootstrapTable("refresh");
                        } else {
                            layer.msg("已启用", { time: 2000 });
                            $('#RightsListTable').bootstrapTable("refresh");
                        }
                    } else {
                        layer.msg(data, { time: 2000 });
                        $('#RightsListTable').bootstrapTable("refresh");
                    }
                },
                error: function (data) {
                    layer.msg(data, { time: 2000 });
                }
            })
        }

        function editRightsUser(SysType, STypeID_, TypeID_, PassWord, ETypeID_, EFullName, Num, LoginID, LoginName, Comment) {//修改权限用户
            if ("@ViewBag.systype" != "1" && SysType=="1") {
                layer.msg("超级用户不可以修改", {time: 2000 });
                return;
            }
            layer.open({
                type: 2,
                title: '<i class="glyphicon glyphicon-edit"></i> 修改权限用户',
                shadeClose: false,
                shade: 0.5,
                area: ['60%', '70%'],
                content: '../WLTManage/NewUserRights?Operation=update&SysType=' + SysType + '&STypeID_=' + STypeID_ + '&TypeID_=' + TypeID_ + '&PassWord=' + PassWord + '&ETypeID_=' + ETypeID_ + '&EFullName=' + EFullName + '&Num=' + Num + '&LoginID=' + LoginID + '&LoginName=' + LoginName + '&Comment=' + Comment
            });
        }

        function deleteUser(uid, num, systype) {//行删除按钮
            if (systype == 1) {
                layer.msg("超级用户不可以删除", {time: 2000 });
                return;
            } else {
                layer.confirm("确认删除？", function (enter) {//删除前提示
                    if (enter) {
                        $.ajax({
                            url: "../WLTManage/DeleteUser",
                            dataType: "text",
                            data: { LodinID: uid, Num: num },
                            type: "post",
                            success: function (data) {//删除成功后刷新table
                                layer.msg(data, { time: 2000 });
                                $('#RightsListTable').bootstrapTable("refresh");
                            },
                            error: function (data) {
                                layer.msg(data, {time: 2000 });
                            },
                        })
                    }
                })
            }
        }

        function SetUserRights(LoginID, SysType) {//设置权限
            if (SysType == 1) {
                layer.msg("超级用户不可以修改", { time: 2000 });
                return;
            }
            layer.open({
                btnClose: 2,
                type: 2,
                title: '<i class="glyphicon glyphicon-user"></i> 设置权限',
                shadeClose: false,
                shade: 0.5,
                area: ['95%', '95%'],
                content: '../WLTManage/WLTRightsSetting?LoginID=' + LoginID,
                end: function () {

                }
            });
        }

        function PriceRights(LoginID, SysType) {//价格权限
            if (SysType == 1) {
                layer.msg("超级用户不可以修改", { time: 2000 });
                return;
            }
            layer.open({
                btnClose: 2,
                type: 2,
                title: '<i class="glyphicon glyphicon-user"></i> 价格授权',
                shadeClose: false,
                shade: 0.5,
                area: ['50%', '60%'],
                content: '../WLTManage/WLTPriceRightsSetting?LoginID=' + LoginID,
                end: function () {
                }
            });
        }

        function MessageRights(LoginID, SysType) {//信息权限
            if (SysType == 1) {
                layer.msg("超级用户不可以修改", {time: 2000 });
                return;
            }
            layer.open({
                btnClose: 2,
                type: 2,
                title: '<i class="glyphicon glyphicon-user"></i> 信息授权',
                shadeClose: false,
                shade: 0.5,
                area: ['95%', '95%'],
                content: '../WLTManage/WLTMessageRightsSetting?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: '../WLTManage/WLTCopyRights?LoginID=' + LoginID + '&LoginName=' + LoginName,
                end: function () {
                }
            });
        }

        //绑定设备
        function BindingPnoneMode(id, SysType) {
            //if (SysType == 1) {
            //    layer.msg("超级用户不可以修改", {time: 2000 });
            //    return;
            //}
            $("#hidUserid").val(id);
            layer.open({
                type: 2,
                title: '<i class="glyphicon glyphicon-edit"></i> 绑定设备',
                shadeClose: false,
                shade: 0.5,
                area: ['60%', '70%'],
                content: '../WLTManage/BindingPnoneMode'
            });
        }



        $(function () {
            //初始化点击冲击波效果
            Array.prototype.forEach.call(document.querySelectorAll('[data-ripple]'), function (element) { new RippleEffect(element); });
            $('#RightsListTable').bootstrapTable({
                url: '../WLTManage/GetUserRightsList',         //请求后台的URL（*）
                method: 'post',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                pagination: true,                   //是否显示分页（*）
                //sortOrder: "asc",                   //排序方式
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 30, 50],        //可供选择的每页的行数（*）
                minimumCountColumns: 2,  //最少允许的列数
                height: $(window).height() - 50,               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "LID",            //每一行的唯一标识，一般为主键列
                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,                    //是否显示详细视图
                maintainSelected: true,
                //showExport: true,                     //是否显示导出
                //exportDataType: "all",              //basic', 'all', 'selected'.
                detailView: false,                   //是否显示父子表
                queryParams: function (params) {
                    return {
                        pagesize: params.limit,//页面大小
                        page: params.offset //页码
                    };
                },//传递参数（*)

                columns: [
                    //{ checkbox: true },
                    //{radio:true},
                    { field: 'SYSTYPE', title: 'SYSTYPE' },
                    { field: 'STYPEID_', title: 'STYPEID_' },
                    { field: 'TYPEID_', title: 'TYPEID_' },
                    { field: 'ETYPEID_', title: 'ETYPEID_' },
                    { field: 'EFULLNAME', title: 'EFULLNAME' },
                    { field: 'DELETED', title: 'DELETED' },
                    { field: 'WEIXINISSTOP', title: 'WEIXINISSTOP' },
                    { field: 'NUM', title: 'NUM' },
                    { field: 'LID', title: '登录编号', align: 'center' },
                    { field: 'LOGINNAME', title: '登录人员', align: 'center' },
                    { field: 'FULLNAME', title: '对应制单人', align: 'center' },
                    {
                        field: 'BINDINGPNONEMODE', title: '绑定设备', align: 'center'
                        , formatter: function (value, row, index) {//绑定设备
                            var strHtml = '<a href="javascript:void(0);" onclick="BindingPnoneMode(\'' + row.LID + '\',\'' + row.SYSTYPE + '\')">' + value + '</a>';
                            return strHtml;
                        }
                    },
                    {
                        field: "LOGINSET", title: "在线验证", align: 'center'
                        //, cellStyle: function (value, row, index) {
                        //    if (row["loginset"] == 0) {
                        //        return {classes:"info"};
                        //    } else {
                        //        return {classes:"danger"}
                        //    }
                        //}
                        , formatter: function (value, row, index) {//在线验证
                            if (row["LOGINSET"] == 0) {
                                var strHtml = '<a href="javascript:void(0);" onclick="OnlineVerificationAndRevOrStop(\'' + row.LOGINSET + '\',\'' + row.LID + '\',\'OnlineVerification\',\'' + row.SYSTYPE + '\')"><li class="glyphicon glyphicon-ok"></li></a>';
                                return strHtml;
                            } else {
                                var strHtml = '<a href="javascript:void(0);" onclick="OnlineVerificationAndRevOrStop(\'' + row.LOGINSET + '\',\'' + row.LID + '\',\'OnlineVerification\',\'' + row.SYSTYPE + '\')"><li class="glyphicon glyphicon-remove"></li></a>';
                                return strHtml;
                            }
                        }
                    },
                    {
                        field: "ISSTOP", title: "启/停用", align: 'center'
                        //, cellStyle: function (value, row, index) {
                        //    if (row["IsStop"] == 0) {
                        //        return {classes:"info"};
                        //    } else {
                        //        return {classes:"danger"}
                        //    }
                        //}
                        , formatter: function (value, row, index) {//启/停用
                            if (row["ISSTOP"] == 0) {
                                var strHtml = '<a href="javascript:void(0);" onclick="OnlineVerificationAndRevOrStop(\'' + row.ISSTOP + '\',\'' + row.LID + '\',\'RevOrStop\',\'' + row.SYSTYPE + '\')"><li class="glyphicon glyphicon-ok"></li></a>';
                                return strHtml;
                            } else {
                                var strHtml = '<a href="javascript:void(0);" onclick="OnlineVerificationAndRevOrStop(\'' + row.ISSTOP + '\',\'' + row.LID + '\',\'RevOrStop\',\'' + row.SYSTYPE + '\')"><li class="glyphicon glyphicon-remove"></li></a>';
                                return strHtml;
                            }
                        }
                    },
                    { field: 'PASSWORD', title: '密码', align: 'center' },
                    { field: 'COMMENT', title: '备注', align: 'center' },
                    {
                        field: 'UPDATE', title: '修改', align: 'center', formatter: function (value, row, index) {//修改
                            var strHtml = '<button id="btnRightsGroupSetting" class="btn" onclick="editRightsUser(\'' + row.SYSTYPE + '\',\'' + row.STYPEID_ + '\',\'' + row.TYPEID_ + '\',\'' + row.PASSWORD + '\',\'' + row.ETYPEID_ + '\',\'' + row.EFULLNAME + '\',\'' + row.NUM + '\',\'' + row.LID + '\',\'' + row.LOGINNAME + '\',\'' + row.COMMENT + '\')"><i class="glyphicon glyphicon-edit"></i> 修改</button>';
                            return strHtml;
                        }
                    },
                    {
                        field: 'RIGHTS', title: '权限', align: 'center', formatter: function (value, row, index) {//权限设置
                            var strHtml = '<button id="btnURightsSet" class="btn" onclick="SetUserRights(\'' + row.LID + '\',\'' + row.SYSTYPE + '\')"><i class="glyphicon glyphicon-cog"></i> 设置</button>';
                            return strHtml;
                        }
                    },
                    {
                        field: 'price', title: '价格权限', align: 'center', formatter: function (value, row, index) {//价格权限
                            var strHtml = '<button id="btnPriceRights" class="btn" onclick="PriceRights(\'' + row.LID + '\',\'' + row.SYSTYPE + '\')"><i class="glyphicon glyphicon-cog"></i> 设置</button>';
                            return strHtml;
                        }
                    },
                    {
                        field: 'Message', title: '信息授权', align: 'center', formatter: function (value, row, index) {//信息授权
                            var strHtml = '<button id="btnMessageRights" class="btn" onclick="MessageRights(\'' + row.LID + '\',\'' + row.SYSTYPE + '\')"><i class="glyphicon glyphicon-comment"></i> 设置</button>';
                            return strHtml;
                        }
                    },
                    {
                        field: 'copy', title: '复制权限', align: 'center', formatter: function (value, row, index) {//复制权限
                            var strHtml = '<button id="btnCopyRights" class="btn" onclick="CopyRights(\'' + row.LID + '\',\'' + row.LOGINNAME + '\')"><i class="glyphicon glyphicon-file"></i> 复制权限</button>';
                            return strHtml;
                        }
                    },
                    {
                        field: "del", title: "删除", align: 'center', formatter: function (value, row, index) {//删除
                            var strHtml = '<button id="btnRightsGroupSetting" class="btn btn-sm" onclick="deleteUser(\'' + row.LID + '\',\'' + row.NUM + '\',\'' + row.SYSTYPE + '\')"><i class="glyphicon glyphicon-trash"></i> 删除</button>';
                            return strHtml;
                        }
                    }
                ], onLoadSuccess: function () {
                    var flag = '@ViewBag.isUserPower';
                    if (flag == "true") {
                        $('#RightsListTable').bootstrapTable('showColumn', 'Message');
                    }
                    else {
                        $('#RightsListTable').bootstrapTable('hideColumn', 'Message');
                    }
                }

            });
            //隐藏列
            $('#RightsListTable').bootstrapTable('hideColumn', 'SYSTYPE');
            $('#RightsListTable').bootstrapTable('hideColumn', 'PASSWORD');
            $('#RightsListTable').bootstrapTable('hideColumn', 'STYPEID_');
            $('#RightsListTable').bootstrapTable('hideColumn', 'TYPEID_');
            $('#RightsListTable').bootstrapTable('hideColumn', 'ETYPEID_');
            $('#RightsListTable').bootstrapTable('hideColumn', 'EFULLNAME');
            $('#RightsListTable').bootstrapTable('hideColumn', 'DELETED');
            $('#RightsListTable').bootstrapTable('hideColumn', 'WEIXINISSTOP');
            $('#RightsListTable').bootstrapTable('hideColumn', 'NUM');
            if ("@ViewBag.IsFzLimit" =="True") {
                $('#RightsListTable').bootstrapTable('hideColumn', 'BINDINGPNONEMODE');
            }
            $(window).resize(function () {//表格布局重置
                $('#RightsListTable').bootstrapTable('resetView');
            });
            $("#btnNew").on("click", function () {//新增或修改权限用户
                layer.open({
                    type: 2,
                    title: '<i class="glyphicon glyphicon-plus-sign"></i> 新增权限用户',
                    shadeClose: false,
                    shade: 0.5,
                    area: ['60%', '70%'],
                    content: '../WLTManage/NewUserRights?Operation=new'
                });
            });
            $("#btnRightsGroupSetting").on("click", function () {//权限组设置
                layer.open({
                    type: 2,
                    title: '<i class="fa fa-asterisk"></i> 权限组设置页面',
                    shadeClose: false,
                    shade: 0.5,
                    area: ['95%', '95%'],
                    content: '../WLTManage/RightsGroupSetting'
                });
            });
            $("#btnCommodityGroupSetting").on("click", function () {//商品组设置
                layer.open({
                    type: 2,
                    title: '<i class="fa fa-asterisk"></i> 商品组设置页面',
                    shadeClose: false,
                    shade: 0.5,
                    area: ['95%', '95%'],
                    content: '../WLTManage/CommodityGroupSetting'
                });
            });
        });
        //批量导入
        $("#btnPLImport").on("click", function () {
            layer.open({
                type: 2,
                title: '<i class="fa fa-asterisk"></i> 筛选制单人',
                shadeClose: false,
                shade: 0.5,
                area: ['60%', '85%'],
                content: '../CommonSelector/EmployeeSelectorMore',
                end: function () {
                    var typeid = $("#Employeebtypeid").val();
                    if (typeid != "") {
                        $.ajax({
                            url: "../WLTManage/PLImportEmploee",
                            dataType: "text",
                            data: {
                                typeid: typeid
                            },
                            type: "post",
                            success: function (data) {
                                layer.msg(data);
                                $('#RightsListTable').bootstrapTable("refresh");
                                $("#Employeebtypeid").val("")
                            },
                            error: function (data) {
                                layer.msg(data);
                                $('#RightsListTable').bootstrapTable("refresh");
                                $("#Employeebtypeid").val("")
                            }
                        })
                    }
                }
            });


        });
    </script>

    @*<script>
        var $table = $('#RightsListTable'),
            selections = [];
        $(function () {
            $table.on('check.bs.table check-all.bs.table ' +
                    'uncheck.bs.table uncheck-all.bs.table', function (e, rows) {
                        var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
                            return row.LoginID;
                        }),
                            func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference';
                        selections = _[func](selections, ids);
                    });
        });
        function responseHandler(res) {
            $.each(res.rows, function (i, row) {
                row.LoginID = $.inArray(row.LoginID, selections) !== -1;
            });
            return res;
        }
    </script>*@
</body>
