operUserInfo.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // pages/operUserInfo/operUserInfo.js
  2. const app = getApp()
  3. const utils = require('../../utils/util.js')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. globalUrl: app.globalData.globalUrl,
  10. userInfo: '', //缓存的用户信息
  11. user: '', //用户信息
  12. other: '', //角色信息
  13. sex: ['男', '女'], //性别列表
  14. sexIndex: '', //当前性别下标
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. this.setData({
  21. userInfo: utils.getInfo()
  22. })
  23. this.getUser()
  24. },
  25. //获取用户信息
  26. getUser() {
  27. utils.getUser({
  28. sendBefore: () => {
  29. wx.showLoading({
  30. title: '加载中...',
  31. mask: true
  32. })
  33. },
  34. complete: () => {
  35. wx.hideLoading()
  36. }
  37. }).then(res => {
  38. if (res.data.sex) {
  39. if (res.data.sex === 'M') {
  40. this.setData({
  41. sexIndex: 0
  42. })
  43. } else if (res.data.sex === 'F') {
  44. this.setData({
  45. sexIndex: 1
  46. })
  47. }
  48. }
  49. this.setData({
  50. user: res.data
  51. })
  52. })
  53. },
  54. //修改或者上传头像
  55. uploadAvatar() {
  56. utils.chooseImage({
  57. sendBefore: () => {
  58. wx.showLoading({
  59. title: '上传中...'
  60. })
  61. }
  62. }).then(res => {
  63. utils.uploadFile({
  64. name: 'file',
  65. url: '/auth/comm/user/avatar/update',
  66. filePath: res.tempFilePaths[0],
  67. formData: {
  68. mobile: this.data.userInfo.mobile,
  69. reqChannel: 5
  70. },
  71. complete: () => {
  72. wx.hideLoading()
  73. }
  74. }).then(res => {
  75. this.updateSuccess()
  76. })
  77. })
  78. },
  79. //修改其他字段
  80. request(params) {
  81. utils.axios({
  82. method: 'post',
  83. url: '/auth/comm/user/personalInfo/save',
  84. data: params,
  85. success: res => {
  86. this.updateSuccess()
  87. }
  88. })
  89. },
  90. //信息修改成功执行的字段
  91. updateSuccess() {
  92. utils.toast('信息修改成功')
  93. this.selectComponent('#nickName').hideModal()
  94. this.selectComponent('#intro').hideModal()
  95. this.getUser()
  96. },
  97. //昵称
  98. showNickName() {
  99. this.selectComponent('#nickName').showModal()
  100. },
  101. getNickName(e) {
  102. let params = {
  103. mobile: this.data.userInfo.mobile,
  104. reqChannel: 5,
  105. nickName: e.detail
  106. }
  107. this.request(params)
  108. },
  109. //性别
  110. setSex(e) {
  111. let sexList = ['M', 'F']
  112. let params = {
  113. mobile: this.data.userInfo.mobile,
  114. reqChannel: 5,
  115. sex: sexList[e.detail.value]
  116. }
  117. this.request(params)
  118. },
  119. //个人简介
  120. showIntro() {
  121. this.selectComponent('#intro').showModal()
  122. },
  123. getIntro(e) {
  124. let params = {
  125. mobile: this.data.userInfo.mobile,
  126. reqChannel: 5,
  127. personalProfile: e.detail
  128. }
  129. this.request(params)
  130. },
  131. /**
  132. * 生命周期函数--监听页面初次渲染完成
  133. */
  134. onReady: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面显示
  138. */
  139. onShow: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面隐藏
  143. */
  144. onHide: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面卸载
  148. */
  149. onUnload: function () {
  150. },
  151. /**
  152. * 页面相关事件处理函数--监听用户下拉动作
  153. */
  154. onPullDownRefresh: function () {
  155. },
  156. /**
  157. * 页面上拉触底事件的处理函数
  158. */
  159. onReachBottom: function () {
  160. },
  161. /**
  162. * 用户点击右上角分享
  163. */
  164. onShareAppMessage: function () {
  165. return {
  166. title: '诺信云',
  167. path: '/pages/index/index'
  168. }
  169. }
  170. })