<%@ page language="C#" masterpagefile="~/Member/MyShopMasterPage.master" autoeventwireup="true" inherits="Member_ClientRelation_AnnalManage, WebApp_deploy" enableeventvalidation="false" title="联系记录管理" %>

<asp:Content ID="contacter" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script src="../../Js/Function.js" type="text/javascript"></script>
    <script src="../../Js/My97DatePicker/config.js" type="text/javascript"></script>
    <script src="../../Js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        //联系时间
        function pickedFunc() {
            $dp.$('<%=txtRelationTime.ClientID %>').value = $dp.cal.getNewDateStr('yyyy-MM-dd HH:mm:ss');
        }
        //提醒时间
        function pickedFuncRe() {
            $dp.$('<%=txtRemindTime.ClientID %>').value = $dp.cal.getNewDateStr('yyyy-MM-dd HH:mm:ss');
        }
        //开始时间
        function pickedFuncBegin() {
            $dp.$('<%=txtBeginTime.ClientID %>').value = $dp.cal.getNewDateStr('yyyy-MM-dd HH:mm:ss');
        }
        //结束时间
        function pickedFuncEnd() {
            $dp.$('<%=txtEndTime.ClientID %>').value = $dp.cal.getNewDateStr('yyyy-MM-dd HH:mm:ss');
        }
    </script>
    <script type="text/javascript">
        //切换选项卡                
        function setButtonActive(flags) {
            var _flag = parseInt(flags);
            var ulObj = document.getElementById("M1");
            for (var i = 0; i < ulObj.childNodes.length; i++) {
                ulObj.childNodes[i].className = "";
            }
            if (ulObj.childNodes.length > 2)
            { _flag = _flag * 2 + 1; }
            ulObj.childNodes[_flag].className = "active";

        }   
    </script>
    <style type="text/css">
        .handType
        {
            cursor: pointer;
        }
    </style>
    <div class="pageTitle" style="line-height: 30px; vertical-align: middle;">
        &nbsp;&nbsp;&nbsp;&nbsp;联系记录管理</div>
    <div id="MainMenu">
        <div class="TabMenu">
            <!--一级导航-->
            <ul id="M1">
                <li class="active"><a href="AnnalManage.aspx?TabMenu=tabMnage">
                    <asp:Label ID="lblManage" runat="server" Text="联系记录管理" />
                </a></li>
                <li id="ContacterAddli"><a href="AnnalManage.aspx?TabMenu=tabAdd&action=addinfo">
                    <asp:Label ID="lblAddOrEdit" runat="server" Text="添加联系记录" />
                </a></li>
            </ul>
        </div>
        <div class="TabText">
            <%--全部联系记录 begin--%>
            <asp:PlaceHolder ID="phManage" runat="server">
                <table class="SearchTableStyle">
                    <tr>
                        <th colspan="3" style="float: left; text-align: left">
                            &nbsp;<b>高级查询：</b>
                        </th>
                    </tr>
                    <tr>
                        <td style="width: 45%;">
                            &nbsp;具体时间：&nbsp;<asp:TextBox ID="txtBeginTime" runat="server" onfocus="WdatePicker()"
                                CssClass="Wdate"></asp:TextBox>
                            &nbsp;至&nbsp;<asp:TextBox ID="txtEndTime" runat="server" onfocus="WdatePicker()"
                                CssClass="Wdate"></asp:TextBox>
                        </td>
                        <td style="width: 20%;">
                            &nbsp;客户名称：<asp:TextBox ID="txtSearchClientName" runat="server" Width="120px"></asp:TextBox>
                        </td>
                        <td style="width: 25%;">
                            &nbsp;联系方式：<asp:DropDownList ID="ddlSearchRelationType" runat="server">
                            </asp:DropDownList>
                            &nbsp;
                            <asp:Button ID="SeachBut" runat="server" Text="查询" OnClick="SeachBut_Click" />
                        </td>
                    </tr>
                    <tr>
                        <th colspan="3" style="float: left; text-align: left">
                            &nbsp;<b>快速查询：</b>
                        </th>
                    </tr>
                    <tr>
                        <td colspan="3">
                            &nbsp;联系记录时间：<asp:DropDownList ID="ddlDate" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SeachBut_Click">
                                <asp:ListItem Value="">全部</asp:ListItem>
                                <asp:ListItem Value="today">今天</asp:ListItem>
                                <asp:ListItem Value="week">本周</asp:ListItem>
                                <asp:ListItem Value="weeklast">上周</asp:ListItem>
                                <asp:ListItem Value="month">本月</asp:ListItem>
                                <asp:ListItem Value="monthlast">上月</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                </table>
                <asp:GridView ID="gvManage" CssClass="tableHead" runat="server" AutoGenerateColumns="false"
                    AllowPaging="True" OnRowDataBound="gvManage_RowDataBound" OnPageIndexChanging="gvManage_PageIndexChanging"
                    PageSize="10">
                    <Columns>
                        <asp:TemplateField HeaderText="选择">
                            <ItemTemplate>
                                <input type="checkbox" id="annalIdSelect" name="annalIdSelect" value='<%# Eval("ClientAnnalID") %>' />
                            </ItemTemplate>
                            <HeaderTemplate>
                                <input type="checkbox" id="chkAll" onclick="SelectAllCheckboxes(this,'annalIdSelect')" />
                            </HeaderTemplate>
                        </asp:TemplateField>
                        <asp:BoundField HeaderText="联系时间" DataField="RelationTime" />
                        <asp:BoundField HeaderText="客户名称" DataField="ClientName" />
                        <asp:TemplateField HeaderText="联系方式">
                            <ItemTemplate>
                                <%# GetDictionaryTitle(Eval("RelationType").ToString().Trim()) %>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField HeaderText="记录内容" DataField="AnnalContent" />
                        <asp:BoundField HeaderText="记录人" DataField="Inputer" />
                        <asp:TemplateField HeaderText="操作">
                            <ItemTemplate>
                                <asp:LinkButton ID="lbtnCheck" CommandName="CheckInfo" CommandArgument='<%# Eval("ClientAnnalID")%>'
                                    OnCommand="Button_Command" runat="server">查看</asp:LinkButton>
                                <asp:LinkButton ID="lbtnUpdate" CommandName="EditInfo" CommandArgument='<%#Eval("ClientAnnalID")%>'
                                    OnCommand="Button_Command" runat="server">修改</asp:LinkButton>
                                <asp:LinkButton ID="lbtnDelete" CommandName="DelInfo" CommandArgument='<%# Eval("ClientAnnalID") %>'
                                    OnCommand="Button_Command" runat="server" OnClientClick="return confirm('确定要删除该信息吗？');">删除</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <EmptyDataTemplate>
                        <table class="tableHead" width="100%">
                            <tr>
                                <th>
                                    联系时间
                                </th>
                                <th>
                                    客户名称
                                </th>
                                <th>
                                    联系方式
                                </th>
                                <th>
                                    记录内容
                                </th>
                                <th>
                                    记录人
                                </th>
                                <th>
                                    操作
                                </th>
                            </tr>
                            <td colspan="6" style="text-align: center">
                                没有符合条件的联系人数据！
                            </td>
                        </table>
                    </EmptyDataTemplate>
                </asp:GridView>
                <div style="text-align: center;">
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Literal ID="ltrPagePanel" runat="server"></asp:Literal>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                </div>
                <div>
                    &nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="btnMoreDelete" CommandName="MoreDelete" OnCommand="Button_Command"
                        runat="server" Text="删除所选中的联系记录" />
                </div>
            </asp:PlaceHolder>
            <%--全部联系记录 end--%>
            <%--查看联系记录 begin--%>
            <br />
            <asp:PlaceHolder ID="phCheck" runat="server" Visible="false">
                <table class="ShopOrderStyle">
                    <caption>
                        &nbsp;&nbsp;&nbsp;&nbsp;联系记录的详细信息
                    </caption>
                    <tr>
                        <td class="OrderTitle">
                            客户名称：
                        </td>
                        <td>
                            <asp:Label ID="lblClientName" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            联系方式：
                        </td>
                        <td>
                            <asp:Label ID="lblRelationType" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            客户方联系人：
                        </td>
                        <td>
                            <asp:Label ID="lblContacter" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            联系时间：
                        </td>
                        <td>
                            <asp:Label ID="lblRelationTime" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            记录信息：
                        </td>
                        <td>
                            <asp:Label ID="lblAnnalContent" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            记录人：
                        </td>
                        <td>
                            <asp:Label ID="lblInputer" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center" style="text-align: center">
                            <input type="button" id="btn" onclick="history.back()" value="返回" />
                        </td>
                    </tr>
                </table>
            </asp:PlaceHolder>
            <%--查看联系记录 end--%>
            <%--添加/修改联系记录 begin--%>
            <asp:PlaceHolder ID="phAddOrEdit" runat="server" Visible="false">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <table class="ShopOrderStyle">
                            <caption>
                                <asp:HiddenField ID="hfClientID" Value="" runat="server" />
                                <asp:HiddenField ID="hfContacterID" Value="" runat="server" />
                                <asp:HiddenField ID="hfClientName" Value="" runat="server" />
                            </caption>
                            <tr>
                                <td class="OrderTitle" style="width:160px;">
                                    客户名称：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtClientName" runat="server" Enabled="false"></asp:TextBox>[<a
                                        onclick="javascript:void(0);" id="showClient" runat="server" style="cursor: pointer;"><span
                                            style="color: Red">选择客户名称</span></a>]<span style="color: Red">*</span>
                                </td>
                            </tr>
                            <tr>
                                <td class="OrderTitle">
                                    联系方式：
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlRelationType" runat="server">
                                    </asp:DropDownList>
                                    <span style="color: Red">*</span>
                                    <asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="ddlRelationType"
                                        ErrorMessage="请选择联系方式!"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td class="OrderTitle">
                                    客户方联系人：
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlContacter" runat="server">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td class="OrderTitle">
                                    联系时间：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtRelationTime" runat="server" onfocus="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss',onpicked:pickedFunc})"
                                        CssClass="Wdate"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="OrderTitle">
                                    记录信息：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtAnnalContent" runat="server" TextMode="MultiLine" Height="120px"
                                        Width="260px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="OrderTitle">
                                    &nbsp;
                                </td>
                                <td>
                                    <span id="nextTiXing" runat="server">
                                        <input id="ckbNextAnnal" type="checkbox" onclick="CheckNextAnnal()" runat="server"
                                            value="下次联系预约提醒" />下次联系预约提醒</span>
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <%--下次联系预约提醒--%>
                <table class="ShopOrderStyle" style="display: none;" id="RemindItem">
                    <tr>
                        <td class="OrderTitle" style="width:160px;">
                            预约联系方式：
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlRemindRelationType" runat="server">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            主动提醒方式：
                        </td>
                        <td>
                            <asp:CheckBox ID="ckbRemindByEmail" runat="server" Text="邮件提醒" />
                            <asp:CheckBox ID="ckbRemindBySms" runat="server" Text="手机短信提醒" />
                            <%--<asp:CheckBox ID="ckbRemindByTips" runat="server" Text="冒泡提示提醒" />--%>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            预约提醒时间：
                        </td>
                        <td>
                            <div style="display: inline;">
                                <div id="TXTime" runat="server" style="display: none; float: left;">
                                    <asp:TextBox ID="txtRemindTime" runat="server" onfocus="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss',onpicked:pickedFuncRe})"
                                        CssClass="Wdate"></asp:TextBox>
                                </div>
                                <div style="display: inline; width: 100px;">
                                    <asp:DropDownList ID="ddlRemindTime" runat="server" onchange="CheckNextRemindTime()">
                                        <asp:ListItem Value="tomorrow" Selected="True">明天</asp:ListItem>
                                        <asp:ListItem Value="aftertomorrow">后天</asp:ListItem>
                                        <asp:ListItem Value="threeday">三天后</asp:ListItem>
                                        <asp:ListItem Value="week">一周后</asp:ListItem>
                                        <asp:ListItem Value="onemonth">一个月后</asp:ListItem>
                                        <asp:ListItem Value="twomonth">两个月后</asp:ListItem>
                                        <asp:ListItem Value="threemonth">三个月后</asp:ListItem>
                                        <asp:ListItem Value="detail">具体设置</asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            提醒内容：
                        </td>
                        <td>
                            <asp:TextBox ID="txtRemindContent" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                </table>
                <table class="ShopOrderStyle">
                    <tr>
                        <td style="text-align: center;" colspan="2">
                            <asp:Button ID="btnSave" OnClick="btnSave_Click" OnClientClick="return checkPass();"
                                runat="server" Text="保存联系记录管理" />&nbsp;&nbsp;
                            <asp:Button ID="btnBack" runat="server" Text="返回联系记录管理" OnClick="btnBack_Click" />
                        </td>
                    </tr>
                </table>
            </asp:PlaceHolder>
            <br />
            <%--添加/修改联系记录 end--%>
        </div>
    </div>
    <script type="text/javascript">        setButtonActive('<%=m_flag %>');</script>
    <script type="text/javascript">
        //客户名称
        function checkKehu() {
            var kehu = $("#<%=txtClientName.ClientID %>"); //客户名称
            if (kehu.val().length == 0) {
                alert("请选择客户名称!");
                return false;
            }
            var kehuhf = $("#<%=hfClientName.ClientID %>"); //客户名称
            kehuhf.attr("value", kehu.val());
            getContValue(); //联系人
            return true;
        }
        //联系方式
        function ChangeType() {
            var typeMode = document.getElementById('<%=ddlRelationType.ClientID %>');
            var bojvalue = "";
            for (i = 0; i < typeMode.options.length; i++) {
                if (typeMode.options[i].selected)
                    bojvalue = typeMode.options[i].value;
            }
            if (bojvalue.length == 0) {
                alert("请选择联系方式！");
                return false;
            }
            return true;
        }
        //联系人
        function checkContacter() {
            // var kehu = $("#<%=txtClientName.ClientID %>"); //客户名称
            var objSelect = document.getElementById("<%=ddlContacter.ClientID %>");
            if (objSelect.length == 0) {
                alert("该客户的联系人不存在，请添加该客户的联系人！");
                // window.location.href = "ContacterManage.aspx?TabMenu=tabAdd&action=addinfo&clientname=" + kehu.val();
                return false;
            }
            return true;
        }
        //联系时间
        function checkRelationtime() {
            var relationtime = $("#<%=txtRelationTime.ClientID %>"); //联系时间
            if (relationtime.val().length == 0) {
                alert("联系时间不能为空!");
                relationtime.focus();
                return false;
            }
            return true;
        }
        function checkPass() {
            if (checkKehu() && checkContacter() && ChangeType() && checkRelationtime()) {
                return true;
            } else {
                return false;
            }
        }
    </script>
    <script type="text/javascript">
        //选择客户名称
        function SelectKehu(kh) {
            var arr = showModalDialog('ClientList.aspx?TypeSelectClientName=clientname&ClientOwner=' +<%= user.UserID %> + '&DefaultValue=' + document.getElementById(kh).value, '', 'dialogWidth:600px; dialogHeight:450px; help: no; scroll: yes; status: no');
            if (arr != null) {
                var temparray = arr.split('|');
                if (temparray != null && temparray.length > 2) {
                    document.getElementById(kh).value = temparray[0];//客户名称
                     //客户名称、客户类型、客户ID
                    GetContact(temparray[0],temparray[1],temparray[2]); //选择客户添加对应的联系人
                }
            }
        }
        //选择客户添加对应的联系人
        function GetContact(kehuName,clienttype,kehuid) {
            var objSelect = document.getElementById("<%=ddlContacter.ClientID %>");
            objSelect.options.length = 0; //清空下拉列表值
            $.post("../../WebService/ClientService.ashx", { 'Action': 'GetContacter', 'ClientName': kehuName }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                     var d = eval (data) ;
                        $.each(d.table1, function (i) {
                            var strName = d.table1[i].TrueName; //文本值
                            var strValue = d.table1[i].ContacterID; //Value值
                            var objOption = new Option(strName, strValue); // 建立Option对象
                            if ($('#<%=hfContacterID.ClientID %>').val() == strValue) {
                                objOption.selected = 'selected';
                            }
                            objSelect.options.add(objOption);
                        });
                    }else{
                        alert("该客户的联系人不存在，请添加该客户的联系人！");
                        if (clienttype=="ClientType_qy") {
                            window.location.href = "ContacterManage.aspx?TabMenu=tabAdd&action=addinfo&clientname=" + kehuName;
                        }else if(clienttype=="ClientType_gr"){
                            window.location.href = "ClientManage.aspx?TabMenu=Addpsn&action=editinfo&clientID=" + kehuid;
                        }
                        return;
                    }
                }
            });
        }

        //联系人(被选中的联系人)
        function getContValue() {
            var ID = $("#<%=hfContacterID.ClientID %>"); //联系人ID
            var objSelect = document.getElementById("<%=ddlContacter.ClientID %>");
            for (var i = 0; i < objSelect.options.length; i++) {
                if (objSelect[i].selected == true) {
                    ID.attr("value", objSelect[i].value);
                }
            }
        }

        //下次预约提醒
        function CheckNextAnnal() {
            var nextAnnal = $("#<%=ckbNextAnnal.ClientID %>"); //下次预约提醒复选框
            var remindItem = document.getElementById("RemindItem");
            
            if (nextAnnal.attr("checked")=="checked") {
                remindItem.style.display="block";
            } else {
                remindItem.style.display= "none";
            }
        }

        //下次预约提醒时间
        function CheckNextRemindTime() {
            var objRemindTime = document.getElementById("<%=ddlRemindTime.ClientID %>"); //下次预约提醒时间
            var objValue="";
            for (var i = 0; i < objRemindTime.options.length; i++) {
                if (objRemindTime[i].selected == true) {
                    objValue= objRemindTime[i].value;
                }
            }
            var remindItem = document.getElementById("<%=txtRemindTime.ClientID %>");//提醒时间的文本框
            var spanTXTime=document.getElementById("<%=TXTime.ClientID %>");
            if (objValue=="detail") {
                remindItem.value="<%=nowTime %>";
                spanTXTime.style.display="block";
           }else{
               spanTXTime.style.display= "none";
           }
        }
        $(function () {
            //修改:editinfo、添加：addinfo
            var editac = "<%=ActionTab %>";
            if (editac == "editinfo") {
                var kehuhf = $("#<%=hfClientName.ClientID %>"); //客户名称
                GetContact(kehuhf.val()); //选择客户添加对应的联系人
                //下次预约提醒
               document.getElementById("<%=nextTiXing.ClientID %>").style.display="none";
                $("#RemindItem").css("display", "none");//隐藏
            }
        });
    </script>
</asp:Content>
