index.js 2.7 KB

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