index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const util = require('../../utils/util.js');
  2. const api = require('../../config/api.js');
  3. const user = require('../../services/user.js');
  4. //获取应用实例
  5. const app = getApp()
  6. Page({
  7. data: {
  8. banner: [],
  9. channel: [],
  10. indexGoods: [],
  11. page: 1,
  12. size: 10,
  13. // newGoods: [],
  14. // hotGoods: [],
  15. // topics: [],
  16. // brands: [],
  17. // floorGoods: [],
  18. // banner: [],
  19. // channel: []
  20. },
  21. onShareAppMessage: function() {
  22. return {
  23. title: '古早交易平台',
  24. desc: '一款开源仿闲鱼交易平台!',
  25. path: '/pages/index/index'
  26. }
  27. },
  28. getIndexData: function() {
  29. let that = this;
  30. util.request(api.IndexUrl).then(function(res) {
  31. console.log(res.data)
  32. // console.log(res.data.hotGoodsList)
  33. // console.log(res.data.categoryList)
  34. if (res.errno === 0) {
  35. that.setData({
  36. // newGoods: res.data.newGoodsList,
  37. // hotGoods: res.data.hotGoodsList,
  38. // topics: res.data.topicList,
  39. // brand: res.data.brandList,
  40. // floorGoods: res.data.categoryList,
  41. indexGoods: res.data.indexGoodsList,
  42. banner: res.data.banner,
  43. channel: res.data.channel
  44. });
  45. }
  46. });
  47. },
  48. getIndexMore: function() {
  49. let that = this;
  50. util.request(api.IndexMore, {
  51. page: this.data.page,
  52. size: this.data.size
  53. }).then(function(res) {
  54. console.log(res.data)
  55. if (res.errno === 0) {
  56. that.setData({
  57. indexGoods: that.data.indexGoods.concat(res.data),
  58. });
  59. }
  60. });
  61. },
  62. onLoad: function(options) {
  63. // wx.setTabBarBadge({
  64. // index: 3,
  65. // text: '1'
  66. // })
  67. this.getIndexData();
  68. },
  69. onReady: function() {
  70. // 页面渲染完成
  71. },
  72. onShow: function() {
  73. // 页面显示
  74. },
  75. onHide: function() {
  76. // 页面隐藏
  77. },
  78. onUnload: function() {
  79. // 页面关闭
  80. },
  81. onPullDownRefresh: function() {
  82. console.log("上拉刷新")
  83. this.onLoad()
  84. setTimeout(function callback() {
  85. wx.stopPullDownRefresh()
  86. }, 500)
  87. },
  88. onReachBottom: function() {
  89. console.log("拉到底")
  90. this.setData({
  91. page: this.data.page + 1
  92. })
  93. this.getIndexMore()
  94. },
  95. })