<%@ page language="C#" autoeventwireup="true" masterpagefile="~/Member/MyShopMasterPage.master" enableeventvalidation="false" inherits="Member_ClientRelation_ServiceManage, WebApp_deploy" 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.$('<%=txtServiceTime.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>
    <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="ServiceManage.aspx?TabMenu=tabMnage">
                    <asp:Label ID="lblManage" runat="server" Text="服务记录管理" />
                </a></li>
                <li><a href="ServiceManage.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: 30%">
                            &nbsp;服务类型：
                            <asp:DropDownList ID="ddlSearchServiceType" runat="server">
                            </asp:DropDownList>
                        </td>
                        <td style="width: 30%">
                            &nbsp;服务方式：
                            <asp:DropDownList ID="ddlSearchServiceMode" runat="server">
                            </asp:DropDownList>
                        </td>
                        <td style="width: 30%">
                            &nbsp;服务结果：
                            <asp:DropDownList ID="ddlSearchServiceResult" runat="server">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;具体时间：
                        </td>
                        <td>
                            &nbsp;开始时间：<asp:TextBox ID="txtBeginTime" runat="server" onfocus="WdatePicker()"
                                CssClass="Wdate"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;结束时间：<asp:TextBox ID="txtEndTime" runat="server" onfocus="WdatePicker()" CssClass="Wdate"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;客户名称：<asp:TextBox ID="txtSearchClientName" runat="server" Width="120px"></asp:TextBox>
                        </td>
                        <td>
                            &nbsp;服务主题：<asp:TextBox ID="txtSearchServiceTitle" runat="server" Width="120px"></asp:TextBox>
                        </td>
                        <td>
                            &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"
                                Width="100px" Height="20px">
                                <asp:ListItem Value="">全部</asp:ListItem>
                                <asp:ListItem Value="10">十天内</asp:ListItem>
                                <asp:ListItem Value="30">一个月内</asp:ListItem>
                                <asp:ListItem Value="month">本月</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="IdSelect" name="IdSelect" value='<%# Eval("ItemID") %>' />
                            </ItemTemplate>
                            <HeaderTemplate>
                                <input type="checkbox" id="chkAll" onclick="SelectAllCheckboxes(this,'IdSelect')" />
                            </HeaderTemplate>
                        </asp:TemplateField>
                        <asp:BoundField HeaderText="服务时间" DataField="ServiceTime" />
                        <asp:BoundField HeaderText="客户名称" DataField="ClientName" />
                        <asp:BoundField HeaderText="主题" DataField="ServiceTitle" />
                        <asp:TemplateField HeaderText="服务类型">
                            <ItemTemplate>
                                <%#GetDictionaryTitle(Eval("ServiceType").ToString().Trim())%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="服务方式">
                            <ItemTemplate>
                                <%#GetDictionaryTitle(Eval("ServiceMode").ToString().Trim())%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="服务结果">
                            <ItemTemplate>
                                <%#GetDictionaryTitle(Eval("ServiceResult").ToString().Trim())%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="操作">
                            <ItemTemplate>
                                <asp:LinkButton ID="lbtnCheck" CommandName="CheckInfo" CommandArgument='<%# Eval("ItemID")%>'
                                    OnCommand="Button_Command" runat="server">查看</asp:LinkButton>
                                <asp:LinkButton ID="lbtnUpdate" CommandName="EditInfo" CommandArgument='<%#Eval("ItemID")%>'
                                    OnCommand="Button_Command" runat="server">修改</asp:LinkButton>
                                <asp:LinkButton ID="lbtnDelete" CommandName="DelInfo" CommandArgument='<%# Eval("ItemID") %>'
                                    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>
                                <th>
                                    操作
                                </th>
                            </tr>
                            <td colspan="7" 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--%>
            <asp:PlaceHolder ID="phCheck" runat="server" Visible="false">
                <br />
                <table class="ShopOrderStyle">
                    <caption>
                        &nbsp;&nbsp;&nbsp;&nbsp;服务记录的详细信息
                    </caption>
                    <tr>
                        <td class="OrderTitle">
                            服务主题：
                        </td>
                        <td>
                            <asp:Label ID="lblServiceTitle" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <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="lblContacter" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            服务类型：
                        </td>
                        <td>
                            <asp:Label ID="lblServiceType" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            服务方式：
                        </td>
                        <td>
                            <asp:Label ID="lblServiceMode" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            服务时间：
                        </td>
                        <td>
                            <asp:Label ID="lblServiceTime" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            花费时间：
                        </td>
                        <td>
                            <asp:Label ID="lblTakeTime" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            服务内容 ：
                        </td>
                        <td>
                            <asp:Label ID="lblServiceContent" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            服务结果：
                        </td>
                        <td>
                            <asp:Label ID="lblServiceResult" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            录入者：
                        </td>
                        <td>
                            <asp:Label ID="lblInputer" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            备注：
                        </td>
                        <td>
                            <asp:Label ID="lblRemark" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: center">
                            <input type="button" id="btn" value="返回" onclick="history.back(-1)" />
                        </td>
                    </tr>
                </table>
            </asp:PlaceHolder>
            <%--查看服务记录 end--%>
            <%--添加/修改服务记录 begin--%>
            <asp:PlaceHolder ID="phAddOrEdit" runat="server" Visible="false">
                <br />
                <table class="ShopOrderStyle">
                    <caption>
                        <asp:HiddenField ID="hfClientID" Value="" runat="server" />
                        <asp:HiddenField ID="hfClientName" Value="" runat="server" />
                        <asp:HiddenField ID="hfContacterID" Value="" runat="server" />
                    </caption>
                    <tr>
                        <td class="OrderTitle">
                            服务主题：
                        </td>
                        <td>
                            <asp:TextBox ID="txtServiceTitle" runat="server"></asp:TextBox>
                            <span style="color: Red">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            客户名称：
                        </td>
                        <td>
                            <asp:TextBox ID="txtClientName" runat="server" Enabled="false"></asp:TextBox>[<a
                                onclick="javascript:void(0);" style="cursor: pointer;" id="showClient" runat="server"><span
                                    style="color: Red">选择客户名称</span></a>]<span style="color: Red">*</span>
                        </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:DropDownList ID="ddlServiceType" runat="server">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            服务方式：
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlServiceMode" runat="server">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            服务时间：
                        </td>
                        <td>
                            <%--<asp:TextBox ID="txtServiceTime" runat="server" onfocus="SelectDate(this,'yyyy-MM-dd hh:mm:ss');"></asp:TextBox>--%>
                            <asp:TextBox ID="txtServiceTime" 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:DropDownList ID="ddlTakeTime" runat="server">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            服务结果：
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlServiceResult" runat="server">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            服务内容 ：
                        </td>
                        <td>
                            <asp:TextBox ID="txtServiceContent" runat="server" TextMode="MultiLine" Height="120px"
                                Width="260px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="OrderTitle">
                            备注 ：
                        </td>
                        <td>
                            <asp:TextBox ID="txtRemark" runat="server" TextMode="MultiLine" Height="120px" Width="260px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: center">
                            <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>
            <%--添加/修改服务记录 end--%>
            <br />
        </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 checkTitle() {
            var title = $("#<%=txtServiceTitle.ClientID %>"); //服务主题
            if (title.val().length == 0) {
                alert("请填写服务主题！");
                title.focus();
                return false;
            }
            return true;
        }
        //服务时间
        function checkServiceTime() {
            var serviceTime = $("#<%=txtServiceTime.ClientID %>"); //服务时间
            if (serviceTime.val().length == 0) {
                alert("请选择服务时间！");
                serviceTime.focus();
                return false;
            }
            return true;
        }
        function checkPass() {
            if (checkKehu() && checkTitle() && checkServiceTime()) {
                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 () {
            //修改:editinfo、添加：addinfo
            var editac = "<%=ActionTab %>";
            if (editac == "editinfo") {
                var kehuhf = $("#<%=hfClientName.ClientID %>"); //客户名称
                GetContact(kehuhf.val()); //选择客户添加对应的联系人              
            }
        });
    </script>
</asp:Content>
