dossier.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import {
  2. api_url,
  3. get,
  4. post
  5. } from '../../utils/http'
  6. const app = getApp()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. userInfo: {},
  13. visible: false,
  14. genders: ['男', '女'],
  15. genderIndex: 0,
  16. date: '2016-09-01',
  17. region: ['广东省', '广州市', '海珠区'],
  18. globalUserInfo: {},
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. this.setData({
  25. globalUserInfo: app.globalData.userInfo
  26. })
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {},
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. this.getUserFiles()
  37. },
  38. /**
  39. * 生命周期函数--监听页面隐藏
  40. */
  41. onHide: function () {
  42. this.setData({
  43. visible: false
  44. })
  45. },
  46. /**
  47. * 生命周期函数--监听页面卸载
  48. */
  49. onUnload: function () {},
  50. /**
  51. * 页面相关事件处理函数--监听用户下拉动作
  52. */
  53. onPullDownRefresh: function () {},
  54. /**
  55. * 页面上拉触底事件的处理函数
  56. */
  57. onReachBottom: function () {},
  58. /**
  59. * 用户点击右上角分享
  60. */
  61. onShareAppMessage: function () {},
  62. isShow() {},
  63. // 选择头像
  64. onChooseAvatar(e) {
  65. let that = this
  66. wx.uploadFile({
  67. url: 'https://api.ijolijoli.com/api/upload', //仅为示例,非真实的接口地址
  68. filePath: e.detail.avatarUrl,
  69. name: 'file',
  70. formData: {
  71. 'type': 'avatar',
  72. },
  73. header: {
  74. 'token': wx.getStorageSync('token')
  75. }, // header 值
  76. success (res){
  77. let data = JSON.parse(res.data)
  78. console.log(data);
  79. if(data.code==200){
  80. post('api/user/save_files',{
  81. avatar_url:data.data.url
  82. },(res=>{
  83. if(res.code==200){
  84. that.getUserFiles()
  85. wx.showToast({
  86. title: '上传成功',
  87. icon:'none'
  88. })
  89. }
  90. }))
  91. }
  92. }
  93. })
  94. },
  95. /**
  96. * 弹框状态
  97. */
  98. onPopupState(e, key, value) {
  99. if (e) {
  100. key = e.currentTarget.dataset.key
  101. value = e.currentTarget.dataset.value
  102. }
  103. this.setData({
  104. [key]: value
  105. })
  106. },
  107. /**
  108. * 选择性别
  109. */
  110. bindGenderChange(e) {
  111. this.setData({
  112. ['userInfo.sex']: Number(e.detail.value) + 1
  113. },
  114. () => {
  115. this.setUserFiles()
  116. }
  117. )
  118. },
  119. /**
  120. * 选择生日
  121. */
  122. bindDateChange: function (e) {
  123. console.log(e)
  124. this.setData({
  125. ['userInfo.birthday']: e.detail.value
  126. // date: e.detail.value
  127. },
  128. () => {
  129. this.setUserFiles()
  130. }
  131. )
  132. },
  133. /**
  134. * 选择所在地
  135. */
  136. bindRegionChange: function (e) {
  137. this.setData({
  138. region: e.detail.value,
  139. ['userInfo.city']: e.detail.value.toString()
  140. },
  141. () => {
  142. this.setUserFiles()
  143. }
  144. )
  145. },
  146. /**
  147. * 获取用户档案
  148. * api/user/files
  149. */
  150. getUserFiles() {
  151. get('api/user/files', {}, (res) => {
  152. this.setData({
  153. userInfo: res.data
  154. })
  155. console.log(res)
  156. })
  157. },
  158. /**
  159. * 更新用户档案
  160. * api/user/save_files
  161. */
  162. setUserFiles() {
  163. let {
  164. real_name,
  165. birthday,
  166. sex,
  167. city,
  168. nickname
  169. } = this.data.userInfo
  170. post(
  171. 'api/user/save_files', {
  172. real_name,
  173. birthday,
  174. sex,
  175. city,
  176. nickname
  177. },
  178. () => {}
  179. )
  180. }
  181. })