phoneEdit.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {
  2. get, post,
  3. } from '../../utils/http';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userInfo: {},
  10. customerInfo: {},
  11. name: '',
  12. type: '',
  13. userId: '',
  14. phone:''
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. console.log(options)
  21. if(options.userId) {
  22. this.setData({
  23. phone: options.phone,
  24. name: options.name,
  25. type: options.type,
  26. userId: options.userId
  27. })
  28. } else {
  29. this.getUserFiles()
  30. }
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面隐藏
  44. */
  45. onHide: function () {
  46. },
  47. /**
  48. * 生命周期函数--监听页面卸载
  49. */
  50. onUnload: function () {
  51. },
  52. /**
  53. * 页面相关事件处理函数--监听用户下拉动作
  54. */
  55. onPullDownRefresh: function () {
  56. },
  57. /**
  58. * 页面上拉触底事件的处理函数
  59. */
  60. onReachBottom: function () {
  61. },
  62. /**
  63. * 用户点击右上角分享
  64. */
  65. onShareAppMessage: function () {
  66. },
  67. /**
  68. * 监听输入姓名
  69. */
  70. onChangePhone(e) {
  71. this.setData({
  72. phone: e.detail.value,
  73. })
  74. },
  75. /**
  76. * 更新客户档案
  77. * Customer
  78. *
  79. */
  80. setCustomerInfo() {
  81. let { userInfo,type,userId,phone } = this.data;
  82. var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  83. if(!myreg.test(phone)) {
  84. wx.showToast({
  85. title: '手机号格式不正确',
  86. icon: 'none'
  87. })
  88. return;
  89. }
  90. post('api/user/update',{
  91. user_id: userId,
  92. mobile: phone
  93. },(res) => {
  94. wx.showToast({
  95. title: '修改成功',
  96. })
  97. setTimeout(() => {
  98. wx.navigateBack()
  99. }, 1000);
  100. })
  101. },
  102. /**
  103. * 获取美导师用户档案
  104. * api/user/files
  105. */
  106. getUserFiles() {
  107. get('api/mruser/info', {}, (res) => {
  108. this.setData({
  109. userInfo: res.data
  110. })
  111. })
  112. },
  113. /**
  114. * 更新美导师档案
  115. * api/user/save_files
  116. */
  117. setUserFiles() {
  118. let {
  119. avatar_url,
  120. realname,
  121. birthday,
  122. sex,
  123. city
  124. } = this.data.userInfo;
  125. post('api/mruser/update', {
  126. avatar_url,
  127. realname,
  128. birthday,
  129. sex,
  130. city
  131. }, () => {
  132. wx.showToast({
  133. title: '修改成功',
  134. })
  135. setTimeout(() => {
  136. wx.navigateBack()
  137. }, 1000);
  138. })
  139. }
  140. })