<%@page contentType="text/html; charset=UTF-8"%>
<%@include file="/inc/init.jsp" %>
<%@include file="/inc/checklogin.jsp" %>
<%@include file="inc/header.jsp" %>
<%
	//分页参数
	int pagex = pu.getInt("pagex", 1);
	if (pagex < 1) {
		pagex = 1;
	}
	int length = 20;
	int start = (pagex - 1) * length;
	int count = 0;
	String querystr = pu.getQueryString();
	querystr=request.getRequestURI()+"?"+querystr;
	//分页参数
	String orderState = pu.getString("state");
	//处理状态多选开始
	ArrayList<String> jStateList=new ArrayList<String>();
	String[] tempState=orderState.split(",");
	for(int i=0;tempState!=null&&i<tempState.length;i++){
			jStateList.add(tempState[i]);
	}
	//处理状态多选结束
	String column = pu.getString("column","contact,address,phone,admin_remark,remark,orderid");
	//处理项目多选开始
	ArrayList<String> jColumnList=new ArrayList<String>();
	String[] tempColumn=column.split(",");
	for(int i=0;tempColumn!=null&&i<tempColumn.length;i++){
		jColumnList.add(tempColumn[i]);
	}
	//处理状态多选结束
	int classid = pu.getInt("classid");
	String keyword = pu.getStringByPage("keyword");
	Order_list_db oldb = new Order_list_db();
	DOC[] docs = null;
	String starttime = pu.getString("starttime");
	String endtime = pu.getString("endtime");
	docs = oldb.getListByMuchLogic(orderState, classid, starttime,
				endtime, column, keyword, start, length); //分页参数应用
	count = oldb.getRealCount();
	Product_db pdb = new Product_db();
	DOC[] classdocs = null;
	Product_class_db pcdb = new Product_class_db();
	classdocs = pcdb.getListAll();
%>
<div id="c">
<%@include file="inc/left.jsp" %>
<div id="right">
<%@include file="inc/position.jsp" %>
<link rel="stylesheet" type="text/css" href="/js/jqueryplus/jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="/js/jqueryplus/jquery-ui.css" />
<script type="text/javascript" src="/js/jquery1.7.js"></script>
<script type="text/javascript" src="/js/jqueryplus/jquery-ui.min.js"></script>
<script type="text/javascript" src="/js/jqueryplus/jquery.multiselect.js"></script>
<div class="right">
<div id="right_box">

	<div class="blank20"></div>

 <div style="float:left;width:760px;margin-left:5px;overflow:hidden;">
     <form name="searchform" id="searchform"  action="" method="get" onsubmit="return checkform();">
              <table width="100%" border="0">
                 <tr>
                 	<td width="63%">&nbsp;搜索：内容项目 
						<select name="jcolumn" multiple="multiple" size="5"  id="jcolumn" class="select" style="width:120px">
                 			<option value="contact" <%=jColumnList.contains("contact")? "selected": ""%>>联 系 人</option>
							<option value="address" <%=jColumnList.contains("address")? "selected": ""%>>收件地址</option>
                 			<option value="phone" <%=jColumnList.contains("phone")? "selected": ""%>>联系电话</option>
                 			<option value="admin_remark" <%=jColumnList.contains("admin_remark")? "selected": ""%>>备注</option>
							<option value="remark" <%=jColumnList.contains("remark")? "selected": ""%>>客户留言</option>
							<option value="orderid" <%=jColumnList.contains("orderid")? "selected": ""%>>订 单 号</option>
                 			</select>
                 			<input type="hidden" id="column" name="column" value="<%=column%>"  />
                 		关 键 词
                 		<input type="text" name="keyword" id="keyword" value="<%=keyword%>" style="width:129px; height:30px;" /></td>
                 	<td width="28%">开始：<input name="starttime" type="text" id="starttime"  class="Wdate"  onfocus="WdatePicker({isShowClear:true,readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="20" value="<%=starttime%>" style="height:28px; width:140px;" title="下单时间开始范围" /></td>
                 	<td width="9%" rowspan="3"><input type="submit" value="搜索" name="seach"  class="btn_e" /></td>
                 	</tr>
				<tr>
					<td height="5" valign="middle">
						</td>
					<td height="5" valign="middle"></td>
					</tr>
				<tr>
					<td valign="middle">&nbsp;过滤：产品类别 
						<select name="classid" id="classid" class="select" style="width:149px">
							<option value=" ">不限</option>
							<%
								for (int i = 0; i < classdocs.length; i++) {
							%>
							<option value="<%=classdocs[i].get("classid")%>" <%=classdocs[i].geti("classid") == classid ? "selected"
						: ""%>><%=classdocs[i].get("name")%><%=classdocs[i].get("retain3")%></option>
							<%
								}
							%>
							</select>
						订单状态 
				<select id ="jstate"  multiple="multiple" name="jstate" size="5" class="select" style="width:120px">
				   <%for (int i = 0; i < Select.stateList.size(); i++) {
						String[] temps=Select.stateList.get(i).split(",");
					%>
							<option value="<%=temps[0]%>" <%=jStateList.contains(temps[0])? "selected": ""%>><%=temps[1]%></option>
					<%
						}
					%>
    			</select>
		<input type="hidden" id="state" name="state" value="<%=orderState%>"  />
	&nbsp;&nbsp;</td>
					<td valign="middle">结束：<input name="endtime" id="endtime" type="text" class="Wdate" onFocus="WdatePicker({isShowClear:true,readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'starttime\')}'})" size="20" value="<%=endtime%>"  style="height:28px; width:140px;"  title="下单时间结束范围"/></td>
					</tr>
          </table>


            <div class="blank5"></div></form>
