<%--
  Created by IntelliJ IDEA.
  User: 01112291
  Date: 16-3-14
  Time: 上午8:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/jsp/includes.jsp" %>
<input type="hidden" id="currentMenu" value="user"/>
<div class="main">
<div class="inner-fmain">

    <div class="search-bar clearfix">
        <div class="search-left">
            <div class="btn-area btn-area-max">
                <a href="javascript:void(0)" class="btn-public btn-del">删除</a>
                <a href="javascript:void(0)" class="btn-public btn-reset-pwd">重置密码</a>
            </div>
        </div>
        <div class="search-right">
            <div class="search-box">
                <div class="search">
                    <input class="input-search searchUser" id="keyword" placeholder='昵称/登录名' type="text" value="${keyword }">
                    <a class="icon-search" id="searchUser" href="javascript:void(0)"><i class="i-search"></i></a>
                </div>
            </div>

        </div>

    </div>
    <table class="table-public table-user">
        <thead>
        <tr>
            <th class="th01"><i class="input-c"></i></th>
            <th style="width: 100px;">序号</th>
            <th>账号</th>
        </tr>
        </thead>
        <tbody>
        <c:if test="${not empty pageMaker.list}">
        <c:forEach items="${pageMaker.list}" var="list" varStatus="status">
            <tr>
                <td><i class="input-c" userId="${list.user_id}"></i></td>
                <td>${beginRow + status.index}</td>
                <td class="td-left">${list.login_name}</td>
            </tr>
        </c:forEach>
        </c:if>
        <c:if test="${empty pageMaker.list}">
            <tr><td colspan="3">暂未检索到记录！</td></tr>
        </c:if>
        </tbody>
    </table>
    <%@include file="/WEB-INF/jsp/common/pageMark.jsp" %>
</div>

</div>

<script type="text/javascript">


    function gotoPage(pageIndex, pageId,pageSize) {
        location.href=CONTEXTPATH+"/platform/user/index.mooc?pageIndex="+pageIndex+"&pageSize="+pageSize;
    }

    $(function(){
        $(".search-right input[placeholder]").defaultValue();
        $("th .input-c").on("click",function(){
            $(this).toggleClass("selected");
            var $inputcs=$(this).closest("table").find("tbody .input-c");
            if($(this).hasClass("selected")){
                $inputcs.addClass("selected");
            }else{
                $inputcs.removeClass("selected");
            }
        })
        $("tbody .input-c").on("click",function(){
            $(this).toggleClass("selected");
        })
        $("select").select();

        /**
         *删除
         */
        $(".btn-del").click(function(){
            var i=0;
            var userId;
            $(".input-c").each(function(){
                if ($(this).hasClass("selected")){
                    if (i==0){
                        userId = $(this).attr("userId");
                    } else {
                        userId = userId +","+ $(this).attr("userId");
                    }
                    i++;
                }
            })
            if (i==0){
                $.dialog.error("请选择记录！");
                return false;
            }
            $.dialog.confirm("确定要删除吗?", function () {
                $.ajax({
                    type:'post',
                    url:CONTEXTPATH+"/platform/user/delete.mooc",
                    data:{
                        userIds:userId
                    },
                    success:function(result){
                        if(result.retCode=="success"){
                            $.dialog.success("操作成功！");
                            location.href=CONTEXTPATH +"/platform/user/index.mooc";
                        } else {
                            $.dialog.error("操作失败！");
                        }
                    }
                })
            }, function () {
                $.dialog.close();
            });

        })

        /**
         *重置密码
         */
        $(".btn-reset-pwd").click(function(){
            var i=0;
            var userId;
            $(".input-c").each(function(){
                if ($(this).hasClass("selected")){
                    if (i==0){
                        userId = $(this).attr("userId");
                    } else {
                        userId = userId +","+ $(this).attr("userId");
                    }
                    i++;
                }
            })
            if (i==0){
                $.dialog.error("请选择记录！");
                return false;
            }
            $.ajax({
                type:'post',
                url:CONTEXTPATH+"/platform/user/resetpwd.mooc",
                data:{
                    userIds:userId
                },
                success:function(result){
                    if(result.retCode=="success"){
                        $.dialog.success("操作成功！");
                    } else {
                        $.dialog.error("操作失败！");
                    }
                }
            })

        })

        //按钮搜索
        $("#searchUser").click(function(){
            var keyword = $.trim($("#keyword").val());
            if (keyword==null || keyword=="" || keyword==undefined){
                location.href=CONTEXTPATH +"/platform/user/index.mooc";
            } else{
                location.href=CONTEXTPATH +"/platform/user/index.mooc?keyword="+keyword;
            }
        })


        //输入框搜索
        $(".searchUser").keydown(function(event) {
            if(event.keyCode == 13) {
                var keyword = $("#keyword").val();
                if (keyword==null || keyword=="" || keyword==undefined){
                    location.href=CONTEXTPATH +"/platform/user/index.mooc";
                } else {
                    location.href=CONTEXTPATH +"/platform/user/index.mooc?keyword="+keyword;;
                }
            }
        })

    })

</script>