Brak opisu

addOrEditPlan.js 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /**
  2. * 外呼计划增加或编辑
  3. * */
  4. var wavpath = ''; //语音路径
  5. $(function() {
  6. autosize($('textarea'));
  7. var nowDate = helper.DateFormat.getNowDate();
  8. var edit_id = helper.request.queryString("edit_id");
  9. var isStart = helper.request.queryString("isStart");
  10. //初始化时间
  11. laydate.render({
  12. elem: '#pro_times',
  13. range: '~',
  14. // type: 'datetime',
  15. theme: '#249fea',
  16. min: nowDate,
  17. });
  18. laydate.render({
  19. elem: '#wtime1',
  20. type: 'time',
  21. range: '~',
  22. theme: '#249fea',
  23. });
  24. $('#wtime1').val("08:30:00 ~ 12:00:00");
  25. laydate.render({
  26. elem: '#wtime2',
  27. type: 'time',
  28. range: '~',
  29. theme: '#249fea',
  30. });
  31. $('#wtime2').val("14:00:00 ~ 18:00:00");
  32. //上传语音文件
  33. $("#btndr").click(function() {
  34. $("#upFile").trigger("click");
  35. });
  36. $("#upFile").change(function() {
  37. upload();
  38. });
  39. if(edit_id) { //修改
  40. getPlan(edit_id, isStart);
  41. }
  42. //呼叫方式的change
  43. $('#calltype').on('change', calltypeChange);
  44. //添加编辑保存按钮点击
  45. $('#pro_save').on('click', savePlan);
  46. });
  47. //呼叫方式的change
  48. function calltypeChange() {
  49. //0为不播放直接转坐席,1为播放转坐席,2为播放后按键转坐席
  50. switch($(this).find('input[name="calltype_radio"]:checked').val()) {
  51. case '1':
  52. $('.fielContext').show();
  53. $('.pressnum').hide();
  54. break;
  55. case '2':
  56. $('.fielContext').show();
  57. // $('.pressnum').show();
  58. break;
  59. default:
  60. $('.fielContext').hide();
  61. $('.pressnum').hide();
  62. break;
  63. }
  64. }
  65. //获取单个计划
  66. function getPlan(ids, isStart) {
  67. if(isStart != '0'){
  68. $('#calltype').find('input[name="calltype_radio"]').attr('disabled', true);
  69. $('#btndr').attr('disabled', true);
  70. $('#pressnum').attr('disabled', true);
  71. }
  72. $.getJSON(huayi.config.callcenter_url + "callcenterapi/api/autocallouttask/getsingle", {
  73. id: ids, //是 string 标识id
  74. }, function(data) {
  75. if(data.state == "success") {
  76. var res = data.data;
  77. if(res) {
  78. $('#pro_title').val(res.taskname); //计划名称
  79. if(res.starttime && res.endtime) {
  80. $('#pro_times').val(res.starttime + ' ~ ' + res.endtime); //计划起止日期
  81. }
  82. if(res.workstarttimes1 && res.workendtimes1) {
  83. $('#wtime1').val(res.workstarttimes1 + ' ~ ' + res.workendtimes1); // 否 string 工作开始时间1工作结束时间1
  84. }
  85. if(res.workstarttimes2 && res.workendtimes2) {
  86. $('#wtime2').val(res.workstarttimes2 + ' ~ ' + res.workendtimes2); // 否 string 工作开始时间2工作结束时间2
  87. }
  88. // 否 int 呼叫方式:0为不播放直接转坐席,1为播放转坐席,2为播放后按键转坐席
  89. $('#calltype').find('input[name="calltype_radio"][value="' + res.calltype + '"]').prop('checked', true).trigger('change'); // 否 int 并发类型
  90. if(res.voicepath && res.voicepath.length > 0) {
  91. $('.audioCon').attr('src', res.voicepath[0].fileurl);
  92. wavpath = res.voicepath[0].fileurl; // 否 string 语音文件路径
  93. }
  94. // $('#pressnum').val(res.pressnum); // 否 string 按键
  95. if(res.bftype) {
  96. $('#bftype').find('input[name="bftype_radio"][value="' + res.bftype + '"]').prop('checked', true); // 否 int 并发类型
  97. }
  98. $('#bfnum').val(res.bfnum); // 否 string 并发数
  99. $('#pro_content').val(res.taskremark); //说明备注
  100. }
  101. }
  102. });
  103. }
  104. //保存计划
  105. function savePlan() {
  106. var edit_id = helper.request.queryString("edit_id");
  107. var wUrl, loadIndex;
  108. //0为不播放直接转坐席,1为播放转坐席,2为播放后按键转坐席3不转坐席
  109. var callTypeVal = $('#calltype').find('input[name="calltype_radio"]:checked').val();
  110. if(!$.trim($('#pro_title').val())) {
  111. layer.confirm('计划名称不能为空!', {
  112. icon: 2,
  113. btn: ['确定'] //按钮
  114. });
  115. return;
  116. }
  117. if(!$.trim($('#pro_times').val())) {
  118. layer.confirm('您还没有选择计划起止日期!', {
  119. icon: 2,
  120. btn: ['确定'] //按钮
  121. });
  122. return;
  123. }
  124. if(!$.trim($('#wtime1').val())) {
  125. layer.confirm('您还没有选择工作时段一!', {
  126. icon: 2,
  127. btn: ['确定'] //按钮
  128. });
  129. return;
  130. }
  131. if(!$.trim($('#wtime2').val())) {
  132. layer.confirm('您还没有选择工作时段二!', {
  133. icon: 2,
  134. btn: ['确定'] //按钮
  135. });
  136. return;
  137. }
  138. if(!regexs.num.test($.trim($('#bfnum').val()))) {
  139. layer.confirm('并发数/进号速率(只能输入数字)!', {
  140. icon: 2,
  141. btn: ['确定'] //按钮
  142. });
  143. return;
  144. }
  145. switch(callTypeVal) {
  146. case '1':
  147. if(!wavpath) {
  148. layer.confirm('您还没有上传语音文件!', {
  149. icon: 2,
  150. btn: ['确定'] //按钮
  151. });
  152. return;
  153. }
  154. $('#pressnum').val('');
  155. break;
  156. case '2':
  157. if(!wavpath) {
  158. layer.confirm('您还没有上传语音文件!', {
  159. icon: 2,
  160. btn: ['确定'] //按钮
  161. });
  162. return;
  163. }
  164. $('#pressnum').val('1');
  165. // if(!regexs.pressnumReg.test($.trim($('#pressnum').val()))) {
  166. // layer.confirm('按键只能输入0-9的一位数字!', {
  167. // icon: 2,
  168. // btn: ['确定'] //按钮
  169. // });
  170. // return;
  171. // }
  172. break;
  173. default:
  174. wavpath = '';
  175. $('#pressnum').val('');
  176. break;
  177. }
  178. if(edit_id) {
  179. wURL = "callcenterapi/api/autocallouttask/update";
  180. } else {
  181. wURL = "callcenterapi/api/autocallouttask/add";
  182. }
  183. $.ajax({
  184. type: "post",
  185. url: huayi.config.callcenter_url + wURL,
  186. dataType: 'json',
  187. async: true,
  188. beforeSend: function() { //触发ajax请求开始时执行
  189. loadIndex = layer.load();
  190. $('#pro_save').attr("disabled", true);
  191. $('#pro_save').text('保存中...');
  192. $(document).off('click', '#pro_save', savePlan);
  193. },
  194. data: {
  195. id: edit_id, //edit_id为空的时候添加
  196. taskname: $('#pro_title').val(), // 是 string 任务名称
  197. stime: $('#pro_times').val() && $('#pro_times').val().split(' ~ ')[0], //否 string 任务开始时间
  198. etime: $('#pro_times').val() && $('#pro_times').val().split(' ~ ')[1], //否 string 任务结束时间
  199. swtime1: $('#wtime1').val() && $('#wtime1').val().split(' ~ ')[0], // 否 string 工作开始时间1
  200. ewtime1: $('#wtime1').val() && $('#wtime1').val().split(' ~ ')[1], // 否 string 工作结束时间1
  201. swtime2: $('#wtime2').val() && $('#wtime2').val().split(' ~ ')[0], // 否 string 工作开始时间2
  202. ewtime2: $('#wtime2').val() && $('#wtime2').val().split(' ~ ')[1], // 否 string 工作结束时间2
  203. calltype: callTypeVal, // 否 int 呼叫方式:0为不播放直接转坐席,1为播放转坐席,2为播放后按键转坐席
  204. voicepath: wavpath, // 否 string 语音文件路径
  205. pressnum: $('#pressnum').val(), // 否 string 按键
  206. bftype: $('#bftype').find('input[name="bftype_radio"]:checked').val(), // 否 int 并发类型
  207. bfnum: $('#bfnum').val(), // 否 string 并发数
  208. taskremark: $('#pro_content').val(), //否 string 说明备注
  209. },
  210. success: function(data) {
  211. layer.close(loadIndex);
  212. if(data.state.toLowerCase() === "success") {
  213. var index = parent.layer.getFrameIndex(window.name);
  214. parent.layer.close(index);
  215. parent.$('#outcryTable').bootstrapTable('refresh');
  216. parent.layer.msg("保存成功");
  217. }
  218. },
  219. error: function(textStatus) {
  220. layer.close(loadIndex);
  221. layer.confirm('网络繁忙,请稍后再试...', {
  222. icon: 7,
  223. closeBtn: 0,
  224. btn: ['确定'] //按钮
  225. });
  226. $('#pro_save').text('保存');
  227. $('#pro_save').attr("disabled", false);
  228. $(document).off('click', '#pro_save', savePlan);
  229. $(document).on('click', '#pro_save', savePlan);
  230. },
  231. complete: function(XMLHttpRequest, textStatus) {
  232. layer.close(loadIndex);
  233. if(textStatus == 'timeout') {
  234. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  235. xmlhttp.abort();
  236. layer.confirm('网络超时,请稍后再试...', {
  237. icon: 7,
  238. closeBtn: 0,
  239. btn: ['确定'] //按钮
  240. });    
  241. }
  242. $('#pro_save').text('保存');
  243. $('#pro_save').attr("disabled", false);
  244. $(document).off('click', '#pro_save', savePlan);
  245. $(document).on('click', '#pro_save', savePlan);
  246. },
  247. });
  248. }
  249. //上传文件
  250. function upload() {
  251. if(document.getElementById("upFile").files.length > 0) {
  252. var formData = new FormData();
  253. formData.append("upFile", document.getElementById("upFile").files[0]);
  254. formData.append("uploadtype", 'outCall');
  255. $.ajax({
  256. url: huayi.config.callcenter_url + "fileserverapi/Api/Upload",
  257. type: "POST",
  258. data: formData,
  259. /**
  260. *必须false才会自动加上正确的Content-Type
  261. */
  262. contentType: false,
  263. /**
  264. * 必须false才会避开jQuery对 formdata 的默认处理
  265. * XMLHttpRequest会对 formdata 进行正确的处理
  266. */
  267. processData: false,
  268. success: function(result) {
  269. document.getElementById("upFile").outerHTML = document.getElementById("upFile").outerHTML;
  270. $("#upFile").change(function() {
  271. upload();
  272. });
  273. var r = $.parseJSON(result);
  274. if(r.state.toLowerCase() == "success") {
  275. $('.audioCon').attr('src', r.data[0].fileurl)
  276. wavpath = r.data;
  277. layer.msg("语音上传成功");
  278. }
  279. }
  280. });
  281. } else {
  282. layer.confirm('请上传文件!', {
  283. icon: 7,
  284. btn: ['确定']
  285. });
  286. }
  287. }