<script type="text/javascript">
$(function(){
    $("#jstate").multiselect({
		minWidth:155,
        noneSelectedText: "==请选择==",
        checkAllText: "全选",
        uncheckAllText: '全不选',
        selectedList:2,
		close: function(){
	      var values= $("#jstate").val();
		  $("#state").val(values);
		}
    });
});
$(function(){
    $("#jcolumn").multiselect({
		minWidth:155,
        noneSelectedText: "==请选择==",
        checkAllText: "全选",
        uncheckAllText: '全不选',
        selectedList:2,
		close: function(){
	      var values= $("#jcolumn").val();
		  $("#column").val(values);
		}
    });
});
</script>
</div>
  <div class="blank5"></div>
<div id="tagscontent" class="right_box">

    <table border="0" cellspacing="0" cellpadding="0" class="list" name="table1" id="table1" width="755">

<thead>

<tr class="th">
	<th width="28" align="center">多选</th>

<th width="59" align="center"><!--id-->订单ID</th>

<th width="214" align="center"><!--oid-->产品名称和数量</th>

<th width="55" align="center"><!--pname-->联系信息</th>

<th width="107" align="center"><!--status-->状态／备注</th>
<th width="62" align="center">原价／实收</th>
<th width="131" align="center"><!--adddate-->下单时间／短信</th>

<th width="88" align="center">操作</th>

</tr>



</thead>

