郑州第一人民医院UI

addOrEditUserManage.js 25KB

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