myEdit_20190327151604.js 4.3 KB

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