personal_info.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. if ($('.content').height() > 750) {
  2. $('#iframe-main', parent.document).css('height', $('.content').height() + 20)
  3. } else {
  4. $('#iframe-main', parent.document).css('height', '750px')
  5. }
  6. window.onload = function () {
  7. // 省市区回显
  8. $("#province10").val($('#provinceHide').val());
  9. $("#province10").trigger("change");
  10. $("#city10").val($('#cityHide').val());
  11. $("#city10").trigger("change");
  12. $("#district10").val($('#areaHide').val());
  13. $("#district10").val($('#areaHide').val());
  14. }
  15. function submit_info() {
  16. var uname = $("#name").val();
  17. var phone = $("#userPhone").val();
  18. var province = $("#province10").val();
  19. var city = $("#city10").val();
  20. var area = $("#district10").val();
  21. var email = $("#email").val();
  22. // var remark = $("#remarks").val();
  23. if (uname == '') {
  24. layer.alert("用户名不能为空!");
  25. return false;
  26. }
  27. if (!/^[1][3,4,5,7,8][0-9]{9}$/.test(phone)) {
  28. layer.alert("手机号格式错误!");
  29. return false;
  30. }
  31. $.ajax({
  32. type: "post",
  33. url: "personal_info",
  34. data: {
  35. req: "info",
  36. username: uname,
  37. email: email,
  38. phone: phone,
  39. // remark: remark,
  40. province: province,
  41. city: city,
  42. area: area
  43. },
  44. dataType: "json",
  45. success: function (data) {
  46. if (data == 0) {
  47. layer.msg("修改成功!");
  48. location.reload()
  49. } else if (data == 1) {
  50. layer.msg("该用户名已存在!");
  51. }
  52. }
  53. });
  54. return false;
  55. }
  56. // file 文件
  57. // divId div id
  58. // imgId 图片id
  59. // fileId 文件id
  60. // width 图片宽
  61. // height 图片高
  62. function previewImage(file, divId, imgId, fileId, width, height) {
  63. var div = document.getElementById(divId);
  64. if (file.files && file.files[0]) {
  65. if (file.files[0].size / 1024 / 1024 < 4) {
  66. div.innerHTML = '<img id=' + imgId + ' onclick=$("#' + fileId + '").click()>';
  67. var img = document.getElementById(imgId);
  68. img.onload = function () {
  69. // var rect = clacImgZoomParam(width, height, img.offsetWidth, img.offsetHeight);
  70. img.width = width;
  71. img.height = height;
  72. // img.style.marginTop = rect.top+'px';
  73. }
  74. var reader = new FileReader();
  75. reader.onload = function (evt) {
  76. img.src = evt.target.result;
  77. // $(window.parent.document).find('.nav-user-photo').attr('src',evt.target.result);
  78. }
  79. reader.readAsDataURL(file.files[0]);
  80. // $('#userPhoto').submit();
  81. sendUserPhoto();
  82. } else {
  83. $(file).val('');
  84. layer.alert("图片过大!");
  85. }
  86. } else {//兼容IE
  87. var sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
  88. file.select();
  89. if (document.selection != undefined) {
  90. var src = document.selection.createRange().text;
  91. div.innerHTML = '<img id=' + imgId + '>';
  92. var img = document.getElementById(imgId);
  93. img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
  94. var rect = clacImgZoomParam(width, height, img.offsetWidth, img.offsetHeight);
  95. status = ('rect:' + rect.top + ',' + rect.left + ',' + rect.width + ',' + rect.height);
  96. div.innerHTML = "<div id=divhead style='width:" + rect.width + "px;height:" + rect.height + "px;" + sFilter + src + "\"'></div>";
  97. }
  98. }
  99. }
  100. function clacImgZoomParam(maxWidth, maxHeight, width, height) {
  101. var param = { top: 0, left: 0, width: width, height: height };
  102. if (width > maxWidth || height > maxHeight) {
  103. var rateWidth = width / maxWidth;
  104. var rateHeight = height / maxHeight;
  105. if (rateWidth > rateHeight) {
  106. param.width = maxWidth;
  107. param.height = Math.round(height / rateWidth);
  108. } else {
  109. param.width = Math.round(width / rateHeight);
  110. param.height = maxHeight;
  111. }
  112. }
  113. param.left = Math.round((maxWidth - param.width) / 2);
  114. param.top = Math.round((maxHeight - param.height) / 2);
  115. return param;
  116. }
  117. // 上传图片
  118. function sendUserPhoto() {
  119. var formData = new FormData($("#userPhoto")[0]);
  120. $.ajax({
  121. url: 'personal_info',
  122. type: 'POST',
  123. data: formData,
  124. contentType: false,
  125. processData: false,
  126. success: function (data) {
  127. if (data == 0) {
  128. $(window.parent.document).find('.nav-user-photo').attr('src', $('#viewPhoto').prop('src'));
  129. }
  130. else { layer.msg("上传失败!"); }
  131. }
  132. });
  133. }