myEdit.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. gradeIndex: 0,
  17. gradeArray: ['一年级', '二年级', '三年级', '四年级', '学前班'],
  18. gradeCode: '',
  19. statusbarobj: {
  20. isshowbtn: false, //是否显示按钮
  21. title: "小学语文朗读配音", //标题
  22. },
  23. gradeObject: [{
  24. code: 'PRIMARY_FIRST_GRADE',
  25. name: '一年级'
  26. },
  27. {
  28. code: 'PRIMARY_SECOND_GRADE',
  29. name: '二年级'
  30. },
  31. {
  32. code: 'PRIMARY_THREE_GRADE',
  33. name: '三年级'
  34. },
  35. {
  36. code: 'PRIMARY_SENIOR_GRADE',
  37. name: '四年级'
  38. },
  39. {
  40. code: 'PRESCHOOL',
  41. name: '学前班'
  42. }
  43. ],
  44. },
  45. chooseGrade: function (e) {
  46. console.log('选择年级')
  47. },
  48. saveNickName: function (e) {
  49. let nickname = e.detail.value;
  50. this.setData({
  51. nicename: nickname
  52. });
  53. },
  54. saveAddress: function (e) {
  55. let msg = e.detail.value;
  56. this.setData({
  57. msg: msg
  58. });
  59. },
  60. bindDateChange: function (e) {
  61. console.log(e.detail.value)
  62. this.setData({
  63. date: e.detail.value
  64. });
  65. },
  66. changeAvatar: function (e) {
  67. const {
  68. avatarUrl
  69. } = e.detail
  70. wx.uploadFile({
  71. url: 'https://reader-api.ai160.com/file/upload',
  72. filePath: avatarUrl,
  73. name: '头像',
  74. header: {
  75. uid: wx.getStorageSync('uid')
  76. },
  77. success: (res) => {
  78. const newAvatar = JSON.parse(res.data).data;
  79. const str = 'user.avatar'
  80. this.setData({
  81. [str]: newAvatar
  82. })
  83. }
  84. })
  85. },
  86. formSubmit: function (e) {
  87. if (e.detail.value.nickname === '') {
  88. wx.showToast({
  89. title: '请填写昵称',
  90. icon: "none"
  91. })
  92. return false
  93. }
  94. // const uid = wx.getStorageSync('uid');
  95. const data = {
  96. nickName: e.detail.value.nickname || '',
  97. gender: e.detail.value.radioGroup1,
  98. schoolName: e.detail.value.address || '',
  99. birthday: e.detail.value.picker || '',
  100. avatar: this.data.user.avatar,
  101. grade: this.data.gradeCode
  102. }
  103. httpRequestApi.settingUserInfo(data).success(res => {
  104. console.log(res.data.data); //修改资料成功后 调用 getUserInfo
  105. // wx.redirectTo({
  106. // url: '/pages/index/index?index=3'
  107. // });
  108. wx.setStorageSync('user', res.data.data);
  109. wx.setStorageSync('grade', res.data.data.grade);
  110. wx.navigateBack({
  111. delta: 1
  112. })
  113. });
  114. },
  115. bindGradeChange: function (e) {
  116. console.log('年级选择', e)
  117. this.setData({
  118. gradeIndex: e.detail.value,
  119. gradeCode: this.data.gradeObject[e.detail.value].code
  120. }, () => {
  121. console.log(this.data.gradeCode)
  122. })
  123. },
  124. /**
  125. * 生命周期函数--监听页面加载
  126. */
  127. getUserInfo: function () {
  128. },
  129. onLoad: function (option) {
  130. httpRequestApi.getUserInfo().success(res => {
  131. const user = res.data.data;
  132. let gradeIndex = 0;
  133. this.data.gradeObject.forEach((item, index) => {
  134. console.log('年级index', item)
  135. console.log('年级index', item)
  136. if (item.code === user.grade) {
  137. console.log('年级index', index)
  138. gradeIndex = index
  139. }
  140. console.log(user)
  141. const birthday = user.birthday ? formatDate(user.birthday, 2) : '2018-01-01';
  142. console.log(birthday)
  143. this.setData({
  144. user: user,
  145. date: birthday,
  146. sexs: [{
  147. value: 2,
  148. checked: user.gender === 2 ? true : false,
  149. sex: '女'
  150. },
  151. {
  152. value: 1,
  153. checked: user.gender === 1 ? true : false,
  154. sex: '男'
  155. }
  156. ],
  157. occupations: [{
  158. value: '家长',
  159. checked: user.profession === '家长' ? true : false
  160. },
  161. {
  162. value: '老师',
  163. checked: user.profession === '老师' ? true : false
  164. },
  165. {
  166. value: '学生',
  167. checked: user.profession === '学生' ? true : false
  168. }
  169. ],
  170. gradeIndex
  171. })
  172. })
  173. console.log(this.data.date)
  174. if (option.title) {
  175. wx.setNavigationBarTitle({
  176. title: option.title //页面标题为路由参数
  177. });
  178. this.setData({
  179. title: option.title
  180. });
  181. }
  182. httpRequestApi.userIntoPage('pages/user/myEdit/myEdit', '修改资料页面').success((res) => {
  183. })
  184. });
  185. },
  186. /**
  187. * 生命周期函数--监听页面初次渲染完成
  188. */
  189. onReady: function () {
  190. },
  191. /**
  192. * 生命周期函数--监听页面显示
  193. */
  194. onShow: function () {
  195. },
  196. /**
  197. * 生命周期函数--监听页面隐藏
  198. */
  199. onHide: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面卸载
  203. */
  204. onUnload: function () {
  205. },
  206. /**
  207. * 页面相关事件处理函数--监听用户下拉动作
  208. */
  209. onPullDownRefresh: function () {
  210. },
  211. /**
  212. * 页面上拉触底事件的处理函数
  213. */
  214. onReachBottom: function () {
  215. },
  216. /**
  217. * 用户点击右上角分享
  218. */
  219. onShareAppMessage() {
  220. return {
  221. title: '课文朗读,从未如此有趣。',
  222. path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
  223. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
  224. }
  225. }
  226. })