myEdit_20190327152604.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. changeAvatar: function (e) {
  42. wx.chooseImage({
  43. count: 1,
  44. sizeType: ['compressed'],
  45. sourceType: ['album', 'camera'],
  46. success(res) {
  47. // tempFilePath可以作为img标签的src属性显示图片
  48. const localImage = res.tempFilePaths[0];
  49. wx.uploadFile({
  50. url: 'https://readertest.lingjiao.cn/readerBase/file/upload',
  51. filePath: localImage,
  52. name: '头像',
  53. header: {
  54. uid: wx.getStorageSync('uid')
  55. },
  56. success: (res) => {
  57. // console.log(JSON.parse(res.data));
  58. const newAvatar = JSON.parse(res.data).data;
  59. const str = 'user.avatar'
  60. this.setData({
  61. [str]: newAvatar
  62. })
  63. }
  64. })
  65. }
  66. })
  67. },
  68. formSubmit: function (e) {
  69. console.log(e.detail.value)
  70. if (e.detail.value.nickname === '') {
  71. return false
  72. }
  73. // const uid = wx.getStorageSync('uid');
  74. const data = {
  75. nickName: e.detail.value.nickname || '',
  76. mobile: '',
  77. gender: e.detail.value.radioGroup1,
  78. schoolProvince: '',
  79. schoolCity: '',
  80. schoolName: e.detail.value.address || '',
  81. profession: e.detail.value.radioGroup2 || '',
  82. birthday: e.detail.value.picker || ''
  83. }
  84. httpRequestApi.settingUserInfo(data).success(res => {
  85. console.log(res.data.data); //修改资料成功后 调用 getUserInfo
  86. // wx.redirectTo({
  87. // url: '/pages/index/index?index=3'
  88. // });
  89. wx.setStorageSync('user', res.data.data);
  90. wx.navigateBack({
  91. delta: 1
  92. })
  93. });
  94. },
  95. /**
  96. * 生命周期函数--监听页面加载
  97. */
  98. getUserInfo: function () {
  99. },
  100. onLoad: function (option) {
  101. httpRequestApi.getUserInfo().success(res => {
  102. const user = res.data.data
  103. console.log(user)
  104. const birthday = user.birthday ? formatDate(user.birthday, 2) : '2018-01-01';
  105. console.log(birthday)
  106. this.setData({
  107. user: user,
  108. date: birthday,
  109. sexs: [{
  110. value: 2,
  111. checked: user.gender === 2 ? true : false,
  112. sex: '女'
  113. },
  114. {
  115. value: 1,
  116. checked: user.gender === 1 ? true : false,
  117. sex: '男'
  118. }
  119. ],
  120. occupations: [{
  121. value: '家长',
  122. checked: user.profession === '家长' ? true : false
  123. },
  124. {
  125. value: '老师',
  126. checked: user.profession === '老师' ? true : false
  127. },
  128. {
  129. value: '学生',
  130. checked: user.profession === '学生' ? true : false
  131. }
  132. ],
  133. })
  134. console.log(this.data.date)
  135. if (option.title) {
  136. wx.setNavigationBarTitle({
  137. title: option.title //页面标题为路由参数
  138. });
  139. this.setData({
  140. title: option.title
  141. });
  142. }
  143. httpRequestApi.userIntoPage('pages/user/myEdit/myEdit', '修改资料页面').success((res) => {
  144. })
  145. });
  146. },
  147. /**
  148. * 生命周期函数--监听页面初次渲染完成
  149. */
  150. onReady: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面显示
  154. */
  155. onShow: function () {
  156. },
  157. /**
  158. * 生命周期函数--监听页面隐藏
  159. */
  160. onHide: function () {
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload: function () {
  166. },
  167. /**
  168. * 页面相关事件处理函数--监听用户下拉动作
  169. */
  170. onPullDownRefresh: function () {
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. onReachBottom: function () {
  176. },
  177. /**
  178. * 用户点击右上角分享
  179. */
  180. onShareAppMessage: function () {
  181. }
  182. })