function setTab(name,cursel,n){ for(i=1;i<=n;i++){ var menu=document.getElementById(name+i); var con=document.getElementById("con_"+name+"_"+i); menu.className=i==cursel?"active":""; con.style.display=i==cursel?"block":"none"; } } function removeHtmlTab(tab) { return tab.replace(/<[^<>]+?>/g,'');//删除所有HTML标签 } function getpara(key) {// 获取参数的函数 var url = document.URL; var rtn = ""; if (url.lastIndexOf("?") > 0) { var para = url.substring(url.lastIndexOf("?") + 1, url.length); var arr = para.split("&"); for ( var i = 0; i < arr.length; i++) { var id = arr[i].split("=")[0]; if (id == key) { rtn = arr[i].split("=")[1]; break; } } } return rtn; } function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = /*date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + */ date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; } var robot = robot||{ robotName:"",//机器人名称 logoUrl:"",//LOGO地址 pictureUrl:"",//图标地址 greeting:"",//欢迎词 unknownWords:"",//未知说辞 unknownWords1:"", //连续未知说辞 url:"", config:{ logoID:"weblogo", path:"http://127.0.0.1:8080/robot", contentID:"left_content", inputID:"text-in", textMaxNum:100, wordremain:"wordremain", problemsID:"topQuestionDiv",//常见问题 SystemInfoID:"Contact_us", quickServiceID:"rservlist",//快捷服务 configurationId:"DD20BE1E6200D8D713970D5354ED0CF6", greetingHTMLID:"jqrhyc",//欢迎html模板 userSendHTMLID:"yhfs", //用户发送HTML replyHTMLID:"reply"//机器人回复模板 } }; robot.initialize = function(config){ robot.config=config; //alert(config.configurationId); $.ajax({ url : config.path+"/znwd/ajaxInitialize/"+config.configurationId+"?ajax",//"/u/solicitation/ajaxToplist/"+code+"?ajax", type : "GET", data : { }, // dataType : "json", dataType : "jsonp", jsonp : "JsonpCallBack", jsonpCallback : "ajaxInitialize", beforeSend: function(){ $("booy").append(' 加载中.'); }, success : function(json) { if (!jQuery.isEmptyObject(json)){ robot.robotName = json.setting.robotName; robot.logoUrl = json.setting.logoUrl; robot.pictureUrl = json.setting.pictureUrl; robot.greeting = json.setting.greeting; robot.unknownWords = json.setting.unknownWords; robot.unknownWords1 = json.setting.unknownWords1; //设置页面title $(document).attr("title",robot.robotName); //设置logo $("#"+config.logoID).attr("src",robot.logoUrl); var greetingHTML = $("#"+config.greetingHTMLID).html(); var re = /{robotName}/ig; greetingHTML = greetingHTML.replace(re,robot.robotName); re = /{pictureUrl}/ig; greetingHTML = greetingHTML.replace(re,''); re = /{greeting}/ig; greetingHTML = greetingHTML.replace(re,robot.greeting); re = /{time}/ig; greetingHTML = greetingHTML.replace(re,getNowFormatDate()); //设置欢迎词 $("#"+config.contentID).append(greetingHTML); robot.url=json.system.url; //获取单位信息 var html = '
'; html+='
名称:'+json.system.name+'
'; html+='
电话:'+json.system.phone+'
'; html+='
网址:'+json.system.url+'
'; html+='
地址:'+json.system.address+'
'; html+='
'; if(config.SystemInfoID!=""&&$("#"+config.SystemInfoID).length>0){ $("#"+config.SystemInfoID).html(html); } var familiarHtml=""; //设置常见问题 if(config.problemsID!=""&&$("#"+config.problemsID).length>0){ if(json.familiarlist){ $.each(json.familiarlist, function(i) { $("#"+config.problemsID).append('
'+(i+1)+'.  '+json.familiarlist[i].name+'
'); }); } } //设置快捷服务 if(config.quickServiceID!=""&&$("#"+config.quickServiceID).length>0){ if(json.quickServiceList&&json.quickServiceList.length>0){ $.each(json.quickServiceList, function(i) { $("#"+config.quickServiceID).append('
  • '); //
    '+json.quickServiceList[i].name+'
    }); $("#kjfw").show(); } } } } }); }; var sycda=0;//记录上一次答案 robot.knowledge = function(v){ var config = robot.config; var queryString = $("#"+config.inputID).val(); if ((queryString!=''&&queryString)||(v!=""&&v)){ if (v!=""&&v) queryString = v; //用户发送 var userSendHTML = $("#"+config.userSendHTMLID).html(); var re = /{content}/ig; userSendHTML = userSendHTML.replace(re,removeHtmlTab(queryString)); re = /{time}/ig; userSendHTML = userSendHTML.replace(re,getNowFormatDate()); //设置欢迎词 $("#"+config.contentID).append(userSendHTML); $.ajax({ url : config.path+"/znwd/ajaxKnowledge/"+config.configurationId+"?ajax",//"/u/solicitation/ajaxToplist/"+code+"?ajax", type : "POST", data : { "queryString":queryString }, // dataType : "json", dataType : "jsonp", jsonp : "JsonpCallBack", jsonpCallback : "ajaxKnowledge", beforeSend: function(){ $("booy").append(' 加载中.'); }, success : function(json) { // if (!jQuery.isEmptyObject(json)){ var replyHTML = $("#"+config.replyHTMLID).html(); var re = /{robotName}/ig; replyHTML = replyHTML.replace(re,robot.robotName); re = /{pictureUrl}/ig; replyHTML = replyHTML.replace(re,''); var content = ""; if(json.knowledge){ content = "
    "+json.knowledge.answer; if(json.knowledge.znwdKnowledges&&json.knowledge.znwdKnowledges.length>0){ content += "
    您是不是要咨询下面的问题?
    "; $.each(json.knowledge.znwdKnowledges, function(i) { content+=""+(i+1)+"、"+json.knowledge.znwdKnowledges[i].name+"
    "; }); } re = /{kid}/ig; replyHTML = replyHTML.replace(re,json.knowledge.id); re = /{classname}/ig; replyHTML = replyHTML.replace(re,"0"); sycda = 0; }else{ /*re = /{display}/ig; replyHTML = replyHTML.replace(re,"display");*/ if(json.list){ content = "
    您是不是要咨询下面的问题?
    "; $.each(json.list, function(i) { content+=""+(i+1)+"、"+json.list[i].name+"
    "; }); re = /{kid}/ig; replyHTML = replyHTML.replace(re,json.problemid); re = /{classname}/ig; replyHTML = replyHTML.replace(re,"1"); re = /不满意/ig; replyHTML = replyHTML.replace(re,"未解决问题"); re = /满意/ig; replyHTML = replyHTML.replace(re,"解决问题"); sycda = 0; }else{ if (sycda==1) content = robot.unknownWords1; else content = robot.unknownWords; re = /{display}/ig; replyHTML = replyHTML.replace(re,"display"); sycda = 1; } } var timestamp = Date.parse(new Date()); var channelTypeHtml = ""; if(json.channelTypeList&&json.channelTypeList.length>0){ var ul = ""; var div = ""; ul += ''; channelTypeHtml +=ul; channelTypeHtml +=div; } re = /{channeltype}/ig; replyHTML = replyHTML.replace(re,channelTypeHtml); re = /{content}/ig; replyHTML = replyHTML.replace(re,content); re = /{time}/ig; replyHTML = replyHTML.replace(re,getNowFormatDate()); //设置欢迎词 $("#"+config.contentID).append(replyHTML); // } $(".nano").nanoScroller(); $(".nano").nanoScroller({scroll:'bottom'}); $("#"+config.contentID).scrollTop( $("#"+config.contentID)[0].scrollHeight ); } }); } $("#"+config.inputID).val(""); $(".ac_results").html(""); $(".ac_results").css("display","none"); }; robot.satisfaction = function(kid,type,classname){ var config = robot.config; if (kid!=""&&kid&&type!=""&&type){ $.ajax({ url : config.path+"/znwd/ajaxSatisfaction/"+kid+"?ajax",//"/u/solicitation/ajaxToplist/"+code+"?ajax", type : "POST", data : { "type":type, "classname":classname }, // dataType : "json", dataType : "jsonp", jsonp : "JsonpCallBack", jsonpCallback : "ajaxSatisfaction", beforeSend: function(){ $("booy").append(' 加载中.'); }, success : function(json) { $(".type_kid_"+kid).html("感谢您的评价!"); if(classname=="1"){ if (type=="0"){ $(".type_kid_"+kid).html("我会尽快完善的!"); }else{ $(".type_kid_"+kid).html("我会继续学习的!"); } } } }); } }; robot.satisfaction1 = function(kid,type,classname){ var config = robot.config; if (kid!=""&&kid&&type!=""&&type){ $.ajax({ url : config.path+"/znwd/ajaxSatisfaction/"+kid+"?ajax",//"/u/solicitation/ajaxToplist/"+code+"?ajax", type : "POST", data : { "type":type, "classname":classname }, // dataType : "json", dataType : "jsonp", jsonp : "JsonpCallBack", jsonpCallback : "ajaxSatisfaction", beforeSend: function(){ $("booy").append(' 加载中.'); }, success : function(json) { var replyHTML = $("#"+config.replyHTMLID).html(); var re = /{robotName}/ig; replyHTML = replyHTML.replace(re,robot.robotName); re = /{pictureUrl}/ig; replyHTML = replyHTML.replace(re,''); var content = ""; if (type=="0"){ content = robot.unknownWords; } else{ content = "谢谢你的配合,我会继续学习的!"; } re = /{display}/ig; replyHTML = replyHTML.replace(re,"display"); sycda = 1; re = /{channeltype}/ig; replyHTML = replyHTML.replace(re,""); re = /{content}/ig; replyHTML = replyHTML.replace(re,content); re = /{time}/ig; replyHTML = replyHTML.replace(re,getNowFormatDate()); //设置欢迎词 $("#"+config.contentID).append(replyHTML); $(".type_problemid_"+kid).remove(); $(".nano").nanoScroller(); $(".nano").nanoScroller({scroll:'bottom'}); $("#"+config.contentID).scrollTop( $("#"+config.contentID)[0].scrollHeight ); } }); } }; robot.topKnowledge = function(queryString){ var config = robot.config; if (queryString!=""&&queryString){ $.ajax({ url : config.path+"/znwd/ajaxTopKnowledge/"+config.configurationId+"?ajax",//"/u/solicitation/ajaxToplist/"+code+"?ajax", type : "POST", data : { "queryString":queryString, "num":10 }, // dataType : "json", dataType : "jsonp", jsonp : "JsonpCallBack", jsonpCallback : "ajaxTopKnowledge", beforeSend: function(){ $("booy").append(' 加载中.'); }, success : function(json) { if(json.list){ var content = ""; var w = $(".input").width()-86; $(".ac_results").width(w); $(".ac_results").css("display",""); $(".ac_results").html(content); }else{ $(".ac_results").css("display","none"); } } }); } }; function countChar(textareaID, spanID, maxNum) { //得到输入的字符的长度 var NowNum = $("#"+textareaID).val().length; //判断输入的长度是否超过规定的长度 if (NowNum > maxNum) { //如果超过就截取规定长度的内容 var v= $("#"+textareaID).val(); $("#"+textareaID).val(v.substring(0, maxNum)); } else { //得到当前的输入长度并且显示在页面上 $("#"+spanID).html(maxNum-NowNum); } } $(function(){ if(robot.config.wordremain!=""&&$("#"+robot.config.wordremain).length>0){ $("#"+robot.config.inputID).keydown(function(event){ countChar(robot.config.inputID, robot.config.wordremain, robot.config.textMaxNum); }); $("#"+robot.config.inputID).keyup(function(){ countChar(robot.config.inputID, robot.config.wordremain, robot.config.textMaxNum); robot.topKnowledge($("#"+robot.config.inputID).val()); }); } $(document).keydown(function(event){ /*var e = e || window.event, keycode = e.ctrlKey || e.keyCode;*/ var keycode = event.which; if (keycode==13) { robot.knowledge(); } }); });