<%@ page language="C#" autoeventwireup="true" inherits="go_issue, 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="Issue" />
<style type="text/css">
   #list{
	   background:#fff;
	   box-sizing:border-box;
	   padding:1rem;
	   min-height:300px;
	   border-radius:0.5rem;
   }
   .table tr{
	   cursor:pointer;
	   background:#fff;   
   }
   .table tr:hover{
	   cursor:pointer;
	   background:#eee;
   }
   td[isbt='yes']:hover{
	   color:#fff;
	   background:#f60;
   }
   body{
   }
   
   #salarydetailtable td[data-is='1']:hover{
	background-color:#eee;
	background-image:url(img/eneditflag.png);
	background-repeat:no-repeat;
	background-position:right top;
}
</style>

<div class="container">
	<div style="box-sizing:border-box; padding:1rem">
	<button class="btn btn-default" style="float:right; margin:1rem" bttype="exportstbt"><i class="fa fa-file-excel-o" bttype="exportstbt">导入excel工资表</i></button>

	<button class="btn btn-default" style="float:right; margin:1rem" bttype="newstbt"><i class="fa fa-plus" bttype="newstbt">手动创建工资表</i></button>

	</div>
	<div style="clear:both"></div>
  <div id="list" class="col-4"></div>
  <div style="height:3rem"></div>
</div>

<div class="modal fade" tabindex="-1" role="dialog" id="modal_st">
  <div class="modal-dialog" role="document" style="width:80%">
    <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">
        <form style="margin:0px;color:#333; float:left; display:block; border:0px solid #000" method="post" name="myform" enctype="multipart/form-data"    id="myform" action="doupload.aspx" target="targetwin">
						<label >
							<input type="file" name="myfile" class="form-control" id="myfile"/>
						</label>
					</form>
					<button class="btn btn-default" onclick="submitform(window.event)">导入</button>

					<div style="clear:both"></div>
					<hr />
					
					<iframe id="targetwin" name="targetwin" style="display: none"></iframe>
				<div id="body" style="display: none; ">
					<div style="text-align:center;">
						<select id="year" class="form-control" style="width: 15%; float: left">
						</select>
						<select id="month" class="form-control" style="width: 15%; float: left">
						</select>

						<select id="databeginrow" class="form-control"  style="width: 15%; float: left;">
						</select>
						<select id="dataendrow" class="form-control"  style="width: 15%; float: left;">
						</select>
						<select id="headrow" class="form-control"  style="width: 15%; float: left;">
						</select>
						<select id="totalcolumn" class="form-control"  style="width: 15%; float: left;">
						</select>

						<select id="selectunits" class="form-control"  style="width: 15%; float: left; font-size:14px; display:none">
						</select>
						<button class="btn btn-success" type="button" style="width: 10%" bttype="issuebt"> 发布工资</button>
					</div>
					<div style="clear:both"></div>
					<div id="databox" style="overflow:auto;border:1px solid #000"></div>
					<div style="text-align:center">
						
					</div>
				</div>
				<div id="tipbox" style=" margin:0.5rem"> <span bttype="viewdemobt"  style="cursor:pointer"><span class="glyphicon glyphicon-info-sign" bttype="viewdemobt" >查看示例</span></span> </div>
				<div id="demo" style="display:none">
				<li class="list-group-item"> <h3>上传xls或xlsx格式文件</h3>
					<img src="img/demo0.png"id="demo0" /> </li>
				<li class="list-group-item"> <h3>工资表结构</h3>
					<img src="img/demo1.png" id="demo1" />
					</li>
					
				<li class="list-group-item">	<ul class="list-group">					
					<li class="list-group-item list-group-item-danger">注意事项：</li>
					<li class="list-group-item">1、工资表位于文件中的第一个工作表(注意，不要有密码,不要有公式、不要有宏)</li>
					<li class="list-group-item">2、工资表中的第一列为手机号，用户通过此手机号接收验证码登录工资查查查询到与之关联的工资数据</li>
					<li class="list-group-item">3、工资表最大导入50列，一个工资表最大1000行，如果工资表超出1000行，可分解为多个工资文件分次上传导入</li>
					<li class="list-group-item">4、每列最多25个汉字，或者50个英文字符</li>
					</ul></li>
				</div>
      </div>
     
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->



