Brak opisu

allocationTask.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /**
  2. * 给计划分配坐席
  3. * */
  4. var arruser = []; //分配的坐席数组
  5. var groupLists = []; //坐席組数组
  6. var rolesLists = []; //角色数组
  7. var loadIndex;
  8. $(function() {
  9. var edit_id = helper.request.queryString("edit_id");
  10. //获取坐席组
  11. $.when(getGroups(), getRoles()).then(function() {
  12. getSeatLists(); //获取全部坐席
  13. });
  14. $('#sc_btns').on('click', getSeatLists);
  15. if(edit_id) {
  16. $(document).on('click', '#allocationGoodTask', ensureAllot);
  17. }
  18. });
  19. //获取全部坐席
  20. function getSeatLists() {
  21. $.ajax({
  22. type: "get",
  23. url: huayi.config.callcenter_url + "signtokenapi/api/useraccount/getseatlist",
  24. dataType: 'json',
  25. async: true,
  26. beforeSend: function() { //触发ajax请求开始时执行
  27. loadIndex = layer.load();
  28. },
  29. data: {
  30. key: $('#allocation_Name').val(),//否 string 模糊查询,坐席工号或坐席名字
  31. },
  32. success: function(data) {
  33. layer.close(loadIndex);
  34. if(data.state.toLowerCase() === "success") {
  35. data = data.data;
  36. $('#seat_lists').html('');
  37. arruser = [];
  38. if(data && data.length > 0) {
  39. $.each(data, function(i, v) {
  40. arruser.push(v.usercode);
  41. $('#seat_lists').append('<div class="col-md-6 clearfix" id="seatItem_' + v.id + '">' +
  42. '<div class="seat_item seat_item_active" data-userCode="' + v.usercode + '">' +
  43. '<div class="seat_img">' +
  44. '<img id="headImg_' + v.id + '" class="img-circle" src="' + v.head_small_img + '" alt="头像" />' +
  45. '</div>' +
  46. '<ul class="seat_content clearfix">' +
  47. '<li><span>工号:</span><span>' + v.usercode + '</span></li>' +
  48. '<li><span>姓名:</span><span>' + v.username + '</span></li>' +
  49. '<li><span>用户类型:</span><span>' + formatterType(v.type) + '</span></li>' +
  50. '<li><span>坐席组:</span><span>' + formatterGroups(groupLists, v.group) + '</span></li>' +
  51. '<li><span>角色:</span><span>' + formatterGroups(rolesLists, v.role_id) + '</span></li>' +
  52. '<li><span>性别:</span><span>' + formatterNull(v.sex) + '</span></li>' +
  53. '<li><span>手机:</span><span>' + v.mobile + '</span></li>' +
  54. '<li><span>邮箱:</span><span>' + formatterNull(v.mail) + '</span></li>' +
  55. '<li><span>入职时间:</span><span>' + formatterNull(v.entrytime) + '</span></li>' +
  56. '<li><span>转正时间:</span><span>' + formatterNull(v.transfertime) + '</span></li>' +
  57. '</ul>' +
  58. '</div>' +
  59. '</div>');
  60. //头像
  61. var ipUrl = v.head_small_img;
  62. if(ipUrl) {
  63. $('#headImg_' + v.id).attr('src', ipUrl);
  64. } else {
  65. $('#headImg_' + v.id).attr('src', '');
  66. }
  67. });
  68. $('.seat_item').on('click', changeActive);
  69. }else{
  70. $('#seat_lists').html('<p class="text-center">没有找到您想要的记录呢!我会努力的...</p>');
  71. }
  72. }
  73. },
  74. error: function(textStatus) {
  75. layer.close(loadIndex);
  76. layer.confirm('网络繁忙,请稍后再试...', {
  77. closeBtn: 0,
  78. btn: ['确定'] //按钮
  79. });
  80. },
  81. complete: function(XMLHttpRequest, textStatus) {
  82. layer.close(loadIndex);
  83. if(textStatus == 'timeout') {
  84. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  85. xmlhttp.abort();
  86. layer.confirm('网络超时,请稍后再试...', {
  87. closeBtn: 0,
  88. btn: ['确定'] //按钮
  89. });    
  90. }
  91. },
  92. });
  93. }
  94. //选中和去掉选中
  95. function changeActive() {
  96. $(this).toggleClass('seat_item_active');
  97. getSeatArrs();
  98. }
  99. //获取选中坐席数组
  100. function getSeatArrs() {
  101. var seat_item = $('#seat_lists').find("[id*=seatItem_]").find('.seat_item');
  102. arruser = [];
  103. if(seat_item && seat_item.length > 0){
  104. $.each(seat_item, function(i, v) {
  105. if($(v).hasClass('seat_item_active')) {
  106. arruser.push($(v).attr('data-userCode'));
  107. }
  108. });
  109. if(seat_item.length === arruser.length) {
  110. $('#CheckAllBtn').text('取消全选');
  111. } else {
  112. $('#CheckAllBtn').text('全选');
  113. }
  114. }
  115. //console.log(arruser);
  116. }
  117. $('#CheckAllBtn').on('click', CheckAllOrNot);
  118. //是否全选
  119. function CheckAllOrNot() {
  120. var seat_item = $('#seat_lists').find("[id*=seatItem_]").find('.seat_item');
  121. if(seat_item && seat_item.length > 0){
  122. switch($(this).text()) {
  123. case "全选":
  124. $(this).text('取消全选');
  125. checkAll();
  126. break;
  127. case "取消全选":
  128. $(this).text('全选');
  129. unCheckAll();
  130. break;
  131. }
  132. }
  133. }
  134. //取消全选
  135. function unCheckAll() {
  136. $('#seat_lists').find("[id*=seatItem_]").find('.seat_item').removeClass('seat_item_active');
  137. getSeatArrs()
  138. }
  139. //全选
  140. function checkAll() {
  141. $('#seat_lists').find("[id*=seatItem_]").find('.seat_item').addClass('seat_item_active');
  142. getSeatArrs();
  143. }
  144. /**
  145. * 去除 null
  146. *optionnull 参数
  147. */
  148. function formatterNull(optionnull) {
  149. return optionnull = optionnull === null ? '-' : optionnull;
  150. }
  151. /**
  152. * 获取坐席组
  153. */
  154. function getGroups() {
  155. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  156. $.getJSON(huayi.config.callcenter_url + "callcenterapi/api/sysseatgroup/getlist", function(data) {
  157. if(data.state.toLowerCase() == "success") {
  158. var content = data.data;
  159. if(content && content.length > 0) {
  160. $(content).each(function(i, n) {
  161. groupLists.push({
  162. 'id': n.id,
  163. 'names': n.zxzname
  164. })
  165. });
  166. }
  167. dtd.resolve(); // 改变Deferred对象的执行状态
  168. }
  169. })
  170. return dtd.promise(); // 返回promise对象
  171. }
  172. //获取角色
  173. function getRoles() {
  174. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  175. $.getJSON(huayi.config.callcenter_url + "configurationapi/api/RoleInfo/getlistdrop", function(data) {
  176. if(data.state.toLowerCase() == "success") {
  177. var content = data.data;
  178. $(content).each(function(i, n) {
  179. rolesLists.push({
  180. 'id': n.id,
  181. 'names': n.role_name
  182. })
  183. });
  184. dtd.resolve(); // 改变Deferred对象的执行状态
  185. }
  186. })
  187. return dtd.promise(); // 返回promise对象
  188. }
  189. /**
  190. * 格式化坐席组 角色
  191. * option1 数组
  192. * option2 id
  193. */
  194. function formatterGroups(option1, option2) {
  195. var groupName = '';
  196. $(option1).each(function(i, n) {
  197. if(option2 === n.id) {
  198. groupName = n.names;
  199. }
  200. });
  201. return groupName;
  202. }
  203. /**
  204. * 格式化用户类型
  205. * option type值
  206. */
  207. function formatterType(option) {
  208. var str = ""
  209. switch(option + '') {
  210. case '0':
  211. str = "内部员工";
  212. break;
  213. case '1':
  214. str = "客户";
  215. break;
  216. default:
  217. str = "其他";
  218. break;
  219. }
  220. return str
  221. }
  222. //确定分配
  223. function ensureAllot() {
  224. var edit_id = helper.request.queryString("edit_id");
  225. $.ajax({
  226. type: "post",
  227. url: huayi.config.callcenter_url + "callcenterapi/api/autocallouttask/fpdata",
  228. dataType: 'json',
  229. async: true,
  230. beforeSend: function() { //触发ajax请求开始时执行
  231. $('#allocationGoodTask').attr("disabled", true);
  232. $('#allocationGoodTask').text('分配中...');
  233. $(document).off('click', '#allocationGoodTask', ensureAllot);
  234. loadIndex = layer.load();
  235. },
  236. data: {
  237. taskid: edit_id, // 是 string 任务id
  238. arruser: arruser, // 否 string[] 分配坐席
  239. },
  240. success: function(data) {
  241. layer.close(loadIndex);
  242. if(data.state.toLowerCase() === "success") {
  243. var index = parent.layer.getFrameIndex(window.name);
  244. parent.layer.close(index);
  245. parent.$('#outcryTable').bootstrapTable('refresh');
  246. parent.layer.msg("分配成功!");
  247. }
  248. },
  249. error: function(textStatus) {
  250. layer.close(loadIndex);
  251. layer.confirm('网络繁忙,请稍后再试...', {
  252. closeBtn: 0,
  253. btn: ['确定'] //按钮
  254. });
  255. $('#allocationGoodTask').text('分配');
  256. $('#allocationGoodTask').attr("disabled", false);
  257. $(document).off('click', '#allocationGoodTask', ensureAllot);
  258. $(document).on('click', '#allocationGoodTask', ensureAllot);
  259. },
  260. complete: function(XMLHttpRequest, textStatus) {
  261. layer.close(loadIndex);
  262. if(textStatus == 'timeout') {
  263. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  264. xmlhttp.abort();
  265. layer.confirm('网络超时,请稍后再试...', {
  266. closeBtn: 0,
  267. btn: ['确定'] //按钮
  268. });    
  269. }
  270. $('#allocationGoodTask').text('分配');
  271. $('#allocationGoodTask').attr("disabled", false);
  272. $(document).off('click', '#allocationGoodTask', ensureAllot);
  273. $(document).on('click', '#allocationGoodTask', ensureAllot);
  274. },
  275. });
  276. }