myEdit_20190327153000.js 4.4 KB

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