myEdit_20190327152518.js 4.4 KB

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