index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. },
  14. onShareAppMessage: function() {
  15. return {
  16. title: '古早交易平台',
  17. desc: '一款开源仿闲鱼交易平台!',
  18. path: '/pages/index/index'
  19. }
  20. },
  21. getIndexData: function() {
  22. let that = this;
  23. util.request(api.IndexUrl).then(function(res) {
  24. console.log(res.data)
  25. if (res.errno === 0) {
  26. that.setData({
  27. indexGoods: res.data.indexGoodsList,
  28. banner: res.data.banner,
  29. channel: res.data.channel
  30. });
  31. }
  32. });
  33. },
  34. getIndexMore: function() {
  35. let that = this;
  36. util.request(api.IndexMore, {
  37. page: this.data.page,
  38. size: this.data.size
  39. }).then(function(res) {
  40. console.log(res.data)
  41. if (res.errno === 0) {
  42. that.setData({
  43. indexGoods: that.data.indexGoods.concat(res.data),
  44. });
  45. }
  46. });
  47. },
  48. onLoad: function(options) {
  49. this.getIndexData();
  50. },
  51. onReady: function() {
  52. // 页面渲染完成
  53. },
  54. onShow: function() {
  55. // 页面显示
  56. },
  57. onHide: function() {
  58. // 页面隐藏
  59. },
  60. onUnload: function() {
  61. // 页面关闭
  62. },
  63. onPullDownRefresh: function() {
  64. console.log("上拉刷新")
  65. this.onLoad()
  66. setTimeout(function callback() {
  67. wx.stopPullDownRefresh()
  68. }, 500)
  69. },
  70. onReachBottom: function() {
  71. console.log("拉到底")
  72. this.setData({
  73. page: this.data.page + 1
  74. })
  75. this.getIndexMore()
  76. },
  77. })