index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. recommendLsit:[],
  21. newList:[],
  22. likeList:[],
  23. offset: 0,
  24. title: "玩命加载中...",
  25. hidden: false
  26. },
  27. goUrl:function(e){
  28. if (e.currentTarget.dataset.url != '#'){
  29. wx.navigateTo({
  30. url: e.currentTarget.dataset.url,
  31. })
  32. }
  33. },
  34. torday:function(e){
  35. wx.switchTab({
  36. url: '/pages/productSort/productSort'
  37. });
  38. },
  39. /**
  40. * 生命周期函数--监听页面加载
  41. */
  42. onLoad: function (options) {
  43. app.setBarColor();
  44. var that = this;
  45. if (options.spid){
  46. app.globalData.spid = options.spid
  47. }
  48. app.setUserInfo();
  49. that.getIndexInfo();
  50. },
  51. getIndexInfo:function(){
  52. var header = {
  53. 'content-type': 'application/x-www-form-urlencoded',
  54. };
  55. var that = this;
  56. wx.request({
  57. url: app.globalData.url + '/routine/auth_api/index?uid=' + app.globalData.uid,
  58. method: 'POST',
  59. header: header,
  60. success: function (res) {
  61. console.log(res.data.data.banner);
  62. that.setData({
  63. imgUrls: res.data.data.banner,
  64. recommendLsit: res.data.data.best,
  65. newList: res.data.data.new,
  66. lovely: res.data.data.lovely,
  67. menus: res.data.data.menus,
  68. likeList: res.data.data.hot
  69. })
  70. }
  71. })
  72. },
  73. onReachBottom: function (p) {
  74. var that = this;
  75. var limit = 20;
  76. var offset = that.data.offset;
  77. if (!offset) offset = 1;
  78. var startpage = limit * offset;
  79. var header = {
  80. 'content-type': 'application/x-www-form-urlencoded',
  81. };
  82. wx.request({
  83. url: app.globalData.url + '/routine/auth_api/get_hot_product?uid=' + app.globalData.uid,
  84. data: { limit: limit, offset: startpage },
  85. method: 'POST',
  86. header: header,
  87. success: function (res) {
  88. var len = res.data.data.length;
  89. for (var i = 0; i < len; i++) {
  90. that.data.likeList.push(res.data.data[i])
  91. }
  92. that.setData({
  93. offset: offset + 1,
  94. likeList: that.data.likeList
  95. });
  96. if (len < limit) {
  97. that.setData({
  98. title: "数据已经加载完成",
  99. hidden: true
  100. });
  101. return false;
  102. }
  103. },
  104. fail: function (res) {
  105. console.log('submit fail');
  106. },
  107. complete: function (res) {
  108. console.log('submit complete');
  109. }
  110. })
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面隐藏
  124. */
  125. onHide: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload: function () {
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh: function () {
  136. },
  137. /**
  138. * 用户点击右上角分享
  139. */
  140. onShareAppMessage: function () {
  141. var that = this;
  142. return {
  143. title: '小程序',
  144. path: '/pages/index/index?spid=' + app.globalData.uid,
  145. // imageUrl: that.data.url + that.data.product.image,
  146. success: function () {
  147. wx.showToast({
  148. title: '分享成功',
  149. icon: 'success',
  150. duration: 2000
  151. })
  152. }
  153. }
  154. }
  155. })