<div class="modal fade" tabindex="-1" role="dialog" id="modal_info">
  <div class="modal-dialog" role="document" style="width:80%">
    <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"   id="salarytabledetail">

	  <div style="overflow:auto; float:left;width:100%" id="salarytabledetailbox"></div>
	  <div style="float:left;display:none; box-sizing:border-box; padding-left:2rem" id="addsalarydetailbox">
	  	<div style="overflow:auto"></div>
		<button class="btn btn-success" style=" width:100%" bttype="addsalarydetailbt">保存工资明细</button>
	  </div>
	  <div style="clear:both; height:1rem"></div>
	  <button class="btn btn-info" bttype="sendsalarynoticebt">发送工资发布短信通知</button>
	  <select class="form-control" style="float:left;width:200px" id="sendtarget">
		  <option value="">选择发送对象</option>
	  	<option value="all">发送给所有人</option>
	  	<option value="notview">发送给未阅工资的人</option>
	  </select>
  	  <button class="btn btn-info" style="float:right" bttype="newsalarydetailbt">增加一条工资记录</button>

  	  <button class="btn btn-danger" style="float:right; margin-right:2rem" bttype="delsalarydetailbt">删除所选择工资</button>
	  </div>    
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<div style="z-index:999999" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" id="modal_editsinglesalary">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
		
	<div class="input-group  input-group-lg">
	<input type="hidden" id="modifydata_id" value="" />
	<input type="hidden" id="modifydata_tableid" value="" />
	<input type="hidden" id="modifydata_c" value="" />
	<input type="text" maxlength="25" id="modifydata_v" class="form-control" style="border:none" value="" />
  <span class="input-group-addon" id="basic-addon2"><button bttype="savecellvaluebt" class="btn btn-warning">修改</button>
</div>
    </div>
  </div>
</div>


<div class="modal fade" tabindex="-1" role="dialog"  id="salarydetailwin">
	<div class="modal-dialog" role="document"  style="width:98%; margin:auto; margin-top:1rem">
		<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" id="salarydetailwin_title">Modal title</h4>
			</div>
			<div class="modal-body" style="overflow:auto; height:300px"> </div>
		</div>
		<!-- /.modal-content --> 
	</div>
	<!-- /.modal-dialog --> 
</div>
<!-- /.modal -->



<div class="modal fade" tabindex="-1" role="dialog"  id="modal_addst">
	<div class="modal-dialog" role="document"  style="width:80%; margin:auto; margin-top:1rem">
		<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;">
				<select id="year_new" class="form-control" style="width:25%; float:left"></select>
				<select id="month_new" class="form-control" style="width:25%; float:left"></select>
				<select id="totalcol_new" class="form-control" style="width:25%; float:left"><option value="">工资合计所在列</option></select>
			<button type="button" class="btn btn-success" style="float:left;width:25%" bttype="donewstbt">创建</button>
				
				<div class="panel panel-default" style="margin-top:5rem">
  <div class="panel-heading">定义工资表字段</div>
  <div class="panel-body">
    <select id="templete" class="form-control"><option>使用预设工资模板</option></select>				
	<textarea id="field" class="form-control" rows="15" placeholder="工资表字段"></textarea>
	<div style="clear:both"></div>
	<div><span class="fa fa-info" style="color:#999"> 每行表示工资表中的一列，第一行固定为手机号，无需输入</span></div>
  </div>
</div>
			</div>
		</div>
		<!-- /.modal-content --> 
	</div>
	<!-- /.modal-dialog --> 
</div>
<!-- /.modal -->



<div class="modal fade" tabindex="-1" role="dialog" id="modal_confirm">
  <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">
        <p>
		<textarea id="confirmcontent" class="form-control"></textarea>
		<button bttype='rebt' id="rebt" tableid='' v='' class="btn btn-success" style="margin-top:1rem">回复</button>
		</p>
		<div class="panel panel-default" id="msglist"></div>
      </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 $templete = [{"name":"模板一","id":"1","th":["姓名","实发合计","应发合计","扣款合计","基本工资","绩效工资","加班工资","全勤奖历","社保"]},{"name":"模板二","id":"2","th":["姓名","实发合计","应发合计","扣款合计","实发合计","个人所得税","基本工资","岗位工资","工龄工资","绩效工资","加班工资","全勤奖历","社保","公积金","交通补助","餐补","住房补助","高温补助","其它补助"]}];
