index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  6. <view class="list-scroll-view">
  7. <discount :Style="Style" :couponList="list"></discount>
  8. </view>
  9. </scroll-view>
  10. </view>
  11. </view>
  12. </mobile-frame>
  13. </template>
  14. <script>
  15. import discount from '@/components/discount/index.vue';
  16. export default {
  17. components: {
  18. discount
  19. },
  20. data() {
  21. return {
  22. Style: {
  23. status: true
  24. },
  25. user: {},
  26. list: [],
  27. total: 0,
  28. skip: 0,
  29. limit: 5,
  30. page: 0
  31. };
  32. },
  33. onLoad: function(e) {
  34. const that = this;
  35. // 监听用户是否登录
  36. that.watchLogin();
  37. },
  38. methods: {
  39. // 监听用户是否登录
  40. watchLogin() {
  41. const that = this;
  42. uni.getStorage({
  43. key: 'token',
  44. success: function(res) {
  45. let user = that.$jwt(res.data);
  46. if (user) that.$set(that, `user`, user);
  47. that.search();
  48. },
  49. fail: function(err) {
  50. uni.navigateTo({
  51. url: `/pages/login/index`
  52. })
  53. }
  54. });
  55. },
  56. // 查询列表
  57. async search() {
  58. const that = this;
  59. let user = that.user;
  60. let info = {
  61. // skip: that.skip,
  62. // limit: that.limit,
  63. customer: user._id
  64. }
  65. const res = await that.$api(`/userCoupon`, 'GET', {
  66. ...info
  67. })
  68. if (res.errcode == '0') {
  69. let list = [...that.list, ...res.data];
  70. that.$set(that, `list`, list)
  71. that.$set(that, `total`, res.total)
  72. } else {
  73. uni.showToast({
  74. title: res.errmsg,
  75. });
  76. }
  77. },
  78. // 分页
  79. toPage(e) {
  80. const that = this;
  81. let list = that.list;
  82. let limit = that.limit;
  83. if (that.total > list.length) {
  84. uni.showLoading({
  85. title: '加载中',
  86. mask: true
  87. })
  88. let page = that.page + 1;
  89. that.$set(that, `page`, page)
  90. let skip = page * limit;
  91. that.$set(that, `skip`, skip)
  92. that.search();
  93. uni.hideLoading();
  94. } else uni.showToast({
  95. title: '没有更多数据了'
  96. });
  97. },
  98. // 清空列表
  99. clearPage() {
  100. const that = this;
  101. that.$set(that, `list`, [])
  102. that.$set(that, `skip`, 0)
  103. that.$set(that, `limit`, 5)
  104. that.$set(that, `page`, 0)
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss">
  110. .main {
  111. background-color: var(--f5Color);
  112. }
  113. </style>