123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>修改资料</title>
- <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
- <meta name="apple-mobile-web-app-capable" content="yes">
- <meta name="apple-mobile-web-app-status-bar-style" content="black">
- <link rel="stylesheet" type="text/css" href="../../css/common/mui.min.css" />
- <link rel="stylesheet" href="../../css/common/common.css">
- <link rel="stylesheet" type="text/css" href="../../css/my/my-set.css" />
- <style type="text/css">
- .mui-content input {
- margin: 0;
- width: 50%;
- height: 20px;
- font-size: 14px;
- padding: 0;
- border: none;
- text-align: right;
- }
-
- textarea {
- border: 1px solid #F3F5F7;
- border: none;
- color: #CCCCCC;
- height: 100px;
- margin-bottom: 0;
- padding: 0;
- font-size: 14px;
- }
-
- #url {
- display: none;
- }
- </style>
- </head>
- <body>
- <header id="header" class="mui-bar mui-bar-nav">
- <a class="mui-action-back mui-icon mui-icon-arrowleft">
- <span class="back">返回</span>
- </a>
- <h1 class="mui-title">修改资料</h1>
- <a class="mui-btn-link mui-pull-right fz">完成</a>
- </header>
- <div class="mui-content">
- <div class="my-set-box">
- <div class="my-header">
- <span>头像</span>
- <span class="imgs">
- </span>
- <a class="my-set-icon mui-pull-right mui-icon mui-icon-arrowright"></a>
- </div>
- <div>
- <span>姓名</span>
- <span>
- <input class="name" type="text"/>
- </span>
- <a class="mui-pull-right mui-icon mui-icon-arrowright"></a>
- </div>
- <div>
- <span>昵称</span>
- <span>
- <input class="nickname" type="text" placeholder="请输入昵称"/>
- </span>
- <a class="mui-pull-right mui-icon mui-icon-arrowright"></a>
- </div>
- <div>
- <span>手机号</span>
- <span>
- <input class="phone" type="text"/>
- </span>
- <a class="mui-pull-right mui-icon mui-icon-arrowright"></a>
- </div>
- <div>
- <textarea class="content">请填写简介</textarea>
- </div>
- </div>
- </div>
- <script src="../../libs/mui.min.js"></script>
- <script type="text/javascript">
- window.onload = function() {
- mui.plusReady(function() {
- //获取token
- var str = plus.storage.getItem('user');
- var user = JSON.parse(str);
- var token = user.Data.Token;
- mui('.name')[0].value = user.Data.Name;
- mui('.phone')[0].value = user.Data.Phone;
- mui('.imgs')[0].innerHTML = '<img class="img" src="http://www.bosshand.cn/' + user.Data.Picture + '">';
- //调用相册
- mui(document.body).on('tap', '.imgs', function() {
- galleryImgs();
- });
- //清空textarea
- mui(document.body).on('tap', '.content', function() {
- mui(this)[0].value = '';
- });
- //调用相册函数
- function galleryImgs() {
- // 从相册中选择图片
- mui.plusReady(function() {
- plus.gallery.pick(function(e) {
- var imghtml = '';
- imghtml += '<img class="img" src="' + e.files[0] + '">';
- mui('.imgs')[0].innerHTML = imghtml;
- }, function(e) {
- mui.toast("取消选择图片");
- }, {
- filter: "image",
- multiple: true,
- maximum: 1,
- system: false,
- onmaxed: function() {
- plus.nativeUI.alert('最多只能选择1张图片');
- }
- });
- })
- }
- //点击发布
- mui(document.body).on('tap', '.fz', function() {
- var image = new Image();
- image.src = mui('.img')[0].src;
- var im = getBaseImage(image);
- var postDatas = {
- "": im
- };
- mui.ajax("http://www.bosshand.cn/api/Customer/Base64StringToImage", {
- data: postDatas,
- dataType: 'json',
- type: "post",
- headers: {
- authorization: token
- },
- success: function(resp) {
- if(resp.Code == 200) {
- var urls = resp.Data;
- var name = mui('.name')[0].value;
- var phone = mui('.phone')[0].value;
- var nickname = mui('.nickname')[0].value;
- var description = mui('.content')[0].value
- var postData = {
- Phone: phone,
- Name: name,
- Picture: urls,
- NickName: nickname,
- Description: description,
- }
- mui.ajax("http://www.bosshand.cn/api/Customer/UpdateUserInfoByCode", {
- data: postData,
- dataType: 'json',
- type: "post",
- timeout: 10000, //超时时间设置为10秒;
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- authorization: token
- },
- success: function(resp) {
- if(resp.Code == 200) {
- user.Data.Picture = urls
- plus.storage.setItem('user', JSON.stringify(user))
- mui.toast('发布成功');
- var old_back = mui.back;
- mui.back = function() {
- var wobj = plus.webview.getWebviewById("tpl/my/my-set.html");
- wobj.reload(true);
- old_back();
- }
- mui.back();
- }
- }
- });
- }
- }
- });
- });
- //图片转换为base64函数
- function getBaseImage(img) {
- var canvas = document.createElement("canvas");
- var width = img.width;
- var height = img.height;
- // calculate the width and height, constraining the proportions
- if(width > height) {
- if(width > 100) {
- height = Math.round(height *= 100 / width);
- width = 100;
- }
- } else {
- if(height > 100) {
- width = Math.round(width *= 100 / height);
- height = 100;
- }
- }
- canvas.width = width; /*设置新的图片的宽度*/
- canvas.height = height; /*设置新的图片的长度*/
- var ctx = canvas.getContext("2d");
- ctx.drawImage(img, 0, 0, width, height); /*绘图*/
- var dataURL = canvas.toDataURL("image/png", 0.8);
- return dataURL.replace("data:image/png;base64,", "");
- };
- })
- }
- </script>
- </body>
- </html>
|