index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. const util = require('../../utils/util.js');
  2. const api = require('../../config/api.js');
  3. const user = require('../../utils/user.js');
  4. //获取应用实例
  5. const app = getApp();
  6. Page({
  7. data: {
  8. newGoods: [],
  9. hotGoods: [],
  10. topics: [],
  11. brands: [],
  12. groupons: [],
  13. floorGoods: [],
  14. banner: [],
  15. channel: []
  16. },
  17. onShareAppMessage: function() {
  18. return {
  19. title: 'litemall小程序商场',
  20. desc: '开源微信小程序商城',
  21. path: '/pages/index/index'
  22. }
  23. },
  24. onPullDownRefresh() {
  25. wx.showNavigationBarLoading() //在标题栏中显示加载
  26. this.getIndexData();
  27. wx.hideNavigationBarLoading() //完成停止加载
  28. wx.stopPullDownRefresh() //停止下拉刷新
  29. },
  30. getIndexData: function() {
  31. let that = this;
  32. util.request(api.IndexUrl).then(function(res) {
  33. if (res.errno === 0) {
  34. that.setData({
  35. newGoods: res.data.newGoodsList,
  36. hotGoods: res.data.hotGoodsList,
  37. topics: res.data.topicList,
  38. brands: res.data.brandList,
  39. floorGoods: res.data.floorGoodsList,
  40. banner: res.data.banner,
  41. groupons: res.data.grouponList,
  42. channel: res.data.channel
  43. });
  44. }
  45. });
  46. },
  47. onLoad: function(options) {
  48. // 页面初始化 options为页面跳转所带来的参数
  49. if (options.scene) {
  50. //这个scene的值存在则证明首页的开启来源于朋友圈分享的图,同时可以通过获取到的goodId的值跳转导航到对应的详情页
  51. var scene = decodeURIComponent(options.scene);
  52. console.log("scene:" + scene);
  53. let info_arr = [];
  54. info_arr = scene.split(',');
  55. let _type = info_arr[0];
  56. let id = info_arr[1];
  57. if (_type == 'goods') {
  58. wx.navigateTo({
  59. url: '../goods/goods?id=' + id
  60. });
  61. } else if (_type == 'groupon') {
  62. wx.navigateTo({
  63. url: '../goods/goods?grouponId=' + id
  64. });
  65. } else {
  66. wx.navigateTo({
  67. url: '../index/index'
  68. });
  69. }
  70. }
  71. // 页面初始化 options为页面跳转所带来的参数
  72. if (options.grouponId) {
  73. //这个pageId的值存在则证明首页的开启来源于用户点击来首页,同时可以通过获取到的pageId的值跳转导航到对应的详情页
  74. wx.navigateTo({
  75. url: '../goods/goods?grouponId=' + options.grouponId
  76. });
  77. }
  78. // 页面初始化 options为页面跳转所带来的参数
  79. if (options.goodId) {
  80. //这个goodId的值存在则证明首页的开启来源于分享,同时可以通过获取到的goodId的值跳转导航到对应的详情页
  81. wx.navigateTo({
  82. url: '../goods/goods?id=' + options.goodId
  83. });
  84. }
  85. // 页面初始化 options为页面跳转所带来的参数
  86. if (options.orderId) {
  87. //这个orderId的值存在则证明首页的开启来源于订单模版通知,同时可以通过获取到的pageId的值跳转导航到对应的详情页
  88. wx.navigateTo({
  89. url: '../ucenter/orderDetail/orderDetail?id=' + options.orderId
  90. });
  91. }
  92. this.getIndexData();
  93. },
  94. onReady: function() {
  95. // 页面渲染完成
  96. },
  97. onShow: function() {
  98. // 页面显示
  99. },
  100. onHide: function() {
  101. // 页面隐藏
  102. },
  103. onUnload: function() {
  104. // 页面关闭
  105. },
  106. })