patternMenu.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function (options) {
  47. this.getGiftNavTab(this)
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面显示
  56. */
  57. onShow: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面隐藏
  61. */
  62. onHide: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面卸载
  66. */
  67. onUnload: function () {
  68. },
  69. /**
  70. * 页面相关事件处理函数--监听用户下拉动作
  71. */
  72. onPullDownRefresh: function () {
  73. },
  74. /**
  75. * 页面上拉触底事件的处理函数
  76. */
  77. onReachBottom: function () {
  78. },
  79. /**
  80. * 用户点击右上角分享
  81. */
  82. onShareAppMessage: function () {
  83. },
  84. tab(e){ // 头部tab切换
  85. let that = this;
  86. that.setData({
  87. isSelect: e.currentTarget.dataset.id,
  88. goodsList:[],
  89. page:1,
  90. })
  91. that.getGiftList(that)
  92. },
  93. timeSortTap(){ // 时间筛选
  94. let that = this;
  95. that.setData({
  96. timeSort: that.data.timeSort === null ? 'asc' : that.data.timeSort === 'asc' ? 'desc' : 'asc',
  97. goodsList: [],
  98. page: 1,
  99. })
  100. that.getGiftList(that)
  101. },
  102. priceSortTap() { // 价格筛选
  103. let that = this;
  104. that.setData({
  105. priceSort: that.data.priceSort === null ? 'asc' : that.data.priceSort === 'asc' ? 'desc' : 'asc',
  106. goodsList: [],
  107. page: 1,
  108. })
  109. that.getGiftList(that)
  110. },
  111. priceMaxMinTap(){ // 价格区间筛选
  112. let that = this;
  113. that.setData({
  114. filterStatic: true
  115. })
  116. },
  117. close(){
  118. let that = this;
  119. that.setData({
  120. filterStatic: false
  121. })
  122. },
  123. blurPriceMin(e){
  124. // event.detail = {value: value}
  125. let that = this;
  126. that.setData({
  127. minPrice: e.detail.value,
  128. page: 1,
  129. goodsList: [],
  130. })
  131. that.getGiftList(that)
  132. },
  133. blurPriceMax(e){
  134. let that = this;
  135. that.setData({
  136. maxPrice:e.detail.value,
  137. page:1,
  138. goodsList:[],
  139. })
  140. that.getGiftList(that)
  141. },
  142. getGiftNavTab(that){
  143. wx.request({
  144. url: host + '/classifyapi/classifyTwoAll',
  145. method: 'get',
  146. data: {
  147. classifyHigher:'3060'
  148. },
  149. success(res){
  150. console.log(res,"res")
  151. that.setData({
  152. dataStateArray:res.data.rows,
  153. isSelect:res.data.rows[0].id
  154. })
  155. that.getGiftList(that)
  156. }
  157. })
  158. },
  159. getGiftList(that){
  160. let data = {
  161. channelId: 5, // 渠道id,现在为5,一件选礼为5
  162. classId: that.data.isSelect,
  163. limit: that.data.limit, // 一页20条数据
  164. offset: that.data.page, //当前页数
  165. }
  166. if (that.data.priceSort) {
  167. data.priceSort = that.data.priceSort
  168. }
  169. if (that.data.timeSort) {
  170. data.timeSort = that.data.timeSort
  171. }
  172. if (that.data.maxPrice){
  173. data.maxPrice = that.data.maxPrice
  174. }
  175. if (that.data.minPrice) {
  176. data.minPrice = that.data.minPrice
  177. }
  178. wx.request({
  179. url: host +'/commodityapi/queryCommodityByClass',
  180. method:'get',
  181. data:data,
  182. success(res){
  183. let dataArray = that.data.goodsList;
  184. res.data.rows.forEach(el=>{
  185. el.logo = el.commodity_logo.split(",")
  186. })
  187. dataArray.push(...res.data.rows)
  188. that.setData({
  189. goodsList: dataArray
  190. })
  191. }
  192. })
  193. }
  194. })