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

<!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() {

        //调用asp.net验证控件自带的js数据验证脚本对控件进行验证；
        var validationResult = Page_ClientValidate('');
        if (!validationResult) {
            return;
        }

        JTongAlertConfirm("确定要发行吗？ <br /><br />请确认填写信息无误！", add);
    }

    function add() {

        $("#btnSubmit").attr("disabled", "disabled");

        openDivWindow("", 300, 100, 220, 180, "divProgressNote");

        var requestType = "POST";
        var url = pageName + "?act=add";  //pageName在BasePage中注册到的客户端；
        var dataType = "html";
        var data = $("form").eq(0).serialize();
        var successFN = function (data, textStatus) {
            closeWindow("divProgressNote");
            if (data == "ok") {
                showActResult("发行成功！", true, doAfterAdd);
            } else if (data.indexOf("01|") != -1) {
                showActResult(data.substring(3), false, doAfterAdd);
            }
            else {
                showActResult("发行失败：" + data, false, doAfterAdd);
            }

            $("#btnSubmit").removeAttr("disabled");
        };
        var errorFN = function (textStatus, callback) {
            closeWindow("divProgressNote");
            showActResult("请求失败！textStatus :" + textStatus, false, callback);

            $("#btnSubmit").removeAttr("disabled");
        }

        ajaxRequest(requestType,
            url,
            dataType,
            data,
            successFN,
            errorFN
            );
    }

    function doAfterAdd(actResult) {
        if (actResult) {
            try{
                if (window.parent != window.self) {
                    window.parent.completeReload();
                }
            }catch(e){}
            resetPage();
        }
    }

    function resetPage() {

        $("#txtVoucherName").val("");        
        $("#txtFaceValue").val("");
        $("#txtLimitMaxUseTimesPerDay").val("0");
        $("#txtLimitMinConsumeAmountPerBill").val("0");
        $("#txtReleaseQuantity").val("");

        clearInputValidatorError();

        $("#txtVoucherName").focus();
    }

    function rbnYxqOptions_ChangeHandler() {
        var sendOption = $('input:radio[name=rbnYxqOptions]:checked').val();
        if (sendOption == "1") { //永久有效
            $("#txtTakeEffectDate").attr("disabled", "disabled");
            $("#txtExpireDate").attr("disabled", "disabled");
            $("#laydate-icon").hide();
        } else if (sendOption == "2") { //指定日期
            $("#txtTakeEffectDate").removeAttr("disabled");
            $("#txtExpireDate").removeAttr("disabled");
            $(".laydate-icon").show();
        }
    }

    $(function () {
        $("#txtVoucherName").focus();

        $('input:radio[name=rbnYxqOptions]').change(function () {
            rbnYxqOptions_ChangeHandler();
        });
        rbnYxqOptions_ChangeHandler();

        //焦点控制
        $("input,select").keydown(function (event) {
            if (event.keyCode == 13) {
                var targetID = event.target.id;
                switch (targetID) {
                    case "txtVoucherName":
                        if ($("#txtVoucherName").val() != "") {
                            $("#txtFaceValue").select();
                        }
                        break;                 
                    case "txtFaceValue":
                        if ($("#txtFaceValue").val() != "") {
                            $("#txtLimitMinConsumeAmountPerBill").select();
                        }
                        break;
                    //case "txtLimitMaxUseTimesPerDay":
                    //    $("#txtLimitMinConsumeAmountPerBill").select();
                    //    break;
                    case "txtLimitMinConsumeAmountPerBill":
                        $("#txtReleaseQuantity").select();
                        break;
                    case "txtReleaseQuantity":
                        save();
                        break;
                    default:
                        break;
                }
            }
        });
    });

    </script>

    <style type="text/css">  
    .editTable .th{
        width:140px;
    }
    </style>
</head>
<body>
<form id="Form1" method="post" runat="server">

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

<%
    if (VA.Modules.JDingMember.Core.SystemInfo.SoftInfo.SoftLevel == VA.Modules.JDingMember.Core.Enums.SoftLevel.Free ||
        VA.Modules.JDingMember.Core.SystemInfo.SoftInfo.SoftLevel == VA.Modules.JDingMember.Core.Enums.SoftLevel.Basic ||
        VA.Modules.JDingMember.Core.SystemInfo.SoftInfo.SoftLevel == VA.Modules.JDingMember.Core.Enums.SoftLevel.Standard)
    {
        base.ShowSoftFunctionLimitNote(VA.Modules.JDingMember.Core.SystemInfo.SoftInfo.SoftLevelName);
    }
