TG.WXCRM.V4/WEB/Scripts/cti/axcti1.js

473 lines
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 艾讯旧接口-使用厂商提供的接口
*/
// 对Date的扩展将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
$(function () {
__Login();
});
function __LoginCallback(res) {
try {
if (res.result == 1) {//操作成功
document.all.lblFJH.innerText = strFJH;
fleshstatus(strFJH);
}
else {
showstatus("操作失败", "err");
}
}
catch (e) { showstatus("系统错误", "err", e); }
}
/*********************************************
方法封装
*********************************************/
//移动坐席登录
function __Login() {
$.getJSON(cti + "registerExten?exten="+strFJH+"&callback=?", function (res) {
if (res.result == 1) {
funEnabledBtn("btnLogout", true);
__LoginCallback(res);
}
});
}
//移动坐席退出
function __Loginout() {
$.ajaxSettings.async = false;
$.getJSON(cti + "?action=mixUserLogout&callback=?", {
user: strFJH
}, function (res) {
if (res.result == 1 || res.result == 5) {
funEnabledBtn("btnLogout", true);
};
$("#btnLogout").val("登录");
$('#btnLogout').unbind();
$("#btnLogout").bind("click", function () {
__Login();
});
});
$.ajaxSettings.async = true;
return true;
}
//分机示闲/示忙
function __setDND(exten, dnd) {
if (dnd==1) {//示忙
$.getJSON(cti + "makeBusy?exten=" + exten+'&callback=?', function (res) {
if (res.result == 1) {
__getDND(exten);
}
});
}
else {
$.getJSON(cti + "makeFree?exten=" + exten+'&callback=?', function (res) {
if (res.result == 1) {
__getDND(exten);
}
});
}
}
//获取分机示闲状态
function __getDND(exten) {
$.getJSON(cti + "getExtenStatus?exten="+exten+'&callback=?', function (res) {
if (res.result == 1) {
__getDNDCallback(exten, res);
__getStatusCallback(exten, res.message);
}
});
}
//获取示闲回调
function __getDNDCallback(exten, res) {
try {
if (res.result == 1) {//操作成功
if (res.message == "Available") {//闲
document.all.btnDND.value = "示忙";
document.all.btnDND.style.color = 'black';
if (strIsAdmin == "1")
funEnabledBtn("btnListen", true);
$('#btnDND').unbind("click").bind("click", function () {
//示忙
clearToListen();
clearTransfer();
cleartimer();
__setDND(strFJH, '1');
});
} else {
document.all.btnDND.value = "示闲";
document.all.btnDND.style.color = 'red';
funEnabledBtn("btnListen", false);
$('#btnDND').unbind("click").bind("click", function () {
//示闲
clearToListen();
clearTransfer();
cleartimer();
__setDND(strFJH, '-1');
});
}
}
else {
showstatus("操作失败", "err");
}
}
catch (e) { showstatus("系统错误", "err", e); }
}
//获取分机状态回调
function __getStatusCallback(exten, onstatus) {
try {
if (onstatus == "Logged Out" || onstatus == 4) {//未注册或不存在
//cleartimer();
funEnabledBtn("btnDND", false);
funEnabledBtn("btnListen", false);
funEnabledBtn("btnHangup", false);
funEnabledBtn("btnTransfer", false);
}
if (onstatus == "Available") {//0 空闲
//cleartimer();
blTimer = false;
funEnabledBtn("btnTransfer", false);
funEnabledBtn("btnHangup", false);
funEnabledBtn("btnDND", true);
if (strIsAdmin == "1") {
funEnabledBtn("btnListen", true);
}
}
if (onstatus == "CALLING") {//1 通话中
funEnabledBtn("btnDND", false);
funEnabledBtn("btnHangup", true);
funEnabledBtn("btnTransfer", true);
funEnabledBtn("btnListen", false);
}
if (onstatus == "RINGING") {//8 振铃中
clearToListen(); clearTransfer();
funEnabledBtn("btnDND", false);
funEnabledBtn("btnTransfer", false);
funEnabledBtn("btnHangup", false);
funEnabledBtn("btnListen", false);
funEnabledBtn("btnHangup", true);
}
blLogined = true;
var lblexstatus = $("#divAction");
var strstats = getstatus(onstatus);
lblexstatus.html(strstats);
}
catch (e) {
showstatus("系统错误", "err", e);
}
}
//挂断
function __Hangup(exten) {
$.getJSON(cti + "HangupCall?exten=" + exten + "&callback=?", function (res) {
__HangupCallback(exten, res);
});
}
//挂机回调
function __HangupCallback(exten, res) {
if (res.result == 1) {
__getDND(exten);
document.getElementById("txtTelNO").value = ""; //清除号码框
funEnabledBtn("btnHangup", false);
cleartimer();
}
}
//外拨
function __Dial(exten, dst) {
$.getJSON(cti + "makeCall?exten=" + exten + "&dst=" + dst + "&callback=?", function (res, status, xhr) {
__DialCallback(exten, res);
});
}
//外拨回调
function __DialCallback(exten, res) {
if (res.result == 1) {
blCallOut = true; //设置外拨状态
blTimer = true;
funEnabledBtn("btnHangup", true);
funEnabledBtn("btnTransfer", true);
setTimer();
}
else { showstatus("外呼失败", "err"); }
}
//刷新状态
function fleshstatus() {
__getDND(strFJH);
window.setTimeout("fleshstatus()", 1000);
}
//转接
function __Transfer(exten, dst) {
$.getJSON(cti + "transferCall?exten=" + exten + "&dst=" + dst + "&callback=?", function (res) {
if (res.result == 1) {
__getDND(exten);
clearTransfer();
}
else {
alert("转接失败");
}
});
}
//监听
function __Chanspy(exten, dst) {
$.getJSON(cti + "monitor?exten=" + exten + "&dst=" + dst + "&callback=?", function (res) {
if (res.result == 1) {
__ChanspyCallback(exten, res);
}
});
}
//监听回调
function __ChanspyCallback(exten, res) {
if (res.result == 1) {
clearToListen();
blTimer = true;
funEnabledBtn("btnHangup", true);
funEnabledBtn("btnTransfer", false);
funEnabledBtn("btnListen", false);
setTimer();
fleshstatus(exten);
}
else {
alert("监听失败");
}
}
//清除转接状态
function clearTransfer() {
document.all.lfjh.style.display = "none";
}
//清除监听状态
function clearToListen() {
document.all.lfjh.style.display = "none";
}
//清除定时器
function cleartimer() {
nTimer = 1;
window.clearTimeout(timer2);
}
/*********************************************
功能代码
*********************************************/
//退出
function btnLogout() {
__Loginout();
}
//软挂机
function funBtnSoftHook() {
clearTransfer();
clearToListen();
__Hangup(strFJH);
blTimer = false;
nTimer = 0;
}
//外拨
function funBtnCall() {
try {
clearToListen(); clearTransfer();
var dst = document.all.txtTelNO.value.Trim();
if (dst.length == 0) {
showstatus("号码为空!", "err");
return;
}
if (strGH == "") {
showstatus("登录超时,请重新登录。", "err");
return;
}
__Dial(strFJH, dst);
}
catch (e) { showstatus("系统错误", "err", e); }
}
// 转接
function funBtnTrans() {
transfer();
}
function transfer() {
var strTransfer = document.all.txtTelNO.value.Trim();
if (strTransfer == "") {
alert('请选择要转接到的分机号。');
return;
}
__Transfer(strFJH, strTransfer);
}
//监听
function funBtnToListen() {
tolisten();
}
//监听
function tolisten() {
var strToLisFJH = document.all.txtTelNO.value.Trim();
if (strToLisFJH == "") {
alert('请选择要监听的分机号。');
return;
}
__Chanspy(strFJH, strToLisFJH);
}
//监控
function btnAgentmonitor() {
ChildAddTab("坐席监控", '/CallRecord/AgentMonitor?strFJH=' + strFJH);
}
//弹屏
//mixcallback:Event=Popscreen&Poptime=Ring&Callerid=8026&CallerIDName=<unknown>&CID=69837518&Calleeid=015305816689&CalleeIDName=&Recordfile=OUT8026-015305816689-20150603-171646-1433323005.359020.WAV&Uniqueid=1433323005.359020&DateTime=2015-06-03 17:16:46&Server=localhost&Method=Dialout
function mixcallback(data) {
blTimer = true;
setTimer();
blCallin = true;
funEnabledBtn("btnSoftHook", true);
var State = data.type;//1呼入2呼出
var call = "";//主叫
var called = "";//被叫
var srid = "";
if (State == 1) {//1呼入
State = 0;
call = data.dst;
called = data.src;
}
else {//2呼出
State = 1;
call = data.src;
called = data.dst;
}
var vStrUrl = "/Call/CallLog?State=" + State + "&CallType=1&DNIS=" + called + "&Tel=" + call + "&SRID=" + srid + "&AGENTID=" + strGH;
//if (State==0)//呼入
{
ShowResDetial(vStrUrl);
document.all.txtTelNO.value = call;
}
}
function getstatus(stats) {
if (stats == "Logged Out")
return "未登录";
if (stats == "Available") {
return "空闲";
}
if (stats == "CALLING") {
var call = document.all.txtTelNO.value;
call = confusedTel(call);
if (call.length > 0)
return "通话中(" + call + ")";
else
return "通话中";
}
if (stats == "Available (On Demand)") {
return "小结";
} if (stats == "RINGING") {
return "振铃";
}
if (stats == "On Break")
return "小休";
return "失败";
}
var timer2;
//设置计时器
function setTimer() {
if (!blTimer) return;
var nHour = parseInt(nTimer / 3600);
var nTmp = nTimer % 3600;
var nMintue = parseInt(nTmp / 60);
var nSecond = nTmp % 60;
var strTimer = funAddZero(nHour) + ":" + funAddZero(nMintue) + ":" + funAddZero(nSecond);
var objTimer = document.getElementById('lblTimer');
if (objTimer) objTimer.innerText = strTimer;
nTimer++;
timer2 = window.setTimeout("setTimer()", 1000);
}
//设置按钮是否显示
function funDisplayBtn(vStrBtnID, vBlDisplay) {
var objBtn = document.getElementById(vStrBtnID);
if (objBtn) {
if (vBlDisplay)
objBtn.style.display = "block";
else
objBtn.style.display = "none";
}
}
// 设置按钮状态
function funEnabledBtn(vStrBtnID, vBlEnabled) {
var objBtn = document.getElementById(vStrBtnID);
if (objBtn) objBtn.disabled = !vBlEnabled;
}
function showstatus(errmsg, typ, err) {
document.all.divAction.innerHTML = errmsg;
if (err)
console.log(err);
if (typ == "err")
document.all.divAction.innerHTML = "<font color='red'>" + errmsg + "</font>";
}
function funAddZero(vIntValue) {
var strRevalue = '0000' + vIntValue;
return strRevalue.substr(strRevalue.length - 2, strRevalue.length);
}
String.prototype.Trim = function () {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
function confusedTel(tel) {
var telstr = tel;
if (tel.length >= 4) {
telstr = tel.substr(tel.length - 4);
telstr = "****" + telstr;
if (tel.length < 8)
telstr = telstr.substr(telstr.length - tel.length);
if (tel.length > 8)
telstr = tel.substr(0, tel.length - telstr.length) + telstr;
}
return telstr;
}
$.extend({
getUrlVars: function (url) {
var vars = [], hash;
var hashes = url.slice(url.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function (url, name) {
return $.getUrlVars(url)[name];
}
});