<%@ Page Language="C#" EnableEventValidation="false"  MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true" Inherits="Kesion.NET.WebSite.Admin.Shop.Admin_ShopCouponPub" Title="优惠券发放管理" Codebehind="KS.CouponPub.aspx.cs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="KSContent" Runat="Server">
    <KS:TopNav ID="TopNav1" runat="server" />
    <div class="content-area">
    <script type="text/javascript">
        function searchUser() {
            jQuery('#ajaxmsg', window.parent.document).fadeIn("slow");
            var url = '../../plus/ajaxs.ashx';
            jQuery.get(url, { a: "SearchUser", key: (jQuery("#key").val()) }, function (s) {
                jQuery('#ajaxmsg', window.parent.document).fadeOut("slow");
                showResponse(s);
            })
        }
        function showResponse(s) {
            var result = s;
            if (result != '') {
                var obj = jQuery('#user_search')[0];
                obj.length = 0;
                var rarr = result.split('|');
                for (var i = 0; i < rarr.length; i++) {
                    if (rarr[i] != '') {
                        var opt = document.createElement('OPTION');
                        opt.value = rarr[i];
                        opt.text = rarr[i];
                        obj.options.add(opt);
                    }
                }
            }
        }
        function addUser() {
            var src = document.getElementById('user_search');
            var dest = document.getElementById('user');

            for (var i = 0; i < src.options.length; i++) {
                if (src.options[i].selected) {
                    var exist = false;
                    for (var j = 0; j < dest.options.length; j++) {
                        if (dest.options[j].value == src.options[i].value) {
                            exist = true;
                            break;
                        }
                    }
                    if (!exist) {
                        var opt = document.createElement('OPTION');
                        opt.value = src.options[i].value;
                        opt.text = src.options[i].text;
                        dest.options.add(opt);
                    }
                }
            }
        }

        function delUser() {
            var dest = document.getElementById('user');

            for (var i = dest.options.length - 1; i >= 0 ; i--) {
                if (dest.options[i].selected) {
                    dest.options[i] = null;
                }
            }
        }
        function check() {
            if (!$("#title").is(":hidden")) {
                if (jQuery("#<%=this.txtTitle.ClientID %>").val() == "") {
                    KesionJS.Alert('请输入消息提示标题!', 'jQuery("#<%=this.txtTitle.ClientID %>").focus();');
                    return false;
                }
            }
            if (jQuery("#<%=this.RadioButtonList1.ClientID %> :radio[checked]").val() == "2") {
                var idArr = new Array();
                var dest = document.getElementById('user');
                for (var i = 0; i < dest.options.length; i++) {
                    dest.options[i].selected = "true";
                    idArr.push(dest.options[i].value);
                }
                if (idArr.length <= 0) {
                    alert("你没有选择用户!");
                    return false;
                }
                else {
                    return true;
                }
            }

        }
        jQuery(document).ready(function () {
            $("#sendmobile").hide();
            $("#sendemail").hide();
            $("#sendsite").hide();


            $("#sendnmobile").hide();
            $("#sendnemail").hide();
            $("#sendnsite").hide();
           
            $("#list2").hide();
            $("#title").hide();
            $("#weixin").hide();
        });
        function show(id) {
            if (id == 1) {
                if (document.getElementById("<%=CKB1.ClientID%>").checked) {
                    $("#sendemail").show();
                    $("#title").show();
                }
                else {
                    if (document.getElementById("<%= CKB2.ClientID%>").checked == false) {
                        $("#sendemail").hide();
                        $("#title").hide();
                    }
                    $("#sendemail").hide();
                }
            }
            else if (id == 2) {
                if (document.getElementById("<%= CKB2.ClientID%>").checked) {
                    $("#sendsite").show();
                    $("#title").show();
                }
                else {
                    if (document.getElementById("<%= CKB1.ClientID%>").checked == false) {
                        $("#sendsite").hide();
                        $("#title").hide();
                    }
                    $("#sendsite").hide();

                }
            }
            else if (id == 5) {
                if (document.getElementById("<%= CKB5.ClientID%>").checked) {
                    $("#sendmobile").show();
                }
                else {
                    $("#sendmobile").hide();
                }

            } else if (id == 6) {
                if (document.getElementById("<%= CKB6.ClientID%>").checked) {
                    //$("#title").show();
                    $("#weixin").show();
                }
                else {
                    //$("#title").hide();
                    $("#weixin").hide();
                }
            }


        }
        function showlist() {
            if (jQuery("#<%=this.RadioButtonList1.ClientID %> :radio[checked]").val() == "1") {
                $("#list1").show();
                $("#list2").hide();
           } else {
                $("#list2").show();
                $("#list1").hide();
           }
        }

        function showType(v) {
            $.ajax({
            type:'Post',
            dataType:'text',
            url:'KS.CouponPub.aspx?action=change&messageid='+v,
            data:{},
            success: function (msg) {
                var msgArr = msg.split('@@@');
                $("#<%=this.txtTitle.ClientID%>").val(msgArr[3]);
                editor1.setContent(msgArr[0]);
                editor2.setContent(msgArr[1]);
                $("#<%=this.TxtSendMobile.ClientID%>").val(msgArr[2]);
                
            }
});

    
}
				</script> 
    
   <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatLayout="Flow" RepeatColumns="2" >
        <asp:ListItem Value="1" Selected="True">按用户组发放</asp:ListItem>
        <asp:ListItem Value="2">按用户发放</asp:ListItem>
    </asp:RadioButtonList> 
    <asp:Panel ID="Panel1" runat="server" Width="100%" Visible="false">
    <div id="list1">

        <table width="100%" border="0" cellpadding="1" cellspacing="1" class="CTable"> 
          <tr>
            <td class="lefttd" height="30" align="right" style="width: 198px"><strong>选择用户组：</strong></td>
            <td class="righttd">
               <div id="GroupPanel" runat="server"></div> 
            </td>
          </tr>
         </table>
        </div>
        <div id="list2">
        <table width="100%" border="0" cellpadding="1" cellspacing="1" class="CTable"> 
          <tr>
            <td class="righttd" colspan="3">
               <strong>关键字：</strong><input type="text" class="textbox" name="key" id="key" size="20"/>
               <input type="button" value="搜索用户" class="button" onclick="searchUser();"/>
            </td>
          </tr>
          <tr align='center'>
						<td height='25' class='clefttitle' style="text-align:center">会员列表</td>
						<td  class='clefttitle' style="text-align:center">操作</td>
						<td  class='clefttitle' style="text-align:center">给下列用户发放</td>
		  </tr>
          <tr align='center'>
						<td height='25' class='righttd' style="text-align:center">
						<select name="user_search" id="user_search" size="15" style="height:300px;width:260px" ondblclick="addUser()" multiple="true">
						  </select>
						</td>
						<td  class='righttd' style="text-align:center">
						<p><input type="button" value=" > " onclick="addUser()" class="button" /></p>
						<br />
						<p><input type="button" value=" < " onclick="delUser()" class="button" /></p>
						</td>
						<td  class='righttd' style="text-align:center">
						<select name="user" id="user" multiple="true" size="15" style="height:300px;width:260px" ondblclick="delUser()">
						  </select>
						</td>
		  </tr>              
         </table>
    </div> 
    <div id="list3">
 <table width="99%"  border="0" cellpadding="1" cellspacing="1" class="CTable"> 
          <tr>
              <td align="right" class="lefttd" height="30" style="width: 198px"><strong>邮件通知选项：</strong></td>
              <td class="righttd">
                  <asp:CheckBox ID="CKB1" runat="server" onclick="show(1)" Text="发送Email邮件通知" />
                  <br />
                  <asp:CheckBox ID="CKB2" runat="server" onclick="show(2)" Text="发送站内短消息通知" />
                    <%
       if (Kesion.Cache.MyCache.GetCacheConfig(32) == "1")
        {  
      %>
                  <br />
                  <asp:CheckBox ID="CKB5" runat="server" onclick="show(5)" Text="发送手机短消息通知" />
        <%} %>
                  <br />
                  <asp:CheckBox ID="CKB6" runat="server" onclick="show(6)" Text="发送微信信息通知" />
                  <br />
              </td>
          </tr>
          <tr>
              <td align="right" class="lefttd" height="30" style="width: 198px"><strong><%=str%>模板：</strong></td>
              <td class="righttd">
                  <asp:DropDownList ID="DropDownList1" runat="server">
                  </asp:DropDownList>
              </td>
          </tr>
     <tr id="weixin">
         <td align="right" class="lefttd" height="30" style="width: 198px">
             <strong>微信消息模板：</strong></td>
         <td class="righttd">
             <asp:TextBox ID="TextBox1" runat="server" CssClass="textbox"></asp:TextBox>
             <span class="tips">如：恭喜您在科汛网站获得5元购物<%=str%>。</span></td>
     </tr>
          <tr id="title">
              <td  align="right" class="lefttd" height="30" style="width: 198px">
                  <strong>消息标题模板：</strong></td>
              <td class="righttd">
                  <asp:TextBox ID="txtTitle" runat="server" CssClass="textbox"></asp:TextBox>
                  <span class="tips">如：恭喜您在科汛网站获得5元购物<%=str%>。</span></td>
          </tr>
          <tr id="sendemail">
              <td align="right" class="lefttd" height="30" style="width: 198px">
                  <div>
                      <strong>发放成功发送一封邮件给用户：</strong>
                      <div class="tips">
                          标签： {$GetSiteName}：网站名称<br /> {$UserName}：用户名<br /> {$BeginDate}：使用时间<br /> {$EndDate}：过期时间<br /> {$FaceValue}：面值<br /> {$CouponNum}：<%=str%>号<br /> 
                      </div>
                  </div>
              </td>
              <td class="righttd">
                  <asp:TextBox ID="TxtRegSuccMail" runat="server" Height="120" TextMode="MultiLine" Width="650"></asp:TextBox>
                  <% Kesion.APPCode.EditorAPI.EchoEditor("editor1", this.TxtRegSuccMail.ClientID, "Basic");%>
                  <br />
                  Tips:内容留空将不发送！！！ </td>
          </tr>
          <tr id="sendsite">
              <td align="right" class="lefttd" height="30" style="width: 198px">
                  <div>
                      <strong>发放成功发送一条站内给用户：</strong>
                      <div class="tips">
                          标签： {$GetSiteName}：网站名称<br /> {$UserName}：用户名<br /> {$BeginDate}：使用时间<br /> {$EndDate}：过期时间<br /> {$FaceValue}：面值<br /> {$CouponNum}：<%=str%>号<br /> 
                      </div>
                  </div>
              </td>
              <td class="righttd">
                  <asp:TextBox ID="TxtSendSite" runat="server" Height="120" TextMode="MultiLine" Width="650"></asp:TextBox>
                  <% Kesion.APPCode.EditorAPI.EchoEditor("editor2", this.TxtSendSite.ClientID, "Basic");%>
                  <br />
                  Tips:内容留空将不发送！！！ </td>
          </tr>
          <tr id="sendmobile">
              <td align="right" class="lefttd" height="30" style="width: 198px">
                  <div>
                      <strong>发放成功发送一条短信给用户：</strong>
                      <div class="tips">
                          标签： {$UserName}：用户名<br /> {$BeginDate}：使用时间<br /> {$FaceValue}：面值<br /> {$CouponNum}：<%=str%>号<br /> 
                      </div>
                  </div>
              </td>
              <td class="righttd">
                  <asp:TextBox ID="TxtSendMobile" runat="server" Columns="60" CssClass="textbox textarea" Height="120" Rows="6" TextMode="MultiLine" Width="650"></asp:TextBox>
                  <a class="textarea_min" href="javascript:zoomtextarea(-5,'<%=this.TxtSendMobile.ClientID %>');"></a><a class="textarea_max" href="javascript:zoomtextarea(5,'<%=this.TxtSendMobile.ClientID %>');"></a>
                  <br />
                  Tips:内容留空将不发送！！！ </td>
          </tr>
          <tr>
           <td class="lefttd" colspan="2" style="text-align:center">
           <asp:Button ID="Button2" runat="server" CssClass="button" Text="确定发放" OnClick="Button2_Click" OnClientClick="return(check())"/>
           </td>
          </tr>
         </table>
        <script type="text/javascript">
            showtips('<span class="state"><strong>操作说明：</strong><br /></span>1.您可以按用户组或是按指定的用户进行<%=str%>发放；<br />2.发放<%=str%>可以以邮件、站内、手机短息，微信四种方式进行短息通知<br />');
		</script>
        </div>
        </asp:Panel>
        <asp:Panel ID="Panel2" runat="server" Width="100%" Visible="false">
        
        <table width="99%" align="center" border="0" cellpadding="1" cellspacing="1" class="CTable"> 
          <tr>
           <td colspan="2" class="lefttd"  style="text-align:left;color:Red;font-weight:bold">批量生成优惠券号</td>
          </tr>
          <tr>
            <td class="lefttd" height="30" align="right" style="width: 198px"><strong>生成数量：</strong></td>
            <td class="righttd">
             <asp:TextBox ID="TxtNum" CssClass="textbox" runat="server" style="text-align:center;" Width="40px" Text="100"></asp:TextBox> 张
            </td>
          </tr>
          <tr>
           <td class="lefttd" colspan="2" style="text-align:center">
           <asp:Button ID="Button3" runat="server" CssClass="button" Text="确定批量生成优惠券号" OnClick="Button3_Click"/>
           </td>
          </tr>
         </table>
        <script type="text/javascript">
            showtips('<span class="state"><strong>操作说明：</strong><br /></span>1.您可以将生成的优惠券号发放给用户使用<br />2.用户得到优惠券号后,可以在会员中心启用,每张优惠券号只能用一次<br />');
		</script>
          
    </asp:Panel>
 </div>   
</asp:Content>

