<%@ page language="C#" autoeventwireup="true" inherits="go_user_index, App_Web_mn45emcx" %>

<%@ Register Src="top.ascx" TagName="TagName" TagPrefix="MyTop" %>
<%@ Register Src="bottom.ascx" TagName="TagName" TagPrefix="MyBottom" %>
<%@ Register Src="user.ascx" TagName="TagName" TagPrefix="MyUser" %>
<MyTop:TagName ID="uc_01" runat="server" MyValue="UserManage" />
<style type="text/css">
    .item
    {        
      height:52rem
    }
	.year{
		height:5rem;
		line-height:5rem;
		list-style:none;
		text-align:center;
		font-size:3rem;
		color:#CF0;
		background:#fff;
		opacity:0.8
	}
	.month{
		list-style:none;
		float:left;
		width:33.33%;
		height:12rem;
		color:#6C0;
		box-sizing:border-box;
		padding:1rem;
		font-size:1.8rem;

		
	}
	
	.month_0{
		background-color: rgba(240,240,240,0.95);
	}
	.month_1{
		background-color: rgba(250,250,250,0.95);
	}
	.container{
		height:100%;
		
	}
	#list{
    
	}
	.monthname{
		height:50%;	
	}
	.totalmoney{
		width:100%;
		height:50%;
		text-align:right;
		font-size:1.8rem;
		padding-bottom:0px;
		line-height:5rem;
	}
	
	.viewed{
		color:#3a3;	
	}
	.notview{
		color:#f60;	
	}
	span[status='1']
	{
		color:#3a3;
	}
	span[bttype='setcogbt']
	{
		cursor:pointer;
	}
	span[bttype='setcogbt']:hover
	{
		color:#f60;
	}
	
	#list tr:hover
	{
		background:#f7f7f7;
		font-weight:bold;
	}
</style>

<div class="container" style="padding:0px; margin:auto;margin-top:1rem;background:#fff; box-sizing:border-box; padding:1rem;; border-radius:5px">
<div class="alert alert-warning alert-dismissible" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<div style="clear:both"></div>
<p>
<button class="btn btn-success" bttype="newuserbt"> <span class="fa fa-user" bttype="newuserbt"> 创建用户</span></button>

<span id="updatenotice"></span>
</p>
</div>
  <div id="list" style="background:#fff"></div>
  <div id="page"></div>
</div>

<div class="modal fade" tabindex="-1" role="dialog" id="modal_setbox">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">设置</h4>
      </div>
      <div class="modal-body" style="overflow:auto">
		
      </div>
     
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->



<div class="modal fade" tabindex="-1" role="dialog" id="modal_edituser">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">创建用户</h4>
      </div>
      <div class="modal-body">

		<label>用户手机号(即用户名)，每行一个用户</label>
		<textarea id="userlist" placeholder="每行一个用户" class="form-control"></textarea><br />


		<label>初始密码，不少于6位</label>
		<input type="text" id="pwd" placeholder="密码" maxlength="30"  class="form-control" />
		<div id="createresult" style="margin-top:2rem"> </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success" bttype="submitnewuserbt">提交</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<MyUser:TagName ID="user" runat="server" />
<MyBottom:TagName ID="TagName1" runat="server" />
</body> </html> 

<script>
    var $o = { "currpage": 1, "ps": 10, "bigpage": 5,"recordnum":0,"pagenum":0,"endpage":1, "listbox": "list", "pagebox": "page", "mask": "mymask", "showStat": true, "showmask": true };
    $(document).ready(function (e) {

        createMask("mymask");
        loadlist($o);

        $(this).bind("click", function (e) {
            var t = e.target;
            var bttype = $(t).attr("bttype");
            switch (bttype) {
                case "setcogbt":
                    setcog($(t).attr("v"));
                    break;
				case "resetpwdbt":
//					$("#resetpwdbox").css("display",$("#resetpwdbox").css("display")=="none"?"block":"none");
					$("#resetpwdbox").fadeToggle();
					
					break;
				case "submitresetpwdbt":
					submitresetpwd();
					break;
				case "setstatusbt":
					setstatus($(t).attr("v"),$(t).attr("status"));
					break;
				case "deluserbt":
					deluser($(t).attr("v"));
					break;
				case "setuserlevelbt":
					setuserlevel();
					break;
				case "saveuserlevelsetbt":
					saveuserlevelset();
					break;
				case "newuserbt":
					newuser();
					break;
				case "submitnewuserbt":
					submitnewuser();
					break;
            }
        });
    });
	
