myEdit_20190327153148.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. avatar: this.user.avatar
  86. }
  87. httpRequestApi.settingUserInfo(data).success(res => {
  88. console.log(res.data.data); //修改资料成功后 调用 getUserInfo
  89. // wx.redirectTo({
  90. // url: '/pages/index/index?index=3'
  91. // });
  92. wx.setStorageSync('user', res.data.data);
  93. wx.navigateBack({
  94. delta: 1
  95. })
  96. });
  97. },
  98. /**
  99. * 生命周期函数--监听页面加载
  100. */
  101. getUserInfo: function () {
  102. },
  103. onLoad: function (option) {
  104. httpRequestApi.getUserInfo().success(res => {
  105. const user = res.data.data
  106. console.log(user)
  107. const birthday = user.birthday ? formatDate(user.birthday, 2) : '2018-01-01';
  108. console.log(birthday)
  109. this.setData({
  110. user: user,
  111. date: birthday,
  112. sexs: [{
  113. value: 2,
  114. checked: user.gender === 2 ? true : false,
  115. sex: '女'
  116. },
  117. {
  118. value: 1,
  119. checked: user.gender === 1 ? true : false,
  120. sex: '男'
  121. }
  122. ],
  123. occupations: [{
  124. value: '家长',
  125. checked: user.profession === '家长' ? true : false
  126. },
  127. {
  128. value: '老师',
  129. checked: user.profession === '老师' ? true : false
  130. },
  131. {
  132. value: '学生',
  133. checked: user.profession === '学生' ? true : false
  134. }
  135. ],
  136. })
  137. console.log(this.data.date)
  138. if (option.title) {
  139. wx.setNavigationBarTitle({
  140. title: option.title //页面标题为路由参数
  141. });
  142. this.setData({
  143. title: option.title
  144. });
  145. }
  146. httpRequestApi.userIntoPage('pages/user/myEdit/myEdit', '修改资料页面').success((res) => {
  147. })
  148. });
  149. },
  150. /**
  151. * 生命周期函数--监听页面初次渲染完成
  152. */
  153. onReady: function () {
  154. },
  155. /**
  156. * 生命周期函数--监听页面显示
  157. */
  158. onShow: function () {
  159. },
  160. /**
  161. * 生命周期函数--监听页面隐藏
  162. */
  163. onHide: function () {
  164. },
  165. /**
  166. * 生命周期函数--监听页面卸载
  167. */
  168. onUnload: function () {
  169. },
  170. /**
  171. * 页面相关事件处理函数--监听用户下拉动作
  172. */
  173. onPullDownRefresh: function () {
  174. },
  175. /**
  176. * 页面上拉触底事件的处理函数
  177. */
  178. onReachBottom: function () {
  179. },
  180. /**
  181. * 用户点击右上角分享
  182. */
  183. onShareAppMessage: function () {
  184. }
  185. })