<#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/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(){
    var length=$("#content_div").find("tr").length
    if(length<=1){
       alert("暂时没有数据,请修改查询条件!");
	   return false;
    }
 	if(!confirm("执行该操作会根据材料采购方式自动创建采购计划和请求配送单，是否继续？")){
		return false;
	}
	var param = {"command":"make_order"};	
	param["obj_date"] = $("#obj_date").val();
	$.post("<@spring.url "kc/guide/baseLimitOperate.html"/>",param,function(data){
		$("#info_body_div").html(data);
		$("#body_div").hide();
		$("#button_div").hide();
	    $("#info_body_div").show();
	});
}

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").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));
}
$(document.body).ready(function(){
	resize();	
	query_click("intalize");	
});
</script>
<body  class="easyui-layout">
<div id="header_div" region="north" border="false" style="height:70px;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>	
			<a href="javascript:void(0);" class="easyui-linkbutton"  style="float:left;margin-left:15px;" iconCls="icon-ok" onClick="make_order();">生成采购计划</a>	
			<a href="javascript:void(0);" class="easyui-linkbutton"  style="float:left;margin-left:15px;" iconCls="icon-ok" onClick="print_excel();">导出Excel格式</a>
		</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="25%">材料名称</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>