function newuser(){
	$("#modal_edituser").modal("show");	
	
}

function submitnewuser(){
	var o = {};
	o.userlist = $("#userlist").val();
	o.pwd = $("#pwd").val();
	
	if(o.userlist==""){
		msgbox("请输入用户手机号","warning");
		$("#userlist").focus();
		return;	
	}
	if(o.pwd==""){
		msgbox("请输入初始密码","warning");
		$("#pwd").focus();
		return;	
	}
	if(o.pwd.length<6){
		msgbox("初始密码至少6位","warning");
		$("#pwd").focus();
		return;	
	}
	
	$("#mymask").modal("show");
	$.post("user_create.aspx",o,function(d){
		$("#mymask").modal("hide");
		var a = [];
		a.push("<div class='alert alert-warning'><table class='table'>");
		a.push("<caption>系统当前用户统计</caption>");
		a.push("<tr><td>系统授权用户数</td><td>"+d.usernum+"</td></tr>");
		a.push("<tr><td>系统当前用户数</td><td>"+d.usernum_curr+"</td></tr>");
		a.push("<tr><td>可用用户数</td><td>"+(d.usernum-d.usernum_curr)+"</td></tr>");
		a.push("</table></div>");		
		
		a.push("<table class='table'>");
		a.push("<caption>本次提交结果</caption>");
		a.push("<tr><td>本次提交数</td><td>"+d.submitusernum+"个用户</td></tr>");
		a.push("<tr><td>成功数</td><td>"+d.successnum+"个成功</td></tr>");
		a.push("<tr><td>失败数</td><td>"+d.repeatnum+"个重复</td></tr>");
		a.push("</table>");
		
		a.push("<table class='table'>");
		a.push("<caption>提交结果明细</caption>");
		if(d.result=="ok"){
			msgbox(d.successnum+"个用户创建完成","ok");
		}
		else if(d.result=="usernumover"){
			msgbox(d.successnum+"个用户创建完成，其余用户未成功创建","warning");
//			a.push("<tr><td>"+d.list+"</td><td><span class='fa fa-remove' style='color:#666'> 超出授权用户数</span></td></tr>");
		}
		
		var list = d.list;
		if(list!=null){
		for(var i=0;i<list.length;i++){
			a.push("<tr>");
			a.push("<td>"+list[i].user+"</td>");
			if(list[i].result=="ok"){
				a.push("<td>"+list[i].user+"</td><td><span class='fa fa-check' style='color:#3a3'> 成功</span></td>");
			}
			else if(list[i].result=="repeat"){
				a.push("<td>"+list[i].user+"</td><td><span class='fa fa-remove' style='color:#f60'> 重复</span></td>");
			}
			else if(list[i].result=="usernumover"){
				a.push("<td>"+list[i].user+"</td><td><span class='fa fa-remove' style='color:#666'> 超出授权用户数</span></td>");
			}
			a.push("</tr>");
		}
		}
		a.push("</table>");
		$("#createresult").html(a.join(""));
	},"json");
}

function setuserlevel(){	
	$("#setuserlevelbox").css("display",$("#setuserlevelbox").css("display")=="none"?"block":"none");	
}

function saveuserlevelset(){
	var o = {};
	o.r = Math.random();
	o.targetuser = $("#saveuserlevelsetbt").attr("v");
	o.accounttype = $("#accounttype").val();
	$("#mymask").modal("show");
	$.get("saveuserlevelset.aspx",o,function(d){
		$("#mymask").modal("hide");
		if(d.result=="ok"){
			msgbox("用户类型设置完成","success");				
		}
		else{
			msgbox("用户类型未设置完成","warning");	
		}
		setcog(o.targetuser);
		loadlist($o);
		$("#modal_setbox").modal("hide");
	},"json");
}

