function jsTelBillQueryCondition() { };

/*条件对象*/
jsTelBillQueryCondition.queryObj=[{
_TelNum:'',
_Name:'',
_Remark:'',
_BeginTime:'',
_EndTime:'',
_callType:'',
_statusType:'',
_IsHaveAudio:''
}];
/*加载本区域内容*/
jsTelBillQueryCondition.showPage = function() {
    var queryCondition = document.getElementById("queryCondition");
    var marginValue=App.ieMargin();
    var menuHeight=document.body.clientHeight-marginValue;//-27;
    marginValue=null;
    var allString = [];
    allString.push('<div id="div-left-menu" class="div-left-menu" style="width:99%;height:'+menuHeight+';overflow:auto;position:relative;">');
    allString.push('<div class="div-left-menu-header"><div class="div-left-menu-title-name" id="divTreeTitle">查询条件</div></div>');
    allString.push('<div id="div-left-menu-content" style="line-height:25px;padding-left:10px; height:91.5%">');
    
    allString.push('<div style="clear:left;"></div><div><h2>电话号码</h2><input id="callRecordNum" type="text" style="width:145;" class="ipt"/></div>');
     allString.push('<h2>通话状态</h2><div><input type="text" id="selCallRecordState"/></div>');
    if(!window.parent.jsIndexPage.IsCallReOrBookReg){
        allString.push('<h2 >名字</h2><input type="text" id="selCallRecordName"/>');
    }
    else{
       allString.push('<div  style="display:none;"><h2>名字</h2><input type="text" id="selCallRecordName"/></div>');
    }
    allString.push('<h2>通话备注</h2><div><input type="text" style="width:145;" class="ipt" id="callRecordRemark" /></div>');
    
    allString.push('<div><h2>通话时间</h2><ul style="float:left;">');
    allString.push('<li><label><input type="radio" name="talkTime" value="0" checked="checked" onclick="jsTelBillQueryCondition.showSearchTimeDiv(this)" />全部</label></li>');
    allString.push('<li><label><input type="radio" name="talkTime" value="1" onclick="jsTelBillQueryCondition.getCurDayData(this)" />今日');
    allString.push('&nbsp;<div id="divPreOrNextDay" style="display:none;"><input type="button" class="button" value="前一天" onclick="jsTelBillQueryCondition.getPreDayData();" style="width:50px;height:20px"/>&nbsp;<input type="button" class="button" value="后一天"  onclick="jsTelBillQueryCondition.getNextDayData();"  style="width:50px;height:20px"/><input id="hideToday" type="hidden" /></div>');
    allString.push('</label></li>');
    allString.push('<li><label><input type="radio" name="talkTime" value="2" onclick="jsTelBillQueryCondition.showSearchTimeDiv(this)" />最近一周</label></li>');
    allString.push('<li><label><input type="radio" name="talkTime" value="3" onclick="jsTelBillQueryCondition.showSearchTimeDiv(this)" />最近一个月</label></li>');
    allString.push('<li><label><input type="radio" name="talkTime" value="4" onclick="jsTelBillQueryCondition.showSearchTimeDiv(this)" />最近三个月</label></li>');
    allString.push('<li><label><input type="radio" name="talkTime" value="5" onclick="jsTelBillQueryCondition.showSearchTimeDiv(this)" />指定时间</label>');
    allString.push('<div id="divSearchTime" style="display:none;">从<input name="txt_BeginTime" type="text" maxlength="30" id="txt_QueryConditionBeginTime" readonly="readonly"/>到<input name="txt_EndTime" type="text" maxlength="30" id="txt_QueryConditionEndTime" readonly="readonly" /></div></li>');

    allString.push('</ul>');
    allString.push('</div>'); 
       allString.push('<div style="clear:both;height:1px;">&nbsp;</div>');
           allString.push('<div><h2>录音查询</h2><ul style="float:left;">');
    allString.push('<li><label><input type="radio" name="IsAudioSea" value="0" onclick="jsTelBillCenterContent.CallRecordSearchString()" checked="checked"/>全部</label></li>');
    allString.push('<li><label><input type="radio" name="IsAudioSea" value="1" onclick="jsTelBillCenterContent.CallRecordSearchString()" />有录音通话</label></li>');
    allString.push('<li><label><input type="radio" name="IsAudioSea" value="2" onclick="jsTelBillCenterContent.CallRecordSearchString()" />无录音通话</label></li>');
    allString.push('</ul></div>');    
    allString.push('<div style="clear:both;height:5px;">&nbsp;</div>');
      allString.push('<div style="float:left;"><input type="button" class="button"  value="查 询" onclick="jsTelBillCenterContent.CallRecordSearchString()"/>&nbsp;<input type="button"  value="清空"  onclick="jsTelBillQueryCondition.Cancel()" id="btnreset" class="button" />&nbsp;</div>');
    allString.push('</div>');  
    allString.push('<div class="div-left-menu-header" style="cursor:hand; float:left; width:100%;display:none;" onclick="jsTelBillQueryCondition.OpenBlackListWin()"><div class="div-left-menu-title-name" id="divBlackList">黑名单</div></div>');
    allString.push('</div>');
    queryCondition.innerHTML = allString.join("");
    /*调用command.js中得showTime 时间初始化时间控件*/
    showTime("txt_QueryConditionBeginTime", "txt_QueryConditionEndTime", false, 80);
    $("#hideToday").val(DBReader.ServerTime().ServerFormat("yyyy-MM-dd"));
    jsTelBillQueryCondition.LoadNameCombox();
    $("#divPreOrNextDay").hide();
    /*通话状态下拉框*/
    jsTelBillQueryCondition.CallStateDropDown();
    allString.length=0;
    allString=null;
    menuHeight=null;
    CollectGarbage();
}