<tbody>
<%
	DOC doc = null;
	Order_SMS_db osdb = new Order_SMS_db();
	DOC[] smscontentdocs = null;
	int price2=0;
	int price=0;
	int curcount=docs.length;
	for (int i = 0; docs != null && i < docs.length; i++) {
		int productid = docs[i].geti("productid");
		doc = pdb.getOne(productid);
		smscontentdocs = osdb.getListByOrderId(docs[i].geti("orderid"),
				0, 1);
		price2+=docs[i].geti("price2");
		price+=docs[i].geti("price");
		String contactColor="";//当天未发送亦无定时，联系人飘红
		String paisongState="";//正在派送时，订单状态加粗
		int stateflag = docs[i].geti("state");
		int curDate=IntUtil.s2i(new DateUtil().getDate().replaceAll("-",""));//换为int型，用来显示明天的定时短信
		int Timing=0;//定时发送的时间
		if(stateflag>=1&&stateflag<=4){  //标识发货期间今天是否发了短信
			if(smscontentdocs.length > 0){
				//短信为派送状态,并且状态是发付或后付已发货的,去除了并是自动发送的,&&smscontentdocs[0].geti("retain3")==1
				if(smscontentdocs[0].geti("type")==5&&(stateflag==2||stateflag==3)){
					paisongState="font-weight:bold;";
				}
				int smsDate=IntUtil.s2i(Util.sub_String(smscontentdocs[0].get("create_time"),10).replaceAll("-",""));//最后一条短信时间
				Timing=IntUtil.s2i(Util.sub_String(smscontentdocs[0].get("retain2"),10).replaceAll("-",""));
				if(curDate!=smsDate&&curDate!=Timing){
					
				}
			}
		}
%>
<tr class="s_out">
	<td align="center">
	<input type="checkbox" name="orderid" value="<%=docs[i].get("orderid")%>" /></td>
<%
boolean haskd_number=StringUtil.isFine(docs[i].get("kd_number"));
%>
<td align="center" <%if(haskd_number){%>onmouseover="tooltip.show('快递公司：<%=Select.getText("kdtype",docs[i].get("kd_type"))%><br />快递单号：<%=docs[i].get("kd_number")%><br />签收日期：<%=docs[i].get("retain4")%>');" onmouseout="tooltip.hide();"<%}%>> <%if(haskd_number){%><a href="viewkd.jsp?kdid=<%=docs[i].get("kd_number")%>&kd_type=<%=docs[i].get("kd_type")%>&orderid=<%=docs[i].get("orderid")%>&contact=<%=docs[i].get("contact")%>&address=<%=docs[i].get("address")%>&phone=<%=docs[i].get("phone")%>" target="_blank"><%=docs[i].get("orderid")%></a><%}else{%><%=docs[i].get("orderid")%><%}%></td>
<td align="center" onmouseover="tooltip.show('<%=doc.get("name")%>');" onmouseout="tooltip.hide();"><%=Util.sub_String(doc.get("name"), 30, "..")%> x<%=docs[i].geti("number")>0?docs[i].get("number"):"1"%></td>

<td align="center" onmouseover="tooltip.show('手机：<%=docs[i].get("phone")%><br />地址：<%=docs[i].get("address")%>');" onmouseout="tooltip.hide();"><font style="<%=contactColor%>"><%=docs[i].get("contact")%></font></td>

<td align="center"  onmouseover="tooltip.show('备注：<%=Util.htmlEncode(docs[i].get("admin_remark"))%>');" onmouseout="tooltip.hide();">
<%
		String red = "color=\"#000000\"";
		if (stateflag >= 4 && stateflag <= 10) {
			red = "color=\"#FF0000\"";
		}
		if (stateflag == 99 || stateflag == 98) {
			red = "color=\"#0066CC\"";
		}
		if (stateflag >= 1 && stateflag <= 3) { //加入已先行付款
			red = "color=\"#33cc00\"";
		}
		if(stateflag==20){
			red = "color=\"#ff7200\"";
		}
		if (stateflag == 5) {
			red = "color=\"#63b1ff\"";
		}
%>
<font <%=red%> style="<%=paisongState %>"><%=StringUtil.isFine(paisongState)?"派送中":Select.getText("state", docs[i].get("state"))%></font></td>
<td align="center" onmouseover="tooltip.show('留言：<%=Util.htmlEncode(docs[i].get("remark"))%>');" onmouseout="tooltip.hide();"><%=docs[i].get("price2")%>/<%=docs[i].get("price")%></td>
<td align="center" onmouseover="tooltip.show('短信：<%=smscontentdocs.length > 0 ? smscontentdocs[0].get("create_time")+"&nbsp;&nbsp;"+smscontentdocs[0].get("retain1") : ""%><br /><%=curDate<=Timing?"定时："+smscontentdocs[0].get("retain2")+" 发送<br />":""%><%=smscontentdocs.length > 0 ? smscontentdocs[0].get("content") : ""%>');" onmouseout="tooltip.hide();"><%=docs[i].get("create_time")%></td>
<td align="center" valign="middle">

<span style="float:left;margin-top:1px;"><a style="background-image: url(/images/button/jiantou.gif);background-repeat: no-repeat;cursor:pointer;display:block;width:20px;height:15px;" href="javascript:void(0)" onClick="$('#modifyorder<%=i%>').toggle();" title="快捷修改"></a> </span>

<span style="width:30px;"><a href="orderView.jsp?orderid=<%=docs[i].get("orderid")%>&keyword=<%=keyword%>">处理</a></span>
 <%
 	if (ConfigUtil.usedel) {
 %>
 <span style="width:30px;"><a href="fun/F_order.jsp?orderid=<%=docs[i].get("orderid")%>&action=del" onclick="javascript: return confirm('确实要删除 <%=docs[i].get("contact")%> 的订单吗?');"><font class="fontred">删除</font></a></a></span>
<%
	}
%>
</td>
</tr>
<!--修改框开始-->
<tr class="s_out" id="modifyorder<%=i%>" style="display:none;">
<td colspan="8" align="center">
<div>
<form name="orderform<%=i%>" method="post" action="fun/F_order.jsp">
<table width="100%" cellspacing="1" cellpadding="1" class="table2" bgcolor="#CCCCCC" name="table2"> 
<tr>
<td width="26%">状态：<%
			boolean disabled=false;  //暂时不启用
			if(docs[i].get("state").equals("12")||docs[i].get("state").equals("00")){
			//disabled=true;	
			}
			%><select name="state" class="select" <%=disabled?"disabled":""%> >
			<%for (int j = 0; j < Select.stateList.size(); j++) {
				String[] temps=Select.stateList.get(j).split(",");
			%>
					<option value="<%=temps[0]%>" <%=temps[0].equals(docs[i].get("state")) ? "selected": ""%>><%=temps[1]%></option>
			<%
				}
			%>
		</select></td>
<td width="56%">快递：
	<select name="kd_type" class="select">
			<%for (int j = 0; j < Select.kdList.size(); j++) {
				String[] temps=Select.kdList.get(j).split(",");
			%>
				<option value="<%=temps[0]%>" <%=temps[0].equals(docs[i].get("kd_type")) ? "selected": ""%>><%=temps[1]%></option>
			<%
			}
			%>
			  </select>
		<input name="kd_number" type="text" value="<%=docs[i].get("kd_number")%>" class="input_d" style="width:120px;" />&nbsp;&nbsp;&nbsp;<input id="FHsms<%=i%>" name="FHsms" type="checkbox" value="1" /><label for="FHsms<%=i%>"> 发送发货短信</label></td>
<td width="18%"><span style="font-size:14px; color:#006600">
	<input name="input" value="提交修改" type="submit" class="btn_a" style="margin:1px 0px;" />
</span></td>
</tr>
</table>
<input name="action" type="hidden" value="single" />
<input name="orderid" type="hidden" value="<%=docs[i].get("orderid")%>" />
</form>
</div>
</td>
</tr>
<!--修改框结束-->
 <%
 	}
 	classdocs = null;
 	docs = null; //释放对象 
 	doc = null;
 	smscontentdocs = null;
 %>