function deluser(v){
	if(!confirm("确定删除吗?"))	{
		return;	
	}
	$("#mymask").modal("show");
	var o = {};
	o.targetuser = v;
	o.r = Math.random();
	$.get("deluser.aspx",o,function(d){
		$("#mymask").modal("hide");
		if(d.result=="ok"){
			msgbox("删除完成","success");				
		}
		else{
			msgbox("未删除","warning");	
		}
		$("#modal_setbox").modal("hide");
		loadlist($o);
	},"json");
}

function setstatus(user,status){
	$("#mymask").modal("show");
	var o = {};
	o.r = Math.random();
	o.targetuser = user;
	$.get("setuserstatus.aspx",o,function(d){
		$("#mymask").modal("hide");
		if(d.result=="ok"){
			msgbox("设置完成","success");				
		}
		else{
			msgbox("未成功设置","warning");	
		}
		setcog(user);
	},"json");
}

function submitresetpwd(){
	if(!confirm("确定重置密码吗？")){
		return;	
	}
	var o = {};
	o.pwd = $("#resetpwd_pwd").val();
	if(o.pwd==""){
		msgbox("请输入密码","warning");
		$("#resetpwd_pwd").focus();
		return;
	}
	if(o.pwd.length<6){
		msgbox("密码至少6位","warning");
		$("#resetpwd_pwd").focus();
		return;
	}	
	o.targetuser = $("#submitresetpwdbt").attr("v");	

	o.initpwd = $("#initpwd").get(0).checked?1:0;
	o.sendsms = $("#sendsms").get(0).checked?1:0;
	$.post("resetuserpwd.aspx",o,function(d){
		if(d.result=="ok"){
			msgbox("密码重置完成","success");
		}
		else{
			msgbox("密码重置失败","warning");
		}
		$("#resetpwd_pwd").val("");
	},"json");
}
    function setcog(v) {
        $("#modal_setbox").modal("show");
        $("#mymask").modal("show");
        var o = {};
        o.v = v;
        o.currpage = 1;
        o.ps = 1;
        $.get("user_load.aspx", o, function (d) {
            $("#mymask").modal("hide");
			var b = d.list[0];
			var a = [];
			a.push("<table class='table'>");
			a.push("<tr>");
			a.push("<td>用户</td>");
			a.push("<td>"+b.openid+"</td>");
			a.push("</tr>");
			
			a.push("<tr>");
			a.push("<td>昵称</td>");
			a.push("<td>"+b.nickname+"</td>");
			a.push("</tr>");
			
			a.push("<tr>");
			a.push("<td>用户类型</td>");
			a.push("<td>"+b.accounttypename+"</td>");
			a.push("</tr>");
			
			a.push("<tr>");
			a.push("<td>状态</td>");
			a.push("<td><span class='fa fa-check-circle' status='"+b.status+"'> "+(b.status==1?"启用":"禁用")+"</span></td>");
			a.push("</tr>");
			
			
			a.push("<tr>");
			a.push("<td>创建日期</td>");
			a.push("<td>"+b.createdate+"</td>");
			a.push("</tr>");
			
			a.push("<tr>");
			a.push("<td>最后登录</td>");
			a.push("<td>"+b.lastlogin+"</td>");
			a.push("</tr>");
			
			a.push("<tr>");
			a.push("<td>登录次数</td>");
			a.push("<td>"+b.loginnum+"</td>");
			a.push("</tr>");
			
			a.push("<tr>");
			a.push("<td colspan='3' style=''><div  id='resetpwdbox' style='display:none' class='alert alert-warning alert-dismissible' > <button type='button' class='close'   bttype='resetpwdbt'><span aria-hidden='true'>&times;</span></button><input style='width:200px;float:left' id='resetpwd_pwd' class='form-control' type='password' maxlength='50' placeholder='设置6位密码' /><button class='btn btn-info' style='float:left' bttype='submitresetpwdbt' id='submitresetpwdbt' v='"+b.openid+"'>确定重置密码</button><div style='clear:both'></div><div class='checkbox'><label><input type='checkbox' value='1' checked='checked' id='initpwd' />重置后用户必须修改密码</label><br /><label><input type='checkbox' value='1' checked='checked' id='sendsms' />同时以短信发送密码给用户</label></div><div style='clear:both'></div></div></td>");
			a.push("</tr>");
			
			
			a.push("<tr>");
			a.push("<td colspan='3'><div id='setuserlevelbox' style='display:none;' class='alert alert-warning alert-dismissible'><button type='button' class='close'   bttype='setuserlevelbt'><span aria-hidden='true'>&times;</span></button><label>设置用户类型</label><br /><select class='form-control' id='accounttype' style='float:left;width:75%'><option value='1'>工资查询人</option><option value='2'>工资管理员</option><option value='3'>系统管理员</option></select><button class='btn btn-success' bttype='saveuserlevelsetbt' id='saveuserlevelsetbt' style='width:25%;float:left'  v='"+b.openid+"'>保存</button><div style='clear:both'></div></div></td>");
			a.push("</tr>");
			
			a.push("<tr>");
			a.push("<td colspan='3' style='text-align:center'>");
			a.push("<button class='btn btn-"+(b.status==0?"success":"default")+"' style='width:120px;margin-right:2rem' bttype='setstatusbt' status='"+b.status+"' v='"+b.openid+"'>"+(b.status==1?"点击禁用":"点击启用")+"</button>");
			a.push("<button class='btn btn-info' style='width:120px;margin-right:2rem' bttype='setuserlevelbt'>用户类型</button>");
			a.push("<button class='btn btn-warning' style='width:120px;margin-right:2rem' bttype='resetpwdbt'>重置密码</button>");
			a.push("<button class='btn btn-danger' style='width:120px;' bttype='deluserbt'  v='"+b.openid+"'>删除</button>");
			a.push("</td>");
			a.push("</tr>");
			
			a.push("</table>");
			$("#modal_setbox").find("div[class='modal-body']").html(a.join(""));
			$("#accounttype").val(b.accounttype);
          }, "json");
    }



    function loadlist(o) {
        $("#"+o.mask).modal("show");
        $.get("user_load.aspx", o, function (d) {
            var a = [];
            var b = d.list;
            var v = "";
			
			$("#updatenotice").html("当前用户数："+d.usernum_curr+",授权用户数："+d.usernum+",请到“系统管理”中升级帐户以增加用户数");
			
            o.pagenum = d.pagenum;
            o.recordnum = d.recordnum;
            a.push("<table class='table'>");
            a.push("<tr>");
            a.push("<th>#</th>");
            a.push("<th>名称</th>");
            a.push("<th>状态</th>");

            a.push("<th>用户类型</th>");
            a.push("<th>登录次数</th>");
            a.push("<th>最后登录</th>");
            a.push("<th>创建日期</th>");
            a.push("<th>设置</th>");
            a.push("</tr>");
            for (var i = 0; i < b.length; i++) {
                a.push("<tr v='" + b[i].openid + "'>");
                a.push("<td>" + (i + 1) + "</td>");
                a.push("<td>" + b[i].openid + "[" + b[i].nickname + "]" + "</td>");
                a.push("<td><span class='fa  fa-check-circle' bttype='setstatusbt' v='" + b[i].openid + "' status='" + b[i].status + "'> </td>");

                a.push("<td>" + b[i].accounttypename + "</td>");
                a.push("<td>" + b[i].loginnum + "</td>");
                a.push("<td>" + b[i].lastlogin + "</td>");
                a.push("<td>" + b[i].createdate + "</td>");
                a.push("<td><span class='fa fa-cog' bttype='setcogbt'  v='" + b[i].openid + "'> 设置</span></td>");
                a.push("</tr>");
            }
            a.push("</table>");
            $("#" + o.listbox).html(a.join(""));
            $("#" + o.mask).modal("hide");
            createpage(loadlist, o);

        }, "json");
    }

</script>