myEdit.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. if(e.detail.value.nickname === ''){
  44. return false
  45. }
  46. // const uid = wx.getStorageSync('uid');
  47. const data = {
  48. wechatName: e.detail.value.nickname || '',
  49. mobile: '',
  50. gender: e.detail.value.radioGroup1,
  51. schoolProvince: '',
  52. schoolCity: '',
  53. schoolName: e.detail.value.address || '',
  54. profession: e.detail.value.radioGroup2 || '',
  55. birthday: e.detail.value.picker || ''
  56. }
  57. httpRequestApi.settingUserInfo(data).success(res => {
  58. console.log(res.data.data); //修改资料成功后 调用 getUserInfo
  59. // wx.redirectTo({
  60. // url: '/pages/index/index?index=3'
  61. // });
  62. wx.navigateBack({
  63. delta: 1
  64. })
  65. });
  66. },
  67. /**
  68. * 生命周期函数--监听页面加载
  69. */
  70. getUserInfo: function () {
  71. },
  72. onLoad: function (option) {
  73. httpRequestApi.getUserInfo().success(res => {
  74. const user = res.data.data
  75. console.log(user)
  76. const birthday = user.birthday ? formatDate(user.birthday, 2) : '2018-01-01';
  77. console.log(birthday)
  78. this.setData({
  79. user: user,
  80. date: birthday,
  81. sexs: [{
  82. value: 2,
  83. checked: user.gender === 2 ? true : false,
  84. sex: '女'
  85. },
  86. {
  87. value: 1,
  88. checked: user.gender === 1 ? true : false,
  89. sex: '男'
  90. }
  91. ],
  92. occupations: [{
  93. value: '家长',
  94. checked: user.profession === '家长' ? true : false
  95. },
  96. {
  97. value: '老师',
  98. checked: user.profession === '老师' ? true : false
  99. },
  100. {
  101. value: '学生',
  102. checked: user.profession === '学生' ? true : false
  103. }
  104. ],
  105. })
  106. console.log(this.data.date)
  107. if (option.title) {
  108. wx.setNavigationBarTitle({
  109. title: option.title //页面标题为路由参数
  110. });
  111. this.setData({
  112. title: option.title
  113. });
  114. }
  115. });
  116. },
  117. /**
  118. * 生命周期函数--监听页面初次渲染完成
  119. */
  120. onReady: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面隐藏
  129. */
  130. onHide: function () {
  131. },
  132. /**
  133. * 生命周期函数--监听页面卸载
  134. */
  135. onUnload: function () {
  136. },
  137. /**
  138. * 页面相关事件处理函数--监听用户下拉动作
  139. */
  140. onPullDownRefresh: function () {
  141. },
  142. /**
  143. * 页面上拉触底事件的处理函数
  144. */
  145. onReachBottom: function () {
  146. },
  147. /**
  148. * 用户点击右上角分享
  149. */
  150. onShareAppMessage: function () {
  151. }
  152. })