index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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元', price: [0,499] },
  14. { name: '2', value: '500~999元', price: [500, 999]},
  15. { name: '3', value: '1000~1999元', price: [1000, 1999]},
  16. { name: '4', value: '2000元以上', price: [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. requestState:true,
  114. })
  115. that.getGoodsList(that)
  116. },
  117. timeSortTap(){
  118. let that = this;
  119. that.setData({
  120. timeSort: that.data.timeSort === null ? 'asc' : that.data.timeSort === 'asc' ? 'desc' : 'asc',
  121. page:1,
  122. goodsList: [],
  123. requestState: true,
  124. })
  125. that.getGoodsList(that)
  126. },
  127. priceSortTap() {
  128. let that = this;
  129. that.setData({
  130. priceSort: that.data.priceSort === null ? 'asc' : that.data.priceSort === 'asc' ? 'desc' : 'asc',
  131. })
  132. },
  133. blurPriceMin(e) {
  134. // event.detail = {value: value}
  135. let that = this;
  136. that.setData({
  137. minPrice: e.detail.value,
  138. page: 1,
  139. goodsList: [],
  140. requestState: true,
  141. })
  142. that.getGoodsList(that)
  143. },
  144. blurPriceMax(e) {
  145. let that = this;
  146. that.setData({
  147. maxPrice: e.detail.value,
  148. page: 1,
  149. goodsList: [],
  150. requestState: true,
  151. })
  152. that.getGoodsList(that)
  153. },
  154. close(){
  155. this.setData({
  156. filterStatic:false
  157. })
  158. },
  159. toGoodsDetail(e) { // 进入商品详情页
  160. let that = this, id = e.currentTarget.dataset.id;
  161. wx.navigateTo({
  162. url: '/pages/buy/buy?com_id=' + id,
  163. })
  164. },
  165. radioChange(e){ // radio切换
  166. console.log(e.detail.value)
  167. let that = this, price = e.detail.value.split(',');
  168. that.setData({
  169. minPrice: price[0],
  170. maxPrice: price[1] == '~' ? null : price[1] ,
  171. requestState: true, //数据初始化
  172. page: 1,//数据初始化
  173. goodsList: []//数据初始化
  174. })
  175. that.getGoodsList(that)
  176. },
  177. search(){
  178. wx.redirectTo({
  179. url: "/pages/search/search",
  180. })
  181. }
  182. })