暫無描述

addOrEditProMailList.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /**
  2. * 增加或编辑 项目通讯录
  3. * */
  4. var imglist = []; //保存头像的数组(大图,小图)
  5. $(function() {
  6. autosize($('textarea'));
  7. var user_id = helper.request.queryString("edit_id");
  8. if(user_id) { //修改
  9. helper.getDropList.getProlistDrop($('#pro_title')).then(function() {
  10. getProject(user_id);
  11. });
  12. } else {
  13. helper.getDropList.getProlistDrop($('#pro_title')); //项目
  14. $(".image-crop > img").attr('src', '');
  15. imgEditor(); //头像图片裁剪
  16. }
  17. //添加编辑保存按钮点击
  18. $('#pro_save').on('click', saveProject);
  19. });
  20. //获取单个信息
  21. function getProject(ids) {
  22. $.getJSON(huayi.config.callcenter_url + "equipmentapi/api/ProjectUser/getdetails", {
  23. id: ids,
  24. }, function(data) {
  25. if(data.state == "success") {
  26. var res = data.data;
  27. if(res) {
  28. $('#pro_title').selectpicker('val', res.projectid).trigger('change'); //项目名称
  29. $('#pro_property').find('input[type=radio][value="' + res.type + '"]').prop('checked', true); //是 int 类型( 1 甲方2诺达)
  30. $('#pro_personname').val(res.name); //是 string 姓名
  31. $('#pro_sex').find('input[type=radio][value="' + res.sex + '"]').prop('checked', true); //否 string 性别
  32. $('#pro_tel').val(res.mobilephone); //否 string 手机
  33. $('#pro_mobile').val(res.telephone); // 否 string 固话
  34. $('#pro_dept').val(res.department); //否 string 科室
  35. $('#pro_post').val(res.position); //否 string 岗位
  36. $('#pro_remark').val(res.remark); //否 string 备注
  37. //项目头像
  38. var ipUrl = res.imgurl;
  39. if(ipUrl) {
  40. imglist = []; //保存头像的数组(大图,小图)
  41. imglist.push(ipUrl); //头像 大图
  42. imglist.push(res.imgsmallurl); //头像 小图
  43. $(".image-crop > img").attr('src', ipUrl);
  44. } else {
  45. $('.crop_left img').attr('src', '');
  46. }
  47. imgEditor();
  48. }
  49. }
  50. });
  51. }
  52. //保存项目
  53. function saveProject() {
  54. var user_id = helper.request.queryString("edit_id");
  55. var wUrl;
  56. if(!$.trim($('#pro_title').val())) {
  57. layer.confirm('你还没有选择项目', {
  58. icon: 2,
  59. btn: ['确定'] //按钮
  60. });
  61. return;
  62. }
  63. if(!$.trim($('#pro_personname').val())) {
  64. layer.confirm('姓名不能为空!', {
  65. icon: 2,
  66. btn: ['确定'] //按钮
  67. });
  68. return;
  69. }
  70. if($.trim($('#pro_tel').val())) {
  71. if(!regexs.phone.test($.trim($('#pro_tel').val()))) {
  72. layer.confirm('手机号码格式不正确,请重新输入!', {
  73. icon: 2,
  74. btn: ['确定'] //按钮
  75. });
  76. return;
  77. }
  78. }
  79. if($.trim($('#pro_mobile').val())) {
  80. if(!regexs.phone.test($.trim($('#pro_mobile').val()))) {
  81. layer.confirm('固定电话格式不正确,请重新输入!', {
  82. icon: 2,
  83. btn: ['确定'] //按钮
  84. });
  85. return;
  86. }
  87. }
  88. if(user_id) {
  89. wURL = "equipmentapi/api/ProjectUser/update";
  90. } else {
  91. wURL = "equipmentapi/api/ProjectUser/add";
  92. }
  93. $.post(huayi.config.callcenter_url + wURL, {
  94. id: user_id, //是 string id
  95. projectid: $('#pro_title').val(), // 是 string 项目id
  96. type: $('#pro_property').find('input[type=radio]:checked').val(), // 是 int 类型( 1 甲方2诺达)
  97. name: $('#pro_personname').val(), //是 string 姓名
  98. sex: $('#pro_sex').find('input[type=radio]:checked').val(), //否 string 性别
  99. mobilephone: $('#pro_tel').val(), //否 string 手机
  100. telephone: $('#pro_mobile').val(), // 否 string 固话
  101. imgurl: imglist[0], //否 string 头像
  102. imgsmallurl: imglist[1], //否 string 头像缩略图
  103. department: $('#pro_dept').val(), //否 string 科室
  104. position: $('#pro_post').val(), //否 string 岗位
  105. remark: $('#pro_remark').val(), //否 string 备注
  106. }, function(data) {
  107. data = JSON.parse(data);
  108. if(data.state == "success") {
  109. var index = parent.layer.getFrameIndex(window.name);
  110. parent.layer.close(index);
  111. parent.$('#table_all').bootstrapTable('refresh');
  112. parent.layer.msg("保存成功");
  113. }
  114. });
  115. }
  116. //图片剪切
  117. function imgEditor() {
  118. var o = $(".image-crop > img");
  119. o.cropper("destroy");
  120. o.cropper({
  121. aspectRatio: 200 / 200,
  122. resizable: true,
  123. dragCrop: true,
  124. preview: ".img-preview",
  125. done: function() {
  126. }
  127. });
  128. var r = $("#inputImage");
  129. var fileName = $("#file_name").val();
  130. if(window.FileReader) {
  131. r.change(function() {
  132. $('.progress-bar').css('width', '0%');
  133. $('.progress-bar').text('0%');
  134. var e, i = new FileReader,
  135. t = this.files;
  136. if(t.length && (e = t[0], /^image\/\w+$/.test(e.type))) {
  137. i.readAsDataURL(e);
  138. fileName = e.name;
  139. i.onload = function() {
  140. r.val("");
  141. o.cropper("reset", !0).cropper("replace", this.result);
  142. }
  143. } else {
  144. layer.msg("请选择本地图片文件");
  145. }
  146. });
  147. $("#setDrag").click(function() {
  148. var self = $(this);
  149. o.cropper("setDragMode", "crop");
  150. var imgUrl = o.cropper("getCroppedCanvas").toDataURL('image/png');
  151. //var dataurl = encodeURIComponent(imgUrl);
  152. var filesjson;
  153. var list = [],
  154. listItem = {};
  155. listItem.filename = fileName;
  156. listItem.fileurl = imgUrl;
  157. list.push(listItem);
  158. filesjson = JSON.stringify(list);
  159. upLoadFile(filesjson, self);
  160. });
  161. $("#zoomIn").click(function() {
  162. $('.progress-bar').css('width', '0%');
  163. $('.progress-bar').text('0%');
  164. o.cropper("zoom", .1)
  165. });
  166. $("#zoomOut").click(function() {
  167. $('.progress-bar').css('width', '0%');
  168. $('.progress-bar').text('0%');
  169. o.cropper("zoom", -.1)
  170. });
  171. $("#rotateLeft").click(function() {
  172. $('.progress-bar').css('width', '0%');
  173. $('.progress-bar').text('0%');
  174. o.cropper("rotate", 45)
  175. });
  176. $("#rotateRight").click(function() {
  177. $('.progress-bar').css('width', '0%');
  178. $('.progress-bar').text('0%');
  179. o.cropper("rotate", -45)
  180. });
  181. } else {
  182. r.addClass("hide");
  183. }
  184. }
  185. /**
  186. * 图片的上传
  187. * fjson 上传图片 的数据
  188. * self 调用者的this
  189. */
  190. function upLoadFile(fjson, self) {
  191. var formData = new FormData();
  192. formData.append("uploadtype", 'proMailList');
  193. formData.append("filesjson", fjson);
  194. $.ajax({
  195. type: "post",
  196. url: huayi.config.callcenter_url + "fileserverapi/Api/Upload",
  197. data: formData, //这里上传的数据使用了formData 对象
  198. processData: false,
  199. contentType: false, //必须false才会自动加上正确的Content-Type
  200. xhr: function() { //这是关键 获取原生的xhr对象 做以前做的所有事情
  201. var xhr = jQuery.ajaxSettings.xhr();
  202. xhr.upload.onload = function() {
  203. //alert('finish downloading')
  204. }
  205. xhr.upload.onprogress = function(ev) {
  206. //console.log(ev);
  207. //if(ev.lengthComputable) {
  208. var percent = 100 * ev.loaded / ev.total;
  209. //console.log(percent, ev);
  210. $('.progress-bar').css('width', percent + '%');
  211. $('.progress-bar').text(percent + '%');
  212. //}
  213. }
  214. return xhr;
  215. },
  216. async: true,
  217. beforeSend: function() { //触发ajax请求开始时执行
  218. self.attr("disabled", true);
  219. self.text('头像上传中...');
  220. $('.anniu').find('.btnn').css('backgroundColor', '#778592');
  221. },
  222. // data: {
  223. // uploadtype: 'proManagement',
  224. // filesjson: fjson,
  225. // },
  226. success: function(result) {
  227. result = $.parseJSON(result);
  228. self.attr("disabled", false);
  229. self.text('上传头像');
  230. $('.anniu').find('.btnn').css('backgroundColor', '#2f4050');
  231. /*验证请求*/
  232. if(result.state.toLowerCase() == "success") {
  233. if(result.data && result.data.length > 0) {
  234. imglist = []; //保存头像的数组(大图,小图)
  235. imglist.push(result.data[0].fileurl);
  236. imglist.push(result.data[0].filesmallurl);
  237. }
  238. layer.msg("头像上传成功");
  239. } else {
  240. layer.msg(result.message);
  241. }
  242. },
  243. error: function(textStatus) {
  244. $('.progress-bar').css('width', '0%');
  245. $('.progress-bar').text('0%');
  246. layer.confirm('网络繁忙,请稍后再试...', {
  247. btn: ['确定'] //按钮
  248. });
  249. self.text('上传头像');
  250. self.attr("disabled", false);
  251. $('.anniu').find('.btnn').css('backgroundColor', '#2f4050');
  252. },
  253. complete: function(XMLHttpRequest, textStatus) {
  254. //$('.progress-bar').css('width', '0%');
  255. //$('.progress-bar').text('0%');
  256. if(textStatus == 'timeout') {
  257. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  258. xmlhttp.abort();
  259. layer.confirm('网络超时,请稍后再试...', {
  260. btn: ['确定'] //按钮
  261. });    
  262. }
  263. self.text('上传头像');
  264. self.attr("disabled", false);
  265. $('.anniu').find('.btnn').css('backgroundColor', '#2f4050');
  266. },
  267. });
  268. }