ispUserInfo.js 3.8 KB

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