123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // pages/setName/setName.js
- import httpRequestApi from '../../utils/APIRequest';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- phone: '',
- name: '',
- headImg: '../../static/image/default.png'
- },
- //获取输入名字
- getName: function ({detail}) {
- this.setData({
- name: detail.value,
- })
- },
- //获取输入手机号
- getPhone: function ({detail}) {
- this.setData({
- phone: detail.value,
- })
- },
- //更改头像
- setHead: function () {
- wx.chooseImage({
- count: 1, // 默认9
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
- success: (res) => {
- // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
- const tempFilePaths = res.tempFilePaths;
- //启动上传等待中...
- wx.showToast({
- title: '正在上传...',
- icon: 'loading',
- mask: true,
- duration: 1000
- })
- wx.navigateTo({
- url: '/pages/clip/clip?imageUrl=' + tempFilePaths[0]
- })
- }
- })
- },
- //保存修改
- Savemodification: function () {
- //console.log(this.data.name,this.data.phone);
- const name = this.data.name;
- const phone = this.data.phone;
- const reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
- if(phone !== '') {
- if(phone.length !== 11 || !reg.test(phone)){
- wx.showModal({
- title: '提示',
- content: '请输入正确手机号'
- })
- return;
- }
- }
- httpRequestApi.setUserInfo({
- "mobileNo": phone,
- "nickName": name,
- "avatar": this.data.headImg
- }).success(res => {
- if(res.data.success) {
- // wx.navigateTo({
- // url: '/pages/index/index?ind=2'
- // })
- wx.reLaunch({
- url: '/pages/index/index?ind=2'
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- //初始化获取个人信息
- httpRequestApi.getUserInfo().success(res => {
- const user = res.data.data;
- const headImg = options.imageUrl ? options.imageUrl : user.avatar;
- this.setData({
- name: user.nickName,
- phone: user.mobileNo,
- headImg
- })
- });
- if (options.imageUrl) {
- this.setData({
- headImg: options.imageUrl
- })
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|