<#import "../../ftllib/spring_new.ftl" as spring />
<#import "../../ftllib/pagecom.ftl" as page />
<#import "../../ftllib/frame.ftl" as frame />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href='<@spring.url ""/>'/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>安全库存补货向导</title>
<link type="text/css" href="css/blue.css" rel="stylesheet">
<link type="text/css" href="css/table.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="javascript/jquery_easy_ui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="javascript/jquery_easy_ui/themes/icon.css">
<style>
	h3{height:20px;line-height:20px;padding-left:5px;}
	.ui-button { outline: 0; margin:0; padding: .4em 1em .5em; text-decoration:none;  !important; cursor:pointer; position: relative; text-align: center; }
	.current-step{display:'';height:100%;width:100%;}
	.step{display:none;height:100%;width:100%;}
	.table-container{height:80%;boder:3px solid #00;overflow-y:scroll;}
</style>
<script language="javascript" type="text/javascript" src="javascript/pic_change.js"></script>
<script type='text/javascript' src='javascript/myfunction.js'></script>
<script type='text/javascript' src="javascript/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="javascript/jquery_easy_ui/jquery.easyui.min.js" charset="utf-8"></script>
<script type='text/javascript' src="javascript/jquery.utils.js"></script>
<script type='text/javascript' src="javascript/convert.js"></script>
</head>
<script language="javascript"> 
var $_select = false;
//重设页面布局.
function resize(){
	$("#content_div").maximizeHeight({margin:20});	
}
function filter_materiel(){
	var val = $("#buyType").val();		
	$("#my_table>tbody>tr").hide();
	if(val != ""){
		$("#my_table>tbody>tr[buy_type='" + val + "']").show();
	}else{
		$("#my_table>tbody>tr").show();
	}
}
function make_order(type){
    var length=$("#content_div").find("input[type='checkbox'][name='mate'][checked='true']").length
    if(!length || length<=0){
       alert("请选择材料!");
	   return false;
    }
 	if(!confirm("该操作会根据材料采购方式创建采购计划或请求配送单，是否继续？")){
		return false;
	}
	var codes="";
	$("#content_div").find("input[type='checkbox'][name='mate'][checked='true']").each(function(i){
		if(codes==""){
			codes += "'"+$(this).attr("code")+"'";
		}else{
			codes += ",'"+$(this).attr("code")+"'";
		}
	});
	
	var param = {"command":"make_order","type":type,"codes":codes};	
	param["obj_date"] = $("#obj_date").val();
	$.post("<@spring.url "kc/guide/baseLimitOperate.html"/>",param,function(data){
		if(data == ''){
			alert("采购类型为【门店自采购】时,可生成采购计划");
		}else{
			$("#info_body_div").append(data);
			alert("生成单据成功");
		}
	});
}

function query_click(type){ 
	var param = {};
	param["widths"] = $("#my_table").widths();	
	param['buyType'] = $("#buyType").val();
	var sort_codes = $("#sort_codes").combotree("getValues");
	if(sort_codes && sort_codes!=""){
		sort_codes = "("+sort_codes+")";
	}
	param['sort_codes'] = sort_codes;
	
	if(type=="intalize"){
	  param['type']=type;
	}
	$("#content_div").load("<@spring.url "kc/guide/get_materiel_data.html"/>",param,function(data){
	    $("#content_div").find("input[type='text']").focus(function(){
			$(this).select();
			var $tr = $(this).closest("tr");
			if($_select){$_select.removeClass("selected");}
			$_select = $tr;
			$tr.addClass("selected");
		}).change(function(){			
			var $tr = $(this).closest("tr");			
			var param = {command:"set_number"};
			param["materiel_code"] = encodeURI($tr.attr("materiel_code"));
			param["number"] = $(this).val();										
			$.post("<@spring.url "kc/guide/baseLimitOperate.html"/>",param,function(data){
				if(data == "N"){
					alert("修改错误,请重新操作!");
				}
			});				
		}).keydown(function(){
			if(event.keyCode==13){
				event.keyCode=9;
			}
		});
	});	
}
function print_excel(){
	var param = {};
	param['buyType'] = $("#buyType").val();
	var sort_codes = $("#sort_codes").combotree("getValues");
	if(sort_codes && sort_codes!=""){
		sort_codes = "("+sort_codes+")";
	}
	param['sort_codes'] = sort_codes;
	window.open("<@spring.url "kc/guide/safestock_print_excel.html?"/>"+$.param(param));
}

function openOrder(url){
	W.OW(url,1024,800);
}

function checkAll(type,no){
	if(type==1){
		var checked=$("#checkAll").attr("checked");
		$("#content_div").find("input[type='checkbox'][name='cate']").each(function(i){
			$(this).attr("checked",checked);
		});
		$("#content_div").find("input[type='checkbox'][name='mate']").each(function(i){
			$(this).attr("checked",$("#checkAll").attr("checked"),checked);
		});
	}else{
		var checked=$("#cate"+no).attr("checked");	
		$("#content_div").find("input.cate"+no).each(function(i){		
			
			$(this).attr("checked",checked);
		});
	}
}


$(document.body).ready(function(){
	resize();	
	query_click("intalize");	
});
</script>
<body  class="easyui-layout">
<div id="header_div" region="north" border="false" style="height:90px;padding:5px;">
	  <@page.bodyTop>
		<@page.bodyTopLink>
			<@page.link "物流管理平台","kc/main_page.html"/>&nbsp;&gt;&nbsp;按安全库存自动补货
		</@page.bodyTopLink>
		<@page.bodyTopImage>
		<@page.topImageButton "back","history.go(-1);"/>
		</@page.bodyTopImage>
	  </@page.bodyTop>
	  <div style="width:99%;height:auto;margin-top:5px;">
			<span style="float:left;">
				<label>材料类别：</label>
				<input id="sort_codes" class="easyui-combotree" url="all/common/load_tree.html?tree=materiel_sort_tree_json" multiple='true' style="width:160px;"/>
			</span>
			<span style="float:left;margin-left:10px;">
				<label>采购类型：</label>
				<select id="buyType" name="buyType">
				    <option value="">全 部</option>
					<option value="0">采购</option>
					<option value="1">配送</option>
				</select>	
			</span>				
			<a href="javascript:void(0);" class="easyui-linkbutton"  style="float:left;margin-left:15px;" iconCls="icon-ok" onClick="query_click();">查询</a>
			<#if loginUser.getUserType()==1 && config.getItemVistor("kc_rest_enable","qp").booleanValue()>
			<#if rbac.checkByName("kc_qp")>
			<a href="javascript:void(0);" class="easyui-linkbutton"  style="float:left;margin-left:15px;" iconCls="icon-ok" onClick="make_order('qpd');">生成请配单</a>	
			</#if>
			</#if>
			<a href="javascript:void(0);" class="easyui-linkbutton"  style="float:left;margin-left:15px;" iconCls="icon-ok" onClick="make_order('cgjh');">生成采购计划</a>	
			<a href="javascript:void(0);" class="easyui-linkbutton"  style="float:left;margin-left:15px;" iconCls="icon-ok" onClick="print_excel();">导出Excel格式</a><br/>
		</div>
		<div id="info_body_div" style='text-align:center;margin-top:5px;'></div>
</div>
<div id="page" region="center" border="false" style="overflow:auto;">
	
		<table id="my_table" class="blue" style="width:100%;margin:0px;table-layout:fixed;">
				<thead>
					<tr>
						<th width="5%"><input type="checkbox" id="checkAll" onclick="checkAll(1,'mate')";/></th>
						<th width="20%">材料名称</th>
						<th width="10%">规格</th>
						<th width="10%">单位</th>				
						<th width="10%">采购类型</th>
						<th width="10%">下限</th>
						<th width="10%">当前库存</th>
						<th width="10%">参考数量</th>
						<th width="15%">订货数量</th>	
						<th width="16px"></th>				
					</tr>
				</thead>	
		</table>
		<div id="content_div" style="width:100%;height:90%;border-bottom:1px solid #ccc;"></div>
</div>
</body>
</html>