/*打开黑名单管理页面*/
jsTelBillQueryCondition.OpenBlackListWin=function(){
   try
    {        
          ShowWindow.ShowMessageDialog('Application/TeleSecretary/frmBLackListManage.htm?formIndex='+ShowWindow.getFormIdx(),'黑名单',550,380);
    }
    catch(e)
    {
        alert("jsTelBillQueryCondition.OpenBlackListWin:"+e.message);
    }
};

/*清空查询条件*/
jsTelBillQueryCondition.Cancel=function(){
   $("#callRecordNum").val("");
   $("#selCallRecordState").val("");
   $("#selCallRecordName").val("");
   $("#callRecordRemark").val("");
   $("#txt_QueryConditionBeginTime").val("");
   $("#txt_QueryConditionEndTime").val(""); 
   var chkItem = document.getElementsByName("talkTime");
   chkItem[0].checked=true;   
   jsTelBillQueryCondition.showSearchTimeDiv();
};

/*名字*/
jsTelBillQueryCondition.LoadNameCombox=function(){
       $('#selCallRecordName').combobox({
            customFunction: jsTelBillQueryCondition.ShowNamePage,
            TextFiled: 'CUSTOMERName',
            dropwidth: 130,
            dropheight:340,
            rp: 10,
            selectedchange:jsTelBillCenterContent.CallRecordSearchString
        });
};

/*通话状态*/
jsTelBillQueryCondition.CallStateDropDown = function() {
    var typeItemArray = eval('[{text: "全部", value:"全部"},{ text: "对方已接", value:"对方已接"},{ text: "对方拒接", value:"对方拒接"},{ text: "对方没空", value:"对方没空"},{ text: "非本人接听", value:"非本人接听"},{ text: "无人接听", value:"无人接听"},{ text: "号码不对", value:"号码不对"},{ text: "对方回拨", value:"对方回拨"},{ text: "稍息再拨", value:"稍息再拨"},{text:"咨询",value:"咨询"},{text:"投诉",value:"投诉"},{text:"报修",value:"报修"},{text:"推销",value:"推销"},{ text: "对方通话中", value:"对方通话中"}]');
    var drop = $("#selCallRecordState").dropdown({
        dropwidth: 130,
        selectedIndex: -1,
        items: typeItemArray,
        isNoItems: true,
        selecteditem: { text: "全部", value: "全部" },
        selectedchange: jsTelBillCenterContent.CallRecordSearchString
    });
};

