<!--#include file="../Include/Const.Asp" -->
<!--#include file="../Include/ConnSiteData.Asp" -->
<!--#include file="../CheckAdmin.Asp"-->
<%
If InStr(session("GroupPurview"),"|13,") = 0 Then
    response.Write ("<br /><br /><div align=""center""><font style=""color:red; font-size:9pt; "")>您没有管理该模块的权限！</font></div>")
    response.End
End If
%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../Images/Admin_style.css">
<script language="javascript" type="text/javascript" src="../My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
<!--
function checktasksseach()
{
   if (tasks.st.value.replace(/[ ]/g,"")=="")
   {
	  alert("请选择开始日期！");
	  return false;
   }
  if (tasks.et.value.replace(/[ ]/g,"")=="")
   {
	  alert("请选择结束日期！");
	  return false;
   }
}
function changePos(thisID){
		var st=document.getElementById(thisID);
		if(document.body.clientWidth+document.body.scrollLeft-st.offsetLeft>=st.clientWidth){
			st.style.left=st.offsetLeft+'px';
		}else{
			st.style.left=(document.body.clientWidth>=st.clientWidth)? (document.body.clientWidth-st.clientWidth+document.body.scrollLeft-80)+'px':document.body.scrollLeft+'px';
			}
		if (document.body.clientHeight + document.body.scrollTop - st.offsetTop - st.clientHeight < st.clientHeight){
			//st.style.top  = (st.offsetTop - document.body.scrollTop < st.clientHeight) ? (st.offsetTop + st.clientHeight) +'px': (st.offsetTop - st.clientHeight)+'px';
			st.style.top=(st.offsetTop - document.body.scrollTop < st.clientHeight) ? (document.body.clientHeight-st.clientHeight+document.body.scrollTop-10) +'px': (st.offsetTop - st.clientHeight)+'px';
		}
	}
function display(display,indexID){
        document.getElementById(indexID).style.display=display;
}
function Show_bt(btID,rid){
		 document.getElementById(btID).style.display="";
		 //document.getElementById(rid).style.width="250px";
		 //document.getElementById(rid).style.height="30px";
 }
function Ushow_bt(btID,rid)
{
	//document.getElementById(btID).style.display="none";
	//document.getElementById(rid).style.width="250px";
	document.getElementById(rid).style.height="";
}
function checkkhreedit(Orstatusid,checkid,forms)
{
	var ors=document.getElementById(Orstatusid).value;
   if (ors.replace(/^\s*/g,"")!=""){
	   if (ors!="C" && ors!="B" && ors!="A" &&ors!="O"){
		   alert("订单状态标识非法!请输入[C]或[B]或[A]或[O]");
	       document.getElementById(Orstatusid).focus();
	       return false;
		   }
	   }
}
-->
</script>
<%
Dim Result,TDemo,TEtime,TasksSortID,TKehuID,TChancesID,Task_frame,TSortID,st,et,s
Dim mOr_status,MemNameList
Result = request.QueryString("Result")
ID = request.QueryString("ID")
'TSortID=trim(request.QueryString("TSortID"))
MemName_Pre=trim(request.QueryString("MemName_Pre")) '获取成员
mPlanSort=trim(request.QueryString("PlanSort"))
mOr_status=trim(request.QueryString("Or_status"))
Action = request.QueryString("Action")

    If Action = "seach" Then
	   st=trim(request.Form("st"))
	   et=trim(request.Form("et"))
	      'if st="" and et="" then '查询分页时
	         'st=trim(request("st"))
             'et=trim(request("et"))
	      'end if
		  'response.Redirect "My_Plan_todo_bypeople.asp?Action=seach&PlanSort="&mPlanSort&"&Or_status="&mOr_status&"&st="&st&"&et="&et&"&Page=1"
	else
	st=trim(request.QueryString("st")) '开始时间
    et=trim(request.QueryString("et")) '结束时间	  
	end if
if st="" and et="" then
   st=date()
   et=date()
end if
s=1

