123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- // pages/ucenter/center/center.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- userInfo: {},
- isLogin: false,
- sexType: [{
- value: 1,
- text: '男'
- }, {
- value: 2,
- text: '女'
- }],
- sexIndex: null,
- phone: null,
- email: null,
- checkPass: false,
- errorMsg: ''
- },
- inputSex(e) {
- //console.log(this.data.sexType[e.detail.value]);
- this.setData({
- sexIndex: e.detail.value
- });
- this.checkAll();
- },
- inputPhone(e) {
- this.setData({
- phone: e.detail.value
- });
- this.checkAll();
- },
- inputEmail(e) {
- this.setData({
- email: e.detail.value
- });
- this.checkAll();
- },
- checkPhone() {
- if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
- return false;
- }
- return true;
- },
- checkMail() {
- if (!(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(this.data.email))) {
- return false;
- }
- return true;
- },
- checkAll() {
- if (this.data.userInfo.sex == null || (this.data.userInfo.sex != 1 && this.data.userInfo.sex != 2)){
- if (!this.data.sexIndex) {
- this.setData({
- errorMsg: '请选择性别'
- });
- this.setData({
- checkPass: false
- });
- return;
- } else {
- this.setData({
- errorMsg: ''
- });
- }
- }
- if (!this.checkPhone()) {
- this.setData({
- errorMsg: '手机号输入有误,请重新输入'
- });
- this.setData({
- checkPass: false
- });
- return;
- } else {
- this.setData({
- errorMsg: ''
- });
- }
- if (!this.checkMail()) {
- this.setData({
- errorMsg: '邮箱输入有误,请重新输入'
- });
- this.setData({
- checkPass: false
- });
- return;
- } else {
- this.setData({
- errorMsg: ''
- });
- }
- this.setData({
- checkPass: true
- });
- },
- bindUpdateUser() {
- let that = this;
- let loginName = this.data.userInfo.loginName;
- let {
- sexIndex,
- phone,
- email
- } = this.data;
- var sex = null;
- if (sexIndex!=null){
- sex = this.data.sexType[sexIndex].value;
- }else{
- sex = this.data.userInfo.sex;
- }
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/updateUser',
- data: {
- loginName,
- sex: sex,
- phonenumber: phone,
- email,
- },
- method: 'POST',
- success(res1) {
- //console.log(res1);
- //console.log(res1.data.code == 1);
- if (res1.data.code == 1) {
- that.setData({
- errorMsg: res1.data.msg
- })
- } else {
- //返回该用户
- //跳转到上一页
- wx.setStorageSync("userInfo", res1.data);
- wx.setStorageSync("isLogin", true);
- wx.navigateBack();
- //let url = `/pages/ucenter/index/index`;
- //wx.redirectTo({
- //url
- //});
- }
- }
- });
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- // 页面显示
- if (userInfo && isLogin) {
- //userInfo.flag = true;
- //console.log(userInfo);
- this.setData({
- userInfo: userInfo,
- isLogin: isLogin,
- phone: userInfo.phonenumber,
- email:userInfo.email
- });
- } else {
- //未登录信息
- this.setData({
- userInfo: {}
- });
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|