/** * 给计划分配坐席 * */ var arruser = []; //分配的坐席数组 var groupLists = []; //坐席組数组 var rolesLists = []; //角色数组 var loadIndex; $(function() { var edit_id = helper.request.queryString("edit_id"); //获取坐席组 $.when(getGroups(), getRoles()).then(function() { getSeatLists(); //获取全部坐席 }); $('#sc_btns').on('click', getSeatLists); if(edit_id) { $(document).on('click', '#allocationGoodTask', ensureAllot); } }); //获取全部坐席 function getSeatLists() { $.ajax({ type: "get", url: huayi.config.callcenter_url + "signtokenapi/api/useraccount/getseatlist", dataType: 'json', async: true, beforeSend: function() { //触发ajax请求开始时执行 loadIndex = layer.load(); }, data: { key: $('#allocation_Name').val(),//否 string 模糊查询,坐席工号或坐席名字 }, success: function(data) { layer.close(loadIndex); if(data.state.toLowerCase() === "success") { data = data.data; $('#seat_lists').html(''); arruser = []; if(data && data.length > 0) { $.each(data, function(i, v) { arruser.push(v.usercode); $('#seat_lists').append('
没有找到您想要的记录呢!我会努力的...
'); } } }, error: function(textStatus) { layer.close(loadIndex); layer.confirm('网络繁忙,请稍后再试...', { closeBtn: 0, btn: ['确定'] //按钮 }); }, complete: function(XMLHttpRequest, textStatus) { layer.close(loadIndex); if(textStatus == 'timeout') { var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp"); xmlhttp.abort(); layer.confirm('网络超时,请稍后再试...', { closeBtn: 0, btn: ['确定'] //按钮 }); } }, }); } //选中和去掉选中 function changeActive() { $(this).toggleClass('seat_item_active'); getSeatArrs(); } //获取选中坐席数组 function getSeatArrs() { var seat_item = $('#seat_lists').find("[id*=seatItem_]").find('.seat_item'); arruser = []; if(seat_item && seat_item.length > 0){ $.each(seat_item, function(i, v) { if($(v).hasClass('seat_item_active')) { arruser.push($(v).attr('data-userCode')); } }); if(seat_item.length === arruser.length) { $('#CheckAllBtn').text('取消全选'); } else { $('#CheckAllBtn').text('全选'); } } //console.log(arruser); } $('#CheckAllBtn').on('click', CheckAllOrNot); //是否全选 function CheckAllOrNot() { var seat_item = $('#seat_lists').find("[id*=seatItem_]").find('.seat_item'); if(seat_item && seat_item.length > 0){ switch($(this).text()) { case "全选": $(this).text('取消全选'); checkAll(); break; case "取消全选": $(this).text('全选'); unCheckAll(); break; } } } //取消全选 function unCheckAll() { $('#seat_lists').find("[id*=seatItem_]").find('.seat_item').removeClass('seat_item_active'); getSeatArrs() } //全选 function checkAll() { $('#seat_lists').find("[id*=seatItem_]").find('.seat_item').addClass('seat_item_active'); getSeatArrs(); } /** * 去除 null *optionnull 参数 */ function formatterNull(optionnull) { return optionnull = optionnull === null ? '-' : optionnull; } /** * 获取坐席组 */ function getGroups() { var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象 $.getJSON(huayi.config.callcenter_url + "callcenterapi/api/sysseatgroup/getlist", function(data) { if(data.state.toLowerCase() == "success") { var content = data.data; if(content && content.length > 0) { $(content).each(function(i, n) { groupLists.push({ 'id': n.id, 'names': n.zxzname }) }); } dtd.resolve(); // 改变Deferred对象的执行状态 } }) return dtd.promise(); // 返回promise对象 } //获取角色 function getRoles() { var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象 $.getJSON(huayi.config.callcenter_url + "configurationapi/api/RoleInfo/getlistdrop", function(data) { if(data.state.toLowerCase() == "success") { var content = data.data; $(content).each(function(i, n) { rolesLists.push({ 'id': n.id, 'names': n.role_name }) }); dtd.resolve(); // 改变Deferred对象的执行状态 } }) return dtd.promise(); // 返回promise对象 } /** * 格式化坐席组 角色 * option1 数组 * option2 id */ function formatterGroups(option1, option2) { var groupName = ''; $(option1).each(function(i, n) { if(option2 === n.id) { groupName = n.names; } }); return groupName; } /** * 格式化用户类型 * option type值 */ function formatterType(option) { var str = "" switch(option + '') { case '0': str = "内部员工"; break; case '1': str = "客户"; break; default: str = "其他"; break; } return str } //确定分配 function ensureAllot() { var edit_id = helper.request.queryString("edit_id"); $.ajax({ type: "post", url: huayi.config.callcenter_url + "callcenterapi/api/autocallouttask/fpdata", dataType: 'json', async: true, beforeSend: function() { //触发ajax请求开始时执行 $('#allocationGoodTask').attr("disabled", true); $('#allocationGoodTask').text('分配中...'); $(document).off('click', '#allocationGoodTask', ensureAllot); loadIndex = layer.load(); }, data: { taskid: edit_id, // 是 string 任务id arruser: arruser, // 否 string[] 分配坐席 }, success: function(data) { layer.close(loadIndex); if(data.state.toLowerCase() === "success") { var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); parent.$('#outcryTable').bootstrapTable('refresh'); parent.layer.msg("分配成功!"); } }, error: function(textStatus) { layer.close(loadIndex); layer.confirm('网络繁忙,请稍后再试...', { closeBtn: 0, btn: ['确定'] //按钮 }); $('#allocationGoodTask').text('分配'); $('#allocationGoodTask').attr("disabled", false); $(document).off('click', '#allocationGoodTask', ensureAllot); $(document).on('click', '#allocationGoodTask', ensureAllot); }, complete: function(XMLHttpRequest, textStatus) { layer.close(loadIndex); if(textStatus == 'timeout') { var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp"); xmlhttp.abort(); layer.confirm('网络超时,请稍后再试...', { closeBtn: 0, btn: ['确定'] //按钮 }); } $('#allocationGoodTask').text('分配'); $('#allocationGoodTask').attr("disabled", false); $(document).off('click', '#allocationGoodTask', ensureAllot); $(document).on('click', '#allocationGoodTask', ensureAllot); }, }); }