index.js 4.7 KB

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