index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. user: {},
  23. list: [],
  24. total: 0,
  25. skip: 0,
  26. limit: 5,
  27. page: 0
  28. };
  29. },
  30. onLoad: function(e) {
  31. const that = this;
  32. // 监听用户是否登录
  33. that.watchLogin();
  34. },
  35. methods: {
  36. // 监听用户是否登录
  37. watchLogin() {
  38. const that = this;
  39. uni.getStorage({
  40. key: 'token',
  41. success: function(res) {
  42. let user = that.$jwt(res.data);
  43. if (user) that.$set(that, `user`, user);
  44. that.search();
  45. },
  46. fail: function(err) {
  47. uni.navigateTo({
  48. url: `/pages/login/index`
  49. })
  50. }
  51. });
  52. },
  53. // 查询列表
  54. async search() {
  55. const that = this;
  56. let user = that.user;
  57. const res = await that.$api(`/userCoupon`, 'GET', {
  58. customer: user._id
  59. });
  60. if (res.errcode == '0') {
  61. let list = [...that.list, ...res.data];
  62. that.$set(that, `list`, list)
  63. that.$set(that, `total`, res.total)
  64. } else {
  65. uni.showToast({
  66. title: res.errmsg,
  67. });
  68. }
  69. },
  70. // 分页
  71. toPage(e) {
  72. const that = this;
  73. let list = that.list;
  74. let limit = that.limit;
  75. if (that.total > list.length) {
  76. uni.showLoading({
  77. title: '加载中',
  78. mask: true
  79. })
  80. let page = that.page + 1;
  81. that.$set(that, `page`, page)
  82. let skip = page * limit;
  83. that.$set(that, `skip`, skip)
  84. that.search();
  85. uni.hideLoading();
  86. } else uni.showToast({
  87. title: '没有更多数据了'
  88. });
  89. },
  90. // 清空列表
  91. clearPage() {
  92. const that = this;
  93. that.$set(that, `list`, [])
  94. that.$set(that, `skip`, 0)
  95. that.$set(that, `limit`, 5)
  96. that.$set(that, `page`, 0)
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss">
  102. .main {
  103. background-color: var(--f5Color);
  104. }
  105. </style>