var $curreditobj = null;
$(document).ready(function (e) {	
   	createMask("mymask");
	loadsalarytable();
	$("#myform").bind("change", function (e) {
       	submitform();
   	});
	
	$("#templete").bind("change",fillTemplete);
	$("#field").bind("change",function(){
		var a = $("#field").val().split("\n");
		fillTotalCol(a);
		
	});
	//$("#modal_addst").modal("show");
		var d = new Date();
        fillselect("y", 2010, d.getFullYear(), "year", d.getFullYear());
        fillselect("m", 1, 12, "month", d.getMonth() + 1);
		
		fillselect("y", 2010, d.getFullYear(), "year_new", d.getFullYear());
        fillselect("m", 1, 12, "month_new", d.getMonth() + 1);
		
		var temp = "<option value=''>使用预设工资模板</option>";
		for(var i = 0;i<$templete.length;i++){
			temp+="<option value='"+$templete[i].id+"'>"+$templete[i].name+"</option>";
		}
		$("#templete").html(temp);
		
		$("#salarytabledetail").bind("click",showedittool);
		$("#databox").css("height",$(window).height()-300)
		$("#modal_info").find("div[class='modal-dialog']").css({"width":$(window).width()-80,"height":$(window).height()-80,"top":-20});
		$("#salarytabledetail").css("height",$(window).height()-120);
		$("#salarytabledetailbox").css("height",$(window).height()-200);
		$("#addsalarydetailbox").find("div").css("height",$(window).height()-240)
		
		$("#totalcolumn").bind("change", function (e) {
            selectcol($(e.target).val());
        });
		
		$("#sendtarget").bind("change",function(e){
			doselect($(e.target).val());
		});
		
        $("#databeginrow,#dataendrow,#headrow").bind("change", function (e) {
            var t = $(e.target);

            if (t.attr("id") == "databeginrow") {
                changeselectrow(t.val(), "begin");
            }
            else if (t.attr("id") == "dataendrow") {
                changeselectrow(t.val(), "end");
            }
            else if (t.attr("id") == "headrow") {
                changeselectrow(t.val(), "head");
            }
        });
		
        $(this).bind("click", function (e) {
            var t = e.target;
            var bttype = $(t).attr("bttype");
			var v =  $(t).parents("tr").attr("v");
            switch (bttype) {
				
				case "exportstbt":
					exportst();
					break;
				case "newstbt":
					newst();
					break;
				case "issuebt":
					issue();
					break;
				case "infobt":
					showinfo(v);
					break;
				case "savecellvaluebt":
					savemodifysinglesalary($curreditobj);
					break;
				case "setstatusbt":
					setstatus(v);
					break;
				case "delbt":
					delsalarytable(v);
					break;
				case "donewstbt":
					donewst();
					break;
				case "addsalarydetailbt":
					addsalarydetail();
					break;
				case "viewdemobt":
					$("#demo").fadeToggle(500);
					break;
				case "newsalarydetailbt":
					newsalarydetail();
					break;
				case "counterselectbt":
					counterselect();
					break;
				case "sendsalarynoticebt":
					sendsalarynotice();
					break;
				default:
					selecttd(t);
					break;
				case "confirmsalarybt":
					confirmsalary_load(t);
					break;
				case "rebt":
					re(t);
					break;
				case "delsalarydetailbt":
					delsalarydetail();
					break;
				
            }
        });
    });
	
function delsalarydetail(){
	
	var a = [];
	$("input[name='selectdetail']").each(function(index, element) {
		if($(this).get(0).checked ){
			a.push($(this).get(0).value);
		}
	});
	
	if(a.length==0){
		msgbox("请选择需要删除的对象","warning");
		return;	
	}
	
	if(!confirm("确定删除吗")){
		return;	
	}
	
	var o = {};
	o.mob = a.join(",");
	o.tableid = $("#modal_info").attr("tableid");
	$("#mymask").modal("show");
	
	
	$.post("admin_salarydetail_del.aspx",o,function(d){
		$("#mymask").modal("hide");
		$("#modal_info").modal("hide");		
		if(d.result=="ok"){
			msgbox("删除了"+d.num+"条工资","success");	
		}
		else{
			msgbox("删除了失败","warning");	
		}
	},"json");
}


function re(t){
	var o = {};
	o.tableid = $(t).attr("tableid");	
	o.id = $(t).attr("v");	
	o.msg = $("#confirmcontent").val();
	if(o.msg==""){
		msgbox("请输入回复内容","warning");
		return;	
	}
	
	$.post("admin_reconfirm.aspx",o,function(d){
		var a = [];
		if(d.result=="ok"){
			var list = d.list;
			if(list!=null){
				for(var i =0;i<list.length;i++)	{
					a.push("<li class='list-group-item' style='padding:1rem'>");
					a.push("<div class='smallico' style='margin-top:0.5rem;background-image:url(img/ico/"+list[i].icon+")'></div>");
					a.push("<div>");
					a.push(list[i].send);
					a.push("<span style='float:right'>"+list[i].createdate+"</span>");
					a.push("</div>");
					a.push("<p>"+list[i].memo+"</p>");
					a.push("</li>");
				}
			}
		}
		else{
			a.push("产生错误:"+d.result);
			msgbox("产生错误:"+d.result,"warning");
		}
		$("#msglist").html(a.join(""));
	},"json");
}
	
