index.js 4.6 KB

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