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