myEdit_20190327151535.js 4.2 KB

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