index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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: 'Renard',
  20. desc: '唯爱与美食不可辜负',
  21. path: '/pages/index/index'
  22. }
  23. },
  24. onPullDownRefresh() {
  25. this.getIndexData();
  26. wx.stopPullDownRefresh() //停止下拉刷新
  27. },
  28. getIndexData: function() {
  29. wx.showLoading({
  30. title: '加载中',
  31. });
  32. setTimeout(function() {
  33. wx.hideLoading()
  34. }, 2000);
  35. let that = this;
  36. util.request(api.IndexUrl).then(function(res) {
  37. if (res.errno === 0) {
  38. that.setData({
  39. newGoods: res.data.newGoodsList,
  40. hotGoods: res.data.hotGoodsList,
  41. topics: res.data.topicList,
  42. brands: res.data.brandList,
  43. floorGoods: res.data.floorGoodsList,
  44. // banner: res.data.banner,
  45. groupons: res.data.grouponList,
  46. channel: res.data.channel
  47. });
  48. wx.hideLoading();
  49. }
  50. });
  51. },
  52. onLoad: function(options) {
  53. var that = this;
  54. wx.getSystemInfo({
  55. success: function(res) {
  56. that.setData({
  57. windowWidth: res.windowWidth,
  58. windowHeight: res.windowHeight
  59. });
  60. }
  61. });
  62. if (options.scene) {
  63. var scene = decodeURIComponent(options.scene);
  64. console.log("scene:" + scene);
  65. let info_arr = [];
  66. info_arr = scene.split(',');
  67. let _type = info_arr[0];
  68. let id = info_arr[1];
  69. if (_type == 'goods') {
  70. wx.navigateTo({
  71. url: '../goods/goods?id=' + id
  72. });
  73. } else if (_type == 'groupon') {
  74. wx.navigateTo({
  75. url: '../goods/goods?grouponId=' + id
  76. });
  77. } else {
  78. wx.navigateTo({
  79. url: '../index/index'
  80. });
  81. }
  82. }
  83. // 页面初始化 options为页面跳转所带来的参数
  84. if (options.grouponId) {
  85. //这个pageId的值存在则证明首页的开启来源于用户点击来首页,同时可以通过获取到的pageId的值跳转导航到对应的详情页
  86. wx.navigateTo({
  87. url: '../goods/goods?grouponId=' + options.grouponId
  88. });
  89. }
  90. // 页面初始化 options为页面跳转所带来的参数
  91. if (options.goodId) {
  92. //这个pageId的值存在则证明首页的开启来源于用户点击来首页,同时可以通过获取到的pageId的值跳转导航到对应的详情页
  93. wx.navigateTo({
  94. url: '../goods/goods?id=' + options.goodId
  95. });
  96. }
  97. // 页面初始化 options为页面跳转所带来的参数
  98. if (options.orderId) {
  99. //这个pageId的值存在则证明首页的开启来源于用户点击来首页,同时可以通过获取到的pageId的值跳转导航到对应的详情页
  100. wx.navigateTo({
  101. url: '../ucenter/orderDetail/orderDetail?id=' + options.orderId
  102. });
  103. }
  104. this.getIndexData();
  105. },
  106. onReady: function() {
  107. // 页面渲染完成
  108. },
  109. onShow: function() {
  110. // 页面显示
  111. },
  112. onHide: function() {
  113. // 页面隐藏
  114. },
  115. onUnload: function() {
  116. // 页面关闭
  117. },
  118. });