<tr class="s_out">
<td colspan="8" align="left">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td valign="middle"><form  action="fun/F_order.jsp" method="post">
			<a href="javascript:void(0)" id="all" class="btn_e" style="margin-top:4px">全选</a> 
			<a href="javascript:void(0)" id="delAll" class="btn_e" style="margin-top:4px">全不选</a> 
			<a href="javascript:void(0)" id="antiAll" class="btn_e" style="margin-top:4px">反选</a> 
			&nbsp;
			<select name="state" class="select" style="width:120px">
				   <%for (int i = 0; i < Select.stateList.size(); i++) {
						String[] temps=Select.stateList.get(i).split(",");
					%>
							<option value="<%=temps[0]%>"><%=temps[1]%></option>
					<%
						}
					%>
    			</select>
				<input name="input" value="批量修改状态" type="submit" class="btn_a" style="margin:1px 0px;" />
				<input id="orderids" name="orderids" type="hidden" value="" />
				<input name="action" type="hidden" value="batchUpdateState" />
				</form></td>
			<td>&nbsp;</td>
		</tr>
	</table></td>
</tr>

<tr class="s_out">
<td colspan="8" align="center"><table width="700" border="0" cellspacing="1" cellpadding="1">
	<tr align="left">
		<td width="567" align="center">合计：<%=count%>条，当前显示<font color="#FF00FF"><%=curcount %></font>条记录里，原价合计：<font color="#FF00FF"><%=price2 %></font>元，实收合计：<font color="#FF00FF"><%=price %></font>元，更详细请使用导出功能</td>
		<td width="126">
		<!--<input type="button" name="button" id="button" value="导出订单资料" onclick="window.location.href='/export.do?state=<%=orderState%>&classid=<%=classid%>&keyword=<%=keyword%>&column=<%=column%>&starttime=<%=starttime%>&endtime=<%=endtime%>'"  class="btn_a" />-->
		
		<input type="button" name="button" id="button" value="导出订单资料" onclick="alert('需要使用此高级定制功能，请联系作者，谢谢，QQ：86827185');"  class="btn_a" /></td>
		</tr>
