<style type="text/css">
body .layui-layer-popup .layui-layer-content{background-color: #f2f2f2;padding: 0px;}
</style>
<title>会员管理</title>
  
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>问答管理</cite></a>
    <a><cite>用户</cite></a>
    <a><cite>会员管理</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <form class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="J_ajaxForm">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">UID</label>
          <div class="layui-input-block" style="width: 100px;">
            <input type="text" name="uid" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-block">
            <input type="text" name="username" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">邮箱</label>
          <div class="layui-input-block">
            <input type="text" name="email" autocomplete="off" class="layui-input">
          </div>
        </div>

        <div class="layui-inline">
          <label class="layui-form-label">用户组</label>
          <div class="layui-input-block">
              <select class="layui-select" name="group">
                <option value="">全部</option>
                {volist name="group" id="item"}
                {if $item.type eq 'default'}
                <option value="{$item.id}">{$item.name}</option>
                {/if}
                {/volist}
              </select>
          </div>
        </div>

        <div class="layui-inline">
          <label class="layui-form-label">管理组</label>
          <div class="layui-input-block">
              <select class="layui-select" name="admin">
                <option value="">全部</option>
                {volist name="group" id="item"}
                {if $item.type eq 'admin'}
                <option value="{$item.id}">{$item.name}</option>
                {/if}
                {/volist}
              </select>
          </div>
        </div>
        
        <div class="layui-inline">
          <label class="layui-form-label">状态</label>
          <div class="layui-input-block">
              <select class="layui-select" name="status">
                <option value="">全部</option>
                <option value="1">正常</option>
                <option value="0">待审核</option>
              </select>
          </div>
        </div>
        
        <div class="layui-inline">
          <button class="layui-btn" lay-submit lay-filter="J_form_search">搜索</button>
        </div>
      </div>
    </form>
    
    <div class="layui-card-body">
      <div style="padding-bottom: 10px;">
        <button type="button" class="layui-btn J_add"><i class="layui-icon layui-icon-add-circle"></i>添加</button>
        <button type="button" class="layui-btn J_remove" role="1"><i class="layui-icon layui-icon-delete"></i>删除</button>
        <a href="wendasns/user/check" class="layui-btn J_req"><i class="layui-icon layui-icon-ok"></i>审核通过</a>
      </div>
      
      <table id="J_table_list" lay-filter="J_table_list"></table>

    </div>
  </div>
</div>

<script type="text/html" id="J_table_status_tpl">
  {{# if(d.status==1){ }}
  <span class="layui-badge layui-bg-green">正常</span>
  {{# }else{ }}
  <span class="layui-badge layui-bg-orange">待审核</span>
  {{# } }}
</script>

<script type="text/html" id="J_table_auths_tpl">
  {{# if(d.auths==1){ }}
  <span>个人认证</span>
  {{# }else if(d.auths==2){ }}
  <span>企业认证</span>
  {{# }else if(d.auths==3){ }}
  <span>专家认证</span>
  {{# }else{ }}
  <span>未认证</span>
  {{# } }}
</script>

<script type="text/html" id="J_table_tool">
  <a href="#J_edit_view" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="popup" title="编辑会员"><i class="layui-icon layui-icon-edit"></i>编辑</a>
  <button type="button" class="layui-btn layui-btn-danger layui-btn-xs J_remove" role="0"><i class="layui-icon layui-icon-delete"></i>删除</button>
</script>

<script>
;!function(){
  var $ = layui.$
  ,admin = layui.admin
  ,form = layui.form
  ,view = layui.view
  ,table = layui.table;

  form.render();

  //执行渲染
table.render({
  elem: '#J_table_list'
  ,url: '{:url('wendasns/user/list')}'
  ,cols: [[
      {type: 'checkbox'}
      ,{field:'user_id',title:'UID',width:80,align:'center',sort: true}
      ,{field:'group',title:'用户组',width:100,align:'center'}
      ,{field:'admin',title:'管理组',width:100,align:'center',templet:'#J_templet_group'}
      ,{field:'username',title:'用户名',minWidth:150}
      ,{field:'email',title:'邮箱',minWidth:200,templet:'<div>{{d.users.email}}</div>'}
      ,{field:'mobile',title:'手机号',minWidth:170,templet:'<div>{{d.users.mobile}}</div>'}
      ,{field:'create_time',title:'注册时间',width:200,templet:'<div>{{d.users.create_time}}</div>'}
      ,{field:'auths',title:'认证',align:'center',width:100,templet:'#J_table_auths_tpl'}
      ,{field:'status',title:'状态',align:'center',width:80,templet:'#J_table_status_tpl'}
      ,{title:'操作',width:150,align:'center',toolbar:'#J_table_tool'}
  ]]
  ,page: true
    ,limit: 20
    ,height: 'auto'
  ,text: {
    none: '暂无数据！'
  }
});

	$(document).on('click','.J_remove',function(event){
		event.preventDefault();
		var role = $(this).attr('role'),post = [];
		if(role==1){
			if(table.checkStatus('J_table_list').data.length === 0){
				layer.msg('\u8bf7\u9009\u62e9\u6570\u636e');
				return false;
			}
			var data = table.checkStatus('J_table_list');
	  	  	$.each(data.data,function(){
	  	  		post.push(this.id);
	        });
		}else{
			var index = $('tr.layui-table-hover').data('index');
			var data = table.cache.J_table_list[index];
			post.push(data.id);
		}
		admin.popup({
			id: 'J_popup_window'
			,title: '删除会员'
			,area: ['420px','560px']
			,type: 1
			,success: function(layero, index){
				var html = $('#J_remove_view').html();
				view(this.id).send(html,{data:post});
				form.render();
			}
		});
	});
	
    form.on('checkbox(J_checkAll)', function(obj){
        $('.checkbox_state').prop('checked', this.checked);
        form.render('checkbox');
    });
    
    form.on('submit(J_ajaxSubmit)', function(obj){
    	var _form = $(obj.form),action = _form.prop('action'),method = _form.prop('method');
        admin.req({
           url: action
           ,type: method
           ,dataType: 'json'
           ,data: obj.field
           ,done: function(res){
               layer.msg(res.msg, {time:1500}, function(){
    				admin.events.refresh();
    		   });
           }
           ,error: function(res){
    			layer.msg(res.msg);
    		}
        });
        return false;
    });
    
	$(document).on('click','.J_add',function(){
		admin.popup({
			id: 'J_popup_window'
			,title: '添加会员'
			,area: ['850px','720px']
			,type: 1
			,skin: 'layui-layer-popup'
			,success: function(layero, index){
				view(this.id).render('wendasns/user/add',{});
			}
		});
	});
}();
</script>

<script type="text/html" id="J_remove_view">
<blockquote class="layui-elem-quote"><font color="red">需要删除哪些关联数据</font><br>
用户操作行为：如提问、回答、评论、登录等操作行为记录数据<br>
用户数据：如提问数、回答数、文章数、粉丝数、收藏数、关注数、采纳数等数据
</blockquote>
<form class="layui-form" action="{:url('wendasns/user/remove')}" method="post">

            <div class="layui-form-item">
              <div class="layui-input-block">
                <input type="checkbox" lay-skin="primary" lay-filter="J_checkAll" title="全选" checked="checked">
              </div>
            </div>
            
            <div class="layui-form-item">
            <label class="layui-form-label">关联数据</label>
            <div class="layui-input-inline">
              <input class="checkbox_state" type="checkbox" name="data[]" value="behavior" lay-skin="primary" title="用户操作行为" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="data" lay-skin="primary" title="用户数据" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="fans" lay-skin="primary" title="粉丝" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="collect" lay-skin="primary" title="收藏" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="question" lay-skin="primary" title="提问" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="article" lay-skin="primary" title="文章" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="answer" lay-skin="primary" title="回答" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="comment" lay-skin="primary" title="评论" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="report" lay-skin="primary" title="举报" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="praise" lay-skin="primary" title="点赞" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="sign" lay-skin="primary" title="签到" checked="checked">
              <input class="checkbox_state" type="checkbox" name="data[]" value="notice" lay-skin="primary" title="消息" checked="checked">
            </div>
          </div>
          
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="J_ajaxSubmit"><i class="layui-icon layui-icon-ok-circle"></i>提交</button>
              </div>
            </div>
            {{# layui.$.each(d.data,function(index,item){ }}
            <input type="hidden" name="id[]" value="{{item}}">
            {{# }); }}
          </form>
</script>

<script type="text/html" id="J_edit_view">
<form class="layui-form" action="{:url('wendasns/user/edit')}" method="post">
	<input type="hidden" name="id" value="{{d.id||0}}">
            
            <div class="layui-form-item">
              <label class="layui-form-label">用户名</label>
              <div class="layui-input-inline">
                <input type="text" value="{{d.username||''}}" class="layui-input layui-disabled" disabled>
              </div>
            </div>
            
            <div class="layui-form-item">
              <label class="layui-form-label">签名</label>
              <div class="layui-input-inline">
                <input type="text" name="usersign" value="{{d.usersign||''}}" class="layui-input">
              </div>
            </div>
 
  <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">用户组</label>
            <div class="layui-input-inline">
              <select name="group_id">
                {volist name="group" id="item"}
                	{if $item.type eq 'default'}
                <option value="{$item.id}" {{# if(d.group_id=={$item.id}){ }}selected="selected"{{# } }}>{$item.name}</option>
                	{/if}
                {/volist}
              </select>
            </div>
          </div>
        </div>

  <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">管理组</label>
            <div class="layui-input-inline">
              <select name="admin_id">
              	<option value="0">无</option>
                {volist name="group" id="item"}
                	{if $item.type eq 'admin'}
                <option value="{$item.id}" {{# if(d.admin_id=={$item.id}){ }}selected="selected"{{# } }}>{$item.name}</option>
                	{/if}
                {/volist}
              </select>
            </div>
          </div>
        </div>
        
  <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
              <select name="status">
                <option value="1" {{# if(d.status==1){ }}selected="selected"{{# } }}>正常</option>
                <option value="0" {{# if(d.status==0){ }}selected="selected"{{# } }}>待审核</option>
              </select>
            </div>
          </div>
        </div>
        
  <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">认证类型</label>
            <div class="layui-input-inline">
              <select name="auths">
              	<option value="0" {{# if(d.auths==0){ }}selected="selected"{{# } }}>未认证</option>
                <option value="1" {{# if(d.auths==1){ }}selected="selected"{{# } }}>个人认证</option>
                <option value="2" {{# if(d.auths==2){ }}selected="selected"{{# } }}>企业认证</option>
                <option value="3" {{# if(d.auths==3){ }}selected="selected"{{# } }}>专家认证</option>
              </select>
            </div>
          </div>
        </div>
        
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="J_ajax_submit_btn"><i class="layui-icon layui-icon-ok-circle"></i>提交</button>
              </div>
            </div>
            
          </form>
</script>