<%@ page language="C#" masterpagefile="~/Admin/AdminIndexMaster.master" autoeventwireup="true" inherits="Admin_Admin_CouponInfo, WebApp_deploy" title="添加优惠券规则" %>

<asp:Content ID="cphContent" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <script src="Js/Jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Js/Function.js" type="text/javascript"></script>
    <table class="nick" id="table_item" runat="server">
        <tr>
            <td class="tit left1">
                &nbsp;&nbsp;优惠券规则管理
            </td>
            <td class="tit" style="text-align: right;">
                <a href="Admin_CouponInfo.aspx?action=addinfo&MenuName=运营管理&FileName=添加优惠券规则">
                    <img style="border: 0px;" src="tpl/img/ico/add.gif" alt="添加" />新增 </a>&nbsp;&nbsp;
            </td>
        </tr>
    </table>
    <%--列表 begin--%>
    <asp:PlaceHolder ID="phManage" runat="server">
        <asp:GridView ID="gvList" runat="server" CssClass="adminlist" AllowPaging="True"
            AutoGenerateColumns="False" PageSize="20" OnRowDataBound="gvList_RowDataBound">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <input type="checkbox" id="chk_select" name="chk_select" value='<%# Eval("CouponInfoID") %>' />
                    </ItemTemplate>
                    <HeaderTemplate>
                        <input id="chkAll" onclick="SelectAllCheckboxes(this,'chk_select');" runat="server"
                            type="checkbox" />
                    </HeaderTemplate>
                    <ItemStyle HorizontalAlign="Center" Width="5%" />
                </asp:TemplateField>
                <asp:BoundField DataField="CouponName" SortExpression="CouponName" HeaderText="名称" />
                <asp:BoundField DataField="CouponNumPattern" SortExpression="CouponNumPattern" HeaderText="号码格式 " />
                <asp:BoundField DataFormatString="{0:0.00}" DataField="CouponParvalue" SortExpression="CouponParvalue"
                    HeaderText="面值" />
                <asp:BoundField DataField="EndDate" SortExpression="EndDate" HeaderText="截止日期" DataFormatString="{0:yyyy-MM-dd}" />
                <asp:TemplateField HeaderText="适用会员">
                    <ItemTemplate>
                        <%# getUserGroupName(Eval("UserGroupID"))%>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" Width="160px" />
                </asp:TemplateField>
                <asp:BoundField DataField="CouponCount" SortExpression="CouponCount" HeaderText="张数 " />
                <asp:TemplateField HeaderText="是否发布">
                    <ItemTemplate>
                        <%# getPublist(Eval("CouponIsPublish"))%>
                        <asp:HiddenField ID="hfCouponIsPublish" runat="server" Value='<%# Eval("CouponIsPublish") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="操作">
                    <ItemTemplate>
                        <a href='<%#"Admin_CouponInfo.aspx?action=checkinfo&MenuName=运营管理&FileName=查看优惠券规则&InfoID="+Eval("CouponInfoID") %>'>
                            查看</a> <a href='<%#"Admin_CouponInfo.aspx?action=editinfo&MenuName=运营管理&FileName=修改优惠券规则&InfoID="+Eval("CouponInfoID") %>'>
                                修改</a> <a href='<%#"Admin_CouponItem.aspx?MenuName=运营管理&FileName=优惠券管理&InfoID="+Eval("CouponInfoID") %>'>
                                    优惠券</a>
                        <asp:LinkButton ID="btnDelete" runat="server" OnClientClick="return confirm('您真的要删除?')"
                            CommandName='DelInfo' CommandArgument='<%# Eval("CouponInfoID") %>' Text="删除"
                            OnCommand="Button_Command" />
                        <asp:LinkButton ID="btnEdit" runat="server" CommandName='EditInfo' CommandArgument='<%# Eval("CouponInfoID") %>'
                            Text="发布" OnCommand="Button_Command" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EmptyDataTemplate>
                <table class="adminlist">
                    <tr>
                        <th>
                            名称
                        </th>
                        <th>
                            号码格式
                        </th>
                        <th>
                            面值
                        </th>
                        <th>
                            截止日期
                        </th>
                        <th>
                            适用会员
                        </th>
                        <th>
                            张数
                        </th>
                        <th>
                            是否发布
                        </th>
                    </tr>
                    <tr>
                        <td colspan="7">
                            优惠券规则无数据!
                        </td>
                    </tr>
                </table>
            </EmptyDataTemplate>
        </asp:GridView>
        <div class="page">
            <asp:Label ID="PagePanel" runat="server" />
        </div>
        <div class="div_btm">
            <asp:Button ID="ButDel" runat="server" CausesValidation="False" CommandName="MoreDel"
                Text="批量删除" OnClientClick="return confirm('您真的要删除?')" OnCommand="Button_Command">
            </asp:Button>&nbsp;
        </div>
    </asp:PlaceHolder>
    <%--列表 end--%>
    <%--添加/修改 begin--%>
    <asp:PlaceHolder ID="phAddOrEdit" runat="server">
        <table class="nick" width="100%" id="AddTable" runat="server">
            <tr>
                <td class="tit" colspan="2">
                    &nbsp;&nbsp;<asp:Literal ID="ltrTitle" runat="server">添加优惠券规则</asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    名称 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtCouponName" runat="server" Text="" Width="300px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    号码格式 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtCouponNumPattern" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    面值 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtCouponParvalue" Text="" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    满足金额 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtNeedsMoney" Text="" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    有效期 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtBeginDate" runat="server" Text="" onfocus="SelectDate(this,'yyyy-MM-dd')"></asp:TextBox>
                    &nbsp;&nbsp;至&nbsp;&nbsp;<asp:TextBox ID="txtEndDate" runat="server" Text="" onfocus="SelectDate(this,'yyyy-MM-dd')"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    会员组 ：
                </td>
                <td class="rtd">
                    <asp:CheckBoxList ID="cblUserGroup" runat="server" DataTextField="GroupName" DataValueField="GroupID"
                        RepeatDirection="Horizontal" RepeatColumns="3" />
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    获得优惠券的方式 ：
                </td>
                <td class="rtd">
                    <asp:RadioButtonList ID="rblGetFashion" runat="server" RepeatDirection="Horizontal"
                        RepeatColumns="2">
                        <%--<asp:ListItem Value="BuyAny">购买任意商品可得到此优惠券</asp:ListItem>
                        <asp:ListItem Value="BuyClassify">购买指定分类商品可得到此优惠券</asp:ListItem>--%>
                        <asp:ListItem Value="BuySpecific" Selected="True">购买指定商品可得到此优惠券</asp:ListItem>
                        <%--<asp:ListItem Value="BuyOrderMoney">订单满足一定金额可得到此优惠券</asp:ListItem>--%>
                    </asp:RadioButtonList>
                </td>
            </tr>
        </table>
        <table class="nick" width="100%" id="CheckTable" runat="server">
            <tr>
                <td class="tit" colspan="2">
                    &nbsp;&nbsp;<asp:Literal ID="ltrCheckTitle" runat="server">查看优惠券规则</asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    名称 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrCouponName" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    号码格式 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrCouponNumPattern" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    面值 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrCouponParvalue" Text="" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    满足金额 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrNeedsMoney" Text="" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    有效期 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrBeginDate" runat="server"></asp:Literal>
                    &nbsp;&nbsp;至&nbsp;&nbsp;<asp:Literal ID="ltrEndDate" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    会员组 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrUserGroup" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    获得优惠券的方式 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrGetFashion" runat="server"></asp:Literal>
                </td>
            </tr>
        </table>
        <%--获得优惠券的方式 begin--%>
        <table cellpadding="0px" cellspacing="0px" class="nick" width="auto" id="tabBuyClassify"
            style="padding: 0px; margin: 0px; display: none;">
            <tr>
                <td class="ltd">
                    商品分类 ：
                </td>
                <td class="rtd">
                    <div>
                        <div>
                            <a id="addBuyClassify" style="cursor: pointer; color: Red; font-weight: bold;" runat="server">
                                添加商品分类</a></div>
                        <div id="divClass" runat="server">
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <table cellpadding="0px" cellspacing="0px" class="nick" width="auto" id="tabBuySpecific"
            style="padding: 0px; margin: 0px; display: block;">
            <tr>
                <td class="ltd">
                    商品商品 ：
                </td>
                <td class="rtd">
                    <div>
                        <div>
                            <a id="addBuySpecific" style="cursor: pointer; color: Red; font-weight: bold;" runat="server">
                                添加商品</a></div>
                        <div id="divProduct" runat="server">
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <table cellpadding="0px" cellspacing="0px" class="nick" width="auto" id="tabBuyOrderMoney"
            style="padding: 0px; margin: 0px; display: none;">
            <tr>
                <td class="ltd">
                    订单金额 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtOrderMoney" runat="server"></asp:TextBox>
                </td>
            </tr>
        </table>
        <%--获得优惠券的方式 end--%>
        <%--限用商品类型 begin--%>
        <table cellpadding="0" id="AddTableLimit" runat="server" cellspacing="0" class="nick"
            width="auto" style="padding: 0px; margin: 0px;">
            <tr>
                <td class="ltd">
                    限用商品类型 ：
                </td>
                <td class="rtd">
                    <asp:RadioButtonList ID="rblUseProductType" runat="server" RepeatDirection="Horizontal">
                        <%--<asp:ListItem Value="LimitAll">所有商品</asp:ListItem>
                        <asp:ListItem Value="LimitClassify">指定分类</asp:ListItem>--%>
                        <asp:ListItem Value="LimitSpecific" Selected="True">指定商品</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
        </table>
        <table cellpadding="0" id="CheckTableLimit" runat="server" cellspacing="0" class="nick"
            width="auto" style="padding: 0px; margin: 0px;">
            <tr>
                <td class="ltd">
                    限用商品类型 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrUseProductType" runat="server"></asp:Literal>
                </td>
            </tr>
        </table>
        <table cellpadding="0px" cellspacing="0px" class="nick" width="auto" id="tabLimitClassify"
            style="padding: 0px; margin: 0px; display: none;">
            <tr>
                <td class="ltd">
                    商品分类 ：
                </td>
                <td class="rtd">
                    <div>
                        <div>
                            <a id="addLimitClassify" style="cursor: pointer; color: Red; font-weight: bold;"
                                runat="server">添加商品分类</a></div>
                        <div id="divLimitClassify" runat="server">
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <table cellpadding="0px" cellspacing="0px" class="nick" width="auto" id="tabLimitSpecific"
            style="padding: 0px; margin: 0px; display: block;">
            <tr>
                <td class="ltd">
                    商品商品 ：
                </td>
                <td class="rtd">
                    <div>
                        <div>
                            <a id="addLimitSpecific" style="cursor: pointer; color: Red; font-weight: bold;"
                                runat="server">添加商品</a></div>
                        <div id="divLimitSpecific" runat="server">
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <%--限用商品类型 end--%>
        <%--是否发布 优惠券张数 begin--%>
        <table cellpadding="0" cellspacing="0" id="AddTablePublisth" runat="server" class="nick"
            width="auto" style="padding: 0px; margin: 0px;">
            <tr>
                <td class="ltd">
                    是否发布 ：
                </td>
                <td class="rtd">
                    <%--<asp:CheckBox ID="chkCouponIsPublish" Text="是" runat="server" Checked="False" />--%>
                    <input id="chkCouponIsPublish" type="checkbox" onclick="CheckPublish()" runat="server"
                        value="是" />是
                </td>
            </tr>
        </table>
        <table cellpadding="0" cellspacing="0" id="CheckTablePublisth" runat="server" class="nick"
            width="auto" style="padding: 0px; margin: 0px;">
            <tr>
                <td class="ltd">
                    是否发布 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrCouponIsPublish" runat="server"></asp:Literal>
                </td>
            </tr>
        </table>
        <table cellpadding="0px" cellspacing="0px" class="nick" width="auto" id="tabCount"
            style="padding: 0px; margin: 0px; display: none;">
            <tr>
                <td class="ltd">
                    优惠券张数 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtCouponCount" runat="server" Text="0"></asp:TextBox>
                    <asp:Literal ID="ltrCouponCount" runat="server" Text="0"></asp:Literal>
                </td>
            </tr>
        </table>
        <%--是否发布 优惠券张数 end--%>
        <table class="nick" width="auto" cellpadding="0px" cellspacing="0px" style="padding: 0px;
            margin: 0px;">
            <tr>
                <td colspan="2" class="btm">
                    <asp:HiddenField ID="hfBuyClassifyID" runat="server" Value="" />
                    <%--hfBuyClassifyID  保存获取优惠券商品分类id--%>
                    <asp:HiddenField ID="hfBuySpecificID" runat="server" Value="" />
                    <%--hfBuyClassifyID  保存获取优惠券商品id--%>
                    <asp:HiddenField ID="hfFashionnContent" runat="server" Value="" />
                    <%--hfFashionnContent 获取优惠券的内容--%>
                    <asp:HiddenField ID="hfLimitClassifyID" runat="server" Value="" />
                    <%--hfLimitClassify  保存限用商品分类id--%>
                    <asp:HiddenField ID="hfLimitSpecificID" runat="server" Value="" />
                    <%--hfLimitSpecific  保存限用商品id--%>
                    <asp:HiddenField ID="hfLimitProductContent" runat="server" Value="" />
                    <%--hfLimitProductContent 限用商品的内容--%>
                    <asp:Button ID="btnAdd" runat="server" Text="添 加" OnClientClick="return checkPass()"
                        OnClick="btnAdd_Click" />
                    <input type="button" onclick="location.href='Admin_CouponInfo.aspx'" value="返 回" />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="color: Blue; text-align: left;">
                    说明：号码格式前面和后面是字母，中间是17位数字；每个?代表一个英文字母，#代表一个数字
                </td>
            </tr>
        </table>
    </asp:PlaceHolder>
    <br />
    <%--添加/修改 end--%>
    <asp:PlaceHolder ID="phPublish" runat="server">
        <table cellpadding="0" cellspacing="0" runat="server" class="nick" width="auto" style="padding: 0px;
            margin: 0px;">
            <tr>
                <td class="tit" colspan="2">
                    &nbsp;&nbsp;<asp:Literal ID="ltrPublistTitle" runat="server">发布优惠券</asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    名称 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrName" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    号码格式 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrPattern" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    面值 ：
                </td>
                <td class="rtd">
                    <asp:Literal ID="ltrValue" Text="" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    优惠券张数 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtPubCount" runat="server" Text="0"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Button ID="btnEdit" runat="server" Text="发布" OnClientClick="return chekcPubCount()"
                        OnClick="btnEdit_Click" />
                    <input type="button" onclick="location.href='Admin_CouponInfo.aspx'" value="返 回" />
                </td>
            </tr>
        </table>
    </asp:PlaceHolder>
    <script type="text/javascript">
        //名称
        function checkCouponName() {
            var txtName = $("#<%=txtCouponName.ClientID %>"); //方案名称
            if (txtName.val().length == 0) {
                alert("优惠券名称不能为空!");
                txtName.focus();
                return false;
            }
            return true;
        }
        //号码格式
        function checkCouponNumPattern() {
            var txtNumpattern = $("#<%=txtCouponNumPattern.ClientID %>"); //号码格式
            if (txtNumpattern.val().length == 0) {
                alert("优惠券号码格式不能为空!");
                txtNumpattern.focus();
                return false;
            }
            var bp = txtNumpattern.val().indexOf('#################'); //yyyyMMddHHmmssmmm
            var ap = txtNumpattern.val().lastIndexOf("#");
            //alert(bp+"\n"+ap);
            if (bp < 0) {
                alert("优惠券号码格式中数字的位数不对!");
                txtNumpattern.focus();
                return false;
            }
            return true;
        }
        //面值
        function chekcParvalue(sen, i) {
            var parvalue = $("#<%=txtCouponParvalue.ClientID %>"); //面值
            //输入的数量是数字且不能小于0
            if (parvalue.val() == null || parvalue.val() == "") {
                alert("请输入优惠券的面值！");
                parvalue.focus();
                return false;
            }
            if ((isNaN(parvalue.val()) == true)) {//判断输入的是否为数字
                alert("请您输入0~9之间的数字！");
                parvalue.focus();
                parvalue.val("");
                return false;
            }
            if (parseFloat(parvalue.val()) <= 0) {
                alert('您输入优惠券的面值不能小于0！');
                parvalue.focus();
                parvalue.val("1");
                return false;
            }
            return true;
        }
        //满足金额
        function chekcNeedsmoney() {
            var needsmoney = $("#<%=txtNeedsMoney.ClientID %>"); //满足金额
            //输入的数量是数字且不能小于0
            if (needsmoney.val() == null || needsmoney.val() == "") {
                alert("请输入优惠券的满足金额值！");
                needsmoney.focus();
                return false;
            }
            if ((isNaN(needsmoney.val()) == true)) {//判断输入的是否为数字
                alert("请您输入0~9之间的数字！");
                needsmoney.focus();
                needsmoney.val("");
                return false;
            }
            if (parseFloat(needsmoney.val()) <= 0) {
                alert('您输入满足金额值不能小于0！');
                needsmoney.focus();
                needsmoney.val("1");
                return false;
            }
            return true;
        }
        //有效期
        function checkTime() {
            var begindate = $("#<%=txtBeginDate.ClientID %>"); //开始时间
            if (begindate.val().length == 0) {
                alert("开始时间不能为空!");
                begindate.focus();
                return false;
            }
            var enddate = $("#<%=txtEndDate.ClientID %>"); //结束时间
            if (enddate.val().length == 0) {
                alert("结束时间不能为空!");
                enddate.focus();
                return false;
            }
            return true;
        }
        //张数
        function chekcCouponCount() {
            //添加：addinfo、修改：editinfo
            var actionInfo = "<%=ActionTab %>";
            if (actionInfo == "addinfo") {
                var ispublish = $("#<%=chkCouponIsPublish.ClientID %>"); //是否发布
                if (ispublish.attr("checked") == "checked" || ispublish.attr("checked")) {
                    var parvalue = $("#<%=txtCouponCount.ClientID %>"); //张数
                    //输入的数量是数字且不能小于0
                    if (parvalue.val() == null || parvalue.val() == "") {
                        alert("请输入优惠券的张数！");
                        parvalue.focus();
                        return false;
                    }
                    if ((isNaN(parvalue.val()) == true)) {//判断输入的是否为数字
                        alert("请您输入0~9之间的数字！");
                        parvalue.focus();
                        parvalue.val("");
                        return false;
                    }
                    if (parseInt(parvalue.val()) < 1) {
                        alert('您输入优惠券张数不能小于0！');
                        parvalue.focus();
                        parvalue.val("1");
                        return false;
                    }
                }
            }
            return true;
        }
        function checkPass() {
            if (checkCouponName() && checkCouponName() && checkCouponNumPattern() && chekcParvalue() && chekcNeedsmoney() && checkTime() && GetFashionContent() && UseProductContent() && chekcCouponCount()) {
                return true;
            } else {
                return false;
            }
        }

        //发布
        function chekcPubCount() {
            var parvalue = $("#<%=txtPubCount.ClientID %>"); //张数
            //输入的数量是数字且不能小于0
            if (parvalue.val() == null || parvalue.val() == "") {
                alert("请输入优惠券的张数！");
                parvalue.focus();
                return false;
            }
            if ((isNaN(parvalue.val()) == true)) {//判断输入的是否为数字
                alert("请您输入0~9之间的数字！");
                parvalue.focus();
                parvalue.val("");
                return false;
            }
            if (parseInt(parvalue.val()) < 1) {
                alert('您输入优惠券张数不能小于0！');
                parvalue.focus();
                parvalue.val("1");
                return false;
            }
            return true;
        }
    </script>
    <script type="text/javascript">
        //获取优惠券的内容
        function GetFashionContent() {
            var productstr = $("#<%=hfFashionnContent.ClientID %>"); //获取优惠券内容
            var selectvalue = $('input:radio[name="ctl00$ContentPlaceHolder1$rblGetFashion"]:checked').val();
            if (selectvalue == "BuyClassify") {
                var productlist = $("#tb_fashion_class tr"); //商品分类信息
                if (productlist.length <= 1) {
                    alert("没有商品分类记录！");
                    return false;
                }
                var str = "";
                var newstr = "";
                if (productlist.length - 1 > 0) {
                    for (var i = 0; i < productlist.length - 1; i++) {
                        var vproductid = $("#CFclassID" + i); //商品分类ID                    
                        newstr = vproductid.val() + ",";
                        str += newstr;
                    }
                    var position = str.lastIndexOf(',');
                    if (position > 0) {
                        str = str.substring(0, str.length - 1);
                    }
                    productstr.val(str);
                }
            } else if (selectvalue == "BuySpecific") {
                var productlist = $("#tb_fashion_product tr"); //商品信息
                if (productlist.length <= 1) {
                    alert("没有商品记录！");
                    return false;
                }
                var str = "";
                var newstr = "";
                if (productlist.length - 1 > 0) {
                    for (var i = 0; i < productlist.length - 1; i++) {
                        var vproductid = $("#productID" + i); //商品ID                    
                        newstr = vproductid.val() + ",";
                        str += newstr;
                    }
                    var position = str.lastIndexOf(',');
                    if (position > 0) {
                        str = str.substring(0, str.length - 1);
                    }
                    productstr.val(str);
                }
            } else if (selectvalue == "BuyOrderMoney") {
                var needsmoney = $("#<%=txtNeedsMoney.ClientID %>"); //满足金额(使用)
                var ordermoney = $("#<%=txtOrderMoney.ClientID %>"); //订单金额(获取)
                //输入的数量是数字且不能小于0
                if (ordermoney.val() == null || ordermoney.val() == "") {
                    alert("请输入优惠券的订单金额！");
                    ordermoney.focus();
                    return false;
                }
                if ((isNaN(ordermoney.val()) == true)) {//判断输入的是否为数字
                    alert("请您输入0~9之间的数字！");
                    ordermoney.focus();
                    ordermoney.val("");
                    return false;
                }
                if (parseFloat(ordermoney.val()) <= 0) {
                    alert('您输入订单金额值不能小于0！');
                    ordermoney.focus();
                    ordermoney.val("1");
                    return false;
                }
                if ((parseFloat(ordermoney.val()) < parseFloat(needsmoney.val()))) {
                    alert('订单金额不能小于满足金额！');
                    ordermoney.focus();
                    ordermoney.val("");
                    return false;
                }
                productstr.val(ordermoney.val());
            } else {
                productstr.val("");
            }
            return true;
        }

        //限用商品的内容
        function UseProductContent() {
            var productstr = $("#<%=hfLimitProductContent.ClientID %>"); //限用商品的内容
            var selectvalue = $('input:radio[name="ctl00$ContentPlaceHolder1$rblUseProductType"]:checked').val();
            if (selectvalue == "LimitClassify") {
                //商品分类
                var productlist = $("#tb_limint_class tr"); //商品信息
                if (productlist.length <= 1) {
                    alert("没有商品记录！");
                    return false;
                }
                var str = "";
                var newstr = "";
                if (productlist.length - 1 > 0) {
                    for (var i = 0; i < productlist.length - 1; i++) {
                        var vproductid = $("#CLclassID" + i); //商品ID                    
                        newstr = vproductid.val() + ",";
                        str += newstr;
                    }
                    var position = str.lastIndexOf(',');
                    if (position > 0) {
                        str = str.substring(0, str.length - 1);
                    }
                    productstr.val(str);
                }
            } else if (selectvalue == "LimitSpecific") {
                //商品
                var productlist = $("#tb_limit_product tr"); //商品信息
                if (productlist.length <= 1) {
                    alert("没有商品记录！");
                    return false;
                }
                var str = "";
                var newstr = "";
                if (productlist.length - 1 > 0) {
                    for (var i = 0; i < productlist.length - 1; i++) {
                        var vproductid = $("#LproductID" + i); //商品ID                    
                        newstr = vproductid.val() + ",";
                        str += newstr;
                    }
                    var position = str.lastIndexOf(',');
                    if (position > 0) {
                        str = str.substring(0, str.length - 1);
                    }
                    productstr.val(str);
                }
            } else {
                productstr.val("");
            }
            return true;
        }
    </script>
    <%--显示/隐藏 获取优惠券方式、限用商品类型、优惠券张数--%>
    <script type="text/javascript">
        //获取优惠券的方式
        function ControlFashion() {
            var selectvalue = $('input:radio[name="ctl00$ContentPlaceHolder1$rblGetFashion"]:checked').val();
            var tabBuyClassify = document.getElementById('tabBuyClassify'); //商品分类
            var tabBuySpecific = document.getElementById('tabBuySpecific'); //商品
            var tabBuyOrderMoney = document.getElementById('tabBuyOrderMoney'); //订单金额

            switch (selectvalue) {
                case "BuyClassify":
                    tabBuyClassify.style.display = "";
                    tabBuySpecific.style.display = "none";
                    tabBuyOrderMoney.style.display = "none";
                    break;
                case "BuySpecific":
                    tabBuyClassify.style.display = "none";
                    tabBuySpecific.style.display = "";
                    tabBuyOrderMoney.style.display = "none";
                    break;
                case "BuyOrderMoney":
                    tabBuyClassify.style.display = "none";
                    tabBuySpecific.style.display = "none";
                    tabBuyOrderMoney.style.display = "";
                    break;
                default:
                    tabBuyClassify.style.display = "none";
                    tabBuySpecific.style.display = "none";
                    tabBuyOrderMoney.style.display = "none";
                    break;
            }
        }

        //限用商品类型
        function ControlUseProductType() {
            var selectvalue = $('input:radio[name="ctl00$ContentPlaceHolder1$rblUseProductType"]:checked').val();
            var tabLimitClassify = document.getElementById('tabLimitClassify'); //商品分类
            var tabLimitSpecific = document.getElementById('tabLimitSpecific'); //商品
            switch (selectvalue) {
                case "LimitClassify":
                    tabLimitClassify.style.display = "";
                    tabLimitSpecific.style.display = "none";
                    break;
                case "LimitSpecific":
                    tabLimitClassify.style.display = "none";
                    tabLimitSpecific.style.display = "";
                    break;
                default:
                    tabLimitClassify.style.display = "none";
                    tabLimitSpecific.style.display = "none";
                    break;
            }
        }
        //是否发布
        function CheckPublish() {
            var ispublish = $("#<%=chkCouponIsPublish.ClientID %>"); //是否发布
            var tabcount = document.getElementById("tabCount");
            if (ispublish.attr("checked") == "checked" || ispublish.attr("checked")) {
                tabcount.style.display = "block";
            } else {
                tabcount.style.display = "none";
            }
        }
    </script>
    <%--添加商品分类--%>
    <script type="text/javascript">
        /*********************************************商品信息(获取优惠券) begin *********************************************/
        //添加商品分类
        function SelectClassify(ctlName) {
            var arr = showModalDialog('Admin_SelectClassify.aspx?ProductType=0&DefaultValue=' + document.getElementById(ctlName).value, '', 'dialogWidth:800px; dialogHeight:650px; help: no; scroll: yes; status: no');
            if (arr != null) {
                document.getElementById(ctlName).value = arr; //商品分类ID
                GetClassByClassIDCF(arr);
            }
        }
        //商品分类(优惠券)
        function GetClassByClassIDCF(classids) {
            var actionInfo = "<%=ActionTab %>";
            var hfClassid = $("#<%=hfBuyClassifyID.ClientID %>"); //商品分类ID
            hfClassid.attr("value", classids);
            var prodcutStr = "";
            $("#<%=divClass.ClientID %>").html("");
            prodcutStr += "<table class='adminlist' width='auto'  id='tb_fashion_class'>" +
                           "<th style='text-align: center;'>ID</th>" +
                           "<th style='text-align: center;'>名称</th>" +
                          "<th style='text-align: center;'>操作</th></tr>";
            $.post("../WebService/Admin_ShopService.ashx", { 'Action': 'GetClassByClassIDs', 'ClassID': classids }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                        var d = eval(data);
                        $.each(d.table1, function (i) {
                            var classid = d.table1[i].ClassID;
                            var classname = d.table1[i].ClassName;
                            prodcutStr += "<tr><td style='text-align: center;'><input type='hidden' id='CFclassID" + i + "' value='" + classid + "' />" + classid + "</td>" +
                                     "<td style='text-align: center;'>" + classname + "</td>";
                            if (actionInfo == "checkinfo") {
                                prodcutStr += "<td style='text-align: center;'><input type='button' name='del1' onclick='delCF(" + classid + ")' disabled='disabled' value='删除' /></td></tr>";
                            } else {
                                prodcutStr += "<td style='text-align: center;'><input type='button' name='del1' onclick='delCF(" + classid + ")' value='删除' /></td></tr>";
                            }
                        });
                    }
                    prodcutStr += "</table>";
                    $("#<%=divClass.ClientID %>").append(prodcutStr);
                }
            });
        }
        //删除
        function delCF(num) {
            var productId = $("#<%=hfBuyClassifyID.ClientID %>"); //分类商品ID
            var productlist = $("#tb_fashion_class tr"); //商品分类信息
            var producttable = document.getElementById("tb_fashion_class"); //商品分类信息
            var str = "";
            if (productlist.length - 1 > 0) {
                for (var i = 0; i < productlist.length - 1; i++) {
                    var vproductid = $("#CFclassID" + i); //商品分类ID
                    if (vproductid.val() == num) {
                        var row = parseInt(i + 1);
                        producttable.deleteRow(row);
                    } else {
                        str += vproductid.val() + ",";
                    }
                }
            }
            var position = str.lastIndexOf(',');
            if (position > 0) {
                str = str.substring(0, str.length - 1);
            }
            productId.attr("value", str);
            GetProductByProductids(str); //商品信息
            return true;
        }
        /*********************************************商品信息(获取优惠券) end *********************************************/
        /*********************************************商品信息(限用商品) begin *********************************************/
        //添加商品分类
        function SelectClassifyL(ctlName) {
            var arr = showModalDialog('Admin_SelectClassify.aspx?ProductType=0&DefaultValue=' + document.getElementById(ctlName).value, '', 'dialogWidth:800px; dialogHeight:650px; help: no; scroll: yes; status: no');
            if (arr != null) {
                document.getElementById(ctlName).value = arr; //商品分类ID
                GetClassByClassIDCL(arr);
            }
        }
        //商品分类(优惠券)
        function GetClassByClassIDCL(classids) {
            var actionInfo = "<%=ActionTab %>";
            var hfClassid = $("#<%=hfLimitClassifyID.ClientID %>"); //商品分类ID
            hfClassid.attr("value", classids);
            var prodcutStr = "";
            $("#<%=divLimitClassify.ClientID %>").html("");
            prodcutStr += "<table class='adminlist' width='auto'  id='tb_limint_class'>" +
                           "<th style='text-align: center;'>ID</th>" +
                           "<th style='text-align: center;'>名称</th>" +
                          "<th style='text-align: center;'>操作</th></tr>";
            $.post("../WebService/Admin_ShopService.ashx", { 'Action': 'GetClassByClassIDs', 'ClassID': classids }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                        var d = eval(data);
                        $.each(d.table1, function (i) {
                            var classid = d.table1[i].ClassID;
                            var classname = d.table1[i].ClassName;
                            prodcutStr += "<tr><td style='text-align: center;'><input type='hidden' id='CLclassID" + i + "' value='" + classid + "' />" + classid + "</td>" +
                                     "<td style='text-align: center;'>" + classname + "</td>";
                            if (actionInfo == "checkinfo") {
                                prodcutStr += "<td style='text-align: center;'><input type='button' name='del1' onclick='delCL(" + classid + ")' disabled='disabled' value='删除' /></td></tr>";
                            } else {
                                prodcutStr += "<td style='text-align: center;'><input type='button' name='del1' onclick='delCL(" + classid + ")' value='删除' /></td></tr>";
                            }
                        });
                    }
                    prodcutStr += "</table>";
                    $("#<%=divLimitClassify.ClientID %>").append(prodcutStr);
                }
            });
        }
        //删除
        function delCL(num) {
            var productId = $("#<%=hfLimitClassifyID.ClientID %>"); //分类商品ID
            var productlist = $("#tb_limint_class tr"); //商品分类信息
            var producttable = document.getElementById("tb_limint_class"); //商品分类信息
            var str = "";
            if (productlist.length - 1 > 0) {
                for (var i = 0; i < productlist.length - 1; i++) {
                    var vproductid = $("#CLclassID" + i); //商品分类ID
                    if (vproductid.val() == num) {
                        var row = parseInt(i + 1);
                        producttable.deleteRow(row);
                    } else {
                        str += vproductid.val() + ",";
                    }
                }
            }
            var position = str.lastIndexOf(',');
            if (position > 0) {
                str = str.substring(0, str.length - 1);
            }
            productId.attr("value", str);
            GetProductByProductids(str); //商品信息
            return true;
        }
        /*********************************************商品信息(限用商品) end *********************************************/
    </script>
    <%--添加商品--%>
    <script type="text/javascript">
        /*********************************************商品信息(获取优惠券) begin *********************************************/
        //添加商品
        function SelectProduct(ctlName) {
            var arr = showModalDialog('Admin_SelectProduct.aspx?ProductType=0&DefaultValue=' + document.getElementById(ctlName).value, '', 'dialogWidth:800px; dialogHeight:650px; help: no; scroll: yes; status: no');
            if (arr != null) {
                document.getElementById(ctlName).value = arr; //商品ID
                GetProductByProductids(arr);
            }
        }
        //商品信息(优惠券)
        function GetProductByProductids(productids) {
            var actionInfo = "<%=ActionTab %>";
            var productId = $("#<%=hfBuySpecificID.ClientID %>"); //商品ID
            productId.attr("value", productids);
            var prodcutStr = "";
            $("#<%=divProduct.ClientID %>").html("");
            prodcutStr += "<table class='adminlist' width='auto'  id='tb_fashion_product'>" +
                           "<th style='text-align: center;'>商品名称</th>" +
                           "<th style='text-align: center;'>商品类型</th>" +
                          "<th style='text-align: center;'>操作</th></tr>";
            $.post("../WebService/Admin_ShopService.ashx", { 'Action': 'GetProductByProductIDs', 'ProductIDs': productids }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                        var d = eval(data);
                        $.each(d.table1, function (i) {
                            var productid = d.table1[i].ProductID;
                            var productname = d.table1[i].ProductName;
                            var pt = d.table1[i].ProductType;
                            var producttype = "";
                            //商品类型（一口价：1、拍卖：2、团购：3、促销(秒杀)：4、积分商品：5）
                            if (pt == "1") {
                                producttype = "一口价";
                            } else if (pt == "4") {
                                producttype = "促销(秒杀)";
                            }
                            if (productname.length > 30) {
                                productname = productname.substring(0, 28) + "...";
                            }
                            prodcutStr += "<tr><td style='text-align: center;'><input type='hidden' id='productID" + i + "' value='" + productid + "' />" + productname + "</td>" +
                                     "<td style='text-align: center;'>" + producttype + "</td>";
                            if (actionInfo == "checkinfo") {
                                prodcutStr += "<td style='text-align: center;'><input type='button' name='del1' onclick='del(" + productid + ")' disabled='disabled' value='删除' /></td></tr>";
                            } else {
                                prodcutStr += "<td style='text-align: center;'><input type='button' name='del1' onclick='del(" + productid + ")' value='删除' /></td></tr>";
                            }
                        });
                    }
                    prodcutStr += "</table>";
                    $("#<%=divProduct.ClientID %>").append(prodcutStr);
                }
            });
        }
        //删除
        function del(num) {
            //var productstr = $("#<%=hfFashionnContent.ClientID %>"); //获取优惠券的内容
            var productId = $("#<%=hfBuySpecificID.ClientID %>"); //商品ID
            var productlist = $("#tb_fashion_product tr"); //商品信息
            var producttable = document.getElementById("tb_fashion_product"); //商品信息
            var str = "";
            if (productlist.length - 1 > 0) {
                for (var i = 0; i < productlist.length - 1; i++) {
                    var vproductid = $("#productID" + i); //商品ID
                    //alert(num + "\n" + vproductid.val() + "\n" + (vproductid.val() == num));
                    if (vproductid.val() == num) {
                        var row = parseInt(i + 1);
                        producttable.deleteRow(row);
                    } else {
                        str += vproductid.val() + ",";
                    }
                }
            }
            var position = str.lastIndexOf(',');
            if (position > 0) {
                str = str.substring(0, str.length - 1);
            }
            productId.attr("value", str);
            GetProductByProductids(str); //商品信息
            return true;
        }
        /*********************************************商品信息(获取优惠券) end *********************************************/

        /*********************************************商品信息(限用商品) begin *********************************************/
        //添加商品
        function SelectProductL(ctlName) {
            var arr = showModalDialog('Admin_SelectProduct.aspx?ProductType=0&DefaultValue=' + document.getElementById(ctlName).value, '', 'dialogWidth:800px; dialogHeight:650px; help: no; scroll: yes; status: no');
            if (arr != null) {
                document.getElementById(ctlName).value = arr; //商品ID                
                GetLProductByProductids(arr);
            }
        }
        //商品信息(限用商品)
        function GetLProductByProductids(productids) {
            var actionInfo = "<%=ActionTab %>";
            var productId = $("#<%=hfLimitSpecificID.ClientID %>"); //限用商品ID
            productId.attr("value", productids);
            var prodcutStr = "";
            $("#<%=divLimitSpecific.ClientID %>").html("");
            prodcutStr += "<table class='adminlist' width='auto'  id='tb_limit_product'>" +
                           "<th style='text-align: center;'>商品名称</th>" +
                           "<th style='text-align: center;'>商品类型</th>" +
                          "<th style='text-align: center;'>操作</th></tr>";
            $.post("../WebService/Admin_ShopService.ashx", { 'Action': 'GetProductByProductIDs', 'ProductIDs': productids }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                        var d = eval(data);
                        $.each(d.table1, function (i) {
                            var productid = d.table1[i].ProductID;
                            var productname = d.table1[i].ProductName;
                            var pt = d.table1[i].ProductType;
                            var producttype = "";
                            //商品类型（一口价：1、拍卖：2、团购：3、促销(秒杀)：4、积分商品：5）
                            if (pt == "1") {
                                producttype = "一口价";
                            } else if (pt == "4") {
                                producttype = "促销(秒杀)";
                            }
                            if (productname.length > 30) {
                                productname = productname.substring(0, 28) + "...";
                            }
                            prodcutStr += "<tr><td style='text-align: center;'><input type='hidden' id='LproductID" + i + "' value='" + productid + "' />" + productname + "</td>" +
                                     "<td style='text-align: center;'>" + producttype + "</td>";
                            if (actionInfo == "checkinfo") {
                                prodcutStr += "<td style='text-align: center;'><input type='button' name='del1' onclick='delL(" + productid + ")' disabled='disabled' value='删除' /></td></tr>";
                            } else {
                                prodcutStr += "<td style='text-align: center;'><input type='button' name='del1' onclick='delL(" + productid + ")' value='删除' /></td></tr>";
                            }
                        });
                    }
                    prodcutStr += "</table>";
                    $("#<%=divLimitSpecific.ClientID %>").append(prodcutStr);
                }
            });
        }
        //删除
        function delL(num) {
            //var productstr = $("#<%=hfLimitProductContent.ClientID %>"); //限用商品的内容
            var productId = $("#<%=hfLimitSpecificID.ClientID %>"); //限用商品ID
            var productlist = $("#tb_limit_product tr"); //商品信息
            var producttable = document.getElementById("tb_limit_product"); //商品信息
            var str = "";
            if (productlist.length - 1 > 0) {
                for (var i = 0; i < productlist.length - 1; i++) {
                    var vproductid = $("#LproductID" + i); //商品ID
                    if (vproductid.val() == num) {
                        var row = parseInt(i + 1);
                        producttable.deleteRow(row);
                    } else {
                        str += vproductid.val() + ",";
                    }
                }
            }
            var position = str.lastIndexOf(',');
            if (position > 0) {
                str = str.substring(0, str.length - 1);
            }
            productId.attr("value", str);
            GetLProductByProductids(str); //商品信息
            return true;
        }
        /*********************************************商品信息(限用商品) end *********************************************/
    </script>
    <script type="text/javascript">
        $(function () {
            //添加：addinfo、修改：editinfo
            var actionInfo = "<%=ActionTab %>";
            if (actionInfo == "editinfo" || actionInfo == "checkinfo") {
                ControlFashion();
                ControlUseProductType();
                CheckPublish();

                var ordermoney = $("#<%=txtOrderMoney.ClientID %>");
                var strPCF = "<%=strPCF %>"; //优惠券内容
                var selectvalue = $('input:radio[name="ctl00$ContentPlaceHolder1$rblGetFashion"]:checked').val();
                if (strPCF != "") {
                    if (selectvalue == "BuyClassify") {
                        GetClassByClassIDCF(strPCF);
                    } else if (selectvalue == "BuySpecific") {
                        GetProductByProductids(strPCF);
                    } else if (selectvalue == "BuyOrderMoney") {
                        ordermoney.val(strPCF);
                    }
                }

                var strPCL = "<%=strPCL %>"; //限用商品
                var selectvalue = $('input:radio[name="ctl00$ContentPlaceHolder1$rblUseProductType"]:checked').val();
                if (strPCL != "") {
                    if (selectvalue == "LimitClassify") {
                        GetClassByClassIDCL(strPCL); //商品分类
                    } else if (selectvalue == "LimitSpecific") {
                        GetLProductByProductids(strPCL);
                    }
                }
            }
        });
    </script>
</asp:Content>
