index.js 2.9 KB

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