dossier.js 2.6 KB

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