function confirmsalary_load(t){
	$("#modal_confirm").modal("show");
	var o = {};
	o.tableid = $(t).attr("tableid");
	o.id = $(t).attr("v");
	$("#msglist").html("载入中...");
	$("#rebt").attr("tableid",o.tableid);
	$("#rebt").attr("v",o.id);
	$.get("admin_confirmsalary_load.aspx",o,function(d){
		var a = [];
		var list = d.list;
		if(list!=null){
			for(var i =0;i<list.length;i++)	{
				a.push("<li class='list-group-item' style='padding:1rem'>");
				a.push("<div class='smallico' style='margin-top:0.5rem;background-image:url(img/ico/"+list[i].icon+")'></div>");
				a.push("<div>");
				a.push(list[i].send);
				a.push("<span style='float:right'>"+list[i].createdate+"</span>");
				a.push("</div>");
				a.push("<p>"+list[i].memo+"</p>");
				a.push("</li>");
			}
		}
		$("#msglist").html(a.join(""));
	},"json");
}

function sendsalarynotice(){
	var a = [];
	$("input[name='selectdetail']").each(function(index, element) {
		if($(this).get(0).checked ){
			a.push($(this).get(0).value);
		}
	});
	if(a.length==0){
		msgbox("请选择发送对象","warning");
		return;	
	}
	
	if(!confirm("确定发送吗?")){
		return;	
	}
	
	var o = {};
	o.mob = a.join(",");
	
	o.sendtype = "soft_issuesalary";
	o.sendall = "yes";
	o.tableid = $("#modal_info").attr("tableid");
	$("#mymask").modal("show");
	$.post("sendsms.aspx",o,function(d){
		$("#mymask").modal("hide");
		switch(d.result){
			case "ok":
				msgbox( d.sendnum+"条工资通知已经发送","success");
//				countDown("sendmobcc_reg_bt",60,60);
				break;
			case "timeover":
				msgbox("图形码超时","danger");
				break;
			case "checkcodebad":
				msgbox("验证非法，请重新发送验证码","danger");
				break;
			case "retryover":
				msgbox("错误次数过多，请重新获取图形码","danger");
				break;
			case "ccerr":
				msgbox("验证码错误","danger");
				break;
			case "nullvalue":
				msgbox("请点击\"图形码，点击刷新\"","danger");
				break;
				
			case "urltimeover":
				msgbox("url超时","danger");
				break;
			case "softnotfound":
				msgbox("未找到软件注册信息","danger");
				break;
			case "softsignerr":
				msgbox("软件签名错误","danger");
				break;
			case "smsnumover":
				msgbox("短信配额已经用完","danger");
				break;
			case "smstasknumover":
				msgbox("可用短信数不足以完成任务","danger");
				break;
		}
	},"json")
}

function newsalarydetail(){
	if($("#addsalarydetailbox").css("display")=="none"){
		$("#salarytabledetailbox").css("width","60%");	
		$("#addsalarydetailbox").css({"width":"40%","display":"block"});
	}
	else{
		$("#salarytabledetailbox").css("width","100%");	
		$("#addsalarydetailbox").css({"width":"40%","display":"none"});	
	}
}

function fillTemplete(e){
	var v = $(e.target).val();
	for(var i=0;i<$templete.length;i++){
		if($templete[i].id*1==v*1)	{
			$("#field").val($templete[i].th.join("\n"));
			fillTotalCol($templete[i].th);
			break;	
		}
	}
}


function fillTotalCol(th){
	var a = [];
	a.push("<option value=''>工资合计所在列</option>");
	for(var i=0;i<th.length;i++){
		a.push("<option value='"+(i+2)+"'>第"+(i+2)+"列:"	+th[i]+"</option>");
	}
	$("#totalcol_new").html(a.join(""));
}

function setrow(rownum){
	var a=[];
	for(var i=2;i<=rownum;i++)	{
		a.push("第"+i+"行");
	}
	$("#field_sn").val(a.join("\n"));
}
function addsalarydetail(){
	var o = {};
	o.tid = $("#modifydata_tableid").val();
	o.v = "";
	var list = $("input[isdata='1']");
	for(var i=0;i<list.length;i++){
		if(i==0){
			if(  $(list[i]).val()=="")	{
				//msgbox("请输入手机号","waring");	
				alert("请输入手机号"+$(list[i]).val());
				$(list[i]).focus();
				
				return;	
			}
			if(!$(list[i]).val()._Mob())	{
				msgbox("手机号格式错误","waring");	
				alert("手机号格式错误");
				$(list[i]).focus();
				return;	
			}
		}
		o.v += $(list[i]).val()+"\n";
	}
	$.post("salarydetail_input.aspx",o,function(d){
		if(d.result=="ok"){
			msgbox("保存成功","success");				
			showinfo(o.tid);
		}
		else{
			msgbox("未成功保存","waring");	
		}
	},"json");
}

