mine.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import {BASE_URL} from '../../utils/request';
  2. import { uploadImage } from '../../utils/upload.js';
  3. import { MAKE_PHONE_CALL } from '../../utils/util.js';
  4. import {userModify} from '../../api/user';
  5. const app = getApp();
  6. Page({
  7. data: {
  8. menuList: [
  9. { icon: '/static/image/me-1.png', title: '活动规则' },
  10. { icon: '/static/image/me-2.png', title: '免责声明' },
  11. { icon: '/static/image/me-3.png', title: '报名记录' },
  12. { icon: '/static/image/me-4.png', title: '优惠券' },
  13. { icon: '/static/image/me-5.png', title: '设置' },
  14. { icon: '/static/image/me-6.png', title: '联系客服' }
  15. ],
  16. userInfo: {},
  17. programConfig:{},
  18. baseUrl:BASE_URL
  19. },
  20. goPage(e){
  21. const index = e.currentTarget.dataset.index;
  22. const pageMap = {
  23. 0: `/pages/rules/rules?type=${index}`,
  24. 1: `/pages/rules/rules?type=${index}`,
  25. 2: `/pages/registrationRecords/registrationRecords`,
  26. 3: `/pages/coupon/coupon`,
  27. 4: `/pages/setting/setting`
  28. };
  29. if (pageMap[index]) {
  30. wx.navigateTo({ url: pageMap[index] });
  31. } else if (index === 5) {
  32. const tabbar = this.getTabBar && this.getTabBar();
  33. if (tabbar && tabbar.openShowAgreementModal) {
  34. tabbar.openShowAgreementModal()
  35. } else {
  36. console.log("没找到 tabbar 组件")
  37. }
  38. }
  39. },
  40. onLoad(options) {
  41. this.setData({
  42. userInfo: app.globalData.userInfo,
  43. programConfig:app.globalData.programConfig
  44. });
  45. },
  46. onShow() {
  47. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  48. this.getTabBar().setData({ selected: 2 })
  49. }
  50. this.setData({
  51. userInfo: app.globalData.userInfo
  52. });
  53. },
  54. // 头像
  55. async onChooseAvatar(e) {
  56. const { avatarUrl } = e.detail;
  57. // 上传到服务器
  58. const res = await uploadImage(avatarUrl);
  59. this.setData({
  60. "userInfo.avatar":avatarUrl
  61. });
  62. this.onSave(res.path);
  63. },
  64. async onSave(pathUrl){
  65. const res = await userModify({avatar:pathUrl});
  66. if(res.code == 200){
  67. // wx.showToast({
  68. // title: '更新成功',
  69. // icon: 'none',
  70. // duration: 2000
  71. // });
  72. app.globalData.userInfo = res.data;
  73. }else{
  74. wx.showToast({
  75. title: res.message || '更新失败',
  76. icon: 'none',
  77. duration: 2000
  78. });
  79. }
  80. },
  81. onPhone(){
  82. MAKE_PHONE_CALL(this.data.programConfig.customer_phone);
  83. },
  84. /**
  85. * 生命周期函数--监听页面隐藏
  86. */
  87. onHide() {
  88. },
  89. /**
  90. * 生命周期函数--监听页面卸载
  91. */
  92. onUnload() {
  93. },
  94. /**
  95. * 页面相关事件处理函数--监听用户下拉动作
  96. */
  97. onPullDownRefresh() {
  98. },
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom() {
  103. },
  104. /**
  105. * 用户点击右上角分享
  106. */
  107. onShareAppMessage() {
  108. }
  109. })