Bez popisu

addOrEditUserManage.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. /**
  2. * 用户增加或编辑
  3. * */
  4. var head_img_data; //保存头像的大图
  5. var small_img_data; //保存头像的小图
  6. var Ids = helper.request.queryString("ids");
  7. var imageArr0 = '',
  8. imageArr1 = '';
  9. var groupid;
  10. uploaderImg(0); //技能证书
  11. uploaderImg(1); //身份证
  12. $(function() {
  13. autosize($('textarea'));
  14. //获取项目
  15. //helper.getDropList.getProlistDrop($('#projectid'));
  16. projectName($('#projectid'))
  17. if(Ids) {
  18. getUserDetails(Ids);
  19. }
  20. // getDepartname($('#administrative'),'',Ids)
  21. // $('#projectid').on('change', function() {
  22. // getDepartname($('#administrative'),'',Ids)
  23. // // GetRoleName($('#administrative'))
  24. // });
  25. //获取角色
  26. getRoleName($('#role_id'));
  27. // getSeatGroup($('#seat_group')); //坐席组下拉
  28. imgEditor(); //头像裁剪
  29. if(Ids) {
  30. //
  31. $('.editPwd').show();
  32. $('.addPwd').hide();
  33. // $.when(helper.getDropList.getProlistDrop($('#projectid')), getRoleName($('#role_id')), getSeatGroup($('#seat_group'))).then(function() {
  34. // getUserDetails(Ids); //详情
  35. // });
  36. }
  37. //添加编辑保存按钮点击
  38. $('#pro_save').on('click', saveUsers);
  39. //日期
  40. lay('.layer_times').each(function() {
  41. laydate.render({
  42. elem: this,
  43. trigger: 'click',
  44. });
  45. });
  46. //是否使用话务标识
  47. $('#seat_flag').on('change', function() {
  48. if($(this).find('input[name="seat_flag_radio"]:checked').val() === "true") {
  49. $('#seat_settings').show();
  50. } else {
  51. $('#seat_settings').hide();
  52. }
  53. });
  54. $('#seat_flag').trigger('change');
  55. //密码对比
  56. $('#password2').blur(function() {
  57. if($(this).val()) {
  58. if($(this).val() !== $('#password').val()) {
  59. layer.confirm('密码输入不一致,请重新输入!', {
  60. icon: 2,
  61. btn: ['确定']
  62. }, function(index) {
  63. layer.close(index);
  64. $('#password2').val('');
  65. $('#password2').trigger('focus');
  66. });
  67. return;
  68. }
  69. } else {
  70. layer.confirm('请确认密码!', {
  71. icon: 2,
  72. btn: ['确定']
  73. });
  74. return;
  75. }
  76. })
  77. });
  78. var pwdHtml = '<ul class="project_items form-horizontal" style="width: 95%">' +
  79. '<li class="form-group addPwd">' +
  80. '<label for="password" class="col-md-2 text-right"><b class="text_require">*</b>密码</label>' +
  81. '<div class="col-md-10">' +
  82. '<input id="password_cz" class="form-control" type="password" autocomplete="off" placeholder="请输入密码" />' +
  83. '</div>' +
  84. '</li>' +
  85. '<li class="form-group addPwd">' +
  86. '<label for="password2" class="col-md-2 text-right"><b class="text_require">*</b>确认密码</label>' +
  87. '<div class="col-md-10">' +
  88. '<input id="password2_cz" class="form-control" type="password" autocomplete="off" placeholder="请再次输入密码" />' +
  89. '</div>' +
  90. '</li>' +
  91. '<li class="form-group addPwd">' +
  92. '<div class="col-md-12" style="text-align: center;">' +
  93. '<button id="submitPwd" class="btn btn-info" onclick="editPwd()">提交</button>' +
  94. '</div>' +
  95. '</li>' +
  96. '</ul>'
  97. var pwdTC, userCodes;
  98. $('#editPwd').click(function() {
  99. pwdTC = layer.open({
  100. type: 1,
  101. title: '密码重置',
  102. area: ['50%', '50%'], //宽高
  103. content: pwdHtml
  104. });
  105. });
  106. //角色
  107. function GetRoleName(obj) {
  108. obj.empty();
  109. obj.append("<option value=''>请选择</option>");
  110. $.getJSON(huayi.config.callcenter_url + "configurationapi/api/Department/getlist", {
  111. projectid: $('#projectid').val(),
  112. }, function(data) {
  113. console.log(data)
  114. if(data.rows.length >= 0) {
  115. var content = data.rows;
  116. $(content).each(function(i, n) {
  117. $("<option value='" + n.departmenname + "'>" + n.departmenname + "</option>").appendTo(obj);
  118. })
  119. obj.selectpicker('refresh');
  120. }
  121. })
  122. }
  123. //科室
  124. function getDepartname(obj, opName,Ids) {
  125. obj.empty();
  126. $.getJSON(huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/getalldeptnlists", {}, function(data) {
  127. if(data.data.length >= 0) {
  128. var content = data.data;
  129. $(content).each(function(i, n) {
  130. $("<option value='" + n.name + "'>" + n.name + "</option>").appendTo(obj);
  131. })
  132. obj.selectpicker('refresh');
  133. console.log(Ids)
  134. if(Ids) {
  135. console.log(22343)
  136. $('.editPwd').show();
  137. $('.addPwd').hide();
  138. $.when(helper.getDropList.getProlistDrop($('#projectid')), getRoleName($('#role_id')), getSeatGroup($('#seat_group'))).then(function() {
  139. getUserDetails(Ids); //详情
  140. });
  141. }
  142. }
  143. })
  144. }
  145. function projectName(obj) {
  146. obj.empty();
  147. obj.append("<option value=''>请选择医院</option>");
  148. $.getJSON(huayi.config.callcenter_url + "equipmentapi/api/ProjectInfo/getlistdrop", function(result) {
  149. if(result.state.toLowerCase() == "success") {
  150. var content = result.data;
  151. $(content).each(function(i, n) {
  152. $("<option value='" + n.id + "'>" + n.text + "</option>").appendTo(obj);
  153. })
  154. obj.selectpicker('refresh');
  155. }
  156. })
  157. }
  158. //密码重置
  159. function editPwd() {
  160. if(!regexs.passwordReg.test($.trim($('#password_cz').val()))) {
  161. layer.confirm('请输入有效的密码(6-32个字符只能是字母、下划线、数字)', {
  162. icon: 2,
  163. btn: ['确定']
  164. });
  165. return;
  166. }
  167. if(!regexs.passwordReg.test($.trim($('#password2_cz').val()))) {
  168. layer.confirm('请输入有效的确认密码(6-32个字符只能是字母、下划线、数字)', {
  169. icon: 2,
  170. btn: ['确定']
  171. });
  172. return;
  173. }
  174. $('#password2_cz').blur(function() {
  175. if($(this).val()) {
  176. if($(this).val() !== $('#password_cz').val()) {
  177. layer.confirm('密码输入不一致,请重新输入!', {
  178. icon: 2,
  179. btn: ['确定']
  180. }, function(index) {
  181. layer.close(index);
  182. $('#password2_cz').val('');
  183. $('#password2_cz').trigger('focus');
  184. });
  185. return;
  186. }
  187. } else {
  188. layer.confirm('请确认密码!', {
  189. icon: 2,
  190. btn: ['确定']
  191. });
  192. return;
  193. }
  194. })
  195. $.post(huayi.config.callcenter_url + "signtokenapi/api/UserAccount/updatepassword", {
  196. usercode: userCodes,
  197. password: $.md5($('#password_cz').val()),
  198. surepassword: $.md5($('#password2_cz').val()),
  199. }, function(data) {
  200. data = JSON.parse(data);
  201. if(data.state == "success") {
  202. layer.msg("密码修改成功!");
  203. layer.close(pwdTC); //关闭弹层
  204. }
  205. });
  206. }
  207. //获取详情
  208. function getUserDetails(ids) {
  209. $.getJSON(huayi.config.callcenter_url + "signtokenapi/api/UserAccount/getdetails", {
  210. id: ids,
  211. }, function(data) {
  212. if(data.state == "success") {
  213. var res = data.data;
  214. // getDepartname($('#administrative'),res.postname)
  215. $('#usercode').val(res.usercode);
  216. userCodes = res.usercode;
  217. $('#user_name').val(res.username);
  218. $('#type').find('input[name="userType_flag"][value="' + res.type + '"]').prop("checked", "checked"); //用户类型
  219. $('#role_id').selectpicker('val', res.role_id).trigger('change'); //角色id
  220. $('input[name="sex"][value="' + res.sex + '"]').prop("checked", "checked"); //性别
  221. $('#mail').val(res.mail); //邮箱
  222. $('#mobile').val(res.mobile); //手机号
  223. // $('#remark').val(res.remark); //备注
  224. $('#remark').selectpicker('val', res.remark).trigger("change");
  225. //$("#administrative").val(res.team_id) //科室
  226. $("#team_id").val(res.remark), //岗位类型
  227. $('#entrytime').val(res.entrytime); // string 入职时间
  228. $('#transfertime').val(res.transfertime); // string 转岗时间
  229. $('#idcardno').val(res.idcardno); //string 身份证号码(新)
  230. getImgVal(res.certificate, 0); // list 技能证书
  231. getImgVal(res.idcard, 1); //list 身份证照片(新)
  232. $('#image_list0').find('.thumbnail').on('click', '.image-close', function() {
  233. $(this).parent().remove();
  234. file_num(0);
  235. });
  236. $('#image_list1').find('.thumbnail').on('click', '.image-close', function() {
  237. $(this).parent().remove();
  238. file_num(1);
  239. });
  240. $('#projectid').selectpicker('val', res.projectlist).trigger("change"); //项目信息
  241. // $('#administrative').selectpicker('val', res.postname).trigger('change');
  242. $('.administrative').val(res.postname)
  243. //头像
  244. var ipUrl = data.data.head_img;
  245. if(ipUrl && ipUrl.length > 0) {
  246. head_img_data = ipUrl;
  247. small_img_data = data.data.head_small_img;
  248. $('.crop_left img').attr('src', ipUrl);
  249. // $.each(ipUrl, function(i, v) {
  250. // $('.crop_left img').attr('src', v.head_img);
  251. // $("#file_name").val(v.filename);
  252. // });
  253. } else {
  254. // $('.crop_left img').attr('src', '../img/p3.jpg');
  255. $('.crop_left img').attr('src', '');
  256. }
  257. imgEditor();
  258. //话务相关
  259. $('#seat_flag').find('input[name="seat_flag_radio"][value="' + res.seat_flag + '"]').prop("checked", "checked").trigger('change'); //话务标志
  260. // $('#extensionnumber').val(res.extensionnumber); //分机号
  261. $('#seat_right').find('input[name="seat_right_radio"][value="' + res.seat_right + '"]').prop("checked", "checked"); //坐席类别
  262. $('#seat_group').selectpicker('val', res.group).trigger('change'); //坐席组id
  263. // $('#seat_level').val(res.seat_level); //坐席等级
  264. // $('input[name="see_flag"][value="' + res.see_flag + '"]').prop("checked", "checked"); //查看权限
  265. // $('input[name="call_type"][value="' + res.call_type + '"]').prop("checked", "checked"); //呼叫类型
  266. // $('#team_id').val(res.team_id); //团队
  267. }
  268. });
  269. }
  270. //保存
  271. function saveUsers() {
  272. // console.log($('#seat_group').val())
  273. // var selvalue = sel
  274. // var sel = document.getElementsByName("seat_group")[0];
  275. // console.log(sel.options[sel.options.selectedIndex].value)
  276. var options = $("#seat_group option:selected")
  277. console.log(options.text());
  278. if($('#seat_settings').css('display') == 'block') {
  279. if(options.text() == '咨询组') {
  280. groupid = 364
  281. } else if(options.text() == '客服组') {
  282. groupid = 365;
  283. }
  284. }
  285. if(!regexs.userReg.test($.trim($('#usercode').val()))) {
  286. layer.confirm('请输入有效的用户工号(只能是字母、下划线、数字)', {
  287. icon: 2,
  288. btn: ['确定']
  289. });
  290. return;
  291. }
  292. if(!$.trim($('#user_name').val())) {
  293. layer.confirm('请输入姓名!', {
  294. icon: 2,
  295. btn: ['确定']
  296. });
  297. return;
  298. }
  299. if(!$.trim($('#role_id').val())) {
  300. layer.confirm('请选择角色!', {
  301. icon: 2,
  302. btn: ['确定']
  303. });
  304. return;
  305. }
  306. if(!regexs.phone.test($.trim($('#mobile').val()))) {
  307. layer.confirm('请输入有效的手机号码!', {
  308. icon: 2,
  309. btn: ['确定']
  310. });
  311. return;
  312. }
  313. if($.trim($('#idcardno').val())) {
  314. if(!regexs.identityCard.test($.trim($('#idcardno').val()))) {
  315. layer.confirm('请输入有效的身份证号码!', {
  316. icon: 2,
  317. btn: ['确定']
  318. });
  319. return;
  320. }
  321. }
  322. if(!$.trim($('#projectid').val())) {
  323. layer.confirm('请选择项目信息', {
  324. icon: 2,
  325. btn: ['确定']
  326. });
  327. return;
  328. }
  329. if($('#seat_flag').find('input[name="seat_flag_radio"]:checked').val() === "true") {
  330. // if(!regexs.extensionNumber.test($.trim($('#extensionnumber').val()))) {
  331. // layer.confirm('请输入有效的分机号(4-20位的数字)', {
  332. // icon: 2,
  333. // btn: ['确定']
  334. // });
  335. // return;
  336. // }
  337. if(!$.trim($('#seat_group').val())) {
  338. layer.confirm('请选择坐席组', {
  339. icon: 2,
  340. btn: ['确定']
  341. });
  342. return;
  343. }
  344. }
  345. if(Ids) {
  346. editUsers(Ids);
  347. } else {
  348. if(!regexs.passwordReg.test($.trim($('#password').val()))) {
  349. layer.confirm('请输入有效的密码(6-32个字符只能是字母、下划线、数字)', {
  350. icon: 2,
  351. btn: ['确定']
  352. });
  353. return;
  354. }
  355. if(!regexs.passwordReg.test($.trim($('#password2').val()))) {
  356. layer.confirm('请输入有效的确认密码(6-32个字符只能是字母、下划线、数字)', {
  357. icon: 2,
  358. btn: ['确定']
  359. });
  360. return;
  361. }
  362. addUsers();
  363. }
  364. }
  365. //添加用户
  366. function addUsers() {
  367. $.post(huayi.config.callcenter_url + "signtokenapi/api/UserAccount/add", {
  368. usercode: $('#usercode').val(),
  369. username: $('#user_name').val(),
  370. password: $.md5($('#password').val()),
  371. type: $('#type').find('input[name="userType_flag"]:checked').val(), //用户类型
  372. role_id: $('#role_id').val(),
  373. sex: $('input[name="sex"]:checked').val(),
  374. mail: $('#mail').val(),
  375. head_img: head_img_data, //头像大图
  376. head_small_img: small_img_data, //头像缩略图
  377. mobile: $('#mobile').val(), //手机号码
  378. remark: $('#remark').val(),
  379. postlist: $(".administrative").val(), //科室 $('#administrative').val() ? $('#projectid').val() : []
  380. team_id: $("#team_id").val(), //岗位类型
  381. idcardno: $('#idcardno').val(), //string 身份证号码(新)
  382. idcard: imageArr1, // list 身份证照片(新)
  383. certificate: imageArr0, // list 技能证书
  384. entrytime: $('#entrytime').val(), // string 入职时间
  385. transfertime: $('#transfertime').val(), // string 转岗时间
  386. projectlist: [$('#projectid').val(), $('#projectid').val()], // list 项目id 如:[“项目id”,”项目id”,”项目id”]
  387. // projectlist: $('#projectid').val() ? $('#projectid').val() : [], // list 项目id 如:[“项目id”,”项目id”,”项目id”]
  388. //话务相关
  389. seat_flag: $('#seat_flag').find('input[name="seat_flag_radio"]:checked').val(), //话务标志
  390. // extensionnumber: $('#extensionnumber').val(), //分机号
  391. seat_right: $('#seat_right').find('input[name="seat_right_radio"]:checked').val(), //坐席类别
  392. group: $('#seat_group').val(), //坐席组id
  393. groupid: groupid
  394. // seat_level: $('#seat_level').val(), //坐席等级
  395. // see_flag: $('input[name="see_flag"]:checked').val(),//string 察看权限(1:个人;2:班组;3:所有)
  396. // call_type: $('input[name="call_type"]:checked').val(),//int 0:呼入;1:呼出
  397. // team_id: $('#team_id').val(),//团队id
  398. }, function(data) {
  399. data = JSON.parse(data);
  400. if(data.state == "success") {
  401. var index = parent.layer.getFrameIndex(window.name);
  402. parent.layer.close(index);
  403. parent.$('#user_table').bootstrapTable('refresh');
  404. parent.layer.msg("保存成功");
  405. }
  406. });
  407. }
  408. //编辑用户
  409. function editUsers(Ids) {
  410. $.post(huayi.config.callcenter_url + "signtokenapi/api/UserAccount/update", {
  411. id: Ids,
  412. usercode: $('#usercode').val(),
  413. username: $('#user_name').val(),
  414. type: $('#type').find('input[name="userType_flag"]:checked').val(), //用户类型
  415. role_id: $('#role_id').val(),
  416. sex: $('input[name="sex"]:checked').val(),
  417. postlist: $(".administrative").val(), //科室
  418. team_id: $("#team_id").val(), //岗位类型
  419. mail: $('#mail').val(),
  420. head_img: head_img_data, //头像大图
  421. head_small_img: small_img_data, //头像缩略图
  422. mobile: $('#mobile').val(),
  423. remark: $('#remark').val(),
  424. idcardno: $('#idcardno').val(), //string 身份证号码(新)
  425. idcard: imageArr1, // list 身份证照片(新)
  426. certificate: imageArr0, // list 技能证书
  427. entrytime: $('#entrytime').val(), // string 入职时间
  428. transfertime: $('#transfertime').val(), // string 转岗时间
  429. projectlist: $('#projectid').val() ? $('#projectid').val() : [], // list 项目id 如:[“项目id”,”项目id”,”项目id”]
  430. //话务相关
  431. seat_flag: $('#seat_flag').find('input[name="seat_flag_radio"]:checked').val(), //话务标志
  432. // extensionnumber: $('#extensionnumber').val(), //分机号
  433. seat_right: $('#seat_right').find('input[name="seat_right_radio"]:checked').val(), //坐席类别
  434. group: $('#seat_group').val(), //坐席组id
  435. groupid: groupid
  436. // seat_level: $('#seat_level').val(), //坐席等级
  437. // see_flag: $('input[name="see_flag"]:checked').val(),//string 察看权限(1:个人;2:班组;3:所有)
  438. // call_type: $('input[name="call_type"]:checked').val(),//int 0:呼入;1:呼出
  439. // team_id: $('#team_id').val(),//团队id
  440. }, function(data) {
  441. data = JSON.parse(data);
  442. if(data.state == "success") {
  443. //更新头像
  444. if($('#usercode').val() === window.localStorage.getItem('userCode')) {
  445. if(head_img_data != window.localStorage.getItem('headImg')) {
  446. window.localStorage.setItem('headImg', head_img_data);
  447. top.$('#head_img').attr('src', head_img_data);
  448. }
  449. }
  450. var index = parent.layer.getFrameIndex(window.name);
  451. parent.layer.close(index);
  452. parent.$('#user_table').bootstrapTable('refresh');
  453. parent.layer.msg("保存成功");
  454. }
  455. });
  456. }
  457. //图片剪切
  458. function imgEditor() {
  459. var o = $(".image-crop > img");
  460. o.cropper("destroy");
  461. o.cropper({
  462. // aspectRatio: 750 / 1334,
  463. aspectRatio: 1 / 1,
  464. resizable: true,
  465. dragCrop: true,
  466. preview: ".img-preview",
  467. done: function() {
  468. }
  469. });
  470. var r = $("#inputImage");
  471. var fileName = $("#file_name").val();
  472. if(window.FileReader) {
  473. r.change(function() {
  474. $('.progress-bar').css('width', '0%');
  475. $('.progress-bar').text('0%');
  476. var e, i = new FileReader,
  477. t = this.files;
  478. if(t.length && (e = t[0], /^image\/\w+$/.test(e.type))) {
  479. i.readAsDataURL(e);
  480. fileName = e.name;
  481. i.onload = function() {
  482. r.val("");
  483. o.cropper("reset", !0).cropper("replace", this.result);
  484. }
  485. } else {
  486. layer.msg("请选择本地图片文件");
  487. }
  488. });
  489. $("#setDrag").click(function() {
  490. var self = $(this);
  491. o.cropper("setDragMode", "crop");
  492. var imgUrl = o.cropper("getCroppedCanvas").toDataURL('image/png');
  493. //var dataurl = encodeURIComponent(imgUrl);
  494. var filesjson;
  495. var list = [],
  496. listItem = {};
  497. listItem.filename = fileName;
  498. listItem.fileurl = imgUrl;
  499. list.push(listItem);
  500. filesjson = JSON.stringify(list);
  501. upLoadFile(filesjson, self);
  502. });
  503. $("#zoomIn").click(function() {
  504. $('.progress-bar').css('width', '0%');
  505. $('.progress-bar').text('0%');
  506. o.cropper("zoom", .1)
  507. });
  508. $("#zoomOut").click(function() {
  509. $('.progress-bar').css('width', '0%');
  510. $('.progress-bar').text('0%');
  511. o.cropper("zoom", -.1)
  512. });
  513. $("#rotateLeft").click(function() {
  514. $('.progress-bar').css('width', '0%');
  515. $('.progress-bar').text('0%');
  516. o.cropper("rotate", 45)
  517. });
  518. $("#rotateRight").click(function() {
  519. $('.progress-bar').css('width', '0%');
  520. $('.progress-bar').text('0%');
  521. o.cropper("rotate", -45)
  522. });
  523. } else {
  524. r.addClass("hide");
  525. }
  526. }
  527. /**
  528. * 图片的上传
  529. * fjson 上传图片 的数据
  530. * self 调用者的this
  531. */
  532. function upLoadFile(fjson, self) {
  533. var formData = new FormData();
  534. formData.append("uploadtype", 'proManagement');
  535. formData.append("filesjson", fjson);
  536. $.ajax({
  537. type: "post",
  538. url: huayi.config.callcenter_url + "fileserverapi/Api/Upload",
  539. data: formData, //这里上传的数据使用了formData 对象
  540.   processData: false,
  541.   contentType: false, //必须false才会自动加上正确的Content-Type
  542. xhr: function() { //这是关键 获取原生的xhr对象 做以前做的所有事情
  543. var xhr = jQuery.ajaxSettings.xhr();
  544. xhr.upload.onload = function() {
  545. //alert('finish downloading')
  546. }
  547. xhr.upload.onprogress = function(ev) {
  548. //console.log(ev);
  549. //if(ev.lengthComputable) {
  550. var percent = 100 * ev.loaded / ev.total;
  551. //console.log(percent, ev);
  552. $('.progress-bar').css('width', percent + '%');
  553. $('.progress-bar').text(percent + '%');
  554. //}
  555. }
  556. return xhr;
  557. },
  558. async: true,
  559. beforeSend: function() { //触发ajax请求开始时执行
  560. self.attr("disabled", true);
  561. self.text('图片上传中...');
  562. $('.anniu').find('.btnn').css('backgroundColor', '#778592');
  563. },
  564. // data: {
  565. // uploadtype: 'proManagement',
  566. // filesjson: fjson,
  567. // },
  568. success: function(result) {
  569. result = $.parseJSON(result);
  570. self.attr("disabled", false);
  571. self.text('上传图片');
  572. $('.anniu').find('.btnn').css('backgroundColor', '#2f4050');
  573. /*验证请求*/
  574. if(result.state.toLowerCase() == "success") {
  575. head_img_data = result.data[0].fileurl;
  576. small_img_data = result.data[0].filesmallurl; //头像缩略图
  577. layer.msg("图片上传成功");
  578. } else {
  579. layer.msg(result.message);
  580. }
  581. },
  582. error: function(textStatus) {
  583. $('.progress-bar').css('width', '0%');
  584. $('.progress-bar').text('0%');
  585. layer.confirm('网络繁忙,请稍后再试...', {
  586. btn: ['确定'] //按钮
  587. });
  588. self.text('上传图片');
  589. self.attr("disabled", false);
  590. $('.anniu').find('.btnn').css('backgroundColor', '#2f4050');
  591. },
  592. complete: function(XMLHttpRequest, textStatus) {
  593. if(textStatus == 'timeout') {
  594. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  595. xmlhttp.abort();
  596. layer.confirm('网络超时,请稍后再试...', {
  597. btn: ['确定'] //按钮
  598. });    
  599. }
  600. self.text('上传图片');
  601. self.attr("disabled", false);
  602. $('.anniu').find('.btnn').css('backgroundColor', '#2f4050');
  603. },
  604. });
  605. }
  606. //角色下拉
  607. function getRoleName(obj) {
  608. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  609. $.getJSON(huayi.config.callcenter_url + "configurationapi/api/RoleInfo/getlistdrop", function(data) {
  610. if(data.state.toLowerCase() == "success") {
  611. obj.empty();
  612. obj.append("<option value=''>请选择角色</option>");
  613. var content = data.data;
  614. $(content).each(function(i, n) {
  615. $("<option value='" + n.id + "'>" + n.role_name + "</option>").appendTo(obj);
  616. });
  617. obj.selectpicker('refresh');
  618. dtd.resolve(); // 改变Deferred对象的执行状态
  619. }
  620. })
  621. return dtd.promise(); // 返回promise对象
  622. }
  623. //坐席组下拉
  624. function getSeatGroup(el) {
  625. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  626. $.getJSON(huayi.config.callcenter_url + "callcenterapi/api/sysseatgroup/getlist", function(data) {
  627. if(data.state.toLowerCase() == "success") {
  628. el.empty();
  629. el.append("<option value=''>请选择坐席组</option>");
  630. var content = data.data;
  631. if(content && content.length > 0) {
  632. $(content).each(function(i, n) {
  633. $("<option value='" + n.id + "'>" + n.zxzname + "</option>").appendTo(el);
  634. });
  635. el.selectpicker('refresh');
  636. }
  637. dtd.resolve(); // 改变Deferred对象的执行状态
  638. }
  639. })
  640. return dtd.promise(); // 返回promise对象
  641. }
  642. //添加技能证书和身份证照片
  643. function uploaderImg(cindex) {
  644. var imgList = $('#image_list' + cindex),
  645. eleId = $('#filePicker' + cindex),
  646. uploader;
  647. uploader = WebUploader.create({
  648. // 自动上传。
  649. auto: true,
  650. // swf文件路径
  651. swf: '../js/Uploader.swf',
  652. // 文件接收服务端。
  653. server: huayi.config.callcenter_url + 'fileserverapi/Api/Upload',
  654. // 选择文件的按钮。可选。
  655. // 内部根据当前运行是创建,可能是input元素,也可能是flash.
  656. pick: eleId,
  657. // 图片数量限制
  658. // fileNumLimit: 4,
  659. //可以重复上传
  660. duplicate: true,
  661. formData: {
  662. uploadtype: 'equipment' //自定义文件夹用于存放图片
  663. },
  664. // 只允许选择文件,可选。
  665. accept: {
  666. title: 'Images',
  667. extensions: 'gif,jpg,jpeg,bmp,png',
  668. mimeTypes: 'image/*'
  669. },
  670. resize: false,
  671. fileSizeLimit: 30 * 1024 * 1024, // 30 M
  672. fileSingleSizeLimit: 5 * 1024 * 1024 // 5 M
  673. });
  674. //上传图片提示
  675. uploader.on('error', function(code) {
  676. switch(code) {
  677. case "Q_EXCEED_NUM_LIMIT":
  678. layer.msg('只能上传六个文件。');
  679. break;
  680. case "Q_TYPE_DENIED":
  681. layer.msg('图片类型不正确。');
  682. break;
  683. case "F_DUPLICATE":
  684. layer.msg('该文件已上传,请选择其它文件。');
  685. break;
  686. case "F_EXCEED_SIZE":
  687. layer.msg('单文件大小不能超过5M。');
  688. break;
  689. case "Q_EXCEED_SIZE_LIMIT":
  690. layer.msg('总文件大小不能超过30M。');
  691. break;
  692. default:
  693. break;
  694. }
  695. });
  696. // 当有文件添加进来的时候
  697. uploader.on('fileQueued', function(file) {
  698. //console.log(file);
  699. var $li = $(
  700. '<div id="' + cindex + '' + file.id + '" class="file-item thumbnail">' +
  701. '<div class="image-close">X</div>' +
  702. '<img>' +
  703. '<div class="info">' + file.name + '</div>' +
  704. '</div>'
  705. ),
  706. $img = $li.find('img');
  707. imgList.prepend($li);
  708. $(".image-close").on('click', function() {
  709. event.stopPropagation();
  710. $(this).parent().remove();
  711. helper.methods.delImgs($(this).parent().attr("data-filesmallurl"), $(this).parent().attr("data-fileurl"));
  712. file_num(cindex)
  713. });
  714. });
  715. // 文件上传成功,给item添加成功class, 用样式标记上传成功。
  716. uploader.on('uploadSuccess', function(file, response) {
  717. //console.log(file)
  718. $.each(response.data, function(i, j) {
  719. // obj=
  720. var $img = $('#' + cindex + file.id).find('img');
  721. $('#' + cindex + file.id).attr({
  722. 'data-filename': j.filename,
  723. 'data-fileext': j.fileext,
  724. 'data-filemd5': j.filemd5,
  725. 'data-filesize': j.filesize,
  726. 'data-fileurl': j.fileurl,
  727. 'data-filesmallurl': j.filesmallurl
  728. });
  729. uploader.makeThumb(file, function(error, src) {
  730. $img.attr('src', j.filesmallurl);
  731. $img.addClass('image-item');
  732. // $img.attr('data-preview-group', "1");
  733. }, 50, 50);
  734. });
  735. $('#' + cindex + file.id).addClass('upload-state-done');
  736. file_num(cindex)
  737. });
  738. // 文件上传失败,现实上传出错。
  739. uploader.on('uploadError', function(file) {
  740. var $li = $('#' + cindex + file.id),
  741. $error = $li.find('div.error');
  742. // 避免重复创建
  743. if(!$error.length) {
  744. $error = $('<div class="error"></div>').appendTo($li);
  745. }
  746. $error.text('上传失败');
  747. });
  748. // 完成上传完了,成功或者失败,先删除进度条。
  749. // uploader.on('uploadComplete', function(file) {
  750. // });
  751. }
  752. //隐藏域值
  753. function file_num(num) {
  754. var arr = [];
  755. $('#image_list' + num).find('.thumbnail').each(function(j, m) {
  756. var obj = {
  757. 'filename': $(m).attr("data-filename"),
  758. 'fileext': $(m).attr("data-fileext"),
  759. 'filemd5': $(m).attr("data-filemd5"),
  760. 'filesize': $(m).attr("data-filesize"),
  761. 'fileurl': $(m).attr("data-fileurl"),
  762. 'filesmallurl': $(m).attr("data-filesmallurl")
  763. }
  764. arr.push(obj)
  765. })
  766. window['imageArr' + num] = arr;
  767. }
  768. //获取详情时 图片展示
  769. function getImgVal(data, num) {
  770. $(data).each(function(i, n) {
  771. var $li = $(
  772. '<div class="file-item thumbnail" data-filename="' + n.filename + '" data-fileext="' + n.fileext + '" data-filemd5="' + n.filemd5 + '" data-filesize="' + n.filesize + '" data-fileurl="' + n.fileurl + '" data-filesmallurl="' + n.filesmallurl + '" >' +
  773. '<div class="image-close">X</div>' +
  774. '<img src="' + n.filesmallurl + '">' +
  775. '<div class="info">' + n.filename + '</div>' +
  776. '</div>'
  777. ),
  778. $img = $li.find('img');
  779. $('#image_list' + num).prepend($li);
  780. })
  781. file_num(num)
  782. }