newkindList.js 4.6 KB

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