index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. this.getIndexData();
  64. },
  65. onReady: function() {
  66. // 页面渲染完成
  67. },
  68. onShow: function() {
  69. // 页面显示
  70. },
  71. onHide: function() {
  72. // 页面隐藏
  73. },
  74. onUnload: function() {
  75. // 页面关闭
  76. },
  77. onPullDownRefresh: function() {
  78. console.log("上拉刷新")
  79. this.onLoad()
  80. setTimeout(function callback() {
  81. wx.stopPullDownRefresh()
  82. }, 500)
  83. },
  84. onReachBottom: function() {
  85. console.log("拉到底")
  86. this.setData({
  87. page: this.data.page + 1
  88. })
  89. this.getIndexMore()
  90. },
  91. })