patternMenu.js 5.1 KB

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