index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // index.js
  2. //获取应用实例
  3. var app = getApp();
  4. let host = app.globalData.servsers; // 请求的url
  5. Page({
  6. data: {
  7. host:host,
  8. classifyNavList:[],
  9. classifyNavActiveId: 2981,
  10. goodsList:[],
  11. commodity_levelTwo:null,
  12. requestState:true, //默认为true,表示还有数据
  13. page:0,
  14. filterArray: [
  15. { name: '1', value: '0~499元' },
  16. { name: '2', value: '500~999元'},
  17. { name: '3', value: '1000~1999元' },
  18. { name: '4', value: '2000元以上' },
  19. ],
  20. filterStatic:false,
  21. isNew:true,
  22. isMin:true,
  23. },
  24. onLoad(){
  25. this.getNavList(this);
  26. this.getGoodsListAllfor(this)
  27. },
  28. onShow(){
  29. },
  30. onReachBottom: function () {
  31. if (this.data.requestState) {
  32. this.setData({
  33. page: this.data.page + 1
  34. })
  35. this.getGoodsList(this)
  36. }
  37. console.log('到底了')
  38. },
  39. getNavList(that){
  40. wx.request({
  41. url: host + '/classifyapi/findAllforhome',
  42. method:'get',
  43. success(res){
  44. console.log(res,"成功后的")
  45. that.setData({
  46. classifyNavList:[...res.data.rows]
  47. })
  48. }
  49. })
  50. },
  51. classifyTap(e){
  52. console.log(e,"classifyTap")
  53. let item = e.currentTarget.dataset.item,that = this;
  54. that.setData({
  55. classifyNavActiveId:item.id,
  56. requestState: true, //数据初始化
  57. page: 0,//数据初始化
  58. goodsList: []//数据初始化
  59. })
  60. that.getGoodsListAllfor(that)
  61. },
  62. getGoodsListAllfor(that){
  63. wx.request({
  64. url: host +'/classifyapi/findAllforviewSce',
  65. method:'get',
  66. data:{
  67. id:that.data.classifyNavActiveId
  68. },
  69. success(res){
  70. that.setData({
  71. commodity_levelTwo:res.data.rows[0].id,
  72. })
  73. that.getGoodsList(that)
  74. }
  75. })
  76. },
  77. getGoodsList(that){
  78. let goodsList = that.data.goodsList, requestState = true
  79. wx.request({
  80. url: host + '/commodityapi/commoditviewfoeeverybody?commodity_levelTwo=2983&offset=0&limit=10',
  81. method:'get',
  82. data:{
  83. commodity_levelTwo: that.data.commodity_levelTwo,
  84. offset:that.data.page,
  85. limit:10,
  86. },
  87. success(res){
  88. console.log(res)
  89. res.data.rows.length < 10 ? requestState = false : requestState = true
  90. goodsList.push(...res.data.rows)
  91. that.setData({
  92. goodsList: goodsList,
  93. requestState: requestState
  94. })
  95. }
  96. })
  97. },
  98. filterTap(){
  99. let that = this;
  100. that.setData({
  101. filterStatic: !that.data.filterStatic
  102. })
  103. },
  104. newTap(){
  105. this.setData({
  106. isNew:!this.data.isNew
  107. })
  108. },
  109. priceTap() {
  110. this.setData({
  111. isMin: !this.data.isMin
  112. })
  113. },
  114. close(){
  115. this.setData({
  116. filterStatic:false
  117. })
  118. }
  119. })