function newst(){
	$("#modal_addst").modal("show");
	
}
function donewst(){
	var o = {};
	o.month = $("#month_new").val();
	o.year = $("#year_new").val();
	o.th = $("#field").val();
	o.totalcol = $("#totalcol_new").val();
	if(o.th==""){
		msgbox("请定义工资表字段","warning");	
		$("#field").val();
		return;		
	}
	if(o.th.split('\n')>=50){
		msgbox("工资表最多只能有50列","warning");	
		$("#field").val();
		return;	
	}
	
	if(o.totalcol==""){
		msgbox("请设置工资合计所在列","warning");
		$("#totalcol_new").val();	
		return;		
	}
	
	
	o.modifytid = $("#modifytid").val();
	$("#mymask").modal("show");
	$.post("savest.aspx",o,function(d){
		$("#mymask").modal("hide");
		$("#modal_addst").modal("hide");
		if(d!="notlogin"){
			msgbox("保存完成","success");	
			showinfo(d);
		}
		else{
			msgbox("登录超时","warning");	
		}
		loadsalarytable();
		
	},"text");
}



function setstatus(v){
	var o = {};
	o.tableid = v;
	$("#mymask").modal("show");
	$.get("salarytable_setstatus.aspx",o,function(d){
		$("#mymask").modal("hide");
		if(d.result=="ok"){
			msgbox("设置成功","success");	
			loadsalarytable();
		}
		else{
			msgbox("未成功设置","warning");	
		}
	},"json");
}

function delsalarytable(v){
	if(!confirm("确定删除吗")){
		return;	
	}
	var o = {};
	o.tableid = v;
	$("#mymask").modal("show");

	$.get("salarytable_del.aspx",o,function(d){
		$("#mymask").modal("hide");
		if(d=="ok"){
			msgbox("删除成功","success");	
			loadsalarytable();
		}
		else{
			msgbox("未成功删除","warning");	
		}
	},"text");
}
function savemodifysinglesalary(t){
	$("#modal_editsinglesalary").modal("hide");
	$(t).html($("#modifydata_v").val());
	var o = {};
	o.tableid = $("#modifydata_tableid").val();
	o.id =  $("#modifydata_id").val();
	o.value = $("#modifydata_v").val();
	o.c = $("#modifydata_c").val();
	$("#mymask").modal("show");
	$.post("salarydata_submitmodify.aspx",o,function(d){
		if(d.result=="ok"){
			msgbox("保存完成","success")
			$(t).html(d.value);
		}
		else{
			msgbox(d.msg,"warning")	
		}
		$("#mymask").modal("hide");
	},"json");
	
}

function counterselect(){
	$("input[name='selectdetail']").each(function(index, element) {
		$(this).get(0).checked = !$(this).get(0).checked;
	});
}

function doselect(v){
	$("input[name='selectdetail']").each(function(index, element) {
		$(this).get(0).checked = "";
	});
	
	if(v=="all"){
		$("input[name='selectdetail']").each(function(index, element) {
			$(this).get(0).checked = "checked";
		});
	}
	else if(v=="notview"){
		$("input[name='selectdetail']").each(function(index, element) {
			$(this).get(0).checked = $(this).attr("viewed")=="0";
		});	
	}	
}


