index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. requestState:true, //默认为true,表示还有数据
  12. filterArray: [
  13. { name: '1', value: '0~499元' },
  14. { name: '2', value: '500~999元'},
  15. { name: '3', value: '1000~1999元' },
  16. { name: '4', value: '2000元以上' },
  17. ],
  18. filterStatic:false,
  19. page: 1, //默认第一页
  20. channelId:null, //渠道id,登录后给,默认为null
  21. maxPrice:null, //最大价格
  22. minPrice:null, //最低价格
  23. limit:10, //分页大小
  24. priceSort: null, //价格排序 desc asc
  25. timeSort: null, //时间排序 desc asc
  26. },
  27. onLoad(){
  28. this.getNavList(this);
  29. },
  30. onShow(){
  31. },
  32. onReachBottom: function () {
  33. if (this.data.requestState) {
  34. this.setData({
  35. page: this.data.page + 1
  36. })
  37. this.getGoodsList(this)
  38. }
  39. console.log('到底了')
  40. },
  41. getNavList(that){
  42. wx.request({
  43. url: host + '/classifyapi/classifyTwoAll',
  44. method:'get',
  45. data:{
  46. classifyHigher:'3053',
  47. },
  48. success(res){
  49. console.log(res,"成功后的")
  50. that.setData({
  51. classifyNavList:res.data.rows,
  52. classifyNavActiveId: res.data.rows[0].id
  53. })
  54. that.getGoodsList(that)
  55. }
  56. })
  57. },
  58. classifyTap(e){
  59. console.log(e,"classifyTap")
  60. let item = e.currentTarget.dataset.item,that = this;
  61. that.setData({
  62. classifyNavActiveId:item.id,
  63. requestState: true, //数据初始化
  64. page: 1,//数据初始化
  65. goodsList: []//数据初始化
  66. })
  67. that.getGoodsList(that)
  68. },
  69. getGoodsList(that){
  70. let data = {
  71. classId: that.data.classifyNavActiveId,
  72. limit: that.data.limit,
  73. offset:that.data.page,
  74. }
  75. if(that.data.channelId){
  76. data.channelId = that.data.channelId
  77. }
  78. if (that.data.maxPrice) {
  79. data.maxPrice = that.data.maxPrice
  80. }
  81. if (that.data.minPrice) {
  82. data.minPrice = that.data.minPrice
  83. }
  84. if (that.data.priceSort) {
  85. data.priceSort = that.data.priceSort
  86. }
  87. if (that.data.timeSort) {
  88. data.timeSort = that.data.timeSort
  89. }
  90. wx.request({
  91. url: host +'/commodityapi/queryCommodityByClass',
  92. method:'get',
  93. data:data,
  94. success(res){
  95. let dataArray = that.data.goodsList;
  96. res.data.rows.forEach(el => {
  97. el.logo = el.commodity_logo.split(",")
  98. })
  99. dataArray.push(...res.data.rows)
  100. that.setData({
  101. goodsList: dataArray,
  102. requestState: res.data.rows.length > that.data.limit
  103. })
  104. }
  105. })
  106. },
  107. filterTap(){
  108. let that = this;
  109. that.setData({
  110. filterStatic: !that.data.filterStatic,
  111. page:1,
  112. goodsList:[],
  113. })
  114. that.getGoodsList(that)
  115. },
  116. timeSortTap(){
  117. let that = this;
  118. that.setData({
  119. timeSort: that.data.timeSort === null ? 'asc' : that.data.timeSort === 'asc' ? 'desc' : 'asc',
  120. page:1,
  121. goodsList: [],
  122. })
  123. that.getGoodsList(that)
  124. },
  125. priceSortTap() {
  126. let that = this;
  127. that.setData({
  128. priceSort: that.data.priceSort === null ? 'asc' : that.data.priceSort === 'asc' ? 'desc' : 'asc',
  129. })
  130. },
  131. blurPriceMin(e) {
  132. // event.detail = {value: value}
  133. let that = this;
  134. that.setData({
  135. minPrice: e.detail.value,
  136. page: 1,
  137. goodsList: [],
  138. })
  139. that.getGoodsList(that)
  140. },
  141. blurPriceMax(e) {
  142. let that = this;
  143. that.setData({
  144. maxPrice: e.detail.value,
  145. page: 1,
  146. goodsList: [],
  147. })
  148. that.getGoodsList(that)
  149. },
  150. close(){
  151. this.setData({
  152. filterStatic:false
  153. })
  154. },
  155. toGoodsDetail(e) { // 进入商品详情页
  156. let that = this, id = e.currentTarget.dataset.id;
  157. wx.navigateTo({
  158. url: '/pages/buy/buy?com_id=' + id,
  159. })
  160. },
  161. search(){
  162. wx.redirectTo({
  163. url: "/pages/search/search",
  164. })
  165. }
  166. })