<%@ Page Language="C#" MasterPageFile="~/webUser/MasterPage.master" AutoEventWireup="true" CodeBehind="myShoppingCart.aspx.cs" Inherits="ZYDN.Web.webUser.myShoppingCart" Title="我的购物车" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content1" runat="server">
<form method="post" id="form1" runat="server">
    <div>
    <script type="text/javascript" language="javascript">
    var objAjax=new JAjax();
        function changeNum(obj)
        {
            var tid = obj.tID;
            var num = obj.value;
            if(isNaN(num)||num=="")
            {
                alert("数量只能是数字！");
                return;
            }
            var price = obj.price;
            var total = parseInt(num)*parseFloat(price)*1.00;
            document.getElementById(tid).innerText = total.toFixed(2);
            var objResponse=new JHttpResponse();
            objResponse.write("num",num);
		    objResponse.write("tid",tid);
		    objResponse.write("price",price);
		    var out=objAjax.getText("post","?type=changeNum",objResponse,null);
		    if(out!=null&&out!="")
		    {
		        document.getElementById("Total").innerText=out;
		    }
        }
        function delItem(obj)
        {
            var rowID = obj.parentNode.parentNode.rowIndex;
            var tid = obj.tID;
            var objResponse=new JHttpResponse();
            objResponse.write("tid",tid);
            var out=objAjax.getText("post","?type=delItem",objResponse,null);
            
		        if(out==0)
		        {
		            document.getElementById("tabObj").style.display = "none";
		            document.getElementById("cMeg").innerText= "您的购物车没有商品";
		        }
		        document.getElementById("tabObj").deleteRow(rowID);
		        document.getElementById("Total").innerText=out;
        }
    </script>
    <div class="maxTitle">
                我的购物车
            </div>

            <div style="text-align:center;">
                <span id="cMeg"></span>
                <asp:Label ID="cartMeg" runat="server" Text=""></asp:Label></div>
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table id="tabObj" cellpadding="0" cellspacing="0" width="100%">
                    <tr class="titleLeft">
                        <td>商品名称</td>
                        <td>商品单价(元)</td>
                        <td>商品数量</td>
                        <td>商品总价</td>
                        <td></td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                    <tr>
                        <td>
                            <a><%# Eval("CommodityName")%></a>
                        </td>
                        <td>
                            <%# Eval("Price")%>
                        </td>
                        <td>
                            <input id="Text1" tID='<%# Eval("ID")%>' price='<%# Eval("Price") %>' type="text" value='<%# Eval("CommodityNum") %>' style="width:60px;" onblur="changeNum(this)" />
                        </td>
                        <td>
                            <span id='<%# Eval("ID")%>'><%# Eval("Total")%></span>
                        </td>
                        <td>
                            <a href="#" tID='<%# Eval("ID")%>' onclick="delItem(this);return false;" style="color:Blue">删除</a>
                        </td>
                    </tr>
            </ItemTemplate>
            <AlternatingItemTemplate>
                    <tr style="background-color:#F4F9FD">
                        <td>
                            <a><%# Eval("CommodityName")%></a>
                        </td>
                        <td>
                            <%# Eval("Price")%>
                        </td>
                        <td>
                            <input id="Text1" tID='<%# Eval("ID")%>' price='<%# Eval("Price") %>' type="text" value='<%# Eval("CommodityNum") %>' style="width:60px;" onblur="changeNum(this)" />
                        </td>
                        <td>
                            <span id='<%# Eval("ID")%>'><%# Eval("Total")%></span>
                        </td>
                        <td>
                            <a href="#" tID='<%# Eval("ID")%>' onclick="delItem(this);return false;" style="color:Blue">删除</a>
                        </td>
                    </tr>
            </AlternatingItemTemplate>
            <FooterTemplate>
                    <tr class="titleLeft">
                    <td colspan="2"></td>
                        <td colspan="2" style="height:20px; font-family:黑体; font-size:16px;">商品金额总计：
                            <span id="Total" class="totalPrice"><%# GetTotal() %></span>元
                        </td>
                        <td>
                            <asp:Button ID="GoBack" runat="server" Text="再逛逛" OnClick="GoBack_Click" />
                            &nbsp&nbsp&nbsp&nbsp
                            <asp:Button ID="MyPay" runat="server" Text="立即购买" OnClick="MyPay_Click" />
                        </td>
                    </tr>
                </table>
            </FooterTemplate>
        </asp:Repeater>
    </div>
    </form>
</asp:Content>
