index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // nova-werun/pages/my/my-profile/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. //屏幕高度
  10. statusBarHeight: 0, // 状态栏高度
  11. screenHeight: 0, // 屏幕高度
  12. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  13. bottomNavHeight: 0, // 底部导航栏高度
  14. contentHeight: 0, // 可用内容高度
  15. contentpadding: 0, //顶部padding高度
  16. User1List: [],
  17. actions: [{
  18. name: '男',
  19. },
  20. {
  21. name: '女',
  22. },
  23. ],
  24. avatar:null,
  25. sex:'男',
  26. nickname:null,
  27. height: null,
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. // 计算
  34. const systemInfo = wx.getSystemInfoSync();
  35. const statusBarHeight = systemInfo.statusBarHeight || 0;
  36. const screenHeight = systemInfo.screenHeight || 0;
  37. const custom = wx.getMenuButtonBoundingClientRect();
  38. const customHeight = custom.height + 10 + 2 || 0;
  39. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  40. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  41. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  42. this.setData({
  43. statusBarHeight,
  44. screenHeight,
  45. customHeight,
  46. bottomNavHeight,
  47. contentHeight,
  48. contentpadding
  49. });
  50. this.getname()
  51. },
  52. /**
  53. * 生命周期函数--监听页面初次渲染完成
  54. */
  55. onReady: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload: function () {
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {
  76. },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. onReachBottom: function () {
  81. },
  82. /**
  83. * 用户点击右上角分享
  84. */
  85. onShareAppMessage: function () {
  86. },
  87. //获取身高
  88. getHeight(e) {
  89. let height = e.detail.value;
  90. // 身高范围在 50 到 250 之间的正则表达式,允许浮点数
  91. let a = /^(?:[5-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|250)(\.\d)?$/;
  92. if (!height.match(a)) {
  93. wx.showToast({
  94. icon: "none",
  95. title: "请填写正确的身高格式",
  96. });
  97. return;
  98. } else {
  99. this.setData({
  100. height: height
  101. });
  102. console.log(this.data.height);
  103. }
  104. },
  105. //获取头像名称
  106. async getname() {
  107. const currentUser = Parse.User.current();
  108. let Userquery = new Parse.Query('_User');
  109. Userquery.equalTo('company', company);
  110. Userquery.equalTo('objectId', currentUser.id);
  111. Userquery.notEqualTo('isDeleted', true)
  112. let P2 = await Userquery.find();
  113. let User1List = P2.map(item => item.toJSON());
  114. this.setData({
  115. User1List
  116. })
  117. this.setData({
  118. avatar:User1List[0].avatar,
  119. nickname:User1List[0].nickname,
  120. sex:User1List[0].sex||'男',
  121. })
  122. console.log(this.data.User1List);
  123. },
  124. onSelect(event) {
  125. console.log(event.detail);
  126. let {
  127. name
  128. } = event.detail
  129. this.setData({
  130. sex : name,
  131. show2: false
  132. })
  133. },
  134. showSelect() {
  135. this.setData({
  136. show2: true
  137. })
  138. },
  139. })