patternMenu.js 5.2 KB

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