<#import "../../ftllib/spring_new.ftl" as spring />
<#import "../../ftllib/pagecom.ftl" as page />
<!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=gb2312">
<title>单据管理中心</title>

<style>	
	*{font-size:12px}		
	.ui-button { outline: 0; margin:0;padding: .2em 4px .3em; text-decoration:none;  !important; cursor:pointer; position: relative; text-align: center; }
</style>
<link type="text/css" href="javascript/jquery_simple_tree/themes/style.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">
<link rel="stylesheet" type="text/css" href="javascript/auto/jquery.autocomplete.css" />


<script type='text/javascript' src='dwr/interface/AjaxReportQueryService.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>
<script type="text/javascript" src="javascript/jquery-1.4.2.min.js" charset="utf-8"></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_easy_ui/easyui-lang-zh_CN.js" charset="utf-8"></script>
<script type="text/javascript" src="javascript/jquery.utils.js" charset="utf-8"></script>
<script type='text/javascript' src='javascript/tools/jquery.qtip-1.0.0-rc3.min.js'></script>
<script type='text/javascript' src='javascript/auto/jquery.autocomplete.js'></script>

<script type='text/javascript'> 

${words?default("")}


function check_orders(){
	var rows = $("#order_table").datagrid("getSelections");
	if(rows.length<=0){
		alert("请选择要审核的单据！");
		return false;
	}
	var codes = "";
	var last_type = "";
	for(var i=0;i<rows.length;i++){
		var type = rows[i].order_name;
		var code = rows[i].code;		
		if(last_type == ""){
			last_type = type;
			codes += code;
		}else{
			if(last_type != type){
				alert("请选择相同类型的单据进行批量审核！");
				return false;
			}else{
				codes += ","+code;				
			}
		}
	}
	
	if(!confirm("确定要审核这[" + rows.length  + "]张单据吗？")){
		return false;
	}		
	var param = {"command":"check_orders"};
	param["codes"]=codes;
	param["type"]=last_type;
	$.post("<@spring.url "kc/guide/order_operate.html"/>",param,function(data){
		if(data == "true"){
			alert("审核成功");
			$("#order_table").datagrid("reload");
		}else{
			alert(data);
		}				
	});	
}

function uncheck_orders(){
	var rows = $("#order_table").datagrid("getSelections");
	if(rows.length<=0){
		alert("请选择要反审核的单据！");
		return false;
	}
	var codes = "";
	var last_type = "";
	for(var i=0;i<rows.length;i++){
		var type = rows[i].order_name;
		var code = rows[i].code;		
		if(last_type == ""){
			last_type = type;
			codes += code;
		}else{
			if(last_type != type){
				alert("请选择相同类型的单据进行批量反审核！");
				return false;
			}else{
				codes += ","+code;				
			}
		}
	}
	if(!confirm("确定要反审核这[" + rows.length + "]张单据吗？")){
		return false;
	}
	var param = {"command":"uncheck_orders"};
	param["codes"]=codes;
	param["type"]=last_type;
	$.post("<@spring.url "kc/guide/order_operate.html"/>",param,function(data){
		if(data == "true"){
			alert("反审核成功");
			$("#order_table").datagrid("reload");
		}else{
			alert(data);
		}				
	});	
}

function delete_orders(){
	var rows = $("#order_table").datagrid("getSelections");
	if(rows.length<=0){
		alert("请选择要删除的单据！");
		return false;
	}
	if(!confirm("确定要删除这[" + rows.length + "]张单据吗？")){
		return false;
	}
	var codes="";
	var type=rows[0].order_name;
	for(var i=0;i<rows.length;i++){
		if(type!=rows[i].order_name){
			alert("每次只能选择一种类型的单据进行删除操作");
			return;
		}
		type=rows[i].order_name;
		codes==""?codes=rows[i].code:codes+=","+rows[i].code;
	}
	var param = {"command":"delete_orders"};
	param["codes"]=codes;
	param["type"]=type;
	$.post("<@spring.url "kc/guide/order_operate.html"/>",param,function(data){
		if(data == "true"){
			alert("删除成功");
			$("#order_table").datagrid("reload");
		}else{
			alert(data);
		}				
	});	
	
}
//重新载入仓库
function reload_bases(type,code){
	if(type && type == "rest"){		
		var param = {command:"get_bases"};
		param['rest_code'] = code;
		$("#base_code").load("<@spring.url "kc/base/stock_operate.html"/>",param);		
	}else{
		$("#base_code").html("<option value=''>全 部</option>");
	}
	
}

