edit.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>修改资料</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <link rel="stylesheet" type="text/css" href="../../css/common/mui.min.css" />
  10. <link rel="stylesheet" href="../../css/common/common.css">
  11. <link rel="stylesheet" type="text/css" href="../../css/my/my-set.css" />
  12. <style type="text/css">
  13. .mui-content input {
  14. margin: 0;
  15. width: 50%;
  16. height: 20px;
  17. font-size: 14px;
  18. padding: 0;
  19. border: none;
  20. text-align: right;
  21. }
  22. textarea {
  23. border: 1px solid #F3F5F7;
  24. border: none;
  25. color: #CCCCCC;
  26. height: 100px;
  27. margin-bottom: 0;
  28. padding: 0;
  29. font-size: 14px;
  30. }
  31. #url {
  32. display: none;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <header id="header" class="mui-bar mui-bar-nav">
  38. <a class="mui-action-back mui-icon mui-icon-arrowleft">
  39. <span class="back">返回</span>
  40. </a>
  41. <h1 class="mui-title">修改资料</h1>
  42. <a class="mui-btn-link mui-pull-right fz">完成</a>
  43. </header>
  44. <div class="mui-content">
  45. <div class="my-set-box">
  46. <div class="my-header">
  47. <span>头像</span>
  48. <span class="imgs">
  49. </span>
  50. <a class="my-set-icon mui-pull-right mui-icon mui-icon-arrowright"></a>
  51. </div>
  52. <div>
  53. <span>姓名</span>
  54. <span>
  55. <input class="name" type="text"/>
  56. </span>
  57. <a class="mui-pull-right mui-icon mui-icon-arrowright"></a>
  58. </div>
  59. <div>
  60. <span>昵称</span>
  61. <span>
  62. <input class="nickname" type="text" placeholder="请输入昵称"/>
  63. </span>
  64. <a class="mui-pull-right mui-icon mui-icon-arrowright"></a>
  65. </div>
  66. <div>
  67. <span>手机号</span>
  68. <span>
  69. <input class="phone" type="text"/>
  70. </span>
  71. <a class="mui-pull-right mui-icon mui-icon-arrowright"></a>
  72. </div>
  73. <div>
  74. <textarea class="content">请填写简介</textarea>
  75. </div>
  76. </div>
  77. </div>
  78. <script src="../../libs/mui.min.js"></script>
  79. <script type="text/javascript">
  80. window.onload = function() {
  81. mui.plusReady(function() {
  82. //获取token
  83. var str = plus.storage.getItem('user');
  84. var user = JSON.parse(str);
  85. var token = user.Data.Token;
  86. mui('.name')[0].value = user.Data.Name;
  87. mui('.phone')[0].value = user.Data.Phone;
  88. mui('.imgs')[0].innerHTML = '<img class="img" src="http://www.bosshand.cn/' + user.Data.Picture + '">';
  89. //调用相册
  90. mui(document.body).on('tap', '.imgs', function() {
  91. galleryImgs();
  92. });
  93. //清空textarea
  94. mui(document.body).on('tap', '.content', function() {
  95. mui(this)[0].value = '';
  96. });
  97. //调用相册函数
  98. function galleryImgs() {
  99. // 从相册中选择图片
  100. mui.plusReady(function() {
  101. plus.gallery.pick(function(e) {
  102. var imghtml = '';
  103. imghtml += '<img class="img" src="' + e.files[0] + '">';
  104. mui('.imgs')[0].innerHTML = imghtml;
  105. }, function(e) {
  106. mui.toast("取消选择图片");
  107. }, {
  108. filter: "image",
  109. multiple: true,
  110. maximum: 1,
  111. system: false,
  112. onmaxed: function() {
  113. plus.nativeUI.alert('最多只能选择1张图片');
  114. }
  115. });
  116. })
  117. }
  118. //点击发布
  119. mui(document.body).on('tap', '.fz', function() {
  120. var image = new Image();
  121. image.src = mui('.img')[0].src;
  122. var im = getBaseImage(image);
  123. var postDatas = {
  124. "": im
  125. };
  126. mui.ajax("http://www.bosshand.cn/api/Customer/Base64StringToImage", {
  127. data: postDatas,
  128. dataType: 'json',
  129. type: "post",
  130. headers: {
  131. authorization: token
  132. },
  133. success: function(resp) {
  134. if(resp.Code == 200) {
  135. var urls = resp.Data;
  136. var name = mui('.name')[0].value;
  137. var phone = mui('.phone')[0].value;
  138. var nickname = mui('.nickname')[0].value;
  139. var description = mui('.content')[0].value
  140. var postData = {
  141. Phone: phone,
  142. Name: name,
  143. Picture: urls,
  144. NickName: nickname,
  145. Description: description,
  146. }
  147. mui.ajax("http://www.bosshand.cn/api/Customer/UpdateUserInfoByCode", {
  148. data: postData,
  149. dataType: 'json',
  150. type: "post",
  151. timeout: 10000, //超时时间设置为10秒;
  152. headers: {
  153. 'Content-Type': 'application/x-www-form-urlencoded',
  154. authorization: token
  155. },
  156. success: function(resp) {
  157. if(resp.Code == 200) {
  158. user.Data.Picture = urls
  159. plus.storage.setItem('user', JSON.stringify(user))
  160. mui.toast('发布成功');
  161. var old_back = mui.back;
  162. mui.back = function() {
  163. var wobj = plus.webview.getWebviewById("tpl/my/my-set.html");
  164. wobj.reload(true);
  165. old_back();
  166. }
  167. mui.back();
  168. }
  169. }
  170. });
  171. }
  172. }
  173. });
  174. });
  175. //图片转换为base64函数
  176. function getBaseImage(img) {
  177. var canvas = document.createElement("canvas");
  178. var width = img.width;
  179. var height = img.height;
  180. // calculate the width and height, constraining the proportions
  181. if(width > height) {
  182. if(width > 100) {
  183. height = Math.round(height *= 100 / width);
  184. width = 100;
  185. }
  186. } else {
  187. if(height > 100) {
  188. width = Math.round(width *= 100 / height);
  189. height = 100;
  190. }
  191. }
  192. canvas.width = width; /*设置新的图片的宽度*/
  193. canvas.height = height; /*设置新的图片的长度*/
  194. var ctx = canvas.getContext("2d");
  195. ctx.drawImage(img, 0, 0, width, height); /*绘图*/
  196. var dataURL = canvas.toDataURL("image/png", 0.8);
  197. return dataURL.replace("data:image/png;base64,", "");
  198. };
  199. })
  200. }
  201. </script>
  202. </body>
  203. </html>