%>
<br />
<table class="tableBorder" width="95%" border="0" align="center" cellpadding="5" cellspacing="1">
  <form name="tasks" method="post" action="?Action=seach&PlanSort=<%=mPlanSort%>&Or_status=<%=mOr_status%>" onSubmit="return checktasksseach()">
    <tr>
      <td class="forumRowHighlight">
      <div class="team_list">按团队成员：&nbsp; <a href="?PlanSort=<%=mPlanSort%>&Or_status=<%=mOr_status%>&st=<%=st%>&et=<%=et%>&t=<%=t%>">全部</a> &nbsp; 
	<%teamlist(session("UserName"))%>
    </div>
      分类为
      <select name="PlanSort" onchange="window.location='?PlanSort=' + this.value+'&MemName_Pre=<%=MemName_Pre%>&Or_status=<%=mOr_status%>&st=<%=st%>&et=<%=et%>'">
      <option value="">所有</option>
      <option value="电话" <%if mPlanSort="电话" then response.Write "selected"%>>电话</option>
	  <option value="拜访" <%if mPlanSort="拜访" then response.Write "selected"%>>拜访</option>
      <option value="其它" <%if mPlanSort="其它" then response.Write "selected"%>>其它</option>
   </select>
   
  
    &nbsp; 订单状态
      <select name="Or_status" onchange="window.location='?MemName_Pre=<%=MemName_Pre%>&PlanSort=<%=mPlanSort%>&Or_status=' + this.value+'&st=<%=st%>&et=<%=et%>'">
      <option value="">所有</option>
      <option value="D" <%if mOr_status="D" then response.Write "selected"%>>D</option>
      <option value="C" <%if mOr_status="C" then response.Write "selected"%>>C</option>
      <option value="B" <%if mOr_status="B" then response.Write "selected"%>>B</option>
      <option value="A" <%if mOr_status="A" then response.Write "selected"%>>A</option>
      <option value="O" <%if mOr_status="O" then response.Write "selected"%>>O</option>
   </select>
   &nbsp;&nbsp;计划日期为：
   <input name="st" id="st" class="Wdate" type="text" onFocus="WdatePicker({skin:'blueFresh',maxDate:'#F{$dp.$D(\'et\')||\'2020-10-01\'}'})" value="<%=st%>"/>
   
   至 
   <input name="et" id="et" class="Wdate" type="text" onFocus="WdatePicker({skin:'blueFresh',minDate:'#F{$dp.$D(\'st\')}',maxDate:'2020-10-01'})" value="<%=et%>"/>
    <input name="submit" type="submit" id="submit" value="显示" />
      </td>
    </tr>
    <tr>
    <td class="forumRow"><img src='../Images/current.jpg' /> 
    <%if MemName_Pre<>"" then%>
       <b><font color="#990000"><%=genjinText(MemName_Pre)%>,</font></b> 
  <%end if%> 
	<%PlaceFlag()%></td>
  </tr>
  </form>
</table>
<table class="tableBorder" width="95%" border="0" align="center" cellpadding="5" cellspacing="1" style="background-color:#e6eff8">
  
  <% MyTasksKehutodo() %>
  
</table>
<%


