index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. clearHeight(){
  107. this.setData({
  108. height:null
  109. })
  110. console.log('清空',this.data.height);
  111. },
  112. //获取头像名称
  113. async getname() {
  114. const currentUser = Parse.User.current();
  115. let Userquery = new Parse.Query('_User');
  116. Userquery.equalTo('company', company);
  117. Userquery.equalTo('objectId', currentUser.id);
  118. Userquery.notEqualTo('isDeleted', true)
  119. let P2 = await Userquery.find();
  120. let User1List = P2.map(item => item.toJSON());
  121. this.setData({
  122. User1List
  123. })
  124. this.setData({
  125. avatar:User1List[0].avatar,
  126. nickname:User1List[0].nickname,
  127. sex:User1List[0].sex||'男',
  128. })
  129. console.log(this.data.User1List);
  130. },
  131. onSelect(event) {
  132. let {
  133. name
  134. } = event.detail
  135. this.setData({
  136. sex : name,
  137. show2: false
  138. })
  139. console.log(this.data.sex);
  140. },
  141. showSelect() {
  142. this.setData({
  143. show2: true
  144. })
  145. },
  146. //修改名字
  147. changenickname(e){
  148. this.setData({
  149. nickname:e.detail
  150. })
  151. console.log(this.data.nickname);
  152. },
  153. //上传信息
  154. async setinfo(){
  155. const currentUser = Parse.User.current();
  156. let Userquery = new Parse.Query('_User');
  157. Userquery.equalTo('company', company);
  158. Userquery.equalTo('objectId', currentUser.id);
  159. Userquery.notEqualTo('isDeleted', true)
  160. let user = await Userquery.first();
  161. user.set('sex',this.data.sex)
  162. user.set('nickname',this.data.nickname)
  163. }
  164. })