<%@ page language="C#" masterpagefile="MyShopMasterPage.master" autoeventwireup="true" inherits="Member_Shop_PayOrder, WebApp_deploy" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script src="../Skin/CommStyle/js/jquery-1.8.3.min.js" type="text/javascript"></script>
    <div class="pageTitle">
        订 单 支 付</div>
    <table class="ShopOrderStyle">
    <caption>订单支付信息</caption>
        <tr>
            <td class="OrderTitle">
                支付内容：
            </td>
            <td style="width: 620px">
                <table>
                    <tr>
                        <td>
                            订单编号：
                        </td>
                        <td>
                            <asp:Label ID="LabOrderNum" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            订单总金额：
                        </td>
                        <td>
                            <asp:Label ID="LabTotalMoney" runat="server" />
                            元
                        </td>
                    </tr>
                    <tr id="Eanest" runat="server" visible="false">
                        <td>
                            订单定金：
                        </td>
                        <td>
                            <asp:Label ID="LbEanest" runat="server" />
                            元
                        </td>
                    </tr>
                    <tr>
                        <td>
                            已 付 款：
                        </td>
                        <td>
                            <asp:Label ID="LabPayedMoney" runat="server" />
                            元
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td class="OrderTitle">
                付款方式：
            </td>
            <td style="width: 620px">
                <asp:RadioButtonList ID="PayTypeList" runat="server" RepeatDirection="Vertical" DataTextField="TypeName"
                    DataValueField="TypeID" AppendDataBoundItems="true">
                    <asp:ListItem Text="商城货币支付" Value="0"></asp:ListItem>
                </asp:RadioButtonList>
                <span id="spanbalance" style="color: Red"></span>
            </td>
        </tr>
        <tr id="avaliblecard_tr" style="display: none">
            <td class="OrderTitle">
                可用卡信息：
            </td>
            <td style="width: 620px">
                <asp:CheckBoxList ID="cbl_card" runat="server">
                    <asp:ListItem Text="t1" Value="v1"></asp:ListItem>
                    <asp:ListItem Text="t2" Value="v2"></asp:ListItem>
                </asp:CheckBoxList>
                <span id="spanselectcard" style="color: Red"></span>
                <input id="h_selectcard" name="h_selectcard" type="hidden" />
            </td>
        </tr>
        <tr>
            <td class="OrderTitle">
                收款日期：
            </td>
            <td style="width: 620px">
                <asp:TextBox ID="ReceiptDate" Enabled="false" runat="server" />
            </td>
        </tr>
        <tr>
            <td class="OrderTitle">
                手续费：
            </td>
            <td style="width: 620px">
                <asp:TextBox ID="TxtPoundage" runat="server" Width="40px" Enabled="false"></asp:TextBox>
                %
                <asp:HiddenField ID="hfPoundage" runat="server" Value="0" />
            </td>
        </tr>
        <tr>
            <td class="OrderTitle">
                <asp:Label ID="LbrePay" runat="server" Text="付款金额："></asp:Label>
            </td>
            <td style="width: 620px">
                <asp:TextBox ID="Money" runat="server"  Enabled="false" />元
                <asp:RangeValidator ID="Rav1" runat="server" ControlToValidate="Money" Display="None"
                    ErrorMessage="格式不对" MaximumValue="9999999999" MinimumValue="0.0001" Type="Double" />
                <asp:RequiredFieldValidator ID="Req1" runat="server" ControlToValidate="Money" Display="None"
                    ErrorMessage="不可以是空值" />
                <span id="spanToolMonery" style="display: none; color: Red">使用商城帐支付时：总金额 = 商品总额 + 运费总额
                    + 发票税额(注意：如果有定金的可以先交定金)</span>
            </td>
        </tr>
        <tr>
            <td class="OrderTitle">
                备注：
            </td>
            <td style="width: 620px">
                <asp:TextBox ID="Remark" Text="支付订单" runat="server" MaxLength="300" Width="300px"
                    Height="50px" TextMode="MultiLine" />
            </td>
        </tr>
        <tr>
            <td class="OrderTitle">
                通知会员：
            </td>
            <td style="width: 620px">
                <asp:CheckBox ID="CheckSendMobileMesToCus" runat="server" Enabled="false" Text="同时发送手机短信通知" /><br />
                <asp:CheckBox ID="CheckSendMesMesToCus" runat="server" Checked="True" Text="同时使用站内短信通知" /><br />
                <asp:CheckBox ID="CheckSendEmailMesToCus" runat="server" Text="同时使用Email通知" /><br />
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center" style="text-align: center;">
                <asp:Button ID="butSubmit" runat="server" Text=" 确认提交 " OnClick="Button1_Click" OnClientClick="return confirm('确认无误并支付吗？')" />
                <asp:Button ID="Button2" runat="server" Text=" 取消返回 " OnClientClick="history.back();return false;"
                    CausesValidation="False" />
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        function setPoundage(obj) {
            var thisval = parseInt($(obj).val(), 10);
            var TxtPoundage = $('#<%=TxtPoundage.ClientID %>');
            //alert($(obj).next().html());
            if (thisval <= 0) {
                $('#spanToolMonery').css('display', "none");
                $("#spanbalance").html("正在查询余额…");
                $.post("/WebService/MBFmember.ashx", { newdate: new Date().getMilliseconds(), 'action': 'GetCardBalance', 'PayTypeID': thisval, 'd': new Date().getSeconds() }, function (data) {
                    if (data != "" && data != "error") {
                        $(this).parent().parent().parent().find("span").remove();
                        //$(this).parent().append("<span style='color:Red'>" + data + "</span>");
                        $("#spanbalance").html(data);
                    }
                    else {
                        alert("获取余额数据失败！");
                    }
                }, "text");
                //post-end
                if (thisval == 0) {
                    TxtPoundage.val($('#<%=hfPoundage.ClientID %>').val());
                    $('#spanToolMonery').css('display', "");
                    $("#avaliblecard_tr").hide();
                }
                else {
                    TxtPoundage.val("0");
                    $("#avaliblecard_tr td:eq(0)").html("您可用的" + $(obj).next().html().replace("支付", "") + "：");
                    GetCardInfo(thisval);
                    $("#avaliblecard_tr").show();

                }

            }
            else {
                $(this).parent().parent().parent().find("span").remove();
                TxtPoundage.val("0");
                $('#spanToolMonery').css('display', "none");
                $("#spanbalance").html("");
            }
        }
        function GetCardInfo(paytypeid) {
            var tb = $('#<%=cbl_card.ClientID %>');
            tb.empty();
            $.post("/WebService/MBFmember.ashx",
                           { data1: new Date().getTime(), action: 'GetCardInfo', 'PayTypeID': paytypeid },
                   function (data) {
                       if (data != "error" && data.length > 4) {
                           var arrData = eval(data);
                           if (paytypeid == -1) {
                               $.each(arrData.table1, function (i, n) {
                                   tb.append("<tr><td><input  cardnumber='" + n.CardNumber + "' balance='" + n.Balance + "' id='ctl00_ContentPlaceHolder1_cbl_" + n.id + "' type='checkbox' name='ctl00_ContentPlaceHolder1_cbl_" + n.id + "' /><label for='ctl00_ContentPlaceHolder1_cbl_" + n.id + "'>卡号：" + n.CardNumber + "(面值：" + n.FaceValue + " 余额：" + n.Balance + ")</label></td></tr>");
                               });
                           }
                           else if (paytypeid == -2) {
                               $.each(arrData.table1, function (i, n) {
                                   tb.append("<tr><td><input cardnumber='" + n.CardNumber + "' balance='" + n.Balance + "' id='ctl00_ContentPlaceHolder1_cbl_" + n.CardNumber + "' type='checkbox' name='ctl00_ContentPlaceHolder1_cbl_" + n.CardNumber + "' /><label for='ctl00_ContentPlaceHolder1_cbl_" + n.CardNumber + "'>卡号：" + n.CardNumber + "(面值：" + n.FaceValue + " 余额：" + n.Balance + ")</label></td></tr>");
                               });
                           }
                           else if (paytypeid == -3) {
                           }
                       }
                       else {
                           //tb.append("<tr><td><input id='ctl00_ContentPlaceHolder1_cbl_cardsss' type='checkbox' name='ctl00$ContentPlaceHolder1$cbl_card$2' /><label for='ctl00_ContentPlaceHolder1_cbl_cardsss'>无数据</label></td></tr>");
                           tb.append("<tr><td>系统会自动使用您已有的中奖券</td></tr>");
                           // alert("无数据！");
                       }
                       $('#<%=cbl_card.ClientID %> [type=checkbox]').live("change",null,cbchange);

                   }, "text");
        }
        $(document).ready(function () {
            var objs = $('input[type=radio]');
            objs.bind('change', function () { setPoundage(this) });
            if ($('#<%=TxtPoundage.ClientID %>').val() != "0") $('#spanToolMonery').css('display', "");
            var inittype = $('input[type=radio]:checked').val();
            if (inittype != "" && parseInt(inittype) < 0) {
                GetCardInfo(inittype);
                $("#avaliblecard_tr").show();

            }



            //            $('#<%=cbl_card.ClientID %>').children(":last").append("<tr><td><input id='ctl00_ContentPlaceHolder1_cbl_cardsss' type='checkbox' name='ctl00$ContentPlaceHolder1$cbl_card$2' /><label for='ctl00_ContentPlaceHolder1_cbl_cardsss'>added</label></td></tr>");
            $('#<%=cbl_card.ClientID %> input[type=checkbox]').change(cbchange);
        });
        function cbchange() {
            var cardinfo = $("#spanselectcard").html();
            if (cardinfo != "") cardinfo = "," + cardinfo;
            if ($(this).is(":checked")) {
                cardinfo = cardinfo + "," + $(this).attr("cardnumber");
            }
            else {
                cardinfo = cardinfo.replace("," + $(this).attr("cardnumber"), "");
                //cardinfo = cardinfo.replace($(obj).attr("cardnumber"), "");
            }
            if (cardinfo.length >= 1 && cardinfo.charAt(0) == ',') cardinfo = cardinfo.substr(1, cardinfo.length - 1);
            $('#spanselectcard').html(cardinfo); //选择卡时，将选择的卡号显示
            $('#h_selectcard').val(cardinfo);
        }
        
    </script>
</asp:Content>
