帮你贷的小程序

list.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // pages/list/list.js
  2. var utils = require('../../utils/util.js');
  3. Page({
  4. data: {
  5. id:0,
  6. page: 1,
  7. dataList:[],
  8. hidden: true,
  9. },
  10. onLoad: function (options) {
  11. var that = this;
  12. that.setData({ id: options.id});
  13. if(that.data.id == 0){
  14. var obj = { 'is_hot': 0, 'is_new': 1 };
  15. utils.initList(that, obj, '', that.data.page);
  16. }else{
  17. initCate(that, '', that.data.page);
  18. }
  19. },
  20. onPullDownRefresh: function () {
  21. //下拉
  22. console.log(123)
  23. var that = this;
  24. if (that.data.id == 0) {
  25. var obj = { 'is_hot': 0, 'is_new': 1 };
  26. utils.initList(that, obj, 'top', that.data.page);
  27. } else {
  28. initCate(that, 'top', ++that.data.page);
  29. }
  30. },
  31. onReachBottom: function () {
  32. //上拉
  33. console.log('text')
  34. var that = this;
  35. if (that.data.id == 0) {
  36. var obj = { 'is_hot': 0, 'is_new': 1 };
  37. utils.initList(that, obj, '', that.data.page);
  38. } else {
  39. initCate(that, '', ++that.data.page);
  40. }
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady: function () {
  46. },
  47. /**
  48. * 生命周期函数--监听页面显示
  49. */
  50. onShow: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面隐藏
  54. */
  55. onHide: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面卸载
  59. */
  60. onUnload: function () {
  61. },
  62. /**
  63. * 页面相关事件处理函数--监听用户下拉动作
  64. */
  65. onPullDownRefresh: function () {
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom: function () {
  71. },
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage: function () {
  76. }
  77. })
  78. // 请求列表数据
  79. var initCate = function (that, orient, page) {
  80. that.setData({ hidden: false });
  81. var list = [];
  82. if (page == 1) {
  83. list = [];
  84. } else {
  85. list = that.data.dataList
  86. }
  87. wx.request({
  88. url: 'http://m.henhaojie.com/user/product/getInfoByCat',
  89. method: "POST",
  90. data: { id: that.data.id, page: page},
  91. success: function (res) {
  92. var data = res.data.rst.data;
  93. if (res.data.errno == '0') {
  94. that.data.hasNext = res.data.rst.pageinfo.hasNext
  95. console.log(that.data.hasNext)
  96. for (var i = 0; i < data.length; i++) {
  97. if (orient == 'top') {
  98. list.unshift(data[i]);
  99. } else {
  100. list.push(data[i]);
  101. }
  102. }
  103. that.setData({ dataList: list });
  104. }
  105. },
  106. complete: function () {
  107. // complete
  108. that.setData({ hidden: true });//加载成功
  109. wx.stopPullDownRefresh() //停止下拉刷新
  110. }
  111. });
  112. }