mine.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. showAgreementModal:false
  20. },
  21. goPage(e){
  22. const index = e.currentTarget.dataset.index;
  23. const pageMap = {
  24. 0: `/pages/rules/rules?type=${index}`,
  25. 1: `/pages/rules/rules?type=${index}`,
  26. 2: `/pages/registrationRecords/registrationRecords`,
  27. 3: `/pages/coupon/coupon`,
  28. 4: `/pages/setting/setting`
  29. };
  30. if (pageMap[index]) {
  31. wx.navigateTo({ url: pageMap[index] });
  32. } else if (index === 5) {
  33. this.setData({ showAgreementModal: true });
  34. }
  35. },
  36. onLoad(options) {
  37. this.setData({
  38. userInfo: app.globalData.userInfo,
  39. programConfig:app.globalData.programConfig
  40. });
  41. },
  42. onShow() {
  43. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  44. this.getTabBar().setData({ selected: 2 })
  45. }
  46. this.setData({
  47. userInfo: app.globalData.userInfo
  48. });
  49. },
  50. // 头像
  51. async onChooseAvatar(e) {
  52. const { avatarUrl } = e.detail;
  53. // 上传到服务器
  54. const res = await uploadImage(avatarUrl);
  55. this.setData({
  56. "userInfo.avatar":avatarUrl
  57. });
  58. this.onSave(res.path);
  59. },
  60. async onSave(pathUrl){
  61. const res = await userModify({avatar:pathUrl});
  62. if(res.code == 200){
  63. // wx.showToast({
  64. // title: '更新成功',
  65. // icon: 'none',
  66. // duration: 2000
  67. // });
  68. app.globalData.userInfo = res.data;
  69. }else{
  70. wx.showToast({
  71. title: res.message || '更新失败',
  72. icon: 'none',
  73. duration: 2000
  74. });
  75. }
  76. },
  77. onPhone(){
  78. MAKE_PHONE_CALL(this.data.programConfig.customer_phone);
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide() {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload() {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh() {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom() {
  99. },
  100. /**
  101. * 用户点击右上角分享
  102. */
  103. onShareAppMessage() {
  104. }
  105. })