<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="PromoteEdit.aspx.cs" Inherits="OAWeb.crm.promote.PromoteEdit" ValidateRequest="false" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<%@ Register Src="../../UserControls/SMSEmailNav.ascx" TagName="SMSEmailNav" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlace" runat="server">
    <script src="/js/jquery.form.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript" src='<%=ResolveUrl("~/ckeditor/ckeditor.js")%>'></script>
    <style type="text/css">
        .table_form .right
        {
            width: 100px;
        }
        .list .table_list th
        {
            padding: 0px;
        }
        .list .table_list td
        {
            line-height: normal;
            padding: 4px;
            height: auto;
        }
        .table_form2 td
        {
            text-align: center;
        }
    </style>
    <table id="plc_profile" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td class="main_left">
                <uc1:SMSEmailNav ID="SMSEmailNav1" runat="server" />
            </td>
            <td class="main_center">
                <!--主体-->
                <div class="page_main">
                    <div class="page_content">
                        <div class="form" style="border: solid 1px #ddd; padding: 5px;">
                            <table cellpadding="0" cellspacing="0" border="0" class="table_form">
                                <tr>
                                    <td class="title">
                                        <em style="float: left">
                                            <img src="/images/08.gif" />
                                        </em>
                                        <h1>
                                            编辑推广计划
                                        </h1>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="tabs" style="margin: 10px;">
                                            <div class="tab_handles">
                                                <span class="current" type="base">基本信息</span> <span type="list">发送列表</span>
                                            </div>
                                            <div class="tab_contents">
                                                <div class="tab_content" style="margin: 10px;">
                                                    <asp:Panel ID="pnlBaseInfo" runat="server">
                                                        <table cellpadding="0" cellspacing="1" border="0" class="table_form2">
                                                            <tr>
                                                                <td>
                                                                    计划发送
                                                                </td>
                                                                <td>
                                                                    成功发送
                                                                </td>
                                                                <td>
                                                                    失败发送
                                                                </td>
                                                                <td>
                                                                    阅读数
                                                                </td>
                                                                <td>
                                                                    注册数
                                                                </td>
                                                                <td>
                                                                    交易数
                                                                </td>
                                                                <td>
                                                                    成交金额
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <asp:Literal ID="litSendNum" runat="server"></asp:Literal>
                                                                </td>
                                                                <td>
                                                                    <asp:Literal ID="litSucceedNum" runat="server"></asp:Literal>
                                                                </td>
                                                                <td>
                                                                    <asp:Literal ID="litFailNum" runat="server"></asp:Literal>
                                                                    <asp:LinkButton ID="lnkbtnSend" runat="server">(失败重发)</asp:LinkButton>
                                                                </td>
                                                                <td>
                                                                    <asp:Literal ID="litReadNum" runat="server"></asp:Literal>
                                                                </td>
                                                                <td>
                                                                    <asp:Literal ID="litRegNum" runat="server"></asp:Literal>
                                                                </td>
                                                                <td>
                                                                    <asp:Literal ID="litBuyNum" runat="server"></asp:Literal>
                                                                </td>
                                                                <td>
                                                                    <asp:Literal ID="litMoney" runat="server"></asp:Literal>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                        <table cellpadding="0" cellspacing="0" border="0" class="table_form">
                                                            <tr>
                                                                <td class="right ">
                                                                    <span class="red">*</span> 名称:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="txtTitle" Text="" runat="server" CssClass="text width400 "></asp:TextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td class="right ">
                                                                    发送方式:
                                                                </td>
                                                                <td>
                                                                    <asp:DropDownList ID="ddlMethod" runat="server" Enabled="false">
                                                                        <asp:ListItem Value="email">电子邮件</asp:ListItem>
                                                                        <asp:ListItem Value="sms">短信</asp:ListItem>
                                                                    </asp:DropDownList>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td class="right ">
                                                                    可插入标签:
                                                                </td>
                                                                <td>
                                                                    <span class="insert_tags"></span>
                                                                </td>
                                                            </tr>
                                                            <tr class="email_send">
                                                                <td class="right ">
                                                                    <span class="red">*</span> 邮件主题:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="txtEmailSubject" Text="" runat="server" CssClass="text width400 "></asp:TextBox><span
                                                                        class="tip01"> 邮件主题必须手动复制标签</span>
                                                                </td>
                                                            </tr>
                                                            <tr class="email_send">
                                                                <td class="right ">
                                                                    <span class="red">*</span> 内容:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="txtEmailContent" runat="server" TextMode="MultiLine" Height="200px"
                                                                        CssClass="text" Width="100%"></asp:TextBox>
                                                                    <script type="text/javascript">
                                                                        CKEDITOR.replace('<%=txtEmailContent.ClientID %>',
                    {
                        skin: 'v2',
                        width: '600',
                        height: '200',
                        font_names: '宋体/宋体;黑体/黑体;仿宋/仿宋_GB2312;楷体/楷体_GB2312;隶书/隶书;幼圆/幼圆;微软雅黑/微软雅黑;',
                        toolbar: [
                        ['Source', 'Bold', 'Italic', 'Underline', 'Strike', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'Link', 'Customupload', '-', 'Table', 'HorizontalRule', 'SpecialChar'],
                        ['Format', 'Font', 'FontSize', 'TextColor', 'BGColor']
                        ],
                        language: 'zh-cn'
                    })                    
                   
                                                                    </script>
                                                                </td>
                                                            </tr>
                                                            <tr class="sms_send hide">
                                                                <td class="right ">
                                                                    <span class="red">*</span> 内容:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="txtSmsContent" runat="server" TextMode="MultiLine" Height="200px"
                                                                        CssClass="text ctl_content" Width="400px"></asp:TextBox>
                                                                </td>
                                                            </tr>
                                                            <tr class="sms_send hide">
                                                                <td class="right ">
                                                                </td>
                                                                <td>
                                                                    短信输入建议不超过65个字，超过则会拆分后发送，当前已输入 <span class="green" id="content_num">0</span>/65 个字
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td class="right ">
                                                                    <span class="email_send red">*</span><span class="email_send">发送人:</span><span class="sms_send hide">签名:</span>
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="txtSendName" runat="server" CssClass="text width120 "></asp:TextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td class="right ">
                                                                </td>
                                                                <td>
                                                                    <input id="btnSave" type="button" value=" 保 存 " class="btn_77px" />
                                                                    <asp:CheckBox ID="chkSendSet" runat="server" Text="开启发送" />
                                                                    <asp:CheckBox ID="chkIsAutoLoad" runat="server" Text="自动加载相似记录" /> &nbsp;间隔
                                                                    <asp:TextBox ID="txtAutoLoadDate" runat="server" CssClass="width40" >0</asp:TextBox>小时再加载
                                                                </td>
                                                            </tr>
                                                        </table>
                                                        <asp:HiddenField ID="hidTaskType" runat="server" />
                                                        <script type="text/javascript">
        $(document).ready(function () {
            $(".tab_handles span").click(function () {
                var Index = $(this).index();
                if(Index == 1){
                    var t = $("#<%=hidTaskType.ClientID %>").val();
                    window.location.href = "PromoteEdit.aspx?Id=<%=Id %>&t="+t+"&type=" + $(this).attr("type");
                }
            })
            var jsonTag = eval('(<%=LoadTagData() %>)');
            $.each(jsonTag, function (name) {
                $(".insert_tags").append("<a href=\"javascript:void(0)\" class=\"field_tags\"><{" + name + "}></a> ");
            })
            $(".field_tags").live("click", function () {
                if($("#<%=ddlMethod.ClientID %>").val() == "email"){
                    CKEDITOR.instances.<%=txtEmailContent.ClientID %>.insertHtml($(this).text());
                }
                else{
                    var txt = document.getElementById("<%=txtSmsContent.ClientID %>");
                    insertAtCursor(txt, $(this).text());
                    changeNum();
                }
            })

            if($("#<%=ddlMethod.ClientID %>").val() == "sms") {
                $(".sms_send").show();
                $(".email_send").hide();
            }
            else{
                $(".sms_send").hide();
                $(".email_send").show();
            }
            $("#btnSave").click(function () {
                //生成遮罩
                CreateZhezao($(".form_submit"),"zhezhao");
                //把编辑值赋值到实际文本框，编辑器只在有post动作时才把值赋值给实际文本框。
                CKEDITOR.instances.<%=txtEmailContent.ClientID %>.updateElement(); 
                FormPostAjax("/crm/promote/PromoteEdit.aspx?op=Save&Id=<%=Id %>",
                 "ok",
                 function () { window.location.href = 'PromoteList.aspx'; },
                 function(){
                    $("#zhezhao").remove();                    
                 });
            });
            $(".ctl_content").keyup(changeNum);
            changeNum();
        })
        //插入图片
        function UploadFun() {
            if(art.dialog != "") art.dialog.data('departValue',""); //清空防止上一次的缓存
            return OpenDialog2('/crm/promote/UploadPic.aspx?r='+Math.random(), '插入图片', function () {
                var bValue = art.dialog.data('departValue');
                if (bValue != null && bValue != "") { 
                    CKEDITOR.instances.<%=txtEmailContent.ClientID %>.insertHtml("<img src='"+bValue+"'/>");
                }
            });
        }
         //短信文本实时统计
        function changeNum() {
            $("#content_num").html($(".ctl_content").val().length);
            if ($(".ctl_content").val().length > 65) {
                $("#content_num").removeClass("green");
                $("#content_num").addClass("red");
            } else {
                $("#content_num").removeClass("red");
                $("#content_num").addClass("green");
            }
        }
                                                        </script>
                                                    </asp:Panel>
                                                    <asp:Panel ID="pnlList" runat="server">
                                                        <div class="page_op">
                                                            <asp:Button ID="btnNew" runat="server" Text="新增" CssClass="btn_77px" />
                                                            <asp:Button ID="btnDelete" runat="server" Text="删除" CssClass="btn_77px" />
                                                        </div>
                                                        <div class="list">
                                                            <asp:GridView ID="gvEmailData" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
                                                                GridLines="None" CellPadding="0" CssClass="table_list" EnableModelValidation="True"
                                                                OnRowDataBound="gvEmailData_RowDataBound">
                                                                <RowStyle HorizontalAlign="Left" />
                                                                <Columns>
                                                                    <asp:TemplateField HeaderText="编号">
                                                                        <HeaderTemplate>
                                                                            <input name="chkHeader" onclick="javascript:SelectAll(this);" type="checkbox" value="chkHeader" />
                                                                        </HeaderTemplate>
                                                                        <ItemTemplate>
                                                                            <input id="chkItem" type="checkbox" value="<%#Eval("Id") %>" />
                                                                        </ItemTemplate>
                                                                        <HeaderStyle HorizontalAlign="Center" ForeColor="White"></HeaderStyle>
                                                                        <ItemStyle HorizontalAlign="Center" Width="10px"></ItemStyle>
                                                                    </asp:TemplateField>
                                                                    <asp:BoundField DataField="ToEmail" HeaderText="接收人邮件"></asp:BoundField>
                                                                    <asp:BoundField DataField="StateText" HeaderText="状态"></asp:BoundField>
                                                                    <asp:TemplateField HeaderText="操作">
                                                                        <ItemTemplate>
                                                                            <asp:LinkButton ID="lbtnDelete" runat="server">删除</asp:LinkButton>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                </Columns>
                                                            </asp:GridView>
                                                            <asp:GridView ID="gvSmsData" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
                                                                GridLines="None" CellPadding="0" CssClass="table_list" EnableModelValidation="True"
                                                                OnRowDataBound="gvSmsData_RowDataBound">
                                                                <RowStyle HorizontalAlign="Left" />
                                                                <Columns>
                                                                    <asp:TemplateField HeaderText="编号">
                                                                        <HeaderTemplate>
                                                                            <input name="chkHeader" onclick="javascript:SelectAll(this);" type="checkbox" value="chkHeader" />
                                                                        </HeaderTemplate>
                                                                        <ItemTemplate>
                                                                            <input id="chkItem" type="checkbox" value="<%#Eval("Id") %>" />
                                                                        </ItemTemplate>
                                                                        <HeaderStyle HorizontalAlign="Center" ForeColor="White"></HeaderStyle>
                                                                        <ItemStyle HorizontalAlign="Center" Width="10px"></ItemStyle>
                                                                    </asp:TemplateField>
                                                                    <asp:BoundField DataField="RealName" HeaderText="姓名"></asp:BoundField>
                                                                    <asp:BoundField DataField="Mobile" HeaderText="手机"></asp:BoundField>
                                                                    <asp:BoundField DataField="StateText" HeaderText="状态"></asp:BoundField>
                                                                    <asp:TemplateField HeaderText="操作">
                                                                        <ItemTemplate>
                                                                            <asp:LinkButton ID="lbtnDelete" runat="server">删除</asp:LinkButton>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                </Columns>
                                                            </asp:GridView>
                                                            <div class="pager-bar">
                                                                <webdiyer:AspNetPager ID="pager" runat="server" CssClass="anpager" currentpagebuttonclass="cpb"
                                                                    PageSize="10" NextPageText="下一页" LastPageText="页 尾" FirstPageText="第一页" PrevPageText="上一页"
                                                                    ShowBoxThreshold="10" SubmitButtonText="跳 转" UrlPaging="True">
                                                                </webdiyer:AspNetPager>
                                                            </div>
                                                        </div>
                                                        <script type="text/javascript">
                                                            $(document).ready(function () {
                                                                $(".tab_handles span").click(function () {
                                                                    var Index = $(this).index();
                                                                    if (Index == 0)
                                                                        window.location.href = "PromoteEdit.aspx?Id=<%=Id %>";
                                                                })
                                                            })
                                                        </script>
                                                    </asp:Panel>
                                                </div>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        $(document).ready(function () {
            var tabs = $(".tab_handles span");
            $.each(tabs, function () {
                if ($(this).attr("type") == "<%=PageType %>")
                    $(this).addClass("current");
                else
                    $(this).removeClass("current");
            })
        })
       
    </script>
</asp:Content>
