<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="授权角色列表" libs=["table"]/>
<div class="container-div">
	<div class="row">
	<div class="col-sm-12 search-collapse">
	<@f.form id="user-form">
     <@f.hidden name="roleId" value="${roleId}" refresh=false />
     <div class="select-list">
             <li>
                 <@ctx.i18n text = "登陆账号"/>:<input type="text" class="form-control" name="username"/>
             </li>
             <li>
                 <@ctx.i18n text = "邮箱"/>:<input type="text" class="form-control" name="email"/>
             </li>
             <li>
                 <@ctx.i18n text = "手机号码"/>:<input type="text" class="form-control" name="mobile"/>
             </li>
             <li>
                 <label><@ctx.i18n text = "机构查询"/></label>：
                 <div class="control-div width-150">
                     <@f.treeselect name="compId" boxTitle="请选择归属机构" url="sys/comp/treeData"
                     expandLevel=true
                     placeholder="请选择上级机构"/>
                 </div>
             </li>
             <li>
                 <@ctx.i18n text = "用户状态"/>：
                 <@f.select name="status" blankValue="" blankLabel="所有" dictType="sys_normal_disable" />
             </li>
             <li>
                 <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;<@ctx.i18n text = "查询"/></a>
                 <a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i>&nbsp;<@ctx.i18n text = "重置"/></a>
             </li>
         </ul>
     </div>
     </@f.form>
    </div>
    <@table id="bootstrap-table">
        <@shiro.hasPermission name="sys:user:add">
           <a class="btn btn-success" onclick="selectUser()"><i class="fa fa-plus"></i>&nbsp;<@ctx.i18n text = "批量添加用户"/></a>
         </@shiro.hasPermission>
         <@shiro.hasPermission name="sys:user:edit">
             <a class="btn btn-primary multiple disabled" onclick="cancelAuthUserAll()"><i class="fa fa-pencil-square-o"></i>&nbsp;<@ctx.i18n text = "批量取消"/></a>
         </@shiro.hasPermission>
        <a class="btn btn-warning" onclick="opt.modal.closeTab()">
            <i class="fa fa-reply-all"></i> <@ctx.i18n text = "关闭"/>
        </a>
    </@table>
    </div>
</div>
<@footer>
<script type="text/javascript">
    var editFlag = "${permission.hasPermi('sys:user:edit')}";
    var delFlag = "${permission.hasPermi('sys:user:del')}";
    var resetPwdFlag = "${permission.hasPermi('sys:user:resetPwd')}";
    var visible = ${permission.isPermitteds("sys:user:edit,
    sys:user:del,sys:user:resetPwd")?string('true', 'false')};
    var datas = ${dict.getDictListJson('sys_user_show_hide')};
    var prefix = baseURL + 'sys/role/authUser';

    $(function() {
        /* 初始表格对象 */
        var options = {
            url: prefix + "/list",
            addUrl: prefix + "/add",
            sortName: "createTime",
            queryParams: queryParams,
            uniqueId: "id", /* 唯一ID */
            modalName: "用户角色权限",
            columns: [
                {
                    title: "<@ctx.i18n text = "序号"/>", width: 10, formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {field: 'username', title: "<@ctx.i18n text = "账号"/>"},
                {field: 'name', title: "<@ctx.i18n text = "姓名"/>"},
                {field: 'compName', title: "<@ctx.i18n text = "归属公司"/>"},
                {field: 'deptName', title:  "<@ctx.i18n text = "归属机构"/>"},
                {field: 'email', title: "<@ctx.i18n text = "邮箱"/>"},
                {field: 'mobile', title: "<@ctx.i18n text = "手机"/>"},
                {
                    field: 'status', title: "<@ctx.i18n text = "状态"/>", formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {field: 'createTime', title: "<@ctx.i18n text = "创建时间"/>", sortable: true},
                {
                    title: "<@ctx.i18n text = "操作"/>",
                    visible: visible,
                    class: 'action',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="' + delFlag + '" href="javascript:void(0)" title="<@ctx.i18n text = "删除"/>" onclick="cancelAuthUser(\'' + row.id + '\')"><i class="fa fa-trash-o"></i></a> ');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.roleId = $("#roleId").val();
        return search;
    }

    function treeCallback(id, event, index, layero, nodes) {
        if(id == "compId"){
            if(event == "ok"){
                /* 点击确认按钮直接刷新表格*/
                $.table.search();
            }
        }
    }
    
    /*取消授权*/
    function cancelAuthUser(userId) {
        opt.modal.confirm("<@ctx.i18n text = "确定确认要取消该用户角色吗?"/>", function() {
            var data = [];
            data.push({"name": "roleId", "value": $("#roleId").val()});
            data.push({"name": "userIds", "value": userId});
            opt.operate.post(prefix + "/cancel",data);
        })
    }

    /*批量添加用户*/
    function selectUser(){
        var url = prefix + '/selectUser/' + $("#roleId").val();
        opt.modal.open("<i class='fa fa-address-book-o'/> <@ctx.i18n text ="选择用户"/>", url,1000);
    }

    /* 分配用户-批量取消授权 */
    function cancelAuthUserAll() {
        var rows = $.table.selectAllColumns();
        /*if (rows.length == 0) {
            opt.modal.warning("请至少选择一条记录!");
            return;
        }*/
        opt.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
            var data = [];
            data.push({"name": "roleId", "value": $("#roleId").val()});
            data.push({"name": "userIds", "value": rows});
            opt.operate.post(prefix + "/cancel",data);
        });
    }

</script>
</@footer>
</@pageTheme>