<%@page contentType="text/html;charset=GBK" %>
<jsp:useBean id="fgorderForm" class="com.keyshop.shop.order.controller.OrderForm" scope="request"/>
<%
   User user= (User)session.getAttribute("User");
	Order bean = (Order)fgorderForm.getBean();
	OrderAddress orderAddress = bean.getOrderAddress();
	OrderConsigneeAddress orderConsigneeAddress = bean.getOrderConsigneeAddress();
%>
<%
	String returnUrl = (String)request.getAttribute("returnUrl");
	if(!StringUtil.isEmpty(returnUrl)) {
%>
<SCRIPT>
window.location = '<%=CONTEXT + returnUrl%>'
</SCRIPT>
<%
	}
%>
<SCRIPT language=JavaScript src="<%=CONTEXT%>/fg/js/pub.js"></SCRIPT>
<script>
function submitOrderForm() {
	var payTypeChecked = false;
	var shipTypeChecked = false;
	if(document.all['bean.payType']) {
	 	if(document.all['bean.payType'].length) {
	 		
	 		for(var i=0; i<document.all['bean.payType'].length; i++) {
	 			var payType = document.all['bean.payType'][i];
	 			if(payType.checked == true) {
	 				payTypeChecked = true;
	 				break;
	 			}
	 		}
	 	} else {
 	 		if(document.all['bean.payType'].checked == true) {
 	 			payTypeChecked = true;
 	 		}
 	 	}
	 }
   	 
 	 if(document.all['bean.shipType']) {
 	 	if(document.all['bean.shipType'].length) {
 	 		
 	 		for(var i=0; i<document.all['bean.shipType'].length; i++) {
 	 			var shipType = document.all['bean.shipType'][i];
 	 			if(shipType.checked == true) {
 	 				shipTypeChecked = true;
 	 				break;
 	 			}
 	 		}
 	 	} else {
 	 		if(document.all['bean.shipType'].checked == true) {
 	 			shipTypeChecked = true;
 	 		}
 	 	}
 	 }
 	 
   if(validateFgorderForm(fgorderForm)) {
   	 if(!payTypeChecked) {
   	 	alert("请选择配送方式。");
   	 	return;
   	 }
   	 
   	 if(!shipTypeChecked) {
   	 	alert("请选择支付方式。");
   	 	return;
   	 }
   	 
   	 if(document.all['bean.note'].value.length > 255) {
   	 	alert("订单备注长度不能超过255");
   	 	return;
   	 }
   	 
	 	 if(confirm("确定该订单内容吗?") ){
	 	 		document.fgorderForm.actionType.value='save';
    	 document.fgorderForm.submit();
     }
   }
}
function changeOrder(equals) {
	document.fgorderForm.actionType.value='add';
	if(equals != null)
		document.fgorderForm.equals.value = equals;
	document.fgorderForm.submit();
}
</script>

