index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //index.js
  2. //获取应用实例
  3. var app = getApp();
  4. var wxh = require('../../utils/wxh.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. url: app.globalData.urlImages,
  11. imgUrls:[],
  12. lovely:[],
  13. menus:[],
  14. indicatorDots: true,//是否显示面板指示点;
  15. autoplay: true,//是否自动播放;
  16. interval: 3000,//动画间隔的时间;
  17. duration: 500,//动画播放的时长;
  18. indicatorColor: "rgba(51, 51, 51, .3)",
  19. indicatorActivecolor: "#ffffff",
  20. recommendList:[],
  21. newList:[],
  22. hotList:[],
  23. benefitList:[],
  24. likeList:[],
  25. offset: 0,
  26. title: "玩命加载中...",
  27. hidden: false
  28. },
  29. goUrl:function(e){
  30. if (e.currentTarget.dataset.url != '#'){
  31. wx.navigateTo({
  32. url: e.currentTarget.dataset.url,
  33. })
  34. }
  35. },
  36. torday:function(e){
  37. wx.switchTab({
  38. url: '/pages/productSort/productSort'
  39. });
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. app.setBarColor();
  46. var that = this;
  47. if (app.globalData.config !=null){
  48. wx.setNavigationBarTitle({
  49. title: app.globalData.config.routine_name,
  50. })
  51. }else{
  52. wx.setNavigationBarTitle({
  53. title: '商城首页',
  54. })
  55. }
  56. // if (options.spid){
  57. // app.globalData.spid = options.spid;
  58. // console.log(options);
  59. // }
  60. app.setUserInfo();
  61. that.getIndexInfo();
  62. },
  63. getIndexInfo:function(){
  64. var header = {
  65. 'content-type': 'application/x-www-form-urlencoded',
  66. };
  67. var that = this;
  68. wx.request({
  69. url: app.globalData.url + '/routine/auth_api/index?uid=' + app.globalData.uid,
  70. method: 'POST',
  71. header: header,
  72. success: function (res) {
  73. that.setData({
  74. imgUrls: res.data.data.banner,
  75. recommendList: res.data.data.best,//精品
  76. newList: res.data.data.new,//首发新品
  77. hotList: res.data.data.hot,//热卖单品
  78. benefitList: res.data.data.benefit,//促销
  79. lovely: res.data.data.lovely,//猜猜你喜欢上面广告位
  80. menus: res.data.data.menus,//导航
  81. likeList: res.data.data.like//猜猜喜欢
  82. })
  83. }
  84. })
  85. },
  86. onReachBottom: function (p) {
  87. var that = this;
  88. var limit = 20;
  89. var offset = that.data.offset;
  90. if (!offset) offset = 1;
  91. var startpage = limit * offset;
  92. var header = {
  93. 'content-type': 'application/x-www-form-urlencoded',
  94. };
  95. wx.request({
  96. url: app.globalData.url + '/routine/auth_api/get_hot_product?uid=' + app.globalData.uid,
  97. data: { limit: limit, offset: startpage },
  98. method: 'POST',
  99. header: header,
  100. success: function (res) {
  101. var len = res.data.data.length;
  102. for (var i = 0; i < len; i++) {
  103. that.data.likeList.push(res.data.data[i])
  104. }
  105. that.setData({
  106. offset: offset + 1,
  107. likeList: that.data.likeList
  108. });
  109. if (len < limit) {
  110. that.setData({
  111. title: "数据已经加载完成",
  112. hidden: true
  113. });
  114. return false;
  115. }
  116. },
  117. fail: function (res) {
  118. console.log('submit fail');
  119. },
  120. complete: function (res) {
  121. console.log('submit complete');
  122. }
  123. })
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面隐藏
  137. */
  138. onHide: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面卸载
  142. */
  143. onUnload: function () {
  144. },
  145. /**
  146. * 页面相关事件处理函数--监听用户下拉动作
  147. */
  148. onPullDownRefresh: function () {
  149. },
  150. /**
  151. * 用户点击右上角分享
  152. */
  153. onShareAppMessage: function () {
  154. var that = this;
  155. return {
  156. title: app.globalData.config.routine_name,
  157. path: '/pages/index/index?scene=' + app.globalData.uid,
  158. // imageUrl: that.data.url + that.data.product.image,
  159. success: function () {
  160. wx.showToast({
  161. title: '分享成功',
  162. icon: 'success',
  163. duration: 2000
  164. })
  165. }
  166. }
  167. }
  168. })