myEdit.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. user: {},
  11. sexs: [],
  12. occupations: [],
  13. date: '',
  14. msg: '',
  15. nickname: ''
  16. },
  17. saveNickName: function (e) {
  18. let nickname = e.detail.value;
  19. this.setData({
  20. nicename: nickname
  21. });
  22. },
  23. saveAddress: function (e) {
  24. let msg = e.detail.value;
  25. this.setData({
  26. msg: msg
  27. });
  28. },
  29. bindDateChange: function (e) {
  30. console.log(e.detail.value)
  31. this.setData({
  32. date: e.detail.value
  33. });
  34. },
  35. optionAction: function (e) {
  36. console.log(e.detail.value);
  37. },
  38. optionSetting: function (e) {
  39. console.log(e.detail.value);
  40. },
  41. formSubmit: function (e) {
  42. console.log(e.detail.value)
  43. // const uid = wx.getStorageSync('uid');
  44. const data = {
  45. wechatName: e.detail.value.nickname || '',
  46. mobile: '',
  47. gender: e.detail.value.radioGroup1,
  48. schoolProvince: '',
  49. schoolCity: '',
  50. schoolName: e.detail.value.address || '',
  51. profession: e.detail.value.radioGroup2 || '',
  52. birthday: e.detail.value.picker || ''
  53. }
  54. httpRequestApi.settingUserInfo(data).success(res => {
  55. console.log(res.data.data); //修改资料成功后 调用 getUserInfo
  56. // wx.redirectTo({
  57. // url: '/pages/index/index?index=3'
  58. // });
  59. wx.navigateBack({
  60. delta: 1
  61. })
  62. });
  63. },
  64. /**
  65. * 生命周期函数--监听页面加载
  66. */
  67. getUserInfo: function () {
  68. },
  69. onLoad: function (option) {
  70. httpRequestApi.getUserInfo().success(res => {
  71. const user = res.data.data
  72. console.log(user)
  73. const birthday = user.birthday ? formatDate(user.birthday, 2) : '2018-01-01';
  74. console.log(birthday)
  75. this.setData({
  76. user: user,
  77. date: birthday,
  78. sexs: [{
  79. value: 2,
  80. checked: user.gender === 2 ? true : false,
  81. sex: '女'
  82. },
  83. {
  84. value: 1,
  85. checked: user.gender === 1 ? true : false,
  86. sex: '男'
  87. }
  88. ],
  89. occupations: [{
  90. value: '家长',
  91. checked: user.profession === '家长' ? true : false
  92. },
  93. {
  94. value: '老师',
  95. checked: user.profession === '老师' ? true : false
  96. },
  97. {
  98. value: '学生',
  99. checked: user.profession === '学生' ? true : false
  100. }
  101. ],
  102. })
  103. console.log(this.data.date)
  104. if (option.title) {
  105. wx.setNavigationBarTitle({
  106. title: option.title //页面标题为路由参数
  107. });
  108. this.setData({
  109. title: option.title
  110. });
  111. }
  112. });
  113. },
  114. /**
  115. * 生命周期函数--监听页面初次渲染完成
  116. */
  117. onReady: function () {
  118. },
  119. /**
  120. * 生命周期函数--监听页面显示
  121. */
  122. onShow: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面隐藏
  126. */
  127. onHide: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面卸载
  131. */
  132. onUnload: function () {
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh: function () {
  138. },
  139. /**
  140. * 页面上拉触底事件的处理函数
  141. */
  142. onReachBottom: function () {
  143. },
  144. /**
  145. * 用户点击右上角分享
  146. */
  147. onShareAppMessage: function () {
  148. }
  149. })