<%@ Page language="c#" Codebehind="MyRepaire.aspx.cs" AutoEventWireup="true" Inherits="XpShop.WebUI.MyRepaire" ValidateRequest="false" %>
<%@ Register TagPrefix="uc1" TagName="Helper" Src="Modules/Helper.ascx" %>
<%@ Register TagPrefix="uc1" TagName="Header" Src="Modules/Header.ascx" %>
<%@ Register TagPrefix="uc1" TagName="Footer" Src="Modules/Footer.ascx" %>
<%@ Register TagPrefix="uc1" TagName="MemberMenu" Src="Modules/MemberMenu.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<!--#include file="../../inc/encoding.inc"-->
		<title>返修/退换货</title>
		<!--#include file="../../inc/head.inc"-->
<%--		<link rel="stylesheet" type="text/css" media="screen" href="<%=webSite %>Template/<%=config.TemplateFolder%>/style/cmxform.css" />--%>
	    <script src="inc/jquery.validate.js" type="text/javascript"></script>
	    <script src="inc/messages_cn.js" type="text/javascript"></script>
		<link href="<%=webSite %>Template/<%=config.TemplateFolder%>/style/member.css" type="text/css" rel="stylesheet" />
		<script type="text/javascript">
		    var shopFolder='<%=ShopFolder %>';
		    var templateFolder='<%=config.TemplateFolder%>';
		    $(document).ready(function(){
		        $('#btnSearch').click(function(){
		            $.ajax({
		                url:'MyRepaire.aspx?NocopyRight=1&type=ajax&Action=GetProducts&stype='+$('[@name=rblRepaireType][@checked]').val() +'&OrderNo=' + escape($.trim($('#txtOrderNo').val())),
		                async:false,
		                cache:false,
		                dataType:'json',
		                success:function(msg){
		                    if(msg.OrderExist == 'true'){
		                        var Products = msg.Products;
		                        if(Products.length>0){
		                            $('#tmp').nextAll().remove();
		                            $.each(Products,function(i,n){
		                                var row = $('#tmp').clone().show();
		                                row.find('.orderpdt_pdtname').html(n.ProductName + (n.ProductSpecs != '' ? '<br>' + n.ProductSpecs : ''));
		                                row.find('.orderpdt_pdtprice').html(n.SubPrice);
                                        row.find('.orderpdt_pdtpmt').html(n.LessMoney);
		                                row.find('.orderpdt_pdtbacknum').html("<img src='/" + shopFolder + "Template/" + templateFolder + "/images/cart_reduce.gif' alt='减少' title='减少数量' class=\"hand\" id=\"reduce_" + n.GoodsID + "\" /><input type=\"hidden\" name=\"num\" value=\""+n.Quantity+"\"/> <input type=\"text\" id=\"quantity_"+n.GoodsID+"\" name=\"quantity\" value=\""+n.Quantity+"\"style=\"width:30px\"/><img src='/" + shopFolder  + "Template/" + templateFolder + "/images/cart_add.gif' alt='增加' title='增加数量' class=\"hand\" id=\"add_" + n.GoodsID + "\" />");
		                                row.find('.orderpdt_pdtbacknum').append('<input type="hidden" id="unitprice_'+n.GoodsID+'" name="unitprice" value="'+n.UnitPrice+'" /><input type="hidden" id="unitless_'+n.GoodsID+'" name="unitless" value="'+n.UnitLess+'" />');
		                                var checkbox = $('<input type="CheckBox" id="gid_'+n.GoodsID+'"name="gid" value="' + n.GoodsID + '" />');
		                                row.find('.orderpdt_check').append(checkbox);
		                                $('#OrderProduct').append(row);                       
    		                            
		                                if($('#txtReceiverAddress').val()=='')
		                                $('#txtReceiverAddress').val(n.ReceiverAddress);
		                                if($('#txtReceiverName').val()=='')
		                                $('#txtReceiverName').val(n.ReceiverName);
		                                if($('#txtMobile').val()=='')
		                                $('#txtMobile').val(n.ReceiverMobile);
                                    });
		                            $('#span_result').html('');
		                            $('#OrderProduct').show();
		                            $('#orderNo').val($('#txtOrderNo').val());
		                        }
//		                        else{
//		                            $('#span_result').html(msg.ErrorMsg);
//		                            $('#OrderProduct').hide();
//                                    $("#OrderProduct  input[@name='gid']:checked").each(function(){
//                                        $(this).attr("checked", false);
//                                    });
//                               }
		                    }else{
		                        $('#span_result').html(msg.ErrorMsg);
		                        $('#OrderProduct').hide();
                                $("#OrderProduct  input[@name='gid']:checked").each(function(){
                                    $(this).attr("checked", false);
                                });
                            };
		                },
		                error:function(){alert('error');}
		            });
		        });
		        
	
               	        
		        $('input[@id^=gid_]').livequery("click",function(){
                var recID = $(this).attr('id').replace('gid_','');
                var obj=$('#quantity_'+recID);
                if($(this).attr('checked')){
                obj.attr("name","pnum");
                }else{
                obj.attr("name","quantity");
               }
               });
               
		       $('[@name=rblRepaireType]').bind("click",function(){
                   $('#btnSearch').click();
               })
               		        		        
		        $('[@name=rblRepaireType][@value=1]').click(function(){
                    $('.refundType').show();
                    if($('[@name=rblRefundType][@value=2]').is(":checked")){
                        $('.bankInfo').show();
                    }
                })
                $('[@name=rblRepaireType][@value!=1]').click(function(){
                    $('.refundType').hide();
                    if($('[@name=rblRefundType]').is(":checked")){
                       $('[@name=rblRefundType]').removeAttr("checked");
                    }
                    HideBankInfo();
                })
                $('[@name=rblRefundType][@value=2]').click(function(){
                    $('.bankInfo').show();
                })
                $('[@name=rblRefundType][@value!=2]').click(function(){
                    HideBankInfo();
                }) 
                
                $('input[@id^=quantity]').livequery('keydown',function(event){
	            var curobj = $(this);
	            curobj.attr('oldvalue',curobj.val());
	            if((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 46 || event.keyCode == 8){
	            }else{return false;}
	             }).livequery('keyup',function(event){
	            var curobj = $(this);
	            var curnum=curobj.val();
                var maxNum= $(this).siblings('[@name=num]').val();
	            if(curobj.attr('oldvalue') == curobj.val() || curobj.val() == ''){return ;};
	            if(curnum<1){
	                alert('退换货/返修的数量必须大于0');
	                curobj.val(1);
	            }
	            else if(curnum>maxNum){
	                alert('退换货/返修的数量不能大于购买数量');
	                curobj.val(maxNum);
                }
                else{
                   var curNum= $(this).val()
                   unitprice= $(this).siblings('[@name=unitprice]').val();
                   lessprice= $(this).siblings('[@name=unitless]').val();
                   $(this).parent().parent().find('.orderpdt_pdtprice').empty().html((unitprice*curNum).toFixed(2));
                   $(this).parent().parent().find('.orderpdt_pdtpmt').empty().html((lessprice*curNum).toFixed(2));                
                }
	            });	     
                
	            //减少数量
	            $('[@id^=reduce_]').livequery('click',function(){
                var recID = $(this).attr('id').replace('reduce_','');
                var obj = $('#quantity_' + recID);
	            var curNum= obj.val()-1;
	            if(curNum>=1){
	               obj.val(curNum);
                   obj.keyup();
	            }
	            else{
	                alert('退换货/返修的数量必须大于0');
	            }
	            });
	            //增加数量
	            $('[@id^=add_]').livequery('click',function(){
                var recID = $(this).attr('id').replace('add_','');
                var obj = $('#quantity_' + recID);
	            var curNum=Number(obj.val())+1;
	            var maxNum= $(this).siblings('[@name=num]').val();
                if(maxNum>=curNum){
	              obj.val(curNum);
	              obj.keyup();
                }
	            else{
	                alert('退换货/返修的数量不能大于购买数量');
	            }
	            });                          
		        
		        $('#btnSubmit').click(function(){
		            if($('[@name=gid][@checked]').length == 0){
		                alert('请选择要返修的商品');
		                return false;
		            };
		        });
                HideBankInfo();
                
                $("#Form1").validate({
		            event: "keyup",
		            rules: {
			            txtReason: {
				            required: true,
				            maxlength:200
			            },
			            txtReceiverAddress: {
			                required:true,
				            maxlength:255
                        },
                        
			            txtReceiverName: {
			                required:true,
				            maxlength:50
			            },
			            txtMobile: {
			                required:true,
				            maxlength:20
			            },
                        txtBankName: {
			                required:function(){
                                if($('#txtBankName').parent().parent().is(":hidden"))
                                return false
                                else
                                return true
				             },
				            maxlength:50
                        },
	                    txtBankAccount: {
			                required:function(){
                                if($('#txtBankAccount').parent().parent().is(":hidden"))
                                return false
                                else
                                return true
				             },
				            maxlength:50
				         
                        },
			            txtBankAccount2: {
			                required:function(){
                                if($('#txtBankAccount2').parent().parent().is(":hidden"))
                                return false
                                else
                                return true
				             },
				            maxlength:50,
				            equalTo:"#txtBankAccount"
                        },
                        txtAccountName: {
			                required:function(){
                                if($('#txtAccountName').parent().parent().is(":hidden"))
                                return false
                                else
                                return true
				             },
				            maxlength:50
                        } 		            
		            },		
		            messages: {
			            txtReason: {
				            required: "退换货/返修理由必填",
				            maxlength: "最大长度只能在(200个字符)以内"
			            },
			            txtReceiverAddress: {
                            required: "收货地址必填",
				            maxlength: "最大长度只能在(255个字符)以内"
			            },
			            txtReceiverName: {
				            required:  "收货人必填",
				            maxlength: "最大长度只能在(50个字符)以内"
			            },
			            txtMobile: {
				            required:  "收货电话必填",
				            maxlength: "最大长度只能在(20个字符)以内"
			            },
			            txtBankName: {
                            required: "退款银行必填",
				            maxlength: "最大长度只能在(50个字符)以内"
			            },
			            txtBankAccount: {
                            required: "退款银行账户必填",
				            maxlength: "最大长度只能在(50个字符)以内"
			            },
                        txtBankAccount2: {
                            required: "再次输入银行账户",
				            maxlength: "最大长度只能在(50个字符)以内",
				            equalTo:"两次输入的账号名不同"
			            },
			            txtAccountName: {
                            required: "退款银行账户名必填",
				            maxlength: "最大长度只能在(50个字符)以内"
			            }		            },
		            debug:"false",
		            submitHandler:function(form){
			            form.submit();
		            }
	            });             
		    });
		    
            function HideBankInfo(){
                $('.bankInfo').hide();
                $('#txtBankName').val('');
                $('#txtBankAccount').val('');
                $('#txtAccountName').val('');
            }
		</script>
		<style type="text/css">
		    .table tr td{ text-align:left; font-size:12px; padding-left:10px; padding-bottom:5px; padding-top:5px; border-bottom:1px #e6e6e6 dotted;}
		    .table .left{width:15%;text-align:right}
		</style>
	</head>
	<body>
		<uc1:Header id="Header1" runat="server"></uc1:Header>
		<div class="xp-qgw clear">
		    <!--位置导航开始-->
            <div class="path"><a href="<%=webSite %><%if(config.html==""){%>default.aspx<%}else{%>Index.<%=config.html%><%}%>"><%=GetResourceString("Home")%></a>&nbsp;&gt;&nbsp;<a href="<%=webSite %>Center.<%=config.html %>"><%=GetResourceString("MemberCenter")%></a>&nbsp;&gt;&nbsp;我的返修</div>
            <!--位置导航结束-->
			<div class="member_left">
				<!--会员中心导航开始-->
				<uc1:MemberMenu id="MemberMenu1" runat="server"></uc1:MemberMenu>
				<!--会员中心导航结束-->
			</div>
			<div class="member_middle_right">
			    <form id="Form1" method="post" runat="server">
				    <div class="mframe">
			            <div class="tl"></div>
			            <div class="tr"></div>
			            <div class="tm">我的退换货/返修</div>
			            <div class="ml"></div>
			            <div class="mr"></div>
			            <div class="mm">
	                        <asp:datagrid id="dgList" CssClass="dgborder" runat="server"
						        AutoGenerateColumns="False" DataKeyField="Ano" Width="100%" HorizontalAlign="Center" BorderWidth="1"
						        BorderColor="#d6d6d6">
						        <ItemStyle BackColor="White"></ItemStyle>
			                    <HeaderStyle BackColor="#fff7d3" Height="20px"></HeaderStyle>
						        <Columns>
							        <asp:TemplateColumn HeaderText="订单编号">
								        <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
								        <ItemStyle HorizontalAlign="Center" Height="20px"></ItemStyle>
								        <ItemTemplate>
										        <%# DataBinder.Eval(Container.DataItem, "OrderNo") %>
								        </ItemTemplate>
							        </asp:TemplateColumn>
							        <asp:TemplateColumn HeaderText="申请编号">
								        <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
								        <ItemStyle HorizontalAlign="Center" Height="20px"></ItemStyle>
								        <ItemTemplate>
										        <%# DataBinder.Eval(Container.DataItem, "Ano") %>
								        </ItemTemplate>
							        </asp:TemplateColumn>
							        <asp:TemplateColumn HeaderText="返修类型">
								        <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
								        <ItemStyle HorizontalAlign="Center" Height="20px"></ItemStyle>
								        <ItemTemplate>
										        <%# (int)DataBinder.Eval(Container.DataItem,"Type") == 1 ? "退货": (int)DataBinder.Eval(Container.DataItem,"Type") == 2?"换货":"返修" %>
								        </ItemTemplate>
							        </asp:TemplateColumn>
							        <asp:BoundColumn DataField="AddTime" HeaderText="申请时间" DataFormatString="{0:yyyy-MM-dd}">
								        <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
								        <ItemStyle HorizontalAlign="Center" Width="15%"></ItemStyle>
							        </asp:BoundColumn>
							        <asp:TemplateColumn HeaderText="状态">
								        <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
								        <ItemStyle HorizontalAlign="Center"></ItemStyle>
								        <ItemTemplate>
                                        <%# GetStatus((bool)DataBinder.Eval(Container.DataItem,"CanRefund"),(int)DataBinder.Eval(Container.DataItem,"IsConfirm"),
                                        (bool)DataBinder.Eval(Container.DataItem,"IsReturn"),(bool)DataBinder.Eval(Container.DataItem, "ReturnConfirm"),(bool)DataBinder.Eval(Container.DataItem, "IsSend"), 
                                        (bool)DataBinder.Eval(Container.DataItem, "SendConfirm"), (int)DataBinder.Eval(Container.DataItem, "IsCompleted"))%>
								        </ItemTemplate>
							        </asp:TemplateColumn>
							        <asp:TemplateColumn HeaderText="操作">
								        <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
								        <ItemStyle HorizontalAlign="Center"></ItemStyle>
								        <ItemTemplate>
									        <a href='MyRepairDetail-<%# DataBinder.Eval(Container.DataItem, "Ano") %>.<%=config.html%>'>查看</a>
								        </ItemTemplate>
							        </asp:TemplateColumn>
						        </Columns>
					        </asp:datagrid>
	                        
	                        <h3 style="padding:10px 0px 0px">填写申请表单</h3>
				            <hr class="itemhr" />
		                    <table class="table" cellpadding="0" cellspacing="0" border="0" width="100%" style="border:1px #e6e6e6 solid;">
		                        <tr>
						            <td style=" background:#fff7d3; font-weight:bold; text-align:left; font-size:12px; padding-left:10px; padding-bottom:5px; padding-top:5px; border-bottom:1px #e6e6e6 dotted;" colspan="3">填写申请表</td>
						        </tr>
		                        <tr>
			                        <td class="left">订单号：</td>
			                            <td><asp:TextBox Runat="server" ID="txtOrderNo" Text=""></asp:TextBox><input type="button" id="btnSearch" name="btnSearch" value="查询" />
                                        <input type="hidden"  id="orderNo" value="" name="orderNo" />
			                        </td>
		                        </tr>
		                        <tr id="trResult">
		                            <td class="left">查询结果：</td>
		                            <td>
		                                <span id="span_result"></span>
		                                <table id="OrderProduct" cellpadding="0" cellspacing="0" border="0" style="width:100%; display:none;">
		                                    <tr>
		                                        <td style="width:5%;">选择</td>
		                                        <td style="width:55%;">商品名称</td>
		                                        <td style="width:10%;">商品价格</td>
		                                        <td style="width:10%;">商品优惠</td>
		                                        <td style="width:10%; ">退回数量</td>
		                                    </tr>
		                                    <tr id="tmp" style="display:none;">
		                                        <td class="orderpdt_check" ></td>
		                                        <td class="orderpdt_pdtname"></td>
		                                        <td class="orderpdt_pdtprice"></td>
		                                        <td class="orderpdt_pdtpmt"></td>
		                                        <td class="orderpdt_pdtbacknum"></td>
                                            </tr>
		                                </table>
		                            </td>
		                        </tr>
		                        <tr>
			                        <td class="left">期待处理方式：</td>
			                        <td><asp:RadioButtonList id="rblRepaireType" runat="server" RepeatDirection="Horizontal" RepeatLayout="flow">
					                        <asp:ListItem Value="1" Selected="True">退货</asp:ListItem>
					                        <asp:ListItem Value="2">换货</asp:ListItem>
                                            <asp:ListItem Value="3">返修</asp:ListItem>
 				                        </asp:RadioButtonList>
 				                    </td>
		                        </tr>
		                        <tr>
			                        <td class="left"><em>*</em>问题描述：</td>
			                        <td><asp:TextBox id="txtReason" runat="server" Columns="50" Rows="5" TextMode="multiLine"></asp:TextBox></td>
		                        </tr>
		                        <tr class="refundType"  >
			                        <td class="left"><em>*</em>退款方式：</td>
                                    <td><asp:RadioButtonList id="rblRefundType" runat="server" RepeatDirection="vertical" RepeatLayout="flow">
					                        <asp:ListItem Value="1" Selected="True">退款至账户余额（推荐，不会收取手续费） </asp:ListItem>
					                        <asp:ListItem Value="2">退款至银行卡（跨行退款需要扣除一定积分用以支付银行手续费）</asp:ListItem>
                                        </asp:RadioButtonList>
                                    </td>
		                        </tr>
		                        <tr class="bankInfo" >
			                        <td class="left"><em>*</em>开 户 行：</td><td><asp:TextBox id="txtBankName" runat="server" ></asp:TextBox></td>
		                        </tr>
		                        <tr class="bankInfo">
			                        <td class="left"><em>*</em>开户人姓名：</td><td><asp:TextBox id="txtAccountName" runat="server"  ></asp:TextBox></td>
		                        </tr>	
                                <tr class="bankInfo">
			                        <td class="left" valign="top"><em>*</em>开户银行账号：</td><td><asp:TextBox id="txtBankAccount" runat="server" ></asp:TextBox><br /><font color="#ff6600">特别提醒：请确认开户人姓名及银行帐号填写正确，否则您的退款资金将有可能无法按时到帐。</font></td>
		                        </tr>
		                        <tr class="bankInfo">
			                        <td class="left"><em>*</em>再次输入账号：</td><td><asp:TextBox id="txtBankAccount2" runat="server" ></asp:TextBox></td>
		                        </tr>
		                        <tr>
			                        <td class="left"><em>*</em>收货地址：</td><td><asp:TextBox id="txtReceiverAddress" runat="server"  Columns="80" ></asp:TextBox></td>
		                        </tr>
		                        <tr>
			                        <td class="left"><em>*</em>联 系 人：</td><td><asp:TextBox id="txtReceiverName" runat="server" ></asp:TextBox></td>
		                        </tr>
		                        <tr>
			                        <td class="left"><em>*</em>手机号码：</td><td><asp:TextBox id="txtMobile" runat="server"></asp:TextBox></td>
		                        </tr>		                        
                                <tr>
			                        <td style="text-align:center;border-bottom-width:0px"></td>
			                        <td style="border-bottom-width:0px">
				                        <asp:Button id="btnSubmit" OnClick="btnSubmit_Click" runat="server" Text="提交"></asp:Button></td>
		                        </tr>
	                        </table>
						</div>
			            <div class="bl"></div>
			            <div class="br"></div>
			            <div class="bm"></div>
			        </div>
					  
				</form>
			</div>
			<div style="clear:both;"></div>
		</div>
		<uc1:Helper id="Helper1" runat="server"></uc1:Helper>
		<uc1:Footer id="Footer1" runat="server"></uc1:Footer>
	</body>
</html>