'客户任务分页列表
Function MyTasksKehutodo()
    Dim idCount
    Dim pages
    pages = 20
    Dim pagec
    Dim page
    page = CLng(request("Page"))
    Dim pagenc
    pagenc = 2
    Dim pagenmax
    Dim pagenmin
    Dim datafrom
    datafrom = "Zqj_Plan INNER JOIN Zqj_Records ON Zqj_Plan.Re_ID = Zqj_Records.Re_ID"
    Dim datawhere
	if MemName_Pre<>"" then
	  if mPlanSort<>"" then ''计划分类不为空时
	    if mOr_status<>"" then
		    datawhere="where Zqj_Plan.MemName in('"&MemName_Pre&"') and PL_SortName='"&mPlanSort&"' and PL_time between #"&st&"# and #"&et&"# and Zqj_Records.Re_status='"&mOr_status&"' and PL_viewflag=false "
		else
            datawhere="where Zqj_Plan.MemName in('"&MemName_Pre&"') and PL_SortName='"&mPlanSort&"' and PL_time between #"&st&"# and #"&et&"# and PL_viewflag=false "
		end if
	  else '计划分类为空时
	    if mOr_status<>"" then
	        datawhere="where Zqj_Plan.MemName in('"&MemName_Pre&"') and PL_time between #"&st&"# and #"&et&"# and Zqj_Records.Re_status='"&mOr_status&"' and PL_viewflag=false "
		else
		    datawhere="where Zqj_Plan.MemName in('"&MemName_Pre&"') and PL_time between #"&st&"# and #"&et&"# and PL_viewflag=false "
		end if
	  end if
	else
	'成员为空时
	  if mPlanSort<>"" then ''计划分类不为空时
	    if mOr_status<>"" then
		    datawhere="where Zqj_Plan.MemName in("&MemNameList&") and PL_SortName='"&mPlanSort&"' and PL_time between #"&st&"# and #"&et&"# and Zqj_Records.Re_status='"&mOr_status&"' and PL_viewflag=false "
		else
            datawhere="where Zqj_Plan.MemName in("&MemNameList&") and PL_SortName='"&mPlanSort&"' and PL_time between #"&st&"# and #"&et&"# and PL_viewflag=false "
		end if
	  else '计划分类为空时
	    if mOr_status<>"" then
	        datawhere="where Zqj_Plan.MemName in("&MemNameList&") and PL_time between #"&st&"# and #"&et&"# and Zqj_Records.Re_status='"&mOr_status&"' and PL_viewflag=false "
		else
		    datawhere="where Zqj_Plan.MemName in("&MemNameList&") and PL_time between #"&st&"# and #"&et&"# and PL_viewflag=false "
		end if
	  end if
	end if
    Dim sqlid
    Dim Myself, PATH_INFO, QUERY_STRING
    PATH_INFO = request.servervariables("PATH_INFO")
    QUERY_STRING = request.ServerVariables("QUERY_STRING")'
    If QUERY_STRING = "" Or InStr(PATH_INFO & "?" & QUERY_STRING, "Page=") = 0 Then
        Myself = PATH_INFO & "?PlanSort="&mPlanSort&"&Or_status="&mOr_status&"&st="&st&"&et="&et&"&"
    Else
        Myself = Left(PATH_INFO & "?" & QUERY_STRING, InStr(PATH_INFO & "?" & QUERY_STRING, "Page=") -1)
    End If
    Dim taxis
    taxis = "order by PL_time Desc,PL_ID Desc"
    Dim i
    Dim rs, sql
    sql = "select Zqj_Plan.PL_ID, Zqj_Plan.PL_SortName, Zqj_Plan.Cp_ID, Zqj_Plan.Co_ID, Zqj_Plan.PL_time, Zqj_Plan.MemName, Zqj_Plan.PL_viewflag, Zqj_Records.Re_time, Zqj_Records.Re_company, Zqj_Records.Re_Contactname, Zqj_Records.Re_Content, Zqj_Records.Re_status, Zqj_Records.Re_ID from "& datafrom &" "&datawhere &taxis
    Set rs = server.CreateObject("adodb.recordset")
    rs.Open sql, conn, 1, 3
    idCount = rs.RecordCount
    If(idcount>0) Then
         If(idcount Mod pages = 0)Then
             pagec = Int(idcount / pages)
         Else
             pagec = Int(idcount / pages) + 1
         End If
         rs.pagesize = pages
         If page < 1 Then page = 1
         If page > pagec Then page = pagec
         If pagec > 0 Then rs.absolutepage = page
    End If
   noli=1
   If not(rs.bof and rs.eof) Then
   %>
   <tr>
    <th width="30">序号</th>
    <th>计划日期</th>
    <th align="left">公 司</th>
    <th align="center">联系人</th>
    <th align="center">电 话</th>
    <th align="center" width="60">订单状态</th>
    <th align="center">沟通内容</th>
    <th align="center"><font color="#006600">跟进时间</font></th>	
    <th>历史沟通</th>
</tr>
   <%
     repeat_rows = 0
     While(repeat_rows < rs.PageSize and Not rs.EOF)