function showinfo(v){
	$("#modifydata_tableid").val(v);
	var o = {};
	o.tid = v;
	o.r = Math.random();
	$("#mymask").modal("show");
	$.get("salarytabledetail_load.aspx",o,function(d){
		$("#mymask").modal("hide");
		$("#modal_info").modal("show");
		$("#modal_info").attr("tableid",v);
		var a = [];
		var b = d.list;
		
		$("#modal_info").find("h4[class='modal-title']").html(d["year"]+"年"+d["month"]+"月工资");

		a.push("<table class='table' id='salarydetailtable'>");
		a.push("<tr>");
		a.push("<th><label><input type='checkbox' bttype='counterselectbt' >反选</label></th>");
		a.push("<th></th>");
		a.push("<th>状态</th>");
		a.push("<th>确认</th>");
		a.push("<th>清除</th>");
		for(var j=0;j<d.head.length;j++){
			a.push("<th nowrap>"+d.head[j]+"</th>");	
		}
		a.push("</tr>");

		var stat = [0,0];
		if(b!=null){
			for(var i=0;i<b.length;i++){
				a.push("<tr data-id='"+b[i].id+"'>");	
				a.push("<td><input type='checkbox' name='selectdetail' value='"+b[i].value[0]+"' viewed='"+b[i].viewed+"'></td>");	
				a.push("<td>"+(i+1)+"</td>");	
				a.push("<td nowrap>"+(b[i].viewed==1?"<span class='label label-success'>已阅</span>":"<span class='label label-default'>未阅</span>")+"</td>");
				if(b[i].audit=="1"){
					a.push("<td nowrap><span class='label label-success'>已确认</span></td>");
				}
				else if(b[i].audit=="2"){
					a.push("<td nowrap><span class='label label-danger'><span class='fa fa-info' bttype='confirmsalarybt'   v='"+b[i].id+"' tableid='"+v+"'> 有问题</span></span></td>");
				}
				else{
					a.push("<td nowrap><span class='label label-default'>未确认</span></td>");
				}
				
				if(b[i].userclear==1){
					a.push("<td nowrap><span class='label label-default' title='已经由用户清除'>已清除</span></td>");
				}
				else{
					a.push("<td nowrap><span class='label label-success'>正常</span></td>");
				}
				for(var j=0;j<b[i].value.length;j++){
					a.push("<td nowrap data-is='1'  data-c='"+(j+1)+"'>"+b[i].value[j]+"</td>");	
				}
				stat[b[i].viewed]++;
				a.push("</tr>");	
			}
		}
		a.push("</table>");
		$("#salarytabledetailbox").html("<div>共"+d["datanum"]+"条记录,未阅<span style='color:#f60'>"+stat[0]+"</span>条,已阅<span style='color:#3a3'>"+stat[1]+"</span>条,发布于:"+d["createdate"]+",当前"+(d["status"]==1?"<span style='color:#3a3'>启用</span>":"<span style='color:#f60'>禁用</span>")+"</div>"+a.join(""));
		buildSalaryDetailEdit(d.head);
		
	},"json");
}
	
function selectcol(v) {
	$("#datatable").find("td[bttype='colbt']").css({ "background": "#fff", "color": "#000" });
	$("#datatable").find("td[bttype='colbt'][v='" + v + "']").css({ "background": "#3a3", "color": "#fff" });
}

