index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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({ type: options.type });
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function () {
  41. var type = this.data.type;
  42. if (type == 1){
  43. this.setData({ 'parameter.title': '精品推荐', name: '精品推荐', icon: 'icon-jingpintuijian'});
  44. } else if (type == 2) {
  45. this.setData({ 'parameter.title': '热门榜单', name: '热门榜单', icon: 'icon-remen', status: 1});
  46. } else if (type == 3) {
  47. this.setData({ 'parameter.title': '首发新品', name: '首发新品', icon: 'icon-xinpin' });
  48. } else if (type == 4) {
  49. this.setData({ 'parameter.title': '促销单品', name: '促销单品', icon: 'icon-cuxiaoguanli' });
  50. }else{
  51. this.setData({ 'parameter.title': '首发新品', name: '首发新品', icon: 'icon-xinpin' });
  52. }
  53. this.getIndexGroomList();
  54. },
  55. getIndexGroomList: function(){
  56. var that=this
  57. if(this.data.loadend) return false;
  58. if(this.data.loading) return false;
  59. that.setData({loading:true,loadTitle:'正在搜索'});
  60. getGroomList(that.data.type,{ page: that.data.page, limit: that.data.limit }).then(res=>{
  61. var list=res.data.list,loadend=list.length < that.data.limit;
  62. var bastList = app.SplitArray(list, that.data.bastList);
  63. that.setData({
  64. loading: false,
  65. bastList: bastList,
  66. page:that.data.page+1,
  67. loadend: loadend,
  68. loadTitle: loadend ? '已全部加载' : '加载更多',
  69. imgUrls: res.data.banner
  70. });
  71. }).catch(err=>{
  72. that.setData({ loading: false, loadTitle: "加载更多" });
  73. });
  74. },
  75. /**
  76. * 生命周期函数--监听页面隐藏
  77. */
  78. onHide: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面卸载
  82. */
  83. onUnload: function () {
  84. },
  85. /**
  86. * 页面相关事件处理函数--监听用户下拉动作
  87. */
  88. onPullDownRefresh: function () {
  89. },
  90. /**
  91. * 页面上拉触底事件的处理函数
  92. */
  93. onReachBottom: function () {
  94. this.getIndexGroomList();
  95. },
  96. /**
  97. * 用户点击右上角分享
  98. */
  99. onShareAppMessage: function () {
  100. }
  101. })