<html:javascript formName="fgorderForm"/> 
<table border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="10" height="10"><img src="<%=CONTEXT%>/img/QQ/i01.gif" width="10" height="10"></td>
    <td  background="<%=CONTEXT%>/img/QQ/i03.gif"></td>
    <td width="10" height="10"><img src="<%=CONTEXT%>/img/QQ/i02.gif" width="10" height="10"></td>
  </tr>
  <tr>
    <td  background="<%=CONTEXT%>/img/QQ/i04.gif">&nbsp;</td>
    <td>
			<table width="100%" height="192" border="0" cellpadding="0" cellspacing="0">
			
			<html:form action="/fg/order/order" type="get">
				<input type="hidden" name="actionType" value="fgsave"/>
			  <tr> 
			    <td align="right">
			      <table width="100%" border="0" cellpadding="0" cellspacing="0" >
			        <tr> 
			          <td height="200" valign="top">
			            <table width="100%" height="183" border="0" align="center" cellpadding="0" cellspacing="1">
			              <tr > 
			                <td colspan="7" class="" align="left">
			                	<img src="<%=CONTEXT%>/img/pic0516.gif" width="36" height="21" align="left">您的购物车</b></font></td>
			              </tr>
			              <%
										 	if(SESSION_USER != null && SESSION_USER.getCartManager() != null) {
										 	List searchResult = (List)SESSION_USER.getCartManager().getProducts();
									  	if(searchResult!= null && searchResult.size() > 0) {
									  %>
			              <tr bgcolor="1EC8FC"> 
			                <td align="center" >商品编号</td>
						          <td align="center" >商品名称</td>
						          <td align="center" >会员价</td>
						          <td align="center" >商品积分</td>
						          <td align="center" >数量</td>										          
						          <td align="center" >小计</td>
						          <td align="center" >积分总计</td>
			              </tr>
									  <%
									 		for(int i=0; i<searchResult.size(); i++) {
									 			CartManager.CartManagerProduct result = (CartManager.CartManagerProduct)searchResult.get(i);
									 	%>
									  <%
									  	if(result.getProduct() != null) {
									  %> 
			              <tr hight="25"  bgcolor="f2f2f2"> 
				              <td align="left"><a class="Index_Title02" href="<%=PRODUCTVIEW%>&bean.id=<%=result.getId()%>" target="_blank">
				              <%=result.getProduct().getProductNo()%></a></td>
				              <td align="center">
				              <a class="dlIndex_Title02" href="<%=PRODUCTVIEW%>&bean.id=<%=result.getId()%>" target="_blank">
				              	<%=result.getProduct().getName()%></a>
				              </td>
				              <td align="center">￥<%=result.getProduct().getUnitPrice()%>元</td>
				              <td align="center">￥<%=result.getProduct().getExtField1()%></td>
				              <td align="center">
				              <input type="text" value="<%=result.getNumber()%>" class="i03" name="cart_productNumber<%=result.getId()%>" size="5" onkeypress="intOnly();"/>
				
				              </td>
						          <td align="center">￥<%=result.getNumber()*result.getProduct().getUnitPriceByUserLevel(user)%>元</td>
						          <td align="center">总积分</td>
				            </tr>
				            <tr align="center">
						          <td colspan="6" height=1 background="<%=CONTEXT%>/img/pic0515.gif"></td>
						        </tr>
						           <%
									  		}
									  	}
									  %>
			              <tr bgcolor="C8EEFF"> 
			                <td  colspan="7"  align="right">
			                	合计：￥<%=SESSION_USER.getCartManager().getTotalAmount(SESSION_USER)%>元&nbsp;&nbsp;</td>
			              </tr>
										  <%
									   		}
									  	}
									  %>
			               </table>
			             </td>
			           </tr>
			           <tr> 
			             <td align="left">
					           <table width="100%" border="1" cellspacing="0" cellpadding="10" 
					           	bordercolordark=white bordercolorlight=e7e7e7>
			                 <tr> 
			                   <td height="100%">
					                 <table width="100%" border="0" cellspacing="0" cellpadding="0" >
			                       <tr > 
			                         <td width="15%" align="center"><font color="#FF0000">☆</font></td>
			                         <td width="85%"><span  class=LoginFast_WordTitle>配送信息</span></td>
			                       </tr>
			                     </table>
			                    <table width="100%" border="0" cellpadding="1" cellspacing="1">
			                      <tr > 
			                        <td width="11%" align="right" class="order02Index_bg">定货人：</td>
			                        <td width="89%" class="order02Index_bg">
			                        	<html:text property="bean.orderAddress.name"  styleClass="i03"  maxlength="32" size="20"/>
			                        </td>
			                      </tr>
			                      <tr > 
			                        <td align="right">性别：</td>
			                        <td><html:radio property="bean.orderAddress.sex" styleClass="check"  value="true"/>
								                  男 
								                  <html:radio property="bean.orderAddress.sex" styleClass="check"  value="false"/>
								                  女</td>
			                      </tr>
			                          <tr > 
			                            <td align="right">地址：</td>
			                            <td>	
			                            	<html:text property="bean.orderAddress.address"  styleClass="i03"  maxlength="180"size="56"/> 
			                            	</td>
			                          </tr>
			                          <tr > 
			                            <td align="right">邮编：</td>
			                            <td><html:text property="bean.orderAddress.zipCode"  styleClass="i03"  maxlength="6" size="8"/></td>
			                          </tr>
			                          <tr > 
			                            <td align="right">电话：</td>
			                            <td><html:text property="bean.orderAddress.areaNo"  styleClass="i03"  maxlength="6" size="6"/>
																			-
				         										<html:text property="bean.orderAddress.telephone"  styleClass="i03"  maxlength="16" size="16"/>
			                              手机： 
			                              <html:text property="bean.orderAddress.mobileTelephone"  styleClass="i03"  maxlength="16" size="20"/></td>
			                          </tr>
			                          <tr > 
			                            <td align="right">提货人：</td>
			                            <td><html:radio styleClass="check" property="equals" onclick="javascript:changeOrder('true')" value="true"/>
									                 	订货人 
									                 	<html:radio styleClass="check" property="equals"  onclick="javascript:changeOrder('false')" value="false"/>
									                  其他人</td>
			                          </tr>
			                          <tr > 
			                            <td align="right" valign="top">邮箱：</td>
			                            <td><html:text property="bean.orderAddress.emailAddress"  styleClass="i03"  maxlength="80" size="24"/>
			                              <br>
			                              (如填写此项，我们将取“@”前面的信息为您在商城使用的用户名，您使用的密码由系统自动生成；用户名、密码将发送到此信箱，请保持邮箱的用效性。) 
			                            </td>
			                          </tr>
			                        </table>
							   <%
									 							if(!fgorderForm.isEquals()) {
									            %>
										            <table width="70%" border="0" cellspacing="0" cellpadding="0">
			                            <tr>
			                              <td width="15%" align="center"><table width="98%" border="0" cellpadding="0" cellspacing="0" class="gwcIndex_tub01">
			                                  <tr> 
			                                    <td></td>
			                                  </tr>
			                                </table></td>
			                              <td width="85%"><span  class=LoginFast_WordTitle>送货信息</span></td>
			                            </tr>
			                          </table>
			                          <table width="100%" border="0" cellpadding="1" cellspacing="1">
			                            <tr >  
			                              <td width="11%" align="right" >收货人：</td>
			                              <td width="89%">
			                              	<html:text property="bean.orderConsigneeAddress.name"  styleClass="i03"  maxlength="32" size="20"/>
			                              </td>
			                            </tr>
			                            <tr >  
			                              <td align="right">性别：</td>
			                              <td>
			                              	<html:radio property="bean.orderConsigneeAddress.sex" styleClass="check"  value="true"/>
											                  男 
											                  <html:radio property="bean.orderConsigneeAddress.sex" styleClass="check"  value="false"/>
											                  女
			                              </td>
			                            </tr>
			                            <tr >  
			                              <td align="right">地址：</td>
			                              <td>
			                              	<html:text property="bean.orderConsigneeAddress.address"  styleClass="i03"  maxlength="180" size="56"/>
			                              </td>
			                            </tr>
			                            <tr >  
			                              <td align="right">邮编：</td>
			                              <td>
			                              	<html:text property="bean.orderConsigneeAddress.zipCode"  styleClass="i03"  maxlength="6" size="8"/>
			                              </td>
			                            </tr>
			                            <tr >  
			                              <td align="right">电话：</td>
			                              <td>
			                              	<html:text property="bean.orderConsigneeAddress.areaNo"  styleClass="i03"  maxlength="6"size="6"/>
			  																-
					         										<html:text property="bean.orderConsigneeAddress.telephone"  styleClass="i03"  maxlength="16" size="16"/>
			                                手机： 
			                                <html:text property="bean.orderConsigneeAddress.mobileTelephone"  styleClass="i03"  maxlength="16" size="20"/>
			                                </td>
			                            </tr>
			                            <tr >  
			                              <td align="right" valign="top">邮箱：</td>
			                              <td><html:text property="bean.orderConsigneeAddress.emailAddress"  styleClass="i03"  maxlength="80" size="24"/>
			                              </td>
			                            </tr>
			                          </table>
									            <%
								              	}
								              %>   
			                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
			                          <tr > 
			                            <td width="14%" align="center">
			                            	<table width="98%" border="0" cellpadding="0" cellspacing="0" 
			                            		class="gwcIndex_tub01">
			                                <tr> 
			                                  <td align="center">★</td>
			                                </tr>
			                              </table></td>
			                            <td width="86%" class="gwIndex_txt">送货方式</td>
			                          </tr>
			                        </table>
			                        <table  width="100%" border="0" cellpadding="1" cellspacing="1" class="order02Index_bg">
			                        	<tr > 
									                <td>配送方式名称</td>
									                <td>配送费用</td>
									                <td>配送方式描述</td>
									              </tr>
			                           <%
										            	List shipTypes = OrderHelper.getShipTypes();
										            	
										            	if(shipTypes != null) {
										            		for(int i=0; i<shipTypes.size(); i++) {
										            			ShipType shipType = (ShipType)shipTypes.get(i);
										            %>
										            <tr> 
										              <td><html:radio property="bean.shipType" styleClass="check" onclick="javascript:changeOrder()" value="<%=shipType.getId()%>"/>
										                <%=shipType.getName()%> </td>
										              <td>
										              	<%
										              		double shipAmount = 0;
										              		double totalCost =  SESSION_USER.getCartManager().getTotalAmount(SESSION_USER);
										              		if ("rate".equals(shipType.getChargeType())) {
															          shipAmount = totalCost * (shipType.getAmount() / 100.0);
															        }
															        else {
															          shipAmount = shipType.getAmount();
															        }
															      %>
										              	<%=shipAmount%>
																		<%
										              	if (com.keyshop.shop.user.util.UserConst.ADVANCEUSERTYPE.equals(SESSION_USER.getUsertype())) {
										              	%>
										              	<font color="red">高级用户免费</font>
																		<%
										              	}
																		%>
										              </td>
										              <td><%=shipType.getNote()%>&nbsp;</td>
										            </tr>
										            <%
										            		}
										            	}
										            %>
			                        </table>
			                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
			                          <tr > 
			                            <td width="14%" align="center"><table width="98%" border="0" cellpadding="0" cellspacing="0" class="gwcIndex_tub01">
			                                <tr> 
			                                  <td align="center">★</td>
			                                </tr>
			                              </table></td>
			                            <td width="86%" class="gwIndex_txt">支付方式</td>
			                          </tr>
			                        </table>
			                        <table width="100%" border="0" cellspacing="1" cellpadding="1">
			                          <tr >  
									                <td width="35%">支付方式名称 <br></td>
									                <td width="65%">支付方式描述</td>
									              </tr>
									               <%	
									              	List payTypes = OrderHelper.getPayTypes();
									              	List relationpayTypes = OrderHelper.getPayTypesByShipTypeId(bean.getShipType());
									              	bean.setPayType("");
									              	if(payTypes != null) {
									              		for(int i=0; i<payTypes.size(); i++) {
									              			PayType payType = (PayType)payTypes.get(i);
									              %>
									              
									              <tr >  
									                <td>
									                	<%
									                		if(OrderHelper.isInPayType(relationpayTypes, payType.getId())) {
									                	%>
									                	<html:radio property="bean.payType" value="<%=payType.getId()%>"/>
									                	<%
									                		} else {
									                	%>
									                	<html:radio property="bean.payType" disabled="true" value="<%=payType.getId()%>"/>
									                	<%
									                		}
									                	%>
									                  <%=payType.getName()%>
									                </td>
									                <td>
									                	<%=payType.getNote()%>&nbsp; 
									                </td>
									              </tr>
									               <%
									              		}
									              	}
									              %>
			                        </table>
			                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
										            <tr >  
										              <td>备注&nbsp;</td>
										              <td><html:textarea  styleClass="i03" property="bean.note" cols="50" rows="5"/></td>
										            </tr>
								          </table>
			                      
							  <p  align="center"> 
			                          <input type="button" onclick="javascript:submitOrderForm()" name="Submit3222" value="提交订单" class="i05">
			                        </p>
			                        </td>
			                    </tr>
			                  </table></td>
			              </tr>
			            </table></td>
			        </tr>
			  </html:form>
			</table>
    </td>
    <td background="<%=CONTEXT%>/img/QQ/i05.gif"></td>
  </tr>
  <tr>
    <td width="10" height="10"><img src="<%=CONTEXT%>/img/QQ/i06.gif" width="10" height="10"></td>
    <td background="<%=CONTEXT%>/img/QQ/i08.gif"></td>
    <td width="10" height="10"><img src="<%=CONTEXT%>/img/QQ/i07.gif" width="10" height="10"></td>
  </tr>
</table>