function selecttd(t) {
        var bttype = $(t).attr("bttype");
        var v = $(t).attr("v");
        if (bttype == "colbt") {
            $("#datatable").find("td[bttype='colbt']").css({ "background": "#fff", "color": "#000" });
            $(t).css({ "background": "#3a3", "color": "#fff" });
            $("#totalcolumn").find("option[value='" + v + "']").get(0).selected = true;
        }
        else if (bttype == "rowbt") {
            $("#databeginrow").find("option[value='" + v + "']").get(0).selected = true;
            changeselectrow(v, "begin");
        }
        else if (bttype == "headbt") {
            $("#headrow").find("option[value='" + v + "']").get(0).selected = true;
            changeselectrow(v, "head");
        }
    }
	
	
 function changeselectrow(v, s) {
        if (s == "begin") {
            $("#datatable").find("td[bttype='rowbt']").css({ "background": "#fff", "color": "#000" });
            $("#datatable").find("td[bttype='rowbt']").attr("select", "");
            $("#datatable").find("td[bttype='rowbt'][v='" + v + "']").css({ "background": "#f60", "color": "#fff" });
            $("#datatable").find("td[bttype='rowbt'][v='" + v + "']").attr("select", "yes");
            $("#dataendrow").find("option[value='0']").get(0).selected = true;
        }
        else if (s == "end") {
            if ($("#datatable").find("td[bttype='rowbt'][select='yes']").length >= 1) {
                var begin = $("#datatable").find("td[bttype='rowbt'][select='yes']:first").attr("v");
                v = parseInt(v);
                begin = parseInt(begin);
                if (parseInt(v) < parseInt(begin)) {
                    msgbox("结束行不能小于开始行", "danger");
                    return;
                }
                else {
                    $("#datatable").find("td[bttype='rowbt']").css({ "background": "#fff", "color": "#000" });
                    for (var i = begin; i <= v; i++) {
                        $("#datatable").find("td[bttype='rowbt'][v='" + i + "']").css({ "background": "#3a3", "color": "#fff" });
                    }
                }
            }
            else {
                msgbox("请先设置工资数据开始行", "danger");
            }
        }
        else if (s == "head") {
            $("#datatable").find("td[bttype='headbt']").html("");
            $("#datatable").find("td[bttype='headbt'][v='" + v + "']").html("<span class='glyphicon glyphicon-hand-right' title='表头所在行' style='color:#3a3'></span>");

        }
    }
	
	
	   function selecttd(t) {
        var bttype = $(t).attr("bttype");
        var v = $(t).attr("v");
        if (bttype == "colbt") {
            $("#datatable").find("td[bttype='colbt']").css({ "background": "#fff", "color": "#000" });
            $(t).css({ "background": "#3a3", "color": "#fff" });
            $("#totalcolumn").find("option[value='" + v + "']").get(0).selected = true;
        }
        else if (bttype == "rowbt") {
            $("#databeginrow").find("option[value='" + v + "']").get(0).selected = true;
            changeselectrow(v, "begin");
        }
        else if (bttype == "headbt") {
            $("#headrow").find("option[value='" + v + "']").get(0).selected = true;
            changeselectrow(v, "head");
        }
    }


 
 function loadsalarytable(){
	 var o = {};
	$("#mymask").modal("show");
	$.get("salarytable_load.aspx",o,function(d){
	$("#mymask").modal("hide");
		var a = [];
		var b = d.list;
		if(b!=null){
		a.push("<table class='table'>");
		for(var i=0;i<b.length;i++){
			a.push("<tr v='"+b[i].id+"'>");	
			a.push("<td>"+(i+1)+"</td>");
			a.push("<td>"+b[i].year+"年/"+b[i].month+"月</td>");
			if(b[i].status==0){
				a.push("<td ><span class='fa fa-circle' isbt='yes' style='color:#999' bttype='setstatusbt'  data-toggle='tooltip' data-placement='top' title='当前禁用，点击启用'>禁用</span></td>");	
			}
			else{
				a.push("<td ><span class='fa fa-circle' isbt='yes' style='color:#3a3' bttype='setstatusbt'  data-toggle='tooltip' data-placement='top' title='当前启用，点击禁用'>启用</span></td>");	
			}
		
			a.push("<td><span class='fa fa-remove'  isbt='yes' bttype='delbt'>删除</span></td>");
			a.push("<td isbt='yes' bttype='infobt'><span class='fa fa-info' bttype='infobt'>详情</span></td>");
			a.push("</tr>");	
		}
		a.push("</table>");
		}
		else{

			a.push("<div class='alert alert-warning'>没有工资表</div>");	
		}
		
		$("#list").html(a.join(""));
		$(function () {
			$('[data-toggle="tooltip"]').tooltip()
		})
	},"json");
 }
 
 
 function exportst(){
	 $("#body").css("display","none");
	 $("#databox").html("");
	 $("#modal_st").modal("show");
 }
 
 
 function doupload(v) {
        $.get("anaexcel.aspx", function (d) {
			switch(d.m){
				case "ok":
					var rownum = parseInt(d["row"]);
					var colnum = parseInt(d["col"]);
					$("#uploadwin").modal("show");
					fillselect("c", 2, colnum, "totalcolumn");
					fillselect("r0", 2, rownum, "databeginrow");
					fillselect("r1", 2, rownum, "dataendrow");
					fillselect("h", 1, rownum, "headrow");
					$("#body").fadeIn(1000);
					
					var a = [];
					var list = d.list;
					a.push("<table class='table' id='datatable'>");
					a.push("<tr><td></td><td></td><td>列1(手机号)</td>");
					for(var j=1;j<d["col"];j++){
						a.push("<td bttype='colbt' v='"+(j+1)+"'>列"+(j+1)+"</td>");	
					}					
					a.push("<tr>");
					for(var i=0;i<list.length;i++){
						

						a.push("<tr>");
						a.push("<td bttype='headbt' v='"+(i+1)+"'></td>");
						a.push("<td bttype='rowbt' v='"+(i+1)+"'>"+(i+1)+"</td>");
						for(var j=0;j<d["col"];j++){
							a.push("<td>"+list[i]["r"+j]+"</td>");	
						}
						a.push("</tr>");
					}
					a.push("</table>");
					$("#databox").html(a.join(""));
					$("#mymask").modal("hide");
					

					break;
				case "row":
					$("#mask").modal("hide");
					msgbox("数据至少要有一行","danger");
					break;
				case "col":
					$("#mask").modal("hide");
					msgbox("数据至少要有两列","danger");
					break;
			}
			
        }, "json")
    }
	

	
 function submitform() {

        var path = $("#myfile").val();

        if (path == "") {
            msgbox("请选择文件", "danger", [100, 100]);
            return;
        }
        else {
			
            
            var temp = path.split(".")[path.split(".").length - 1];
            if ((temp.toLowerCase() != 'xls') && (temp != "xlsx")) {
                msgbox("请上传excel文件", "danger");
				$("#mask").modal("hide");
                return;
            }
			$("#mask").modal("show");
			$("#uploadwin").modal("hide");
            $("#myform").submit();

        }

    }