%>

    <tr <%if (noli mod 2)=1 then%>bgcolor='#F0F8FF'<%end if%> onMouseOver="this.style.backgroundColor='#F3D2A8'" onMouseOut="this.style.backgroundColor=''">
    <td align="center"><a name="m<%=s%>" id="m<%=s%>"></a><%=(page-1)*pages+noli%></td>
    <td align="center" style="color:#2C5322" >
    <%=rs("PL_time")%>
    </td>
     <td align="left"><%=rs("Re_company")%></td>
     <td align="left"><%=rs("Re_Contactname")%></td>
     <td align="left"><%call KHtel(rs("Cp_ID"))%></td>
     <td align="center"><b>
     <%
	 Select Case rs("Re_status")
	    case "D"
		     response.Write "<font color=""#6699FF"">D</font>"
	    case "C"
		    response.Write "<font color=""gray"">C</font>"
		case "B"
		    response.Write "<font color=""#354C80"">B</font>"
		case "A"
		    response.Write "<font color=""#C87701"">A</font>"
		case "O"
		     response.Write "<font color=""#FF0000"">O</font>"
		case else
	End Select
	 %>
     </b>
     </td>
     <td><%=rs("Re_Content")%></td>
     <td align="center">
	 <%
	strDateTime=rs("Re_time")
    If datediff("d",strDateTime,Now())=0 then
       response.Write "<font color=""#ff0000"">"&strDateTime&"</font>"
    else
       response.Write strDateTime
    End if
	%>
     </td>
   <td align="center" id="<%=s%>">
	 ( <a href="../Kehu/My_people_KehuView.Asp?Result=Modify&ID=<%=rs("Cp_ID")%>&showid=3"><font color="#FF0000"><%call KHRe(rs("Cp_ID"))%></font></a> )
     <script type="text/javascript">
           document.getElementById("<%=s%>").onmouseover=function(){display('block','w<%=s%>');changePos('w<%=s%>');};
           document.getElementById("<%=s%>").onmouseout=function(){display('none','w<%=s%>')};         //document.getElementById("wpi13").onmouseover=function(){display('block','w14')}
     </script>
     <div class="dayPlanTable" id="w<%=s%>" onMouseOut="display('none','m<%=s%>')">
  <%call KHRelist(rs("Cp_ID"))%>
     </div>
     </td>
     </tr>
<%
   noli=noli+1
   s=s+1
   repeat_rows = repeat_rows + 1
   rs.movenext
   Wend
Response.Write "<tr>" & vbCrLf
Response.Write "<td colspan='9' nowrap class=""forumRow"">" & vbCrLf
Response.Write "<table width='98%' border='0' align='center' cellpadding='5' cellspacing='1' style=""margin-bottom:20px;"">" & vbCrLf
Response.Write "<tr>" & vbCrLf
Response.Write "<td class=""forumRow"">&nbsp; 共计：<font color='red'>"&idcount&"</font>条记录 页次：<font color='red'>"&page&"</font></strong>/"&pagec&" 每页：<font color='red'>"&pages&"</font>条</td>" & vbCrLf
Response.Write "<td align='right' class=""forumRow"">" & vbCrLf
pagenmin = page - pagenc
pagenmax = page+pagenc
If(pagenmin<1) Then pagenmin = 1
If(page>1) Then response.Write ("<a href='"& myself &"Page=1'><font style='font-size: 14px; font-family: Webdings'>9</font></a> ")
If(pagenmin>1) Then response.Write ("<a href='"& myself &"Page="& page - (pagenc * 2 + 1) &"'><font style='font-size: 14px; font-family: Webdings'>7</font></a> ")
If(pagenmax>pagec) Then pagenmax = pagec
For i = pagenmin To pagenmax
    If(i = page) Then
    response.Write (" <font color='red'>"& i &"</font> ")
Else
    response.Write ("[<a href="& myself &"Page="& i &">"& i &"</a>]")
