setName.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // pages/setName/setName.js
  2. import httpRequestApi from '../../utils/APIRequest';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. phone: '',
  9. name: '',
  10. headImg: '../../static/image/default.png'
  11. },
  12. //获取输入名字
  13. getName: function ({detail}) {
  14. this.setData({
  15. name: detail.value,
  16. })
  17. },
  18. //获取输入手机号
  19. getPhone: function ({detail}) {
  20. this.setData({
  21. phone: detail.value,
  22. })
  23. },
  24. //更改头像
  25. setHead: function () {
  26. wx.chooseImage({
  27. count: 1, // 默认9
  28. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  29. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  30. success: (res) => {
  31. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  32. const tempFilePaths = res.tempFilePaths;
  33. //启动上传等待中...
  34. wx.showToast({
  35. title: '正在上传...',
  36. icon: 'loading',
  37. mask: true,
  38. duration: 1000
  39. })
  40. wx.navigateTo({
  41. url: '/pages/clip/clip?imageUrl=' + tempFilePaths[0]
  42. })
  43. }
  44. })
  45. },
  46. //保存修改
  47. Savemodification: function () {
  48. //console.log(this.data.name,this.data.phone);
  49. const name = this.data.name;
  50. const phone = this.data.phone;
  51. const reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
  52. if(phone !== '') {
  53. if(phone.length !== 11 || !reg.test(phone)){
  54. wx.showModal({
  55. title: '提示',
  56. content: '请输入正确手机号'
  57. })
  58. return;
  59. }
  60. }
  61. httpRequestApi.setUserInfo({
  62. "mobileNo": phone,
  63. "nickName": name,
  64. "avatar": this.data.headImg
  65. }).success(res => {
  66. if(res.data.success) {
  67. // wx.navigateTo({
  68. // url: '/pages/index/index?ind=2'
  69. // })
  70. wx.reLaunch({
  71. url: '/pages/index/index?ind=2'
  72. })
  73. }
  74. })
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. */
  79. onLoad: function (options) {
  80. //初始化获取个人信息
  81. httpRequestApi.getUserInfo().success(res => {
  82. const user = res.data.data;
  83. const headImg = options.imageUrl ? options.imageUrl : user.avatar;
  84. this.setData({
  85. name: user.nickName,
  86. phone: user.mobileNo,
  87. headImg
  88. })
  89. });
  90. if (options.imageUrl) {
  91. this.setData({
  92. headImg: options.imageUrl
  93. })
  94. }
  95. },
  96. /**
  97. * 页面相关事件处理函数--监听用户下拉动作
  98. */
  99. onPullDownRefresh: function () {
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. onReachBottom: function () {
  105. },
  106. /**
  107. * 用户点击右上角分享
  108. */
  109. onShareAppMessage: function () {
  110. }
  111. })