function fillselect(v, n0, n1, id, defaultvalue) {
        var a = [];
        var o = $("#" + id);
        switch (v) {
            case "y":
                a.push("<option value='0'>工资年份</option>");
                for (var i = n0; i <= n1; i++) {
                    a.push("<option value='" + i + "'>" + i + "年</option>");
                }
                o.html(a.join(""));
                if (defaultvalue) {
                    o.find("option[value='" + defaultvalue + "']").get(0).selected = true;
                }
                break;
            case "m":
                a.push("<option value='0'>工资月份</option>");
                for (var i = n0; i <= n1; i++) {
                    a.push("<option value='" + i + "'>" + i + "月</option>");
                }
                o.html(a.join(""));
                if (defaultvalue) {
                    o.find("option[value='" + defaultvalue + "']").get(0).selected = true;
                }
                break;
            case "c":
                a.push("<option value='0'>工资合计所在列</option>");
                for (var i = n0; i <= n1; i++) {
                    a.push("<option value='" + i + "'>第" + i + "列</option>");
                }
                o.html(a.join(""));
                if (defaultvalue) {
                    o.find("option[value='" + defaultvalue + "']").get(0).selected = true;
                }
                break;
            case "r0":
                a.push("<option value='0'>工资数据开始行</option>");
                for (var i = n0; i <= n1; i++) {
                    a.push("<option value='" + i + "'>第" + i + "行</option>");
                }
                o.html(a.join(""));
                if (defaultvalue) {
                    o.find("option[value='" + defaultvalue + "']").get(0).selected = true;
                }
                break;
            case "r1":
                a.push("<option value='0'>工资数据结束行</option>");
                for (var i = n1; i >= n0; i--) {
                    a.push("<option value='" + i + "'>第" + i + "行</option>");
                }
                o.html(a.join(""));
                if (defaultvalue) {
                    o.find("option[value='" + defaultvalue + "']").get(0).selected = true;
                }
                break;
            case "h":
                a.push("<option value='0'>表头所在行</option>");
                for (var i = n0; i <= n1; i++) {
                    a.push("<option value='" + i + "'>第" + i + "行</option>");
                }
                o.html(a.join(""));
                if (defaultvalue) {
                    o.find("option[value='" + defaultvalue + "']").get(0).selected = true;
                }
                break;
        }

    }
	
 function issue() {
        var o = {};
        o.databeginrow = $("#databeginrow").val();
        o.dataendrow = $("#dataendrow").val();
        o.headrow = $("#headrow").val();
        o.totalcolumn = $("#totalcolumn").val();
        o.year = $("#year").val();
        o.month = $("#month").val();
        o.unitsid = $("#selectunits").val();

        if (o.year == "0") {
            msgbox("请选择工资年份", "danger");
            $("#year").focus();
            return;
        }
        if (o.month == "0") {
            msgbox("请选择工资月份", "danger");
            $("#month").focus();
            return;
        }
        if (o.databeginrow == "0") {
            msgbox("请选择工资数据开始行", "danger");
            $("#databeginrow").focus();
            return;
        }
        if (o.dataendrow == "0") {
            msgbox("请选择工资数据结束行", "danger");
            $("#dataendrow").focus();
            return;
        }
        if (o.headrow == "0") {
            msgbox("请选择表头所在行", "danger");
            $("#headrow").focus();
            return;
        }
        if (o.totalcolumn == "0") {
            msgbox("请选择工资合计所在列", "danger");
            $("#totalcolumn").focus();
            return;
        }

        $.get("doissue.aspx", o, function (d) {
            if (d!="err"){
				if(d*1>0){
    	            loadsalarytable();
					$("#modal_st").modal("hide");
					$("#qrcodewin").modal("show");
					$currtable = d*1;
					$("#sendsmsallbt").attr("data-v",d);
	                msgbox("发布成功", "success");
				}
				else{
					msgbox("发布完成，视乎出了点问题，代码："+d, "warning");
				}
			}
			else{
            	msgbox("发生错误", "danger");
			}
        }, "text");
    }


function showedittool(e){
	var t = e.target;
	if(t.tagName!="TD"){
		return;
	}
	if($(t).attr("data-is")!="1"){
		return;	
	}
	$curreditobj = t;
	var c = $(t).attr("data-c")*1;
	$("#modifydata_id").val($(t).parents("tr").attr("data-id"))
	$("#modal_editsinglesalary").modal("show");
	$("#modifydata_v").val($(t).html());
	$("#modifydata_c").val(c);
	$("#modifydata_v").focus();
}


function buildSalaryDetailEdit(th){
	var a = [];
	a.push("<table class='table'>");
	
	/*
	a.push("<tr>");
	for(var i=0;i<th.length;i++){
		a.push("<td>"+th[i]+"</td>");
	}
	a.push("</tr>");
	*/
	
	for(var i=0;i<th.length;i++){
		a.push("<tr>");
		a.push("<td>"+th[i]+"</td>");
		a.push("<td><input isdata='1' type='text' class='form-control' /></td>");
		a.push("</tr>");
	}
	a.push("</table>");
	$("#addsalarydetailbox").find("div").html(a.join(""));
}
</script>
