myEdit_20190123180844.js 3.6 KB

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