<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="salestrategy_config_setdonatepointrule.aspx.cs" Inherits="VA.Modules.JDingMember.sale.salestrategy_config_setdonatepointrule" %>

<!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>
    <title></title>
    <!--#include virtual="/include/css/edit.aspx"-->
    <!--#include virtual="/include/js/edit.aspx"-->     
    <script type="text/javascript">

        function save(flag) {

            var enableRule = $("input[name=rbnEnableRule]:checked").val();
            if (enableRule == "1") { //启用规则
                var donatePoint = $("#txtDonatePoint").val();
                if ($.trim(donatePoint) == "" || $.trim(donatePoint) == "0") {
                    JTongAlert('提示', '赠送积分数量不能为空！', 'info');
                    return;
                }
            }

            if (flag == 1) {
                update();
            }
        }

        function update() {
            $.ajax({
                type: "POST",
                url: "salestrategy_config_setdonatepointrule.aspx?act=update",
                dataType: "html",
                data: $("form").eq(0).serialize(),
                success: function (data, textStatus) {
                    if (data == "ok") {
                        showActResult("修改成功！", true);
                    } else if (data.indexOf("01|") != -1) {
                        showActResult(data.substring(3), false);
                    }
                    else {
                        showActResult("修改失败：" + data, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    showActResult("修改失败！textStatus :" + textStatus, false);
                }
            });
        }

        //显示操作结果；
        function showActResult(sMsg, actResult) {
            if (actResult) {
                JTongAlert('操作结果', sMsg, 'info');
            } else {
                JTongAlert('操作结果', sMsg, 'error');
            }

            if (actResult) {
                try {
                    window.parent.reload();
                } catch (e) { }
            }
        }

        function resetPage() {
            $("#txtRuleExpression").val("");
        }

        $(function () {
            $("#txtRuleExpression").focus();          
        });
    </script>

</head>
<body>
<form id="Form1" method="post" runat="server">

<div class="editPageWrapper" style="width:700px;">

<div class="centerFormTitle">
   <h1><asp:Label ID="lblFormTitle" runat="server">设置营销规则</asp:Label></h1>
</div>

<table cellspacing="0" cellpadding="3" class="editTable">
<tr id="trEditResult" runat="server" visible="false">
<td colspan="2" style="text-align:center;">
    <div class="editResult">
    <asp:Literal id="litEditResult" runat="server" />
    </div>
</td>
</tr>
<tr>
<td class="th">策略类型：</td>
<td>
    <asp:Label ID="lblBizType" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="th">策略名称：</td>
<td>              
    <asp:Label ID="lblStrategyName" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="th">启用规则：</td>
<td>              
    <asp:RadioButtonList ID="rbnEnableRule" runat="server"
         RepeatDirection="Horizontal"
         RepeatLayout="Flow">
        <asp:ListItem Value="1" Selected="True">启用</asp:ListItem>
        <asp:ListItem Value="0">不启用</asp:ListItem>
    </asp:RadioButtonList>                 
</td>
</tr>
</table>

<table id="Table1" cellspacing="0" cellpadding="3" class="editTable" style="margin-top:-1px;">
<tr>
<td class="th">积分赠送规则：</td>
<td style="text-align:left;">
    
    每充值/消费1元，赠送积分
    <VACTL:TextBox ID="txtDonatePoint" Runat="server"
            EnableViewState="False"
            CssClass="input"
            Width="60px"
            FieldName="赠送积分"
            RequiredFieldType="Integer"
            MaxLength="10" /> 分      
</td>
</tr>
</table>

<table cellspacing="0" cellpadding="3" class="editTable" style="margin-top:-1px;">
<tr>
<td class="footer">

    <input type="button" id="btnUpdate" runat="server" class="btn" style="width:100px" onclick="save(1)" value="保存" />
    <input type="button" id="btnReset" class="btn" style="width:80px" onclick="resetPage()" value="重置" />
    <asp:Label ID="lblNote" runat="server" ForeColor="Red"></asp:Label>

    <asp:HiddenField ID="hfKey" runat="server" />
    
    <VACTL:Hint ID="Hint1" runat="server" HintImageUrl="/app_themes/default/images/textbox" />
    <VACTL:ValidationSummary ID="ValidationSummary1" runat="server"
            DisplayMode="List"
            EnableClientScript="true" />
    
    <!--注意：这个文件一定要放到页面底部，以便覆盖asp.net验证脚本中的同名函数-->
    <script type="text/javascript" src="/scripts/utils/aspnet_validator_extend.js"></script>  
        
</td>
</tr>
</table>

</div><!--editPageWrapper.END-->

</form>
</body>
</html>

<%    
    Response.Write("<script type=\"text/javascript\">");       
    Response.Write("var itemList = [");       
       
    var i = 0;
    System.Collections.Generic.List<VA.Modules.JDingMember.Core.Model.Sale.Strategy.SSDonatePointRuleInfo> rules = base.strategy.GetDonatePointRules(base.strategyCode);
    foreach (VA.Modules.JDingMember.Core.Model.Sale.Strategy.SSDonatePointRuleInfo item in rules)
    {
        string chargeAmount = item.Charges.ToString("F2");
        string donatePoints = item.Donate_Points.ToString("F2");

        Response.Write("{");
        Response.Write("\"chargeAmount\":\"" + chargeAmount + "\",\"donatePoints\":\"" + donatePoints + "\"");

        if (i == rules.Count - 1)
            Response.Write("}");
        else
            Response.Write("},");
        
        i++;
    }

    Response.Write("];");      
    Response.Write("</script>");        
%>

<script type="text/javascript">
    for (var i = 0; i < itemList.length; i++) {
        formEditListTable_addRow(
            itemList[i].chargeAmount,
            itemList[i].donatePoints);
    }
</script>