$(document).ready(function(){	

	$("#order_type_text,#btn_order_type").click(function(data){
		if(!$('#order_type_div').is(":visible")){
			$('#order_type_div').show();
		}
		$('#order_type_div').dialog({
			left:$("#order_type_text").position().left,
			top:$("#order_type_text").position().top+24,
			buttons:[{
					text:'确认',
					iconCls:'icon-ok',
					handler:function(){
						var node = $('#order_type_tree').tree('getSelected');
						$('#order_type_text').val(node.text);
						$("#order_type").val(node.id);
						$('#order_type_div').dialog('close');
						$("#order_table").datagrid("reload");
					}
				},{
					text:'取 消',
					handler:function(){
						$('#order_type_div').dialog('close');
					}
			}]									
		});
	});
	
	$("#rest_text").combotree({
		onSelect:function(node){
			var attr = node.attributes;					
			$('#rest_text').val(node.text);						
			if(attr.type == "rest"){
				$("#rest_code").val(attr.code);
				$("#rest_area").val("0");
			}else{
				$("#rest_code").val("");
				$("#rest_area").val(attr.code);							
			}
						
			reload_bases(attr.type,attr.code);	
						
			$("#order_table").datagrid("reload");
		}		
	});	
	
	$("#supplier_text").combotree({
		onSelect:function(node){
			var attr = node.attributes;					
			$('#supplier_text').val(node.text);
			$("#supplier_code").val(attr.code);
			if(attr.code == "0"){
				$("#supplier_code").val("");
			}
			$("#order_table").datagrid("reload");
		},
		autoSelect:function(code){			
			$("#supplier_code").val(code);
			$("#order_table").datagrid("reload");
		}
	});	
	
	$("#order_table").datagrid({
		method:'post',
		queryParams:{"command":"search_orders"},
		url:"<@spring.url "kc/guide/order_operate.html"/>",		
		width:"100%",
		height:$("#main_body").height()-10,
		singleSelect:false,
		pagination:true,
		pageList:[20,40,60,80,100],		
		striped: true,
		rownumbers:false,
		onBeforeLoad:function(param){					
			param["type"] = $("#order_type").val();	
			param["state"] = $("#state").val();	
			param["start_date"] = $("#start_date").val();	
			param["end_date"] = $("#end_date").val();
			param["base_code"] = $("#base_code").val();
			param["rest_code"] = $("#rest_code").val();	
			param["rest_area"] = $("#rest_area").val();
			param["supplier_code"] = $("#supplier_code").val();	
			param["dateType"] = $("select[name='dateType']").val();
			//param["key"] = $("#query_key").val();				
		},
		onLoadSuccess:function(){
		 	$('#order_table td[title]').qtip({
     			content: {
         			text: false
     		 	},
      			style: 'cream'
   			});		
		},
		onDblClickRow:function(rowIndex,rowData){
			var param = {"command":"get_url"};
			param["code"]=rowData.code;
			param["type"]=rowData.order_name;
			$.post("<@spring.url "kc/guide/order_operate.html"/>",param,function(data){
				if(data != "null"){
					window.open("<@spring.url "/"/>"+data,'','top=50,left=50,width=900,height=600');
				}else{
					alert("未找到单据访问路径！");
				}				
			});			
		}
	});
	
	$("#btn_query").click(function(data){
		$("#order_table").datagrid("reload");
	});
	
	$("#date_select").change(function(){
		var val = $(this).val();
		AjaxReportQueryService.getFixDate(val,function(data){
					if(data){	
						$("#start_date").val(data.start);
						$("#end_date").val(data.end);
					}
		});	
	});
	
	
});


</script>
	
