index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. const res = await that.$api(`/userCoupon`, 'GET', {
  61. customer: user._id
  62. });
  63. if (res.errcode == '0') {
  64. let list = [...that.list, ...res.data];
  65. that.$set(that, `list`, list)
  66. that.$set(that, `total`, res.total)
  67. } else {
  68. uni.showToast({
  69. title: res.errmsg,
  70. });
  71. }
  72. },
  73. // 分页
  74. toPage(e) {
  75. const that = this;
  76. let list = that.list;
  77. let limit = that.limit;
  78. if (that.total > list.length) {
  79. uni.showLoading({
  80. title: '加载中',
  81. mask: true
  82. })
  83. let page = that.page + 1;
  84. that.$set(that, `page`, page)
  85. let skip = page * limit;
  86. that.$set(that, `skip`, skip)
  87. that.search();
  88. uni.hideLoading();
  89. } else uni.showToast({
  90. title: '没有更多数据了'
  91. });
  92. },
  93. // 清空列表
  94. clearPage() {
  95. const that = this;
  96. that.$set(that, `list`, [])
  97. that.$set(that, `skip`, 0)
  98. that.$set(that, `limit`, 5)
  99. that.$set(that, `page`, 0)
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss">
  105. .main {
  106. background-color: var(--f5Color);
  107. }
  108. </style>