@{
    ViewBag.Title = "价格权限";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<body style="background-color:white">
    <div style="width:100%;height:100%;background-color:white; float:left">
        @*<table class="table table-bordered table-striped table-hover">
                <tr>
                    <td style="text-align:left">
                        <button id="btnSave" class="btn btn-default btn-sm" onclick="Save()"><i class="glyphicon glyphicon-saved"></i> 保 存</button>
                    </td>
                </tr>
            </table>*@
        <table id="RightsTable"></table>
    </div>
    <script type="text/javascript">
    $(function () {
        $('#RightsTable').bootstrapTable({
            url: '../WLTManage/GetPriceRightsList?LoginID=' + '@ViewBag.LoginID',         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: false,                   //是否显示分页（*）
            sortOrder: "asc",                   //排序方式
            sidePagination: "server",
            minimumCountColumns: 2,  //最少允许的列数
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            //height: "636",               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "",            //每一行的唯一标识，一般为主键列
            clickToSelect: true,              //是否启用点击选中行
            sortable: true,                     //是否启用排序
            silentSort: true,
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: false,
            showColumns: false,            //是否显示所有的列
            showRefresh: false,              //是否显示刷新按钮
            showToggle: false,                     //是否显示详细视图和列表视图的切换按钮
             cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            columns: [
                {
                    checkbox: true, field: 'che', formatter: function (value, row, index) {
                        if (row["isused"] == "1") {
                            return true;
                        } else {
                            return false;
                        }
                    }
                },
                {
                    field: "FullName", title: "价格类型名称"
                },
                {
                    field: "PriceType", title: "PriceType"
                },
                {
                    field: "isused", title: "isused"
                }
            ],
            onCheck: function (row) {
                var selval = "";
                selval = row.PriceType + ":" + row.FullName;
                $.ajax({
                    url: "../WLTManage/UpdateWLTPriceRights?operation=check&LoginID=" + '@ViewBag.LoginID',
                    dataType: "text",
                    data: { selval: selval },
                    type: "post",
                    success: function (data) {//删除成功后刷新table
                        layer.msg("启用成功", { time: 2000 });
                    },
                    error: function (data) {
                        layer.msg(data, { icon: 5, time: 2000 });
                    }
                })
            },
            onUncheck: function (row) {
                var selval = "";
                selval = row.PriceType + ":" + row.FullName;
                $.ajax({
                    url: "../WLTManage/UpdateWLTPriceRights?operation=uncheck&LoginID=" + '@ViewBag.LoginID',
                    dataType: "text",
                    data: { selval: selval },
                    type: "post",
                    success: function (data) {//删除成功后刷新table
                        layer.msg("取消成功", { time: 2000 });
                    },
                    error: function (data) {
                    }
                })
            },
            onCheckAll: function (rows) {
                var nsel = "";
                for (var i = 0; i < rows.length; i++) {
                    if (i == rows.length - 1)
                    { nsel += rows[i].PriceType + ":" + rows[i].FullName; }
                    else
                    { nsel += rows[i].PriceType + ":" + rows[i].FullName + ","; }
                }
                $.ajax({
                    url: "../WLTManage/UpdateWLTPriceRights?operation=check&LoginID=" + '@ViewBag.LoginID',
                    dataType: "text",
                    data: { selval: nsel },
                    type: "post",
                    success: function (data) {//删除成功后刷新table
                        layer.msg("启用成功", { time: 2000 });
                    },
                    error: function (data) {
                    }
                })
            },
            onUncheckAll: function (rows) {
                var nsel = "";
                for (var i = 0; i < rows.length; i++) {
                    if (i == rows.length - 1)
                    { nsel += rows[i].PriceType + ":" + rows[i].FullName; }
                    else
                    { nsel += rows[i].PriceType + ":" + rows[i].FullName + ","; }
                }
                $.ajax({
                    url: "../WLTManage/UpdateWLTPriceRights?operation=uncheck&LoginID=" + '@ViewBag.LoginID',
                    dataType: "text",
                    data: { selval: nsel },
                    type: "post",
                    success: function (data) {//删除成功后刷新table
                        layer.msg("取消成功", { time: 2000 });
                    },
                    error: function (data) {
                    }
                })
            }
        });
        $('#RightsTable').bootstrapTable('hideColumn', 'PriceType');
        $('#RightsTable').bootstrapTable('hideColumn', 'isused');
    });
    //function Save() {//保存
    //    layer.msg("保存成功！", { time: 2000 });
    //}
    </script>
</body>
