patternMenu.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // newsShop/pages/patternMenu/patternMenu.js
  2. let app = getApp();
  3. let host = app.globalData.servsers; // 请求的url
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. host:host,
  10. isSelect: "1", //默认全部
  11. dataStateArray: [
  12. {
  13. state: '1',
  14. label: "营销礼赠",
  15. },
  16. {
  17. state: '2',
  18. label: "商务送礼",
  19. },
  20. {
  21. state: '3',
  22. label: "员工/福利",
  23. }
  24. ],
  25. filterArray: [
  26. // { name: '1', value: '0~499元' },
  27. // { name: '2', value: '500~999元' },
  28. // { name: '3', value: '1000~1999元' },
  29. // { name: '4', value: '2000元以上' },
  30. ],
  31. requestState:true, //检测请求状态是否结束了
  32. filterStatic: false,
  33. isNew: true,
  34. isMin: true,
  35. goodsList:[],
  36. page:1, //默认是第一页
  37. limit:20, //一页20条数据
  38. maxPrice:null,//最大价格
  39. minPrice:null,//最低价格
  40. priceSort: null, //价格排序,默认降序
  41. timeSort: null, //价时间排序,默认降序
  42. requestState:true, //默认是可以向下请求的
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. this.getGiftNavTab(this)
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面隐藏
  62. */
  63. onHide: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面卸载
  67. */
  68. onUnload: function () {
  69. },
  70. /**
  71. * 页面相关事件处理函数--监听用户下拉动作
  72. */
  73. onPullDownRefresh: function () {
  74. let that = this;
  75. if (that.data.requestState){
  76. that.setData({
  77. page:that.data.page + 1
  78. })
  79. that.getGiftList(that)
  80. }
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom: function () {
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage: function () {
  91. },
  92. tab(e){ // 头部tab切换
  93. let that = this;
  94. that.setData({
  95. isSelect: e.currentTarget.dataset.id,
  96. goodsList:[],
  97. page:1,
  98. requestState: true,
  99. })
  100. that.getGiftList(that)
  101. },
  102. timeSortTap(){ // 时间筛选
  103. let that = this;
  104. that.setData({
  105. timeSort: that.data.timeSort === null ? 'asc' : that.data.timeSort === 'asc' ? 'desc' : 'asc',
  106. goodsList: [],
  107. page: 1,
  108. requestState: true,
  109. })
  110. that.getGiftList(that)
  111. },
  112. priceSortTap() { // 价格筛选
  113. let that = this;
  114. that.setData({
  115. priceSort: that.data.priceSort === null ? 'asc' : that.data.priceSort === 'asc' ? 'desc' : 'asc',
  116. goodsList: [],
  117. page: 1,
  118. requestState: true,
  119. })
  120. that.getGiftList(that)
  121. },
  122. priceMaxMinTap(){ // 价格区间筛选
  123. let that = this;
  124. that.setData({
  125. filterStatic: true
  126. })
  127. },
  128. close(){
  129. let that = this;
  130. that.setData({
  131. filterStatic: false
  132. })
  133. },
  134. blurPriceMin(e){
  135. // event.detail = {value: value}
  136. let that = this;
  137. that.setData({
  138. minPrice: e.detail.value,
  139. page: 1,
  140. requestState:true,
  141. goodsList: [],
  142. })
  143. that.getGiftList(that)
  144. },
  145. blurPriceMax(e){
  146. let that = this;
  147. that.setData({
  148. maxPrice:e.detail.value,
  149. page:1,
  150. requestState: true,
  151. goodsList:[],
  152. })
  153. that.getGiftList(that)
  154. },
  155. getGiftNavTab(that){
  156. wx.request({
  157. url: host + '/classifyapi/classifyTwoAll',
  158. method: 'get',
  159. data: {
  160. classifyHigher:'3060'
  161. },
  162. success(res){
  163. console.log(res,"res")
  164. that.setData({
  165. dataStateArray:res.data.rows,
  166. isSelect:res.data.rows[0].id
  167. })
  168. that.getGiftList(that)
  169. }
  170. })
  171. },
  172. getGiftList(that){
  173. let data = {
  174. channelId: 5, // 渠道id,现在为5,一件选礼为5
  175. classId: that.data.isSelect,
  176. limit: that.data.limit, // 一页20条数据
  177. offset: that.data.page, //当前页数
  178. }
  179. if (that.data.priceSort) {
  180. data.priceSort = that.data.priceSort
  181. }
  182. if (that.data.timeSort) {
  183. data.timeSort = that.data.timeSort
  184. }
  185. if (that.data.maxPrice){
  186. data.maxPrice = that.data.maxPrice
  187. }
  188. if (that.data.minPrice) {
  189. data.minPrice = that.data.minPrice
  190. }
  191. wx.request({
  192. url: host +'/commodityapi/queryCommodityByClass',
  193. method:'get',
  194. data:data,
  195. success(res){
  196. let dataArray = that.data.goodsList;
  197. res.data.rows.forEach(el=>{
  198. el.logo = el.commodity_logo.split(",")
  199. })
  200. dataArray.push(...res.data.rows)
  201. that.setData({
  202. goodsList: dataArray,
  203. requestState: res.data.rows.length == that.data.limit
  204. })
  205. }
  206. })
  207. },
  208. toGoodsDetail(e){ // 进入商品详情页
  209. let that = this, id = e.currentTarget.dataset.id;
  210. wx.navigateTo({
  211. url: '/pages/buy/buy?com_id='+id,
  212. })
  213. }
  214. })