index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. 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. banIndex: e.currentTarget.dataset.index,
  64. requestState: true, //数据初始化
  65. page: 1,//数据初始化
  66. goodsList: []//数据初始化
  67. })
  68. that.getGoodsList(that)
  69. },
  70. getGoodsList(that){
  71. let data = {
  72. classId: that.data.classifyNavActiveId,
  73. limit: that.data.limit,
  74. offset:that.data.page,
  75. channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : ""
  76. }
  77. if (that.data.maxPrice) {
  78. data.maxPrice = that.data.maxPrice
  79. }
  80. if (that.data.minPrice) {
  81. data.minPrice = that.data.minPrice
  82. }
  83. if (that.data.priceSort) {
  84. data.priceSort = that.data.priceSort
  85. }
  86. if (that.data.timeSort) {
  87. data.timeSort = that.data.timeSort
  88. }
  89. wx.request({
  90. url: host +'/commodityapi/queryCommodityByClass',
  91. method:'get',
  92. data:data,
  93. success(res){
  94. let dataArray = that.data.goodsList;
  95. res.data.rows.forEach(el => {
  96. el.logo = el.commodity_logo.split(",")
  97. })
  98. dataArray.push(...res.data.rows)
  99. that.setData({
  100. goodsList: dataArray,
  101. requestState: res.data.rows.length > that.data.limit
  102. })
  103. }
  104. })
  105. },
  106. filterTap(){
  107. let that = this;
  108. that.setData({
  109. filterStatic: !that.data.filterStatic,
  110. page:1,
  111. goodsList:[],
  112. requestState:true,
  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. requestState: true,
  123. })
  124. that.getGoodsList(that)
  125. },
  126. priceSortTap() {
  127. let that = this;
  128. that.setData({
  129. priceSort: that.data.priceSort === null ? 'asc' : that.data.priceSort === 'asc' ? 'desc' : 'asc',
  130. })
  131. },
  132. blurPriceMin(e) {
  133. // event.detail = {value: value}
  134. let that = this;
  135. that.setData({
  136. minPrice: e.detail.value,
  137. page: 1,
  138. goodsList: [],
  139. requestState: true,
  140. })
  141. that.getGoodsList(that)
  142. },
  143. blurPriceMax(e) {
  144. let that = this;
  145. that.setData({
  146. maxPrice: e.detail.value,
  147. page: 1,
  148. goodsList: [],
  149. requestState: true,
  150. })
  151. that.getGoodsList(that)
  152. },
  153. close(){
  154. this.setData({
  155. filterStatic:false
  156. })
  157. },
  158. toGoodsDetail(e) { // 进入商品详情页
  159. let that = this, id = e.currentTarget.dataset.id;
  160. wx.navigateTo({
  161. url: '/pages/buy/buy?com_id=' + id,
  162. })
  163. },
  164. radioChange(e){ // radio切换
  165. console.log(e.detail.value)
  166. let that = this, price = e.detail.value.split(',');
  167. that.setData({
  168. minPrice: price[0],
  169. maxPrice: price[1] == '~' ? null : price[1] ,
  170. requestState: true, //数据初始化
  171. page: 1,//数据初始化
  172. goodsList: []//数据初始化
  173. })
  174. that.getGoodsList(that)
  175. },
  176. search(){
  177. wx.redirectTo({
  178. url: "/pages/searchList/searchList",
  179. })
  180. }
  181. })