/*获取名字下拉框数据*/
jsTelBillQueryCondition.ShowNamePage=function(pageSize, pageIndex, searchStr) 
{
    var countTop=pageSize*(pageIndex-1);
    var txtSql="select distinct iif(ISNULL(CUSTOMER),'无',CUSTOMER) as CUSTOMERName  from T_CALLBILL ";
    var strWhere="where 1=1 ";
    if(searchStr!="")
    {
        searchStr=(searchStr.split('\'').join('’')).split('\"').join('”');
        strWhere +=  " and CUSTOMER like '%" + searchStr + "%'";
    }
     txtSql = txtSql + strWhere;
    if(countTop >0)
    {
          txtSql="select TOP "+ pageSize +" (select count(*) from ( " + txtSql +")) as AllCount, * from (" + txtSql +") where CUSTOMERName NOT IN (SELECT TOP "+ countTop +" * from (" + txtSql + "))";
    }
    else
    {
         txtSql="select TOP "+ pageSize +" (select count(*) from ( " + txtSql +")) as AllCount,  * from (" + txtSql +") ";
    } //window.clipboardData.setData("text",txtSql);
    var strResult = DBReader.selectSqlForJson(txtSql);
    var result;
    if(strResult!=null)
    {
         result=$.parseJSON("[{"+strResult+"}]");
    }
    result[0].pageIndex=pageIndex;
    countTop=null;
    txtSql="";
    strWhere="";
    strResult=null;
    CollectGarbage();
    return result[0];
}     

