<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<title>订单管理</title>
</head>
<body>

<!-- 发货 -->
	<div class="layui-layer layui-anim layui-layer-iframe" id="layui-layer4" times="4" showtime="0" contype="string" style="display:none;z-index: 19891018; width: 400px; height: 260px; position: absolute; top: 100px; left: 379px;">
		<form action="" method="post" class="form form-horizontal" id="form-admin-add">
		<div class="layui-layer-title" id="sendOrderDivTitle" style="cursor: move;" move="ok">确认发货</div>
		<br>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red"></span>&nbsp;&nbsp;物流编号：</label>
			<div class="formControls col-5">
				<input type="text" id="order-post-num-id" class="input-text" value="" placeholder="请输入物流编号" name="postNum" datatype="*2-16" nullmsg="用户名不能为空">
			</div>
			<div class="col-4"> </div>
		</div>
		<br>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red"></span>&nbsp;&nbsp;物流公司：</label>
			<div class="formControls col-5"> <span class="select-box" style="width:150px;">
				<select class="select" name="postFirm" size="1">
					<option value="">请选择物流公司</option>
					<option value="sto">申通快递</option>
					<option value="yto">圆通快递</option>
					<option value="sf">顺丰快递</option>
					<option value="longbanwuliu">龙邦快递</option>
				</select>
				</span> </div>
		</div>
		<br>
		<div class="col-9 col-offset-3">
	        <input class="btn btn-primary radius" onclick="return submitSendOrder()" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
	      </div>
	    </form>
		<span class="layui-layer-setwin">
			<a class="layui-layer-ico layui-layer-close layui-layer-close1" onclick="exitWindowsDiv(this)" href="javascript:;"></a>
		</span>
	</div>
	
	<!-- 后台备注 -->
	<div class="layui-layer layui-anim layui-layer-iframe" id="layui-remark" times="4" showtime="0" contype="string" style="display:none;z-index: 19891018; width: 400px; height: 260px; position: absolute; top: 100px; left: 379px;">
		<form action="" method="post" class="form form-horizontal" id="form-admin-remark">
		<div class="layui-layer-title" id="sendOrderDivTitle" style="cursor: move;" move="ok">订单备注</div>
		<br>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>&nbsp;&nbsp;备注信息：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" value="" placeholder="请输入备注信息" id="remarkInfoInput" name="postNum" datatype="*2-16" nullmsg="用户名不能为空">(不超过100字)
			</div>
			<div class="col-4"> </div>
		</div>
		<br>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>&nbsp;&nbsp;备注颜色：</label>
			<div class="formControls col-5"> <span class="select-box" style="width:150px;">
				<select class="select" id="adminRemarkColor" size="1">
					<option value="1" class="optionclass" id="optionclass1">红色</option>
					<option value="2" class="optionclass" id="optionclass2">黄色</option>
					<option value="3" class="optionclass" id="optionclass3">绿色</option>
				</select>
				</span> </div>
		</div>
		<br>
		<div class="col-9 col-offset-3">
	        <input class="btn btn-primary radius" type="button" onclick="remrakSumbit()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
	      </div>
	    </form>
		<span class="layui-layer-setwin">
			<a class="layui-layer-ico layui-layer-close layui-layer-close1" onclick="exitWindowsDiv(this)" href="javascript:;"></a>
		</span>
	</div>
	<nav class="breadcrumb">
		<i class="Hui-iconfont">&#xe67f;</i> 
		首页 <span class="c-gray en">&gt;</span>
		订单管理 <span class="c-gray en">&gt;</span> 
		订单列表 
		<a class="btn btn-success radius r mr-20" style="line-height: 1.6em; margin-top: 3px" href="javascript:location.replace(location.href);" title="刷新">
		<i class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
	<div class="pd-20">
		<div class="text-c">
		<form action="${pageContext.request.contextPath }/admin/order/selectShopOrderByOrderId" method="post" id="myForm">
			<input type="hidden" name="orderStatus" value="${orderStatusStr }" />
			<input type="text" name="text" id="text" value="${selectInput }" placeholder="订单编号" style="width: 300px" class="input-text">
			日期范围： 
			<input type="text" readonly="readonly" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')||\'2020-10-01\'}'})" id="beginDate" value="${beginDate }" name="beginDate" class="input-text Wdate" style="width: 120px;">
			- <input type="text" readonly="readonly" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'beginDate\')}',maxDate:'2020-10-01'})" id="endDate" value="${endDate }" name="endDate" class="input-text Wdate" style="width: 120px;">
			<button name="" id="submitBtn" class="btn btn-success" type="submit">
				<i class="Hui-iconfont">&#xe665;</i> 搜索
			</button>

			<button style="" name="" class="btn btn-danger" type="button" onclick="downloadExcel()">下载订单</button>
		</form>
		</form>
		</div>
		<div class="cl pd-5 bg-1 bk-gray mt-20">
			<div id="tab_demo" class="HuiTab">
			  <div class="tabBar cl">
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=allOrder'" class="allOrder">所有订单</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=returnOrderEtc'" class="returnOrderEtc">申请退货中</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=inOrder'" class="inOrder">申请换货中</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=paySuccess'" class="paySuccess">已支付、待发货</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=returnOrder'" class="returnOrder">退款申请中</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=returnOrderEtcAdmin'" class="returnOrderEtcAdmin">退货中</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=theOrderSuccess'" class="theOrderSuccess">换货中</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=sendOrder'" class="sendOrder">已发货</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=returnOrderThe'" class="returnOrderThe">订单退货，订单关闭</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=inFinish'" class="inFinish">已完成</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=quitOrder'" class="quitOrder">取消订单</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=etcOrder'" class="etcOrder">待支付</span>
			  	<span onclick="location.href='${pageContext.request.contextPath }${statusUrl }&orderStatus=returnOrderSuccess'" class="returnOrderSuccess">已退款</span>
			  </div>
			</div>
		</div>
		<div class="mt-20">
			<table class="table table-border table-bordered table-bg table-hover table-sort">
				<thead>
					<tr class="text-c">
						<th width="10">订单编号</th>
						<th width="140">收货人</th>
						<th width="150">昵称</th>
						<th width="100">手机号码</th>
						<th width="150">订单金额</th>
						<th width="150">支付金额</th>
						<th width="150">订单状态</th>
						<th width="150">时间</th>
						<th width="150">我们的备注</th>
						<th width="50">备注图标</th>
						<th width="150">用户备注</th>
						<th width="150">操作</th>
					</tr>
				</thead>
				<!-- href="${pageContext.request.contextPath }/order/getShopOrderByOrderId?orderId="+${order.salesOrderid } -->
				<tbody>
					<c:if test="${ !(empty orderList)}">
						<c:forEach items="${orderList}" var="order">
							<tr>
								<td width="10">${order.salesOrderid }</td>
								<td width="140">${order.salesAddressName }</td>
								<td width="150">${order.userNickname }</td>
								<td width="100">${order.salesAddressTel }</td>
								<td><fmt:formatNumber type="number" value="${order.salesAmount/100}" pattern="0.00" maxFractionDigits="2"/></td>
								<td><fmt:formatNumber type="number" value="${order.salesYetAmount/100}" pattern="0.00" maxFractionDigits="2"/></td>
								<td width="150">
									<c:choose>
										<c:when test="${order.salesStatus ==0 }">
											取消订单
										</c:when>
										<c:when test="${order.salesStatus ==1 }">
											待支付
										</c:when>
										<c:when test="${order.salesStatus ==2 }">
											已支付、待发货
										</c:when>
										<c:when test="${order.salesStatus ==3 }">
											退款申请中
										</c:when>
										<c:when test="${order.salesStatus ==4 }">
											已退款
										</c:when>
										<c:when test="${order.salesStatus ==5 }">
											已发货
										</c:when>
										<c:when test="${order.salesStatus ==6 }">
											申请退货中
										</c:when>
										<c:when test="${order.salesStatus ==7 }">
											退货中
										</c:when>
										<c:when test="${order.salesStatus ==8 }">
											订单退货，订单关闭
										</c:when>
										<c:when test="${order.salesStatus ==9 }">
											换货中
										</c:when>
										<c:when test="${order.salesStatus ==10 }">
											换货完成
										</c:when>
										<c:when test="${order.salesStatus ==11 }">
											申请换货中
										</c:when>
										<c:when test="${order.salesStatus ==12 }">
											订单完成
										</c:when>
									</c:choose>
								</td>
								<td width="150"><fmt:formatDate value="${order.salesCreateDate }" pattern="MM-dd HH:mm" /></td>
								<c:if test="${fn:length(order.salesAdminRemark)>'3'}">  
	                   				<td title="${order.salesAdminRemark }" id="${order.salesOrderid }AdminRemark">${fn:substring(order.salesAdminRemark,0,3)}...</td>  
				            	</c:if>  
				          		<c:if test="${fn:length(order.salesAdminRemark)<='3'}">  
				             		<td title="${order.salesAdminRemark }" id="${order.salesOrderid }AdminRemark">${order.salesAdminRemark}</td>  
				          		</c:if>
								<td width="50">
									<c:choose>
										<c:when test="${order.salesColorType==1 }">
											<div style="width:100%;height:20px;background-color: red;" id="${order.salesOrderid }AdminRemarkColor" lang="1"></div>
										</c:when>
										<c:when test="${order.salesColorType==2 }">
											<div style="width:100%;height:20px;background-color: yellow;" id="${order.salesOrderid }AdminRemarkColor" lang="2"></div>
										</c:when>
										<c:when test="${order.salesColorType==3 }">
											<div style="width:100%;height:20px;background-color: green;" id="${order.salesOrderid }AdminRemarkColor" lang="3"></div>
										</c:when>
										<c:otherwise>
											<div style="width:100%;height:20px;background-color: white;" id="${order.salesOrderid }AdminRemarkColor" lang="3"></div>
										</c:otherwise>
									</c:choose>
								</td>
								<td width="150">${order.salesUserRemark }</td>
								<!-- 遍历操作 -->
							<td class="td-manage">
								<div class="dropDown dropDown_hover">
								  <a class="dropDown_A" href="#">操作</a>
								  <div class="dropDown-menu box-shadow" style="left:-22px;">
								    <ul>
								    <c:if test="${!empty order.operations }">
								      	<c:forEach items="${order.operations }" var="oper">
								      		<li><a href="${pageContext.request.contextPath }${oper.url}" lang="${order.salesOrderid }" 
								      					title="${oper.name}" alt="${oper.name}" onclick="return orderAction(this)">
								      				<i class="Hui-iconfont">${oper.img}</i><font>${oper.name}</font>
								      			</a>
								      		</li>
								      	</c:forEach>
								      </c:if>
								    </ul>
								  </div>
								</div>
							</td>
							</tr>
						</c:forEach>
					</c:if>
				</tbody>
				</table>
				</div>
				<div align="right">
					<%@include file="/common/other/paper/pager.jsp"%>
				</div>
				</div>
				<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script>
				<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
				<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/My97DatePicker/WdatePicker.js"></script>
				<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script>
				<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
				<script type="text/javascript">
				// 选中对应的订单头信息
				$(".${orderStatusStr}").attr("class", "current");
				// 订单操作
				function orderAction(_this) {
					var $a = $(_this);
					var orderStatusStr = $a.children("font").text();
					if (orderStatusStr == "发货" || orderStatusStr == "录入物流信息并发货") {
						$("#layui-layer4").show();
						$("#sendOrderDivTitle").html("为'" + $a.attr("lang") + "'发货:");
						$("#form-admin-add").attr("action", $a.attr("href"));
						return false;
					} else if (orderStatusStr == "备注") {
						orderid = $a.attr("lang");
						$("#layui-remark").show();
						$("#form-admin-remark").attr("action", $a.attr("href"));
						// 回显现有的备注
						$("#remarkInfoInput").val($("#" + $a.attr("lang") + "AdminRemark").attr("title"));
						$(".optionclass").attr("selected", "");
						$("#optionclass" + $("#" + $a.attr("lang") + "AdminRemarkColor").attr("lang")).attr("selected", true);
						return false;
					}
					return true;
				}
				
				// 提交备注
				function remrakSumbit() {
					var remarkInfoInput = $("#remarkInfoInput").val();
					if (remarkInfoInput.length >= 0 && remarkInfoInput.length <= 100) {
						var adminRemarkColor = $("#adminRemarkColor").val();
						var remarkInfoInput = $('#remarkInfoInput').val();
						var url = $("#form-admin-remark").attr("action");
						var args = {"datetime" : new Date().getTime(), "remark" : remarkInfoInput, "remarkColor" : adminRemarkColor};
						$.ajax({
							   type: "POST",
							   url: url,
							   data: args,
							   dataType: "json",
							   success: function(data){
									if (data.status) {
										$("#layui-remark").hide();
										layer.msg(data.info,{icon:1,time:2000});
										$("#" + orderid + "AdminRemark").attr("title", remarkInfoInput);
										if (remarkInfoInput.length >= 3) {
											remarkInfoInput = remarkInfoInput.substr(0, 3) + "...";
										}
										$("#" + orderid + "AdminRemark").text(remarkInfoInput);
										var color = "";
										if (adminRemarkColor == "1") {
											color = "red";
										} else if (adminRemarkColor == "2") {
											color = "yellow";
										} else if (adminRemarkColor == "3") {
											color = "green";
										}
										
										$("#" + orderid + "AdminRemarkColor").css("background-color", color);
										$('#' + orderid + 'AdminRemark').html(remarkInfoInput);
									} else {
										layer.msg(data.info,{icon:5,time:2000});
									}
							   }
						});
					}
					
				}
				
				// 关闭窗口
				function exitWindowsDiv(_this) {
					$(_this).parent().parent().hide();
				}
				function showInfo(obj){
					window.location=" <%=request.getContextPath()%>/order/getShopOrderByOrderId?orderId="+obj;
				}
				
				// 搜索事件
					/* $("#submitBtn").click(function() {
						var orderId = $("#text").val();
						if (orderId == null && orderId == "") {
							layer.msg("输入信息不能为空哦!",{icon:5,time:2000});
							return false;
						}
					 $.ajax({
				         "type" : "post",
				         "url" : "/iamberry/admin/order/getShopOrderByOrderId/"+orderId,
				         "dataType" : "json",
				         "data" :{
				        	 "type":"2"
				         },
				         "success" : function(resp) {
				        	 //alert(resp);
				        	 var htmloption="<option value=0 >无模板</option>";
				        	 for(var i=0,l=resp.length;i<l;i++){
				        		 htmloption=htmloption+"<option value='"+resp[i].templateId+"' selected>"+resp[i].templateName+"</option>";
				        	 }
				        	 $("#templateId").html(htmloption);
				        	 flage2=true;
				         },
				         "error":function(data){
				  			  alert(data.message);
				  			  alert("操作失败，请联系管理员！");
				  		  }
					    });
					}) */


                function downloadExcel(){
                    var beginDate = $("#beginDate").val();
                    var endDate = $("#endDate").val();
                    if(beginDate == "" && endDate == ""){
                        var dd = new Date();
                        beginDate = dd.getFullYear() + "-" + ( dd.getMonth()+1) + "-" + 01;

                        dd.setMonth(dd.getMonth()+1);//获取下月月份
                        endDate = dd.getFullYear() + "-" + ( dd.getMonth()+1) + "-" + 01;
                    }
                    window.location=" <%=request.getContextPath()%>/admin/order/download_order?beginDate="+ beginDate +"&endDate=" + endDate;
                }
				</script>
</body>
</html>