郑州第一人民医院UI

addOrEditUserManage.js 24KB

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