index.js 4.8 KB

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