</head>
<body class="easyui-layout">	

	<div region="north"  border="false" style="height:70px;padding-top:5px;">
			<input type="hidden" name="order_type" id="order_type" value="all"/>	
			<input type="hidden" name="rest_area" id="rest_area" value=""/>	
			<input type="hidden" name="rest_code" id="rest_code" value="${restCode?default("")}"/>	
			<input type="hidden" name="supplier_code" id="supplier_code" value=""/>	
			<table width="100%">
				<tr>
					<td>
						<span style="margin:0px 10px;">
							<label>查询日期:</label>		
							<select name="dateType">
								<#if state== 1>
									<option value="check_time" selected>审核日期</option>
									<option value="make_time">制单日期</option>
								<#else>
									<option value="make_time" selected>制单日期</option>
								</#if>
								<option value="order_time">单据日期	</option>
							</select>									
							<select id="date_select">
								<option value='' <#if state== 0>selected</#if>>全 部</option>
								<option value='currentDay' <#if state== 1>selected</#if>>本  日</option>
								<option value='currentWeek'>本  周</option>
								<option value='currentMonth'>本  月</option>
								<option value='currentYear'>本  年</option>
								<option value='yesterday'>上  日</option>
								<option value='previousMonth'>上  月</option>
								<option value='previousYear'>上  年</option>								
							</select>									
							<input class="easyui-datebox" type="text" name="start_date" id="start_date" required="true" <#if state== 1> value="${start_date?default("")}"</#if> style="width:100px;"/>
							 至 						
							<input class="easyui-datebox" type="text" name="end_date" id="end_date" required="true" <#if state== 1>value="${end_date?default("")}"</#if> style="width:100px;"/>
						</span>	
						<span style="margin:0px 10px;">
							<label>单据类型:</label>
							<input type="text" name="order_type_text" id="order_type_text" value="全部单据" style="width:80px;" readonly/><input type="button" id="btn_order_type" value=".."/>
						</span>						
						<span style="margin:0px 10px;display:none;">
							<label>单据状态:</label>
							<select id="state" style="width:106px;">
								<option value=''>全部</option>
								<option value='0' <#if state== 0>selected</#if>>未审核</option>
								<option value='1' <#if state== 1>selected</#if>>已审核</option>								
							</select>
						</span>						
					</td>
				</tr>				
				<tr>
					<td>
						<span style="margin:0px 10px;">
							<label>相关门店:</label>						
							<input type="text" name="rest_text" id="rest_text" value="${restName?default("")}" panelWidth="300" panelHeight="400" style="width:104px;" animate="true" url="all/common/load_tree.html?tree=area_rest_tree_json&manage=1"/>
						</span>
						<span style="margin:0px 10px;">
							<label>相关仓库:</label>
							<select id="base_code" style="width:106px;">	
								<option value=''>全 部</option>							
							</select>
						</span>
						<span style="margin:0px 10px;">
							<label>供  应  商:</label>
							<input type="text" name="supplier_text" id="supplier_text" value="全部供应商" style="width:200px;" editable="true" autoWord="suppliers" panelHeight="400" panelWidth="300" animate="true" url="all/common/load_tree.html?tree=supplier_tree_json" readonly/>
						</span>
						<!--
						<span style="margin:0px 10px;">
							<label>关  键  字:</label>
							<input name="query_key" id="query_key" value="" style="width:100px;"/>
						</span>
						-->
						<span style="margin:0px 10px;">
							<button id="btn_query" style="padding:3px 7px;">查 询</button>
						</span>
					</td>
				</tr>
			</table>				
	</div>
	<div id="main_body" region="center" border="false"  style="overflow:hidden;">	
		<table id="order_table">
    		<thead>
    			<tr>
    				<th field="ck" checkbox="true"></th>
    				<th field="code" width="100">单据编码</th> 
    				<#if state== 1>
    				<th field="check_time" width="120" sortable="true">审核日期</th>
    				</#if>
    				<th field="make_time" width="120" sortable="true">制单日期</th>
    				<th field="order_time" width="80" sortable="true">单据日期</th>
    				<th field="rest_name" width="120">相关门店</th>
    				<th field="type_name" width="80">单据类型</th>   				  				
    				<th field="state" width="80">单据状态</th>
    				<th field="title" width="360" tip="detail">摘要</th>       							
    			</tr>
    		</thead>
    	</table>
	</div>
	<div region="south"  border="false" style="height:40px;padding-left:10px;">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" onClick="check_orders();">审核</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-undo" onClick="uncheck_orders();">反审核</a>
		<#if state== 0><a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-cancel" onClick="delete_orders();">删除</a></#if>
	</div>
	<div id="order_type_div"  title="单据类型选择" style="width:240px;height:400px;border:2px solid #FFFFFF;background-color:#FFFFFF;overflow-y:auto;display:none;">
		<ul id="order_type_tree" class="easyui-tree" animate="true">
			<li id="all">
				<span>全部单据</span>
				<ul>
					<li id="cg" state="closed">
							<span>采购管理</span>
							<ul>									
								<li id='cgyd'>采购订单</li>
								<li id='cgsh'>采购收货单</li>
								<li id='cgth'>采购退货单</li>		
								<li id='cgfk'>付款单</li>												
							</ul>
					</li>
					<li id="ck" state="closed">
							<span>仓库管理</span>
							<ul>					
								<li id='wldb'>内部调拨单</li>
								<li id='check'>仓库盘点单</li>
								<li id='wlsy'>物料损溢单</li>										
								<li id='wlly'>物料领用单</li>
								<li id='wlth'>物料退还单</li>
								<li id='yddb'>异店调拨单</li>
								<li id='other_rk'>其它入库单</li>
								<li id='other_ck'>其它出库单</li>
							</ul>
					</li>
					<li id="qp" state="closed">
							<span>请配和配送</span>
							<ul>					
								<li id='qqps'>请配单</li>
								<li id='pssh'>配送单</li>										
							</ul>
					</li>		
					<li id="menu" state="closed">
							<span>配菜成本</span>
							<ul>					
								<li id='jk'>销售减库单</li>										
							</ul>
					</li>
				</ul>
			</li>
		</ul>
	</div>	
</body>
</html>