</table></td>
</tr>
</tbody>
</table>

<div class="page" align="center">
<%=PagingUtil.splitPages(pagex,querystr,count, length)%> 
</div>
<div class="blank10"></div>
</div>
<div class="blank10"></div>

<div class="clear"></div>
</div>
</div>

<div class="right_bottom">
</div>
</div>

<div id="footer">
</div>
</div>
<script type="text/javascript">
function selectChange(){
	document.searchform.submit();
}

function checkform(){
	/*var column=$('select[name="column"] option:selected').val();
	var keyword=document.searchform.keyword.value;
	if(column==""&&keyword!=""){
		alert('请选择要搜索的项目！');
		return false;
	}
	if(column!=""&&keyword==""){
		alert('请输入关键字！');
		document.searchform.keyword.focus();
		return false;
	}*/
	var starttime=document.searchform.starttime.value;
	var endtime=document.searchform.endtime.value;
	if(starttime!=""&&endtime==""){
		alert('请选择结束时间！');
		document.searchform.endtime.focus();
		return false;
	}
	if(endtime!=""&&starttime==""){
		alert('请选择开始时间！');
		document.searchform.starttime.focus();
		return false;
	}
	document.searchform.submit();
	return true;
}

//全部选择
 $("#all").click(function(){
	$('#orderids').val('');
    $("input[name='orderid'][type='checkbox']").each(function(){
		$(this).attr("checked",true);
		$('#orderids').val($('#orderids').val()+$(this).val()+',');
  });  
 });
 
 //取消选择
 $("#delAll").click(function(){  
  $("input[name='orderid'][type='checkbox']").each(function(){
		$(this).attr("checked",false);
		$('#orderids').val('');
  });  
 });
 
 //反向选择
 $("#antiAll").click(function(){
	$('#orderids').val('');
  	$("input[name='orderid'][type='checkbox']").each(function(){
		if(!$(this).attr("checked")){
			$('#orderids').val($('#orderids').val()+$(this).val()+',');
		}
		$(this).attr("checked",!this.checked);
     });
	});
 //自行选择
  $("input[name='orderid'][type='checkbox']").click(function(){
	$('#orderids').val('');
  	$("input[name='orderid'][type='checkbox']:checked").each(function(){
		$('#orderids').val($('#orderids').val()+$(this).val()+',');
     });
	});
</script>
<%@include file="inc/msg.jsp" %>
<%@include file="inc/footer.jsp" %>
