<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="True" Inherits="Plus.Collage.KS_CosCollage" Codebehind="KS.CosCollage.aspx.cs" %>

<%@ Register Assembly="Kesion.APPCode" Namespace="Kesion.Controls" TagPrefix="cc1" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<asp:Content ID="Content1" ContentPlaceHolderID="KSContent" runat="server">
    <div id="manage_top" class="menu_top_fixed">
        <ul class="titleTab">
            <li class="curr"><a href="KS.CosCollage.aspx">拼团管理</a></li>
            <li><a href="KS.CosCollageOrder.aspx">拼团订单</a></li>
            <li><a href="KS.CosCollageStatistics.aspx">拼团数据统计</a></li>
        </ul>
    </div>
    <div class="menu_top_fixed_height"></div>
    <div class="listedit">
        <div class="floatLeft allCheck">
            <label><input type="checkbox" value="" id="selectAll" />全选</label>
        </div>
        <ul class="fl">
            <asp:LinkButton ID="PiDelete" runat="server" CssClass="button" OnClientClick="return(GetIDS('del'));" OnClick="PiDelete_Click">批量删除</asp:LinkButton>
        </ul>
    </div>
    <asp:Panel ID="ListPanel" runat="server">
        <div class="content-area pageBlank">
            <div class="myTitle">拼团管理</div>
            <script>
                $(function () {
                    //全选反选
                    $("#selectAll").click(function () {
                        if ($(this).is(":checked")) {
                            $(".Ctd").find("input[type=checkbox]").attr("checked", true);
                        }
                        else {
                            $(".Ctd").find("input[type=checkbox]").attr("checked", false);
                        };
                    });
                });
                function keyWordFocus() {
                    if (jQuery("#<%=this.TxtKeyWord.ClientID %>").val() == '请输入要搜索的课程名称') {
                        jQuery("#<%=this.TxtKeyWord.ClientID %>").val('');
                    }
                }
                function keyWordBlur() {
                    if (jQuery("#<%=this.TxtKeyWord.ClientID %>").val() == '') {
                        jQuery("#<%=this.TxtKeyWord.ClientID %>").val('请输入要搜索的课程名称');
                    }
                }
                function SetDate() {
                    var today = new Date();
                    if ($("#showsearchdate").is(":hidden")) {
                        $("#showsearchdate").show();
                        $('#<%=TxtSearchBeginDate.ClientID%>').val(today.getFullYear() + '-' + (today.getMonth() + 1) + '-01');
                        $('#<%=TxtSearchEndDate.ClientID%>').val(today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate());
                    }
                    else {
                        $("#showsearchdate").hide();
                        $('#<%=TxtSearchBeginDate.ClientID%>').val('');
                        $('#<%=TxtSearchEndDate.ClientID%>').val('');
                    }
                }
            </script>
            <div class="quickSearch clearfix">
                <div class="SearchBox fl">
                    <asp:TextBox runat="server" Width="200px" ID="TxtKeyWord" CssClass="textbox" Onfocus="keyWordFocus();" Onblur="keyWordBlur();" Style="color: #ccc" Text="请输入要搜索的课程名称" />
                    <b onclick="SetDate()" class="link-color">日期范围？</b>
                    <span id="showsearchdate" <%if (this.TxtSearchBeginDate.Text == "") { %> style="display: none" <%} %>>
                        <asp:TextBox ID="TxtSearchBeginDate" Width="160px" runat="server" onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd&#39;});" CssClass="textbox Wdate"></asp:TextBox>至
                        <asp:TextBox ID="TxtSearchEndDate" Width="160px" runat="server" onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd&#39;});" CssClass="textbox Wdate"></asp:TextBox>
                    </span>
                    <asp:Button ID="BtnSearch" runat="server" CssClass="button" Text="开始搜索" OnClick="BtnSearch_Click" />
                </div>
                <div class="property">
                    <div class="name button ml15">筛选</div>
                    <div class="propertyBox">
                        <ul class="clearfix">
                            <span class="screen fl">拼团状态：</span>
                            <li <%=KSCMS.S("status")=="0"?" class='active'":string.Empty %>><a href="KS.CosCollage.aspx?status=0"><span>全部</span></a></li>
                            <li <%=KSCMS.S("status")=="1"?" class='active'":string.Empty %>><a href="KS.CosCollage.aspx?status=1"><span>未启用</span></a></li>
                            <li <%=KSCMS.S("status")=="2"?" class='active'":string.Empty %>><a href="KS.CosCollage.aspx?status=2"><span>未开始</span></a></li>
                            <li <%=KSCMS.S("status")=="3"?" class='active'":string.Empty %>><a href="KS.CosCollage.aspx?status=3"><span>进行中</span></a></li>
                            <li <%=KSCMS.S("status")=="4"?" class='active'":string.Empty %>><a href="KS.CosCollage.aspx?status=4"><span>已结束</span></a></li>
                        </ul>
                    </div>
                </div>
                <div class="fr liwrap"><a href="?action=add" class="button button_on">添加拼团</a></div>
            </div>
            <div class="border">
                <asp:Repeater ID="RptList" runat="server">
                    <HeaderTemplate>
                        <table width="99%" class="CTable" border="0" cellpadding="1" cellspacing="1">
                            <tr class="CTitle">
                                <td align="center"><b>选择</b></td>
                                <td align="center"><b>课程封面</b></td>
                                <td align="center"><b>拼团课程</b></td>
                                <td align="center"><b>课程原价</b></td>
                                <td align="center"><b>团长价格</b></td>
                                <td align="center"><b>团员价格</b></td>
                                <td align="center"><b>组团人数</b></td>
                                <td align="center"><b>活动时间</b></td>
                                <td align="center"><b>有效时限</b></td>
                                <td align="center"><b>状态</b></td>
                                <td align="center"><b>总团数</b></td>
                                <td align="center"><b>已成团</b></td>
                                <td align="center"><b>操作</b></td>
                            </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                            <tr onmouseover="this.className='CtrMouseOver'" onmouseout="this.className='CtrMouseOut'">
                                <td class="Ctd" style="text-align: center" onclick="doNone(event)"><input type="checkbox" name="ids" id="ids" value="<%#Eval("CollageID") %>" /></td>
                                <td class="Ctd" style="text-align: center"><img src="<%# Eval("PictureUrl")%>" onerror="this.src='../../admin/images/nopic.png'" style="width:120px;height:80px;"/></td>
                                <td class="Ctd" style="text-align: center"><a href="<%# BaseFun.GetRewriteUrl(Eval("CourseType").ToString() == "2"?"faceview":Eval("CourseType").ToString() == "1"?"liveview":"courseview",Utils.StrToInt(Eval("CourseID").ToString())) %>" target="_blank"><%# Eval("Cname")%></a></td>
                                <td class="Ctd" style="text-align: center"><%# Utils.StrToFloat(Eval("Price").ToString())%>元</td>
                                <td class="Ctd" style="text-align: center"><%# Utils.StrToFloat(Eval("HeaderPrice").ToString())%>元</td>
                                <td class="Ctd" style="text-align: center"><%# Utils.StrToFloat(Eval("CommonPrice").ToString())%>元</td>
                                <td class="Ctd" style="text-align: center"><%# Eval("Number")%>人</td>
                                <td class="Ctd" style="text-align: center">开始时间：<%# Utils.StrToDateTime(Eval("BeginDate").ToString()).ToString("yyyy-MM-dd HH:mm:ss")%><br/>结束时间：<%# Utils.StrToDateTime(Eval("EndDate").ToString()).ToString("yyyy-MM-dd HH:mm:ss")%></td>
                                <td class="Ctd" style="text-align: center"><%# Utils.StrToInt(Eval("LimitHours").ToString()) == 0?"不限时":Eval("LimitHours").ToString() + "小时"%></td>
                                <td class="Ctd" style="text-align: center"><%# CollageStatus(Utils.StrToInt(Eval("Status").ToString()), Eval("BeginDate").ToString(), Eval("EndDate").ToString())%></td>
                                <td class="Ctd" style="text-align: center"><%# Eval("TotalCount")%></td>
                                <td class="Ctd" style="text-align: center"><%# Eval("SuccessCount")%></td>
                                <td class="Ctd" style="text-align: center">
                                    <a onclick="doNone(event);" href="KS.CosCollageDetail.aspx?collageid=<%#Eval("CollageID") %>" class="greenFont btn"><span>详情</span></a>&nbsp;&nbsp;
                                    <a onclick="doNone(event);" href="?action=edit&id=<%# Eval("CollageID")%>" class="greenFont btn"><span>编辑</span></a>&nbsp;&nbsp;
                                    <a href="?action=del&id=<%#Eval("CollageID") %>" class="greenFont btn" onclick="return(confirm('此操作不可逆，确定删除操作吗?'))"><span>删除</span></a>
                                </td>
                            </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                            <tr class="tdbg emptycss" <%# bool.Parse((RptList.Items.Count==0).ToString())?"":"style='display:none'"%>>
                                <td class="Ctd" style="text-align: center" colspan="14">找不到课程拼团信息！</td>
                            </tr>
                        </table>
                    </FooterTemplate>
                </asp:Repeater>
                <asp:Label ID="LabPage" runat="server"></asp:Label>
                <br />
                <script type="text/javascript">
                    showtips('<span class="state"><strong>说明：课程拼团一旦添加成功，不建议进行修改或删除</strong><br /></span>');
                </script>
            </div>
        </div>
    </asp:Panel>

    <asp:Panel ID="AddPanel" runat="server" Visible="false">
        <div class="content-area footBlank">
            <div class="myTitle">编辑课程</div>
            <table style="width: 100%; margin: 0 auto;" align="center" cellpadding="0" cellspacing="0" class="CTable no-borderTable">
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>课程类型:</strong></td>
                    <td class="righttd">
                        <asp:DropDownList ID="DrpCourseType" runat="server" RepeatDirection="horizontal">
                            <asp:ListItem Value="0" Text="点播"></asp:ListItem>
                            <asp:ListItem Value="1" Text="直播"></asp:ListItem>
                            <asp:ListItem Value="2" Text="面授"></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>课程名称:</strong></td>
                    <td class="righttd">
                        <asp:DropDownList ID="DrpCourse" runat="server"></asp:DropDownList>
                        <input type="hidden" id="courseid" name="courseid" />
                        <input type="hidden" id="cname" name="cname" />
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>课程图片:</strong></td>
                    <td class="righttd">
                        <asp:Image ID="CoursePic" runat="server" Width="120px" Height="100px" onerror="this.src='../../admin/images/nopic.png'"/>
                        <input type="hidden" id="pictureurl" name="pictureurl" />
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>课程价格:</strong></td>
                    <td class="righttd">
                        <asp:Label ID="LabPrice" runat="server" Text="0"></asp:Label>&nbsp;元
                        <input type="hidden" id="price" name="price" />
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>拼团人数:</strong></td>
                    <td class="righttd">
                        <asp:TextBox ID="TxtNumber" runat="server" Width="50px"></asp:TextBox>&nbsp;人
                        <span class="tips">（拼团人数 > 1）</span>
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>拼团开始日期:</strong></td>
                    <td class="righttd">
                        <asp:TextBox CssClass="textbox  Wdate" ID="TxtBeginDate" runat="server" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-%d'});" Width="160px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>拼团结束日期:</strong></td>
                    <td class="righttd">
                        <asp:TextBox CssClass="textbox  Wdate" ID="TxtEndDate" runat="server" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-%d'});" Width="160px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>拼团时限:</strong></td>
                    <td class="righttd">
                        <asp:TextBox ID="TxtLimitHours" runat="server" Width="50px"></asp:TextBox>&nbsp;分钟
                        <span class="tips">（设置“0”为不限时）</span>
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>团长价格:</strong></td>
                    <td class="righttd">
                        <asp:TextBox ID="TxtHeaderPrice" runat="server" Width="50px"></asp:TextBox>&nbsp;元
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>团员价格:</strong></td>
                    <td class="righttd">
                        <asp:TextBox ID="TxtCommonPrice" runat="server" Width="50px"></asp:TextBox>&nbsp;元
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" align="right" style="width: 102px"><font color="red">*</font><strong>状态:</strong></td>
                    <td class="righttd">
                        <asp:RadioButtonList ID="RdbStatus" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Value="1" Text="启用" Selected></asp:ListItem>
                            <asp:ListItem Value="0" Text="不启用"></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
            </table>
            <br />
            <cc1:Foot ID="Foot1" runat="server" OnSubmit="Foot1_Submit" />
        </div>
        <script>
            $(function () {
                GetCourseInfo();
            })
            $("#<%=DrpCourseType.ClientID%>").change(function () {
                var costype = $("#<%=DrpCourseType.ClientID%>").val();
                $.ajax({
                    type: "get",
                    url: "KS.CosCollage.aspx",
                    data: { action: "getcourselist", costype: costype },
                    dataType: "text",
                    success: function (data) {
                        $("#<%=DrpCourse.ClientID%>").find("option").remove();
                        $("#<%=DrpCourse.ClientID%>").append(data);
                    }
                })
            })
            $("#<%=DrpCourse.ClientID%>").change(function () {
                GetCourseInfo();
            })

            function GetCourseInfo() {
                var costype = $("#<%=DrpCourseType.ClientID%>").val();
                var courseid = $("#<%=DrpCourse.ClientID%>").val();
                if (courseid != "0") {
                    $.ajax({
                        type: "get",
                        url: "KS.CosCollage.aspx",
                        data: { action: "getcourseinfo", costype: costype, courseid: courseid },
                        dataType: "json",
                        success: function (data) {
                            $("#<%=LabPrice.ClientID%>").html(data.price);
                            $("#price").val(data.price);
                            $("#<%=CoursePic.ClientID%>").attr("src", data.photourl);
                            $("#pictureurl").val(data.photourl);
                            $("#courseid").val(courseid);
                            $("#cname").val(data.cname);
                        }
                    })
                } else {
                    $("#<%=LabPrice.ClientID%>").val("0");
                }
            }
            Date.prototype.Format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1, //月份 
                    "d+": this.getDate(), //日 
                    "H+": this.getHours(), //小时 
                    "m+": this.getMinutes(), //分 
                    "s+": this.getSeconds(), //秒 
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
                    "S": this.getMilliseconds() //毫秒 
                };
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            }
            $("#<%=TxtBeginDate.ClientID%>").blur(function () {
                var startDate = new Date($("#<%=TxtBeginDate.ClientID%>").val());
                if (startDate != "Invalid Date") {
                    var startDate = new Date($("#<%=TxtBeginDate.ClientID%>").val());
                    var endDate = new Date(startDate.setDate(startDate.getDate() + 2)).Format("yyyy-MM-dd HH:mm:ss");
                    $("#<%=TxtEndDate.ClientID%>").val(endDate);
                }
            })
            function CheckForm() {
                if ($("#<%=DrpCourse.ClientID%>").val() == "0") {
                    KesionJS.Alert('请选择拼团的课程!', '$("#<%=DrpCourse.ClientID%>").focus();');
                    return false;
                }
                if ($("#<%=TxtNumber.ClientID%>").val() == "" || parseInt($("#<%=TxtNumber.ClientID%>").val()) <= 1) {
                    KesionJS.Alert('拼团的人数必须大于1!', '$("#<%=TxtNumber.ClientID%>").focus();');
                    return false;
                }
                if ($("#<%=TxtBeginDate.ClientID%>").val() == "") {
                    KesionJS.Alert('请填写拼团的开始日期!', '$("#<%=TxtBeginDate.ClientID%>").focus();');
                    return false;
                }
                if ($("#<%=TxtEndDate.ClientID%>").val() == "") {
                    KesionJS.Alert('请填写拼团的结束日期!', '$("#<%=TxtEndDate.ClientID%>").focus();');
                    return false;
                }
                var beginDate = new Date($("#<%=TxtBeginDate.ClientID%>").val());
                var endDate = new Date($("#<%=TxtEndDate.ClientID%>").val());
                var nowDate = new Date();
                if (beginDate.getTime() >= endDate.getTime() || endDate.getTime() <= nowDate.getTime()) {
                    KesionJS.Alert('拼团开始时间必须小于结束时间,且结束时间必须大于当前时间!', '$("#<%=TxtEndDate.ClientID%>").focus();');
                    return false;
                }
                console.log("3333");
                if ($("#<%=TxtLimitHours.ClientID%>").val() == "" || parseInt($("#<%=TxtLimitHours.ClientID%>").val()) < 0) {
                    KesionJS.Alert('请填写正确的拼团时限!', '$("#<%=TxtLimitHours.ClientID%>").focus();');
                    return false;
                }
                if ($("#<%=TxtHeaderPrice.ClientID%>").val() == "") {
                    KesionJS.Alert('请填写拼团的团长价格!', '$("#<%=TxtHeaderPrice.ClientID%>").focus();');
                    return false;
                }
                if (parseFloat($("#<%=TxtHeaderPrice.ClientID%>").val()) > parseFloat($("#price").val())) {
                    KesionJS.Alert('团长价格不能大于课程的原价!', '$("#<%=TxtHeaderPrice.ClientID%>").focus();');
                    return false;
                }
                if ($("#<%=TxtCommonPrice.ClientID%>").val() == "") {
                    KesionJS.Alert('请填写拼团的团员价格!', '$("#<%=TxtCommonPrice.ClientID%>").focus();');
                    return false;
                }
                if (parseFloat($("#<%=TxtCommonPrice.ClientID%>").val()) > parseFloat($("#price").val())) {
                    KesionJS.Alert('团员价格不能大于课程的原价!', '$("#<%=TxtCommonPrice.ClientID%>").focus();');
                    return false;
                }
            }
        </script>
    </asp:Panel>

</asp:Content>
