groupIndex.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. var app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. list: [],
  8. loadText: "加载中...",
  9. noData: 0,
  10. loadMore: true,
  11. keyword: ""
  12. },
  13. page: 1,
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.getData();
  19. },
  20. /**
  21. * 生命周期函数--监听页面显示
  22. */
  23. onShow: function () {
  24. },
  25. /**
  26. * 获取列表
  27. */
  28. getData: function () {
  29. let that= this;
  30. wx.showLoading();
  31. const token = wx.getStorageSync('token');
  32. app.util.request({
  33. url: 'entry/wxapp/index',
  34. data: {
  35. controller: 'solitaire.get_head_solitairelist',
  36. token: token,
  37. page: this.page,
  38. keyword: this.data.keyword
  39. },
  40. dataType: 'json',
  41. success: function (res) {
  42. wx.hideLoading();
  43. if (res.data.code == 0) {
  44. let h = {};
  45. let list = res.data.data;
  46. if (list.length < 20) h.noMore = true;
  47. let oldList = that.data.list;
  48. list = oldList.concat(list);
  49. that.page++;
  50. that.setData({ list, ...h })
  51. } else if (res.data.code == 1) {
  52. // 无数据
  53. if (that.page == 1) that.setData({ noData: 1 })
  54. that.setData({ loadMore: false, noMore: false, loadText: "没有更多记录了~" })
  55. } else if (res.data.code == 2) {
  56. app.util.message('您还未登录', 'switchTo:/lionfish_comshop/pages/index/index', 'error');
  57. return;
  58. } else {
  59. app.util.message(res.data.msg, 'switchTo:/lionfish_comshop/pages/index/index', 'error');
  60. return;
  61. }
  62. }
  63. })
  64. },
  65. goResult: function (e){
  66. let keyword = e.detail.value || '', that = this;
  67. this.page = 1;
  68. this.setData({
  69. list: [],
  70. loadText: "加载中...",
  71. noData: 0,
  72. loadMore: true,
  73. keyword
  74. }, ()=>{
  75. that.getData();
  76. })
  77. },
  78. goDetails: function (e){
  79. var id = e ? e.currentTarget.dataset.id : '';
  80. if (!id) return;
  81. let link = `/lionfish_comshop/moduleA/solitaire/groupDetails?id=${id}`;
  82. var pages_all = getCurrentPages();
  83. if (pages_all.length > 3) {
  84. wx.redirectTo({
  85. url: link
  86. })
  87. } else {
  88. wx.navigateTo({
  89. url: link
  90. })
  91. }
  92. },
  93. /**
  94. * 页面相关事件处理函数--监听用户下拉动作
  95. */
  96. onPullDownRefresh: function () {
  97. },
  98. /**
  99. * 页面上拉触底事件的处理函数
  100. */
  101. onReachBottom: function () {
  102. if (!this.data.loadMore) return false;
  103. this.getData();
  104. }
  105. })