index.js 3.5 KB

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