index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const App = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. isLogin: false,
  8. userInfo: {}, // 用户信息
  9. orderCount: {}, // 订单数量
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad(options) {
  15. },
  16. /**
  17. * 生命周期函数--监听页面显示
  18. */
  19. onShow() {
  20. let _this = this;
  21. _this.setData({
  22. isLogin: App.checkIsLogin()
  23. });
  24. // 获取当前用户信息
  25. _this.getUserDetail();
  26. // 更新购物车角标
  27. App.setCartTabBadge()
  28. },
  29. /**
  30. * 获取当前用户信息
  31. */
  32. getUserDetail() {
  33. let _this = this;
  34. App._get('user.index/detail', {}, function (result) {
  35. _this.setData(result.data);
  36. });
  37. },
  38. /**
  39. * 订单导航跳转
  40. */
  41. onTargetOrder(e) {
  42. let _this = this;
  43. if (!_this.onCheckLogin()) {
  44. return false;
  45. }
  46. let urls = {
  47. all: '/pages/order/index?type=all',
  48. payment: '/pages/order/index?type=payment',
  49. received: '/pages/order/index?type=received',
  50. refund: '/pages/order/refund/index',
  51. };
  52. // 转跳指定的页面
  53. wx.navigateTo({
  54. url: urls[e.currentTarget.dataset.type]
  55. })
  56. },
  57. /**
  58. * 菜单列表导航跳转
  59. */
  60. onTargetMenus(e) {
  61. let _this = this;
  62. if (!_this.onCheckLogin()) {
  63. return false;
  64. }
  65. wx.navigateTo({
  66. url: '/' + e.currentTarget.dataset.url
  67. })
  68. },
  69. /**
  70. * 跳转我的钱包页面
  71. */
  72. onTargetWallet(e) {
  73. let _this = this;
  74. if (!_this.onCheckLogin()) {
  75. return false;
  76. }
  77. wx.navigateTo({
  78. url: './wallet/index'
  79. })
  80. },
  81. /**
  82. * 跳转积分明细页
  83. */
  84. onTargetPoints(e) {
  85. let _this = this;
  86. if (!_this.onCheckLogin()) {
  87. return false;
  88. }
  89. wx.navigateTo({
  90. url: '../points/log/index'
  91. });
  92. },
  93. /**
  94. * 跳转到登录页
  95. */
  96. onLogin() {
  97. // wx.navigateTo({
  98. // url: '../login/login',
  99. // });
  100. App.doLogin();
  101. },
  102. /**
  103. * 验证是否已登录
  104. */
  105. onCheckLogin() {
  106. let _this = this;
  107. if (!_this.data.isLogin) {
  108. App.showError('很抱歉,您还没有登录');
  109. return false;
  110. }
  111. return true;
  112. },
  113. })