brandList.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // brandList.js
  2. //获取应用实例
  3. var brandList = [
  4. {}
  5. ];
  6. var app = getApp()
  7. Page({
  8. data: {
  9. brandList: brandList,
  10. page: 1,
  11. hasMore: true,
  12. isFromSearch: true, // 用于判断searchSongList数组是不是空数组,默认true,空的数组
  13. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  14. callbackcount: 10, //返回数据的个数
  15. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  16. searchLoadingComplete: false //“没有数据”的变量,默认false,隐藏
  17. },
  18. onLoad: function () {
  19. var that = this;
  20. var host = getApp().globalData.servsers;
  21. //品牌定制
  22. wx.request({
  23. url: host + "brandapi/brandall",
  24. data: {
  25. offset: 0,
  26. limit : 10
  27. },
  28. method: 'GET',
  29. header: {
  30. 'Accept': 'application/json'
  31. },
  32. success: function (res) {
  33. var size = res.data.total;
  34. that.setData({
  35. brandList: res.data.rows,
  36. searchPageNum: 0, //第一次加载,设置1
  37. isFromSearch: true, //第一次加载,设置true
  38. searchLoading: true, //把"上拉加载"的变量设为true,显示
  39. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  40. });
  41. if (res == null || res.data == null) {
  42. console.error('网络请求失败');
  43. return;
  44. }
  45. }
  46. })
  47. },
  48. //下拉刷新
  49. onPullDownRefresh: function (e) {
  50. this.onLoad();
  51. wx.stopPullDownRefresh();
  52. },
  53. fetchSearchList: function () {//加载更多
  54. var that = this;
  55. var host = getApp().globalData.servsers;
  56. wx.request({
  57. url: host + "brandapi/brandall",
  58. data: {
  59. offset: parseInt(that.data.searchPageNum)*10
  60. },
  61. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  62. header: {
  63. 'Accept': 'application/json'
  64. },
  65. success: function (res) {
  66. if (res.data.rows.length != 0) {
  67. let searchList = [];
  68. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  69. that.data.isFromSearch ? searchList = res.data.rows : searchList = that.data.brandList.concat(res.data.rows)
  70. that.setData({
  71. brandList: searchList , //获取数据数组
  72. searchLoading: true //把"上拉加载"的变量设为false,显示
  73. });
  74. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  75. } else {
  76. that.setData({
  77. searchLoadingComplete: true, //把“没有数据”设为true,显示
  78. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  79. });
  80. }
  81. if (res == null || res.data == null) {
  82. console.error('网络请求失败');
  83. return;
  84. }
  85. wx.hideNavigationBarLoading(
  86. that.setData({
  87. hidden: 'hidden'
  88. })
  89. )
  90. }
  91. });
  92. },
  93. //滚动到底部触发事件
  94. searchScrollLower: function () {
  95. var that = this;
  96. if (that.data.searchLoading && !that.data.searchLoadingComplete) {
  97. that.setData({
  98. searchPageNum: that.data.searchPageNum + 1, //每次触发上拉事件,把searchPageNum+1
  99. isFromSearch: false //触发到上拉事件,把isFromSearch设为为false
  100. });
  101. that.fetchSearchList();
  102. }
  103. }
  104. })
  105. var that;
  106. var Util = require('../../utils/util.js');