End If
Next
If(pagenmax<pagec) Then response.Write (" <a href='"& myself &"Page="& page+(pagenc * 2 + 1) &"'><font style='font-size: 14px; font-family: Webdings'>8</font></a> ")
If(page<pagec) Then response.Write ("<a href='"& myself &"Page="& pagec &"'><font style='font-size: 14px; font-family: Webdings'>:</font></a> ")
Response.Write "第<input name='SkipPage' onKeyDown='if(event.keyCode==13)event.returnValue=false' onchange=""if(/\D/.test(this.value)){alert('请输入需要跳转到的页数并且必须为整数！');this.value='"&Page&"';}"" style='width: 28px;' type='text' value='"&Page&"'>页" & vbCrLf
Response.Write "<input name='submitSkip' type='button' onClick='GoPage("""&Myself&""")' value='转到'>" & vbCrLf
Response.Write " </td>" & vbCrLf
Response.Write "</tr>" & vbCrLf
Response.Write "</table>" & vbCrLf
Response.Write "</td>" & vbCrLf
Response.Write "</tr>" & vbCrLf
   Else
       response.Write "<tr><td nowrap align='center' colspan='9'><img src=""../Images/question.gif"" width=""18"" height=""18""/> <font color='#999999'>暂时没有找到相关的销售报告...</font><br><div style=""text-align:center; padding:15px""></div></td></tr>"
	   
   End If
rs.Close
Set rs = Nothing
End Function

'==============================
'函 数 名：KHRe
'作    用：显示关联跟进记录数量
'参    数：
'==============================
Function KHRe(ID) 
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "select * from Zqj_Records where MemName='"&session("UserName")&"' and Cp_ID="&ID
    rs.Open sql, conn, 1, 1
	max=rs.recordcount
	if rs.bof and rs.eof then
	response.Write max
	else
	   Response.Write max
	end if 
    rs.Close
    Set rs = Nothing
End Function

'==============================
'函 数 名：KHtel
'作    用：显示客户电话
'参    数：
'==============================
Function KHtel(ID) 
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "select * from Zqj_Contactperson where Cp_ID="&ID
    rs.Open sql, conn, 1, 1
	if rs.bof and rs.eof then
	response.Write ""
	else
	   tel=rs("Cp_tel")
	   tel2=rs("Cp_mobile")
	       if tel2="" then
	          Response.Write tel2
	       else
		      Response.Write tel2
		   end if
	end if 
    rs.Close
    Set rs = Nothing
End Function
'==============================
'函 数 名：KHRelist
'作    用：显示近期关联跟进记录数量
'参    数：
'==============================
Function KHRelist(ID)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "select top 10 * from Zqj_Records where Cp_ID="&ID&" order by Re_time desc"
    rs.Open sql, conn, 1, 1
	if rs.bof and rs.eof then
	    response.Write "<img src=""../Images/question.gif"" width=""18"" height=""18""> <font color='#999999'>暂无跟进记录...</font>"
	else
	     response.Write "<table width=""90%"" border=""0"">"
		 response.Write "<tr>"
		 response.Write "<td ><img src=""../Images/img.gif"" width=""20"" height=""20"">&nbsp;<font color=""#FF0000"">最近10条沟通记录</font></td>"
		 
		 response.Write "</tr>"
		 i=1
	   While Not rs.EOF
	     
		 response.Write "<tr>"
		 response.Write "<td align=""left""><font color='#006600'>"&i&"、"&rs("Re_time")&"</font></td>"
		 response.Write "</tr><tr>"
		 response.Write "<td>"&rs("Re_Content")&"</td>"
		 response.Write "</tr>"
	    rs.movenext
		 i=i+1
       Wend
		 response.Write "</table>"
	end if
    rs.Close
    Set rs = Nothing
End Function

Function PlaceFlag()
        If mOr_status<>"" Then
            Response.Write " 订单状态：<b><font color='#ff6600'>"&mOr_status&"</font></b>"
        Else
            Response.Write " 订单状态：<font color='#ff6600'>全部</font>"
        End If
End Function

Function teamlist(MemName)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Zqj_Members where MemName='"&MemName&"' and Working"
    rs.Open sql, conn, 1, 1
    If rs.eof and rs.bof  Then
        response.Write "<script language='javascript'>alert('参数错误！');history.back(-1);</script>"
        response.End
    else
        SortPath=rs("SortPath") '读取当前用户的部门
		SortID=rs("SortID")
    end if
    rs.Close
    Set rs = Nothing
	'列出团队成员
	Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Zqj_Members where SortID="&SortID&" and Working"
    rs.Open sql, conn, 1, 1
	if rs.eof and rs.bof then
	    response.Write "无成员"
	else
	    While Not rs.EOF
        response.Write(" <img src='../Images/doing.gif' /> <a href='?MemName_Pre="&rs("MemName")&"&PlanSort="&mPlanSort&"&Or_status="&mOr_status&"&st="&st&"&et="&et&"&Page=1'>"&rs("RealName")&"</a> &nbsp;")
		MemNameList=MemNameList+"'"+rs("MemName")+"'"
        rs.movenext
		if not rs.eof then
		   MemNameList=MemNameList+","
		end if		
        Wend
	end if
	rs.close
	set rs=nothing
End Function

Function genjinText(MemName)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Zqj_Members where MemName='"&MemName&"'"
    rs.Open sql, conn, 1, 1
	if rs.bof and rs.eof then
	genjinText="无跟进人"
	else
    genjinText = rs("RealName")
	end if
    rs.Close
    Set rs = Nothing
End Function
%>