personinfo.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // pages/personinfo/personinfo.js
  2. import userApi from '../../api/user'
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. endDate: "",
  10. birth: "1993-12-12",
  11. sex: 0,
  12. array: ["未知", "男", "女"],
  13. userName: "",
  14. imgUrl: "",
  15. userInfo: {}
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: async function (options) {
  21. var d = new Date();
  22. var endDate = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
  23. this.setData({
  24. endDate
  25. })
  26. let userInfo = await app.getWxUserInfo();
  27. let userId = userInfo.userId;
  28. let user = await userApi.getUserById(userId);
  29. console.log(user)
  30. this.setData({
  31. sex: userInfo.gender,
  32. imgUrl: user.info.avatar,
  33. userName: user.info.name,
  34. })
  35. },
  36. changeUserName: function (e) {
  37. this.setData({
  38. userName: e.detail.value
  39. })
  40. },
  41. changeBirth: function (e) {
  42. this.setData({
  43. birth: e.detail.value
  44. })
  45. },
  46. changeSex: function (e) {
  47. console.log(e.detail)
  48. this.setData({
  49. sex: e.detail.value
  50. })
  51. },
  52. upload: function () {
  53. var _this = this;
  54. wx.chooseImage({
  55. count: 1, // 默认9
  56. sizeType: ['original', 'compressed'],
  57. // 指定是原图还是压缩图,默认两个都有
  58. sourceType: ['album', 'camera'],
  59. // 指定来源是相册还是相机,默认两个都有
  60. success: function (res) {
  61. // 返回选定照片的本地文件路径tempFilePath可以作为img标签的src属性显示图片
  62. _this.setData({
  63. imgUrl: res.tempFilePaths
  64. })
  65. }
  66. })
  67. },
  68. updatePersonInfo: async function () {},
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面隐藏
  81. */
  82. onHide: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面卸载
  86. */
  87. onUnload: function () {
  88. console.log('隐藏啦')
  89. console.log(this.data)
  90. },
  91. /**
  92. * 页面相关事件处理函数--监听用户下拉动作
  93. */
  94. onPullDownRefresh: function () {
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. onReachBottom: function () {
  100. },
  101. /**
  102. * 用户点击右上角分享
  103. */
  104. onShareAppMessage: function () {
  105. }
  106. })