index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. {
  10. brief: "耐用",
  11. counterPrice: 599,
  12. id: 1152008,
  13. isHot: true,
  14. isNew: false,
  15. name: "600ML新晶彩茶韵国民水杯",
  16. picUrl: "/static/images/1152008.png",
  17. retailPrice: 59
  18. }
  19. ,{
  20. brief: "耐用",
  21. counterPrice: 299,
  22. id: 1152009,
  23. isHot: true,
  24. isNew: false,
  25. name: "400ML都市暖心保温杯秋日系列",
  26. picUrl: "/static/images/1152009.png",
  27. retailPrice: 59
  28. }
  29. ,{
  30. brief: "耐用",
  31. counterPrice: 299,
  32. id: 1152031,
  33. isHot: true,
  34. isNew: false,
  35. name: "400ML花香鸟鸣晶彩随心杯",
  36. picUrl: "/static/images/1152031.png",
  37. retailPrice: 59
  38. },
  39. {
  40. brief: "耐用",
  41. counterPrice: 299,
  42. id: 1152095,
  43. isHot: true,
  44. isNew: false,
  45. name: "新款晶彩茶韵杯/国民水杯",
  46. picUrl: "/static/images/1152095.png",
  47. retailPrice: 59
  48. }
  49. ],
  50. hotGoods: [
  51. {
  52. brief: "耐用",
  53. counterPrice: 599,
  54. id: 1152008,
  55. isHot: true,
  56. isNew: false,
  57. name: "新款晶彩茶韵杯/国民水杯",
  58. picUrl: "/static/images/1152008.png",
  59. retailPrice: 59
  60. }
  61. ],
  62. // topics: [],
  63. // brands: [],
  64. // groupons: [],
  65. // floorGoods: [],
  66. // banner: [],
  67. channel: []
  68. },
  69. onShareAppMessage: function() {
  70. return {
  71. title: 'Renard',
  72. desc: '特百惠国民水杯',
  73. path: '/pages/index/index'
  74. }
  75. },
  76. onPullDownRefresh() {
  77. this.getIndexData();
  78. wx.stopPullDownRefresh() //停止下拉刷新
  79. },
  80. getIndexData: function() {
  81. wx.showLoading({
  82. title: '加载中',
  83. });
  84. setTimeout(function() {
  85. wx.hideLoading()
  86. }, 2000);
  87. let that = this;
  88. util.request(api.IndexUrl).then(function(res) {
  89. if (res.errno === 0) {
  90. that.setData({
  91. // newGoods: res.data.newGoodsList, TODO
  92. // hotGoods: res.data.hotGoodsList, TODO
  93. // topics: res.data.topicList,
  94. // brands: res.data.brandList,
  95. // floorGoods: res.data.floorGoodsList,
  96. // banner: res.data.banner,
  97. // groupons: res.data.grouponList,
  98. // channel: res.data.channel
  99. });
  100. wx.hideLoading();
  101. }
  102. });
  103. },
  104. onLoad: function(options) {
  105. var that = this;
  106. wx.getSystemInfo({
  107. success: function(res) {
  108. that.setData({
  109. windowWidth: res.windowWidth,
  110. windowHeight: res.windowHeight
  111. });
  112. }
  113. });
  114. if (options.scene) {
  115. var scene = decodeURIComponent(options.scene);
  116. console.log("scene:" + scene);
  117. let info_arr = [];
  118. info_arr = scene.split(',');
  119. let _type = info_arr[0];
  120. let id = info_arr[1];
  121. if (_type == 'goods') {
  122. wx.navigateTo({
  123. url: '../goods/goods?id=' + id
  124. });
  125. } else if (_type == 'groupon') {
  126. wx.navigateTo({
  127. url: '../goods/goods?grouponId=' + id
  128. });
  129. } else {
  130. wx.navigateTo({
  131. url: '../index/index'
  132. });
  133. }
  134. }
  135. // 页面初始化 options为页面跳转所带来的参数
  136. if (options.grouponId) {
  137. //这个pageId的值存在则证明首页的开启来源于用户点击来首页,同时可以通过获取到的pageId的值跳转导航到对应的详情页
  138. wx.navigateTo({
  139. url: '../goods/goods?grouponId=' + options.grouponId
  140. });
  141. }
  142. // 页面初始化 options为页面跳转所带来的参数
  143. if (options.goodId) {
  144. //这个pageId的值存在则证明首页的开启来源于用户点击来首页,同时可以通过获取到的pageId的值跳转导航到对应的详情页
  145. wx.navigateTo({
  146. url: '../goods/goods?id=' + options.goodId
  147. });
  148. }
  149. // 页面初始化 options为页面跳转所带来的参数
  150. if (options.orderId) {
  151. //这个pageId的值存在则证明首页的开启来源于用户点击来首页,同时可以通过获取到的pageId的值跳转导航到对应的详情页
  152. wx.navigateTo({
  153. url: '../ucenter/orderDetail/orderDetail?id=' + options.orderId
  154. });
  155. }
  156. this.getIndexData();
  157. },
  158. onReady: function() {
  159. // 页面渲染完成
  160. },
  161. onShow: function() {
  162. // 页面显示
  163. },
  164. onHide: function() {
  165. // 页面隐藏
  166. },
  167. onUnload: function() {
  168. // 页面关闭
  169. },
  170. });