/*是否显示指定时间选择控件*/
jsTelBillQueryCondition.showSearchTimeDiv=function(obj)
{
    /*按指定日期查询*/
    if($(obj).val()==5)
    {
        $("#divSearchTime").show();
        $("#divPreOrNextDay").hide();
    }
    else
    {
        $("#divSearchTime").hide();
        $("#divPreOrNextDay").hide();
    
        if($(obj).val()==0)
        {
            /*查询全部*/
            $("#hideToday").val('');
        }
        else if($(obj).val()==1)
        {
            /*按今日查询*/
            $("#hideToday").val(DBReader.ServerTime().ServerFormat("yyyy-MM-dd"));
            $("#divPreOrNextDay").show();
        }
        jsTelBillCenterContent.CallRecordSearchString();
    }
};
/*天数据查询类型：默认是今天*/
jsTelBillQueryCondition.DayType="today";
/*今日*/
jsTelBillQueryCondition.getCurDayData=function(obj)
{
    jsTelBillQueryCondition.DayType="today";
    jsTelBillQueryCondition.showSearchTimeDiv(obj);
}
/*前一天*/
jsTelBillQueryCondition.getPreDayData=function()
{
    jsTelBillQueryCondition.DayType="Pre";
    /*调用查询方法*/
    jsTelBillCenterContent.CallRecordSearchString();
};
/*后一天*/
jsTelBillQueryCondition.getNextDayData=function()
{
    jsTelBillQueryCondition.DayType="Next";
    /*调用查询方法*/
    jsTelBillCenterContent.CallRecordSearchString();
};
/*生成查询条件*/
jsTelBillQueryCondition.queryString=function()
{
    try
    {
        var htxt_BeginTime="";
        var htxt_EndTime="";
        jsTelBillQueryCondition.queryObj[0]._TelNum=$("#callRecordNum").val().split('\"').join('“').split('\'').join('‘');
        jsTelBillQueryCondition.queryObj[0]._statusType=$("#selCallRecordState").val()=="全部"?"":$("#selCallRecordState").val();
        jsTelBillQueryCondition.queryObj[0]._Name=$("#selCallRecordName").val();
        jsTelBillQueryCondition.queryObj[0]._Remark=$("#callRecordRemark").val().split('\"').join('“').split('\'').join('‘');
        var selAudio=$("input[name='IsAudioSea'][checked]").val();
        switch(selAudio)
        {
            case "0":
                jsTelBillQueryCondition.queryObj[0]._IsHaveAudio='';
            break;
            case "1":
                jsTelBillQueryCondition.queryObj[0]._IsHaveAudio=1;
            break;
            case "2":
                jsTelBillQueryCondition.queryObj[0]._IsHaveAudio=2;
            break;
            default:
            break;
        }
        var selTime= $("input[name='talkTime'][checked]").val();
        switch(selTime)
        {
            case "1":
            { 
                /*今天*/      
                if(jsTelBillQueryCondition.DayType=="Pre")
                {
                    var preDay=jsCommonLogic.TimeFormatSpace($("#hideToday").val(),'day',1,'minus'); 
                    htxt_BeginTime="#"+preDay+" 00:00:00"+"#";
                    htxt_EndTime="#"+preDay+" 23:59:59"+"#";                                           
                    $("#hideToday").val(preDay);
                    preDay=null;
                }
                else if(jsTelBillQueryCondition.DayType=="Next")
                {
                    var nextDay=jsCommonLogic.TimeFormatSpace($("#hideToday").val(),'day',1,'add');
                    htxt_BeginTime="#"+nextDay+" 00:00:00"+"#";
                    htxt_EndTime="#"+nextDay+" 23:59:59"+"#";  
                    $("#hideToday").val(nextDay); 
                    nextDay=null;
                }
                else if(jsTelBillQueryCondition.DayType=="today")
                {
                    htxt_BeginTime="#"+  $("#hideToday").val()+" 00:00:00"+"#";
                    htxt_EndTime="#"+ $("#hideToday").val()+" 23:59:59"+"#";
                }
            }
            break;
            case "2":
            {/*最近一周*/
                var curToday=DBReader.ServerTime().ServerFormat("yyyy-MM-dd");
                htxt_EndTime="#"+curToday+" 23:59:59"+"#";
                htxt_BeginTime="#"+jsCommonLogic.TimeFormatSpace(curToday,'day',7,'minus')+" 23:59:59"+"#";
                curToday="";
            }
            break;
            case "3":
            {/*最近一个月*/
                var curToday=DBReader.ServerTime().ServerFormat("yyyy-MM-dd");
                 htxt_EndTime="#"+curToday+" 23:59:59"+"#";
                htxt_BeginTime="#"+jsCommonLogic.TimeFormatSpace(curToday,'month',1,'minus')+" 00:00:00"+"#";
                curToday="";
            }
            break;
            case "4":
            {/*最近三个月*/
                var curToday=DBReader.ServerTime().ServerFormat("yyyy-MM-dd");
                  htxt_EndTime="#"+curToday+" 23:59:59"+"#";
                  htxt_BeginTime="#"+jsCommonLogic.TimeFormatSpace(curToday,'month',3,'minus')+" 00:00:00"+"#";
                 curToday="";
            }
            break;
            case "5":
            {/*指定时间*/
               if($("#txt_QueryConditionBeginTime").val()!=""){
                   htxt_BeginTime="#"+$("#txt_QueryConditionBeginTime").val()+" 00:00:00"+"#";
                }
                if($("#txt_QueryConditionEndTime").val()!=""){
                   htxt_EndTime="#"+$("#txt_QueryConditionEndTime").val()+" 23:59:59"+"#";
               }
            }
            break;
            default:break;
        }
    }
    catch(e)
    {
        alert("jsTelBillQueryCondition.queryString:"+e.message);
    }
    jsTelBillQueryCondition.queryObj[0]._BeginTime=htxt_BeginTime;
    jsTelBillQueryCondition.queryObj[0]._EndTime=htxt_EndTime;
    htxt_BeginTime=null;
    htxt_EndTime=null;
    CollectGarbage();
};

jsTelBillQueryCondition.setTelNumValue=function(strNum){
    $("#callRecordNum").val(strNum);
};