clientInfoEdit.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import {
  2. get, post,
  3. } from '../../utils/http';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userInfo: {},
  10. visible: false,
  11. genders: ["男","女"],
  12. genderIndex: 0,
  13. date: '2016-09-01',
  14. region: ['广东省', '广州市', '海珠区'],
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. console.log(options)
  21. if(options.userId) {
  22. this.setData({
  23. userId: options.userId
  24. },() => {
  25. // this.getUserInfo()
  26. })
  27. }
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow: function () {
  38. // this.getUserFiles()
  39. this.getUserInfo()
  40. },
  41. /**
  42. * 生命周期函数--监听页面隐藏
  43. */
  44. onHide: function () {
  45. this.setData({
  46. visible: false
  47. })
  48. },
  49. /**
  50. * 生命周期函数--监听页面卸载
  51. */
  52. onUnload: function () {
  53. },
  54. /**
  55. * 页面相关事件处理函数--监听用户下拉动作
  56. */
  57. onPullDownRefresh: function () {
  58. },
  59. /**
  60. * 页面上拉触底事件的处理函数
  61. */
  62. onReachBottom: function () {
  63. },
  64. /**
  65. * 用户点击右上角分享
  66. */
  67. onShareAppMessage: function () {
  68. },
  69. isShow() {},
  70. /**
  71. * 弹框状态
  72. */
  73. onPopupState(e, key, value) {
  74. if (e) {
  75. key = e.currentTarget.dataset.key
  76. value = e.currentTarget.dataset.value
  77. }
  78. console.log(key)
  79. console.log(value)
  80. this.setData({
  81. [key]: value
  82. })
  83. },
  84. /**
  85. * 选择性别
  86. */
  87. bindGenderChange(e) {
  88. this.setData({
  89. ['userInfo.sex']: Number(e.detail.value) + 1,
  90. },() => {
  91. this.setUserFiles()
  92. })
  93. },
  94. /**
  95. * 选择生日
  96. */
  97. bindDateChange: function(e) {
  98. console.log(e)
  99. this.setData({
  100. ['userInfo.birthday']: e.detail.value,
  101. // date: e.detail.value
  102. },() => {
  103. this.setUserFiles()
  104. })
  105. },
  106. /**
  107. * 选择所在地
  108. */
  109. bindRegionChange: function (e) {
  110. this.setData({
  111. region: e.detail.value,
  112. ['userInfo.city']: e.detail.value.toString(),
  113. },() => {
  114. this.setUserFiles()
  115. })
  116. },
  117. /**
  118. * 获取用户档案
  119. * api/user/files
  120. */
  121. getUserFiles() {
  122. get('api/user/files',{},(res) => {
  123. this.setData({
  124. userInfo: res.data
  125. })
  126. console.log(res)
  127. })
  128. },
  129. /**
  130. * 更新用户档案
  131. * api/user/save_files
  132. */
  133. setUserFiles() {
  134. let { user_id,avatar_url,nickname,realname,sex,birthday,mobile,city,tags } = this.data.userInfo;
  135. post('api/user/update',{
  136. user_id,
  137. avatar_url,
  138. nickname,
  139. realname,
  140. sex,
  141. birthday,
  142. mobile,
  143. city,
  144. tags
  145. },() => {
  146. })
  147. },
  148. /**
  149. * 获取用户信息
  150. * api/user/info
  151. */
  152. getUserInfo() {
  153. let { userId } = this.data;
  154. get('api/user/info',{
  155. user_id: userId
  156. },(res) => {
  157. this.setData({
  158. userInfo: res.data
  159. })
  160. console.log(res)
  161. })
  162. },
  163. })