127 lines
3.6 KiB
JavaScript
127 lines
3.6 KiB
JavaScript
// pages/mine/mineAccount/mineInfo/mineInfo.js
|
|
import UserApi from '../../../../net/api/userApi'
|
|
const {
|
|
isValidPhone
|
|
} = require('../../../../utils/validator')
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
userInfo: null,
|
|
showError: false,
|
|
errorHint: '',
|
|
showSuccess: false,
|
|
successHint: '',
|
|
infoHint: '',
|
|
showInfo: false
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
wx.setNavigationBarTitle({
|
|
title: '个人信息',
|
|
})
|
|
wx.setNavigationBarColor({
|
|
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
|
|
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
|
|
animation: { // 可选项
|
|
duration: 500,
|
|
timingFunc: 'easeIn'
|
|
}
|
|
})
|
|
this.doGetMineInfo()
|
|
},
|
|
//输入姓名
|
|
inputName(e) {
|
|
console.log(e)
|
|
this.setData({
|
|
'userInfo.userInfoName': e.detail.value
|
|
})
|
|
},
|
|
//输入电话号码
|
|
inputPhone(e) {
|
|
console.log(e)
|
|
this.setData({
|
|
'userInfo.contactPhone': e.detail.value
|
|
})
|
|
},
|
|
//校验参数
|
|
checkParams() {
|
|
if (this.data.userInfo.userInfoName == '') {
|
|
this.setData({
|
|
errorHint: '请输入姓名',
|
|
showError: true
|
|
})
|
|
return false
|
|
}
|
|
if (this.data.userInfo.contactPhone == '' || !isValidPhone(this.data.userInfo.contactPhone)) {
|
|
this.setData({
|
|
errorHint: '请输入正确的联系电话',
|
|
showError: true
|
|
})
|
|
return false
|
|
}
|
|
return true
|
|
},
|
|
//修改信息
|
|
doUpdateInfo() {
|
|
const _self = this
|
|
const isLegal = _self.checkParams()
|
|
if (isLegal) {
|
|
wx.showLoading({
|
|
title: '保存中...',
|
|
})
|
|
const data = {
|
|
userInfoName: _self.data.userInfo.userInfoName,
|
|
contactPhone: _self.data.userInfo.contactPhone,
|
|
idCardType: 'ID_CARD',
|
|
userInfoType: 'PERSONAL',
|
|
}
|
|
UserApi.doUpdateUserInfo(data)
|
|
.then(res => {
|
|
wx.hideLoading()
|
|
console.log(res)
|
|
_self.setData({
|
|
successHint: '个人信息修改成功',
|
|
showSuccess: true
|
|
})
|
|
})
|
|
.catch(err => {
|
|
wx.hideLoading()
|
|
_self.setData({
|
|
errorHint: err.msg ? err.msg : '信息修改失败,请稍后重试',
|
|
showError: true
|
|
})
|
|
})
|
|
}
|
|
},
|
|
//获取个人信息
|
|
doGetMineInfo() {
|
|
const _self = this
|
|
wx.showLoading({
|
|
title: '加载中...',
|
|
})
|
|
UserApi.doGetUserInfo()
|
|
.then(res => {
|
|
console.log(res)
|
|
wx.hideLoading()
|
|
_self.setData({
|
|
userInfo: res
|
|
})
|
|
}, err => {
|
|
wx.hideLoading()
|
|
console.log(res)
|
|
_self.setData({
|
|
errorHint: '个人信息获取过程中出现异常,建议您稍作等待后再次尝试。',
|
|
showError: true
|
|
})
|
|
setTimeout(() => {
|
|
wx.navigateBack()
|
|
}, 1500);
|
|
})
|
|
}
|
|
}) |