mem_list.html 5.6 KB
<include file="public@header" />
</head>
<body>
<button type="button" class="btn btn-default" style="margin:10px 10px;" data-toggle="modal" data-target="#myModal">添加会员</button>
<table class="table table-bordered" style="margin:10px 10px;">
    <caption>会员列表</caption>
    <thead>
    <tr>
        <th>用户名</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody class="zhuijia">
    <volist name="data" id="vo">
        <tr class="tr{$vo.id}">
            <td>{$vo.name}</td>
            <td>
                <button type="button" class="btn btn-default" data-toggle='modal' data-target='#editModal' onclick="edit({$vo.id})">编辑</button>
                <button type="button" class="btn btn-default" onclick="del({$vo.id})">删除</button>
            </td>
        </tr>
    </volist>
    </tbody>
</table>
<!-- 添加模态框(Modal) -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">添加会员</h4>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <span class="input-group-addon">用户名:</span>
                    <input type="text" name="name" class="form-control">
                </div>
                <div class="input-group" style="margin-top: 5px;">
                    <span class="input-group-addon">密码:</span>
                    <input type="text" name="passwd" class="form-control">
                </div>
                <div class="input-group" style="margin-top: 5px;">
                    <span class="input-group-addon">积分:</span>
                    <input type="text" name="jifen" class="form-control">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default guanbi" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="add()">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!-- 编辑模态框(Modal) -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">编辑会员</h4>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <span class="input-group-addon">用户名:</span>
                    <input type="text" name="ename" class="form-control">
                </div>
                <div class="input-group" style="margin-top: 5px;">
                    <span class="input-group-addon">密码:</span>
                    <input type="text" name="epasswd" class="form-control">
                </div>
                <div class="input-group" style="margin-top: 5px;">
                    <span class="input-group-addon">积分:</span>
                    <input type="text" name="ejifen" class="form-control">
                </div>
                <input type="hidden" name="id" value="">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default eguanbi" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="tjedit()">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script>
    //添加会员
    function add(){

        name = $("input[name='name']").val();
        passwd = $("input[name='passwd']").val();
        jifen = $("input[name='jifen']").val();
        $.post("{:url('Members/mem_add')}",{name:name,passwd:passwd,jifen:jifen},function(data){
            $('.guanbi').trigger('click');
            $('.zhuijia').append("<tr class='tr"+data+"'><td>"+name+"</td><td><button type='button' class='btn btn-default' data-toggle='modal' data-target='#editModal' onclick='edit("+data+")'>编辑</button><button type='button' class='btn btn-default' onclick='del("+data+")'>删除</button></td></tr>");
            $('.form-control').val('');

        });
    }

    //编辑会员
    function edit(id){
        $.post("{:url('Members/mem_edit_show')}",{id:id},function(data){
            shuju = JSON.parse(data);
            $("input[name='ename']").val(shuju.name);
            $("input[name='epasswd']").val(shuju.passwd);
            $("input[name='ejifen']").val(shuju.jifen);
            $("input[name='id']").val(shuju.id);
        });
    }

    //编辑模态框提交
    function tjedit(){
        id = $("input[name='id']").val();
        name = $("input[name='ename']").val();
        passed = $("input[name='epasswd']").val();
        jifen = $("input[name='ejifen']").val();
        $.post("{:url('Members/mem_edit_up')}",{id:id,name:name,passed:passed,jifen:jifen},function(data){

            $('.eguanbi').trigger('click');
        });

    }

    //删除数据
    function del(id){
       ccc = window.confirm('是否删除?');
       if(ccc){
           $.post("{:url('Members/mem_del')}",{id:id},function(data){
               $('.tr'+id).remove();
           });
       }
    }


</script>
</body>
</html>