123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- // pages/ucenter/center/center.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- userInfo: {},
- isLogin: false,
- isBindPhone:0,
- sexType: [
- {
- value: 0,
- text: '保密'
- },{
- value: 1,
- text: '男'
- }, {
- value: 2,
- text: '女'
- }],
- sexIndex: 0,
- carNum: null,
- email: null,
- checkPass: false,
- errorMsg: ''
- },
- inputSex(e) {
- this.setData({
- sexIndex: parseInt(e.detail.value)
- });
- let userdata= {
- sexIndex: e.detail.value,
- carNum: null,
- email: null,
- };
- this.bindUpdateUser(userdata);
- },
- inputCarNum(e){
- let that = this;
- wx.showModal({
- title: '修改车牌号',
- showCancel:true,
- editable: true,
- confirmColor:'#00AADD',
- success: function (res1) {
- if (res1.confirm) {
- let carNum = res1.content;
- that.confirmCarNum(carNum);
- }
- }
- });
- },
- confirmCarNum(carNum) {
- if (!this.checkCarNum(carNum)) {
- wx.showModal({
- title: '提示',
- showCancel:false,
- content: '车牌号输入有误,请重新输入',
- confirmColor:'#00AADD',
- });
- return;
- } else {
- this.setData({
- carNum: carNum,
- errorMsg: ''
- });
- }
- let userdata= {
- sexIndex: null,
- carNum: carNum,
- email: null,
- };
- this.bindUpdateUser(userdata);
- },
- inputEmail(e) {
- let that = this;
- wx.showModal({
- title: '修改邮箱',
- showCancel:true,
- editable: true,
- confirmColor:'#00AADD',
- success: function (res1) {
- if (res1.confirm) {
- let email = res1.content;
- that.confirmEmail(email);
- }
- }
- });
- },
- confirmEmail(email) {
- if (!this.checkMail(email)) {
- wx.showModal({
- title: '提示',
- showCancel:false,
- content: '邮箱输入有误,请重新输入',
- confirmColor:'#00AADD',
- });
- return;
- } else {
- this.setData({
- email: email,
- errorMsg: ''
- });
- }
- let userdata= {
- sexIndex: null,
- carNum: null,
- email: email
- };
- this.bindUpdateUser(userdata);
- },
- checkMail(email) {
- if(email){
- if (!(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(email))) {
- return false;
- }
- }
- return true;
- },
- checkCarNum(carNum){
- if (carNum){
- // if (!(/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/.test(this.data.carNum))) {
- if (!/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领].*$/.test(carNum)) {
- return false;
- }
- }
- return true;
- },
- bindUpdateUser(userdata) {
- let that = this;
- let loginName = this.data.userInfo.loginName;
- let {
- sexIndex,
- carNum: license_number,
- email
- } = userdata;
- var sex = null;
- if (sexIndex!=null){
- sex = this.data.sexType[sexIndex].value;
- }
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/updateUser',
- data: {
- loginName,
- sex: sex,
- license_number,
- email,
- },
- method: 'POST',
- success(res1) {
- if (res1.data.code == 1) {
- that.setData({
- errorMsg: res1.data.msg
- })
- }else if (res1.data.code == 2) {
- wx.showModal({
- title: '提示',
- content: '您未绑定手机号,请重新登录后自动刷新绑定信息',
- confirmText: '去登录',
- showCancel:false,
- confirmColor:'#00AADD',
- success: function (res1) {
- if (res1.confirm) {
- wx.removeStorageSync('userInfo');
- wx.removeStorageSync('isLogin');
- let url = '/pages/login/phone_login/phone_login';
- wx.redirectTo({
- url
- })
- }
- }
- });
- } else {
- //返回该用户
- //跳转到上一页
- wx.setStorageSync("userInfo", res1.data);
- wx.setStorageSync("isLogin", true);
- let userInfo = wx.getStorageSync('userInfo');
- console.info("fffffffffffff")
- console.info(userInfo)
- that.setData({
- userInfo: userInfo
- });
-
- // 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,
- isBindPhone: userInfo.bindingPhone,
- carNum: userInfo.license_number,
- email:userInfo.email,
- sexIndex:userInfo.sex
- });
- } else {
- //未登录信息
- this.setData({
- userInfo: {}
- });
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|