%>

<div class="centerFormTitle">
   <h1><asp:Label ID="lblFormTitle" runat="server">创建并发行代金券</asp:Label></h1>
</div>

<table cellspacing="0" cellpadding="3" class="editTable">
<tr>
<td class="th">(<span class="note mustfill">*</span>)代金券名称：</td>
<td>              
    <VACTL:TextBox ID="txtVoucherName" Runat="server"
            EnableViewState="False"
            CssClass="input"
            Width="300px"
            CanBeNull="No"
            FieldName="代金券名称"
            MaxLength="50" />        
</td>
</tr>
<tr>
<td class="th">(<span class="note mustfill">*</span>)代金券面值：</td>
<td>
    <VACTL:TextBox runat="server" ID="txtFaceValue" 
            CssClass="input" 
            Width="100px"
            CanBeNull="No"
            FieldName="txtFaceValue"
            RequiredFieldType="Money"
            /> 元
</td>
</tr>
<tr runat="server" visible="false">
<td class="th">(<span class="note mustfill">*</span>)每日限使用次数：</td>
<td>
     <VACTL:TextBox runat="server" ID="txtLimitMaxUseTimesPerDay" 
            CssClass="input" 
            Width="100px"
            CanBeNull="Yes"
            FieldName="每日限使次数"
            RequiredFieldType="Integer"
            Text="0"
            /> <span class="note">（0表示不限制）</span>
</td>
</tr>
<tr>
<td class="th">(<span class="note mustfill">*</span>)限最低消费金额：</td>
<td>
     <VACTL:TextBox runat="server" ID="txtLimitMinConsumeAmountPerBill" 
            CssClass="input" 
            Width="100px"
            CanBeNull="No"
            FieldName="限最低消费金额"
            RequiredFieldType="Money"
            Text="0"
            /> <span class="note">（消费金额不低于该值才能使用该代金券，0表示不限）</span>
</td>
</tr>
<tr>
<td class="th">(<span class="note mustfill">*</span>)发行数量：</td>
<td>
     <VACTL:TextBox runat="server" ID="txtReleaseQuantity" 
            CssClass="input" 
            Width="100px"
            CanBeNull="No"
            FieldName="发行数量"
            RequiredFieldType="PositiveInteger"
            Text="0"
            /> <span class="note">注：建议数量不要超过5000，后续可以继续发行。</span>
</td>
</tr>
<tr>
<td class="th">(<span class="note mustfill">*</span>)有 效 期：</td>
<td>
     <asp:RadioButtonList ID="rbnYxqOptions" runat="server"
         RepeatDirection="Horizontal"
         RepeatLayout="Flow">
        <asp:ListItem Value="1" Selected="True">永久有效</asp:ListItem>
        <asp:ListItem Value="2">指定日期</asp:ListItem>
    </asp:RadioButtonList>

    <VACTL:TextBox ID="txtTakeEffectDate" Runat="server"
            EnableViewState="False"
            CssClass="input"
            Width="130px"
            ReadOnly="true"
            onclick="laydate({istime:true,format: 'YYYY-MM-DD hh:mm'})"
            MaxLength="20" />
    <span id="laydate-icon1" class="laydate-icon" onclick="laydate({elem: '#txtTakeEffectDate',istime:true,format: 'YYYY-MM-DD hh:mm'});"></span>
    至
    <VACTL:TextBox ID="txtExpireDate" Runat="server"
            EnableViewState="False"
            CssClass="input"
            Width="130px"
            ReadOnly="true"
            onclick="laydate({istime:true,format: 'YYYY-MM-DD hh:mm'})"
            MaxLength="20" />
    <span id="laydate-icon1" class="laydate-icon" onclick="laydate({elem: '#txtExpireDate',istime:true,format: 'YYYY-MM-DD hh:mm'});"></span>
</td>
</tr>
<tr>
<td colspan="2" class="footer">

    <input type="button" id="btnSubmit" class="btn" style="width:100px" onclick="save()" value="发行" />
    <input type="button" id="btnClear" class="btn" style="width:100px" onclick="resetPage()" value="重置" />

    <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-->

<div id="divProgressNote" style="display:none;line-height:80px;text-align:center;">
    <span style="font-weight:bold;font-size:14px;">正在执行，请稍后……</span>
</div>



<div style="padding:10px;">
<h3>代金券使用流程</h3>
<br />
<img src="/app_themes/images/system/voucher.png" />
</div>

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

