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

557 lines
15 KiB
JavaScript
Raw Permalink 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.

/*
* 深海捷固定坐席 - 南京
*/
window.console = window.console || (function () {
var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
= c.clear = c.exception = c.trace = c.assert = function () { };
return c;
})();
$(function () {
if (ctiver=="1")
__Login();
else
__init();
});
function __LoginCallback(res) {
try {
if (res.result == 1) {//操作成功
if (res.data.status == 1 || res.data.status == 5) {//已登录
$("#btnLogout").val("退出");
if (strIsAdmin == "1")
funEnabledBtn("btnListen", true);
$('#btnLogout').unbind("click").bind("click", function () {
//退出
clearToListen();
clearTransfer();
__Hangup(strFJH);
__Loginout();
});
} else {
$("#btnLogout").val("登录");
funEnabledBtn("btnListen", false);
$('#btnLogout').unbind("click").bind("click", function () {
//登录
clearToListen();
clearTransfer();
__Login();
});
}
__getStatus(strFJH);
}
else {
showstatus("操作失败", "err");
}
}
catch (e) { showstatus("系统错误", "err", e); }
__init();
}
function __init() {
try {
if (strGH == "") {
showstatus("未登录");
return;
}
document.all.lblFJH.innerText = strFJH;
__getDND(strFJH);
__getStatus(strFJH);
} catch (e1) {
showstatus("系统错误", "err", e1);
}
}
/*********************************************
方法封装
*********************************************/
//移动坐席登录
function __Login() {
$.getJSON(cti + "?action=mixUserLogin&callback=?", {
user: strFJH,
device: strDevice
}, function (res) {
if (res.result == 1 && (res.data.status == 1 || res.data.status == 5)) {
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) {
$.getJSON(cti + "?action=setdnd&callback=?", {
extension: exten,
dnd: dnd
}, function (res) {
if (res.result == 1) {
__getDND(exten);
}
});
}
//获取分机示闲状态
function __getDND(exten) {
$.getJSON(cti + "?action=getdnd&callback=?", {
extension: exten
}, function (res) {
if (res.result == 1) {
__getDNDCallback(exten, res);
}
});
}
//获取示闲回调
function __getDNDCallback(exten, res) {
try {
if (res.result == 1) {//操作成功
if (res.data == -1) {//闲
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 __getStatus(exten) {
$.getJSON(cti + "?action=extenstatus&callback=?", {
extension: exten,
}, function (res) {
if (res.result == 1) {
__getStatusCallback(exten, res.data);
}
});
}
//获取分机状态回调
function __getStatusCallback(exten, onstatus) {
try {
if (onstatus == -1 || onstatus == 4) {//未注册或不存在
cleartimer();
funEnabledBtn("btnDND", false);
funEnabledBtn("btnListen", false);
funEnabledBtn("btnHangup", false);
funEnabledBtn("btnTransfer", false);
}
if (onstatus == 0) {//0 空闲
cleartimer();
blTimer = false;
funEnabledBtn("btnTransfer", false);
funEnabledBtn("btnHangup", false);
funEnabledBtn("btnDND", true);
if (strIsAdmin == "1") {
funEnabledBtn("btnListen", true);
}
}
if (onstatus == 1) {//1 通话中
funEnabledBtn("btnDND", false);
funEnabledBtn("btnHangup", true);
funEnabledBtn("btnTransfer", true);
funEnabledBtn("btnListen", false);
}
if (onstatus == 8) {//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 + "?action=hangup&callback=?", {
extension: exten,
}, function (res) {
if (res.result == 1) {
__HangupCallback(exten, res);
}
});
}
//挂机回调
function __HangupCallback(exten, res) {
if (res.result == 1) {
__getStatus(exten);
document.getElementById("txtTelNO").value = ""; //清除号码框
funEnabledBtn("btnHangup", false);
cleartimer();
}
}
//外拨
function __Dial(exten, dst) {
if (dst.indexOf("020") == 0)
dst = dst.replace("020", "");
var callout = $("#txtCallingNo").val();
if (callout == "0")
callout = "";
$.getJSON(cti + "?action=dial&callback=?", {
extension: exten,
extensionDst: callout+dst
}, function (res) {
if (res.result == 1) {
__DialCallback(exten, res);
}
});
}
//外拨回调
function __DialCallback(exten, res) {
if (res.result == 1) {
blCallOut = true; //设置外拨状态
blTimer = true;
funEnabledBtn("btnHangup", true);
funEnabledBtn("btnTransfer", true);
setTimer();
fleshstatus(exten);
}
else { showstatus("外呼失败", "err"); }
}
var timer1;
//刷新状态
function fleshstatus() {
__getStatus(strFJH);
timer1 = window.setTimeout("fleshstatus()", 2000);
}
//转接
function __Transfer(exten, dst) {
$.getJSON(cti + "?action=transfer&callback=?", {
extension: exten,
extensionDst: dst
}, function (res) {
if (res.result == 1) {
__getStatus(exten);
clearTransfer();
}
else {
alert("转接失败");
}
});
}
//监听
function __Chanspy(exten, dst) {
$.getJSON(cti + "?action=chanspy&callback=?", {
extension: exten,
extensionDst: dst,
option: 'b'
}, 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(timer1);
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() {
$('#btnFJH').unbind();
document.all.txtTelNO.value = "";
document.all.btnFJH.value = "转接";
document.all.lfjh.style.display = "";
$("#btnFJH").bind("click", function () {
transfer();
});
}
function transfer() {
var strTransfer = document.all.txtTelNO.value.Trim();
if (strTransfer == "") {
alert('请选择要转接到的分机号。');
return;
}
$.getJSON(cti + "?action=getdnd&extension=" + strTransfer + "&callback=?", function (res) {
if (res.result == 1 && res.data == -1) {//示闲
$.getJSON(cti + "?action=extenstatus&extension=" + strTransfer + "&callback=?", function (res2) {
if (res2.result == 1 && res2.data == 0) {//空闲
__Transfer(strFJH, strTransfer);
} else {
alert("转接失败," + getstatus(parseInt(res2.data)));
}
});
} else {
alert("转接失败,对方忙!");
}
});
}
//监听
function funBtnToListen() {//clearTransfer();
$('#btnFJH').unbind();
document.all.txtTelNO.value = "";
document.all.btnFJH.value = "监听";
document.all.lfjh.style.display = "";
$("#btnFJH").bind("click", function () {
tolisten();
});
}
//监听
function tolisten() {
var strToLisFJH = document.all.txtTelNO.value.Trim();
if (strToLisFJH == "") {
alert('请选择要监听的分机号。');
return;
}
$.getJSON(cti + "?action=extenstatus&extension=" + strToLisFJH + "&callback=?", function (res2) {
if (res2.result == 1 && res2.data == 1) {//通话中
__Chanspy(strFJH, strToLisFJH);
} else {
alert("该分机未在通话中");
}
});
}
//监控
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(res) {
blTimer = true;
setTimer();
blCallin = true;
funEnabledBtn("btnSoftHook", true);
var method = $.getUrlVar(res, 'Method');
var call = $.getUrlVar(res, 'Callerid');
var called = $.getUrlVar(res, 'Calleeid');
var srid = $.getUrlVar(res, 'Uniqueid');
var State = -1; //呼入 = 0, 呼出 = 1, 预览呼出 = 2
if (method == "Dialout")
State = 1;
if (method == "Dialin")
{
State = 0;
call = $.getUrlVar(res, 'MixExtVar');
}
var vStrUrl = "/Call/CallLog?State=" + State + "&CallType=1&DNIS=" + called + "&Tel=" + call + "&SRID=" + srid + "&AGENTID=" + strGH;
ShowResDetial(vStrUrl);
document.all.txtTelNO.value = call;
fleshstatus(strFJH);
}
function getstatus(stats) {
if (stats == -1)
return "不存在";
if (stats == 0) {
return "空闲";
}
if (stats == 1) {
var call = document.all.txtTelNO.value;
call = confusedTel(call);
if (call.length > 0)
return "通话中(" + call + ")";
else
return "通话中";
}
if (stats == 2) {
return "忙";
}
if (stats == 4)
return "未注册";
if (stats == 8) {
return "振铃中";
}
if (stats == 16)
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];
}
});