Skip to content

Commit

Permalink
个人中心
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobinwu committed May 13, 2017
1 parent a981300 commit aa44373
Show file tree
Hide file tree
Showing 25 changed files with 565 additions and 8 deletions.
6 changes: 5 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"pages/detail/detail",
"pages/list/list",
"pages/more/more",
"pages/center/center"
"pages/center/center",
"pages/user-detail/user-detail",
"pages/editname/editname",
"pages/editphone/editphone",
"pages/login/login"
],
"window":{
"navigationBarBackgroundColor": "#e61773",
Expand Down
11 changes: 10 additions & 1 deletion app.wxss
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,13 @@ page {
.status-bar text{
padding: 0 3px;
color: #e61773;
}
}
/*按钮primary*/
button[type="primary"] {
border-radius: 0;
background-color: #e61773;
}
button[disabled][type="primary"] {
border-radius: 0;
background-color:#ccc;
}
11 changes: 10 additions & 1 deletion pages/center/center.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Page({
isLogin: false,
userImg: null,
userName: null,
userInfo: {}
},
goDetail: function(){
if(this.data.isLogin){
Expand Down Expand Up @@ -37,7 +38,8 @@ Page({
appInstance.globalData.userInfo = polyfill.object.assignIn(appInstance.globalData.userInfo, res.data);
_self.setData({
userImg: appInstance.globalData.userInfo.avatar,
userName: appInstance.globalData.userInfo.nickname
userName: appInstance.globalData.userInfo.nickname,
userInfo: appInstance.globalData.userInfo
});
}).catch(err => {
if(err.status === 4002) {
Expand All @@ -56,6 +58,13 @@ Page({
},
onShow:function(){
// 页面显示
if(!polyfill.object.isObjectValueEqual(appInstance.globalData.userInfo, this.data.userInfo)){
this.setData({
userImg: appInstance.globalData.userInfo.avatar,
userName: appInstance.globalData.userInfo.nickname,
userInfo: appInstance.globalData.userInfo
});
}
},
onHide:function(){
// 页面隐藏
Expand Down
4 changes: 2 additions & 2 deletions pages/center/center.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
</view>
</view>
<view class="list section">
<navigator url="{{isLogin ? '/page/address/address' : '/page/login/login'}}" >
<navigator url="{{isLogin ? '../address/address' : '../login/login'}}" >
<view class="flex-con">
<span class="icon icon-map"></span>
<text>配送地址管理</text>
<span class="icon icon-right"></span>
</view>
</navigator>
<navigator url="{{isLogin ? '/page/coupon/coupon' : '/page/login/login'}}">
<navigator url="{{isLogin ? '../coupon/coupon' : '../login/login'}}">
<view class="flex-con">
<span class="icon icon-mendianyouhuiquan"></span>
<text>门店优惠券</text>
Expand Down
62 changes: 62 additions & 0 deletions pages/editname/editname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// pages/editname/editname.js
//获取app实例
var util = require('../../utils/util.js');
var ports = require('../../utils/ports.js');
var appInstance = getApp();
Page({
data:{
userName: ''
},
judge: function(){
if(!appInstance.globalData.userInfo.hasData){
wx.navigateBack({
delta: 2
});
}
},
submit(e){
var _self = this;
util.getToken().then(token => {
util.wxRequest({
method: 'POST',
url: ports.updateNickName,
header:{ 'X-Auth-Token': token, 'content-type': 'application/x-www-form-urlencoded' },
data: {
nickname: e.detail.value
}
}).then((res) => {
appInstance.globalData.userInfo.nickname = e.detail.value;
wx.showToast({
title: '修改成功',
icon: 'success',
duration: 1000,
success: function(){
setTimeout(function(){
wx.navigateBack({
delta: 1
});
}, 1000);
}
})
});
});
},
onLoad:function(options){
this.judge();
this.setData({
userName: appInstance.globalData.userInfo.nickname
});
},
onReady:function(){
// 页面渲染完成
},
onShow:function(){
// 页面显示
},
onHide:function(){
// 页面隐藏
},
onUnload:function(){
// 页面关闭
}
})
1 change: 1 addition & 0 deletions pages/editname/editname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions pages/editname/editname.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--pages/editname/editname.wxml-->
<view class="edit-box">
<view class="edit-dec">请在输入框编辑用户名</view>
<input value="{{userName}}" focus="true" confirm-type="提交" bindconfirm="submit"/>
</view>
16 changes: 16 additions & 0 deletions pages/editname/editname.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* pages/editname/editname.wxss */

.edit-box .edit-dec{
font-size: 24rpx;
color: #222;
margin: 30rpx 0 20rpx 20rpx;
}
.edit-box input{
border: 1px #efefef solid;
height: 88rpx;
line-height: 88rpx;
display: block;
background-color: #efefef;
padding-left: 20rpx;
font-size: 28rpx;
}
178 changes: 178 additions & 0 deletions pages/editphone/editphone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// pages/editphone/editphone.js
var util = require('../../utils/util.js');
var ports = require('../../utils/ports.js');
//引入倒计时组件
var CountDown = require('../../template/count-down/count-down.js');
var appInstance = getApp();
Page({
data:{
oldUserPhone: '',
newUserPhone: '',
code: '',
isNotSubmit: true,
},
judge: function(){
if(!appInstance.globalData.userInfo.hasData){
wx.navigateBack({
delta: 2
});
}
},
checkPhone: function(phone){
if(!/^1[34578]\d{9}$/.test(phone) || phone === ''){
return false;
}
return true;
},
checkOldPhone: function(e){
this.countDown.setDisabledValue(true);
if(!this.checkPhone(e.detail.value)){
return wx.showToast({
title: '旧手机号格式不正确或为空',
duration: 1000
});
}
var _this = this;
util.getToken().then(token => {
util.wxRequest({
method: 'POST',
url: ports.checkPhone,
header:{ 'X-Auth-Token': token, 'content-type': 'application/x-www-form-urlencoded'},
data: {
old_phone: e.detail.value
}
}).then((res) => {
if(res.status !== 0){
return wx.showToast({
title: res.msg,
duration: 1000
});
}
_this.countDown.setDisabledValue(false);
_this.setData({
oldUserPhone: e.detail.value
});
}).catch((err) => {
return wx.showToast({
title: err,
duration: 1000
});
});
});
},
updateNewPhone: function(e){
this.setData({
newUserPhone: e.detail.value
});
},
updateCode: function(e){
this.setData({
code: e.detail.value
});
},
_getCode: function(){
if(!this.checkPhone(this.data.newUserPhone)){
return wx.showToast({
title: '新手机号格式不正确或为空',
duration: 1000
});
}
var _this = this;
util.getToken().then(token => {
util.wxRequest({
method: 'POST',
url: ports.sendMsg,
header:{'X-Auth-Token': token, 'content-type': 'application/x-www-form-urlencoded'},
data: {
phone: _this.data.newUserPhone
}
}).then((res) => {

wx.showToast({
title: '请查收手机验证码',
duration: 1000
});
_this.setData({
isNotSubmit: false
});
_this.countDown.run(60);
}).catch((err) => {
return wx.showToast({
title: err,
duration: 1000
});
});
});
},
submit(){
var _this = this;
if(!this.checkPhone(this.data.newUserPhone)){
return wx.showToast({
title: '手机号格式不正确或为空',
duration: 1000
});
}
if(!/^\d{6}$/.test(this.code)){
return wx.showToast({
title: '验证码为6个数字',
duration: 1000
});
}
util.getToken().then(token => {
util.wxRequest({
method: 'POST',
url: ports.updatePhone,
header:{'X-Auth-Token':token, 'content-type': 'application/x-www-form-urlencoded'},
data: {
phone: _this.data.newUserPhone,
old_phone: _this.data.oldUserPhone,
verifycode: _this.data.code,
}
}).then((res) => {
if(res.status === 0){
appInstance.globalData.userInfo.phone = res.data.phone;
wx.showToast({
title: res.msg,
icon: 'success',
duration: 1000,
success: function(){
setTimeout(function(){
wx.navigateBack({
delta: 1
});
}, 1000);
}
});
}else{
return wx.showToast({
title: res.msg,
duration: 1000
});
}
}).catch((err) => {
return wx.showToast({
title: err,
duration: 1000
});
});
});
},
onLoad:function(options){
// 页面初始化 options为页面跳转所带来的参数
this.judge();
//初始化倒计时组件
this.countDown = new CountDown(this);
},
onReady:function(){
// 页面渲染完成
},
onShow:function(){
// 页面显示
},
onHide:function(){
// 页面隐藏
},
onUnload:function(){
// 页面关闭
}
})
1 change: 1 addition & 0 deletions pages/editphone/editphone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
17 changes: 17 additions & 0 deletions pages/editphone/editphone.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--pages/editphone/editphone.wxml-->
<import src="../../template/count-down/count-down.wxml"/>
<view class="phone-box">
<view class="check-box">
<view class="title">输入您当前微信账号绑定的手机号码以校验信息</view>
<input class="input" type="number" value="{{oldUserPhone}}" placeholder="手机号码" bindblur="checkOldPhone"/>
</view>
<view class="edit-box">
<view class="title">输入您需要绑定的新手机号码</view>
<input class="input new-phone" type="number" value="{{newUserPhone}}" placeholder="手机号码" bindinput="updateNewPhone"/>
<view class="code-box">
<input class="input" type="text" value="{{code}}" placeholder="短信验证码" bindinput="updateCode"/>
<template is="countDown" data="{{disabled: disabled, plain: plain, text: text}}" />
</view>
</view>
<button class="bind-btn" type="primary" disabled="{{isNotSubmit}}" bindtap="submit">验证重新绑定</button>
</view>
Loading

0 comments on commit aa44373

Please sign in to comment.