index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // 首发新品子页面
  2. import {
  3. getGroomList
  4. } from '../../api/store.js';
  5. import {
  6. getCoupons
  7. } from '../../api/api.js';
  8. const app = getApp();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. parameter: {
  15. 'navbar': '1',
  16. 'return': '1',
  17. 'title': '首发新品'
  18. },
  19. imgUrls: [],
  20. bastList: [],
  21. name: '',
  22. icon: '',
  23. type: 0,
  24. status: 0,
  25. loading: false,
  26. loadend: false,
  27. page: 1,
  28. limit: 20,
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. this.setData({
  35. type: options.type
  36. });
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. var type = this.data.type;
  48. if (type == 1) {
  49. this.setData({
  50. 'parameter.title': '精品推荐',
  51. name: '精品推荐',
  52. icon: 'icon-jingpintuijian'
  53. });
  54. } else if (type == 2) {
  55. this.setData({
  56. 'parameter.title': '热门榜单',
  57. name: '热门榜单',
  58. icon: 'icon-remen',
  59. status: 1
  60. });
  61. } else if (type == 3) {
  62. this.setData({
  63. 'parameter.title': '首发新品',
  64. name: '首发新品',
  65. icon: 'icon-xinpin'
  66. });
  67. } else if (type == 4) {
  68. this.setData({
  69. 'parameter.title': '促销单品',
  70. name: '促销单品',
  71. icon: 'icon-cuxiaoguanli'
  72. });
  73. } else {
  74. this.setData({
  75. 'parameter.title': '首发新品',
  76. name: '首发新品',
  77. icon: 'icon-xinpin'
  78. });
  79. }
  80. this.getIndexGroomList();
  81. },
  82. getIndexGroomList: function () {
  83. var that = this
  84. if (this.data.loadend) return false;
  85. if (this.data.loading) return false;
  86. that.setData({
  87. loading: true,
  88. loadTitle: '正在搜索'
  89. });
  90. getGroomList(that.data.type, {
  91. page: that.data.page,
  92. limit: that.data.limit
  93. }).then(res => {
  94. var list = res.data.list,
  95. loadend = list.length < that.data.limit;
  96. var bastList = app.SplitArray(list, that.data.bastList);
  97. that.setData({
  98. loading: false,
  99. bastList: bastList,
  100. page: that.data.page + 1,
  101. loadend: loadend,
  102. loadTitle: loadend ? '已全部加载' : '加载更多',
  103. imgUrls: res.data.banner
  104. });
  105. }).catch(err => {
  106. that.setData({
  107. loading: false,
  108. loadTitle: "加载更多"
  109. });
  110. });
  111. },
  112. /**
  113. * 生命周期函数--监听页面隐藏
  114. */
  115. onHide: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面卸载
  119. */
  120. onUnload: function () {
  121. },
  122. /**
  123. * 页面相关事件处理函数--监听用户下拉动作
  124. */
  125. onPullDownRefresh: function () {
  126. },
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom: function () {
  131. this.getIndexGroomList();
  132. },
  133. /**
  134. * 用户点击右上角分享
  135. */
  136. onShareAppMessage: function () {
  137. }
  138. })