recommendList.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // kindSecondList.js
  2. //获取应用实例
  3. var app = getApp();
  4. //导航标题
  5. var navigationBarTitle = {};
  6. //二级菜单项
  7. var navlist = [];
  8. // 列表
  9. var contentList = [];
  10. Page({
  11. data: {
  12. pageNo: 1,
  13. activeIndex: 0,
  14. navList: navlist,
  15. contentList: contentList,
  16. navId: 0,
  17. systemInfo: [],
  18. loadingHidden: false,
  19. list: [],
  20. num: 1,
  21. limt: 20,
  22. tab: '',
  23. classify_name: '',
  24. classify_des: '',
  25. currentItem: 0,
  26. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  27. callbackcount: 15, //返回数据的个数
  28. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  29. searchLoadingComplete: false //“没有数据”的变量,默认false,隐藏
  30. },
  31. onLoad: function (options) {
  32. that = this;
  33. var host = getApp().globalData.servsers;
  34. //热销
  35. wx.request({
  36. url: host+"commodityapi/findAllforNewproduct",
  37. data: {
  38. commodity_recommend: '2',
  39. offset: parseInt(that.data.searchPageNum) * 10,
  40. limit: 10,
  41. },
  42. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  43. header: {
  44. 'Accept': 'application/json'
  45. },
  46. success: function (res) {
  47. that.setData({
  48. contentList: res.data.rows,
  49. searchPageNum: 1, //第一次加载,设置1
  50. searchSongList: [], //放置返回数据的数组,设为空
  51. isFromSearch: true, //第一次加载,设置true
  52. searchLoading: true, //把"上拉加载"的变量设为true,显示
  53. searchLoadingComplete: false //把“没有数据”设为false,隐藏
  54. });
  55. if (res == null || res.data == null) {
  56. console.error('网络请求失败');
  57. return;
  58. }
  59. }
  60. });
  61. // wx.setNavigationBarTitle({
  62. // title: navigationBarTitle.title
  63. // })
  64. this.setData({
  65. classify_name: options.classify_name,
  66. classify_des: options.classify_des,
  67. })
  68. },
  69. //切换TAB
  70. tagChoose: function (options) {
  71. var that = this
  72. var id = options.currentTarget.dataset.id;
  73. //设置当前样式
  74. that.setData({
  75. 'firstActive': "",
  76. 'currentItem': id
  77. })
  78. },
  79. fetchSearchList: function () {//加载更多
  80. var that = this;
  81. var host = getApp().globalData.servsers;
  82. wx.request({
  83. url: host + "commodityapi/findAllforNewproduct",
  84. data: {
  85. commodity_recommend: that.data.searchPageNum,
  86. offset: parseInt(that.data.searchPageNum) * 10,
  87. limit: 10,
  88. },
  89. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  90. header: {
  91. 'Accept': 'application/json'
  92. },
  93. success: function (res) {
  94. if (res.data.rows.length != 0) {
  95. let contentList = [];
  96. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  97. that.data.isFromSearch ? contentList = res.data.rows : contentList = that.data.contentList.concat(res.data.rows)
  98. that.setData({
  99. contentList: contentList, //获取数据数组
  100. searchLoading: true //把"上拉加载"的变量设为false,显示
  101. });
  102. //没有数据了,把“没有数据”显示,把“上拉加载”隐藏
  103. } else {
  104. console.log(22);
  105. that.setData({
  106. searchLoadingComplete: true, //把“没有数据”设为true,显示
  107. searchLoading: false //把"上拉加载"的变量设为false,隐藏
  108. });
  109. }
  110. if (res == null || res.data == null) {
  111. console.error('网络请求失败');
  112. return;
  113. }
  114. wx.hideNavigationBarLoading(
  115. that.setData({
  116. hidden: 'hidden'
  117. })
  118. )
  119. }
  120. });
  121. },
  122. //滚动到底部触发事件
  123. searchScrollLower: function () {
  124. var that = this;
  125. console.log(that.data.searchLoading);
  126. if (that.data.searchLoading && !that.data.searchLoadingComplete) {
  127. that.setData({
  128. searchPageNum: that.data.searchPageNum + 1, //每次触发上拉事件,把searchPageNum+1
  129. isFromSearch: false //触发到上拉事件,把isFromSearch设为为false
  130. });
  131. that.fetchSearchList();
  132. }
  133. }
  134. })
  135. var that;
  136. var Util = require('../../utils/util.js');