<%--
  Created by IntelliJ IDEA.
  User: njc
  Date: 2022/5/28
  Time: 11:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/javascript">
  /**
   * 显示博客标题
   * @param val
   * @param row
   * @returns {*}
   */
  function formatRole(val, row) {
    if (val === 1){
      return "管理员";
    }
    return "普通用户";
  }

  /**
   * 审核
   */
  function commentReview(state) {
    var selectedRows = $("#cr-dg").datagrid("getSelections");
    if (selectedRows.length === 0) {
      $.messager.alert("系统提示", "请至少选择一条要编辑的数据！");
      return;
    }
    var strIds = [];
    for (var i = 0; i < selectedRows.length; i++) {
      strIds.push(selectedRows[i].id);
    }
    var ids = strIds.join(",");
    $.messager.confirm("系统提示", "您确定要改变用户角色吗？", function (r) {
      if (r) {
        $.post("${pageContext.request.contextPath}/admin/blogger/review.do", {
          ids: ids,
          state: state
        }, function (result) {
          if (result.success) {
            $.messager.alert("系统提示", "提交成功！");
            $("#cr-dg").datagrid("reload");
          } else {
            $.messager.alert("系统提示", "数据删除失败！");
          }
        }, "json");
      }
    });
  }
</script>
<table id="cr-dg" title="角色修改" class="easyui-datagrid" fitcolumns="true" rownumber="true" pagination="true"
       url="${pageContext.request.contextPath}/admin/blogger/list.do" fit="true" toolbar="#cr-tb">
  <thead>
  <tr>
    <th field="cb" checkbox="true" align="center"></th>
    <th field="id" width="20" align="center">用户编号</th>
    <th field="userName" width="200" align="center" >用户名</th>
    <th field="userTag" width="100" align="center" formatter="formatRole">用户角色</th>
    <th field="nickName" width="200" align="center">用户昵称</th>
    <th field="sign" width="50" align="center">用户职业</th>
  </tr>
  </thead>
</table>
<div id="cr-tb">
  <a href="javascript:commentReview(1)" class="easyui-linkbutton" iconcls="icon-ok" plain="true">变为管理员</a>
  <a href="javascript:commentReview(0)" class="easyui-linkbutton" iconcls="icon-no" plain="true">变为普通用户</a>
</div>
