index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  6. <view class="list-scroll-view">
  7. <discount :Style="Style" :couponList="list"></discount>
  8. <view class="is_bottom" v-if="is_bottom">
  9. <text>{{config.bottom_title}}</text>
  10. </view>
  11. </view>
  12. </scroll-view>
  13. </view>
  14. </view>
  15. </mobile-frame>
  16. </template>
  17. <script>
  18. import discount from '@/components/discount/index.vue';
  19. export default {
  20. components: {
  21. discount
  22. },
  23. data() {
  24. return {
  25. // 系统设置
  26. config: {},
  27. Style: {
  28. status: true
  29. },
  30. user: {},
  31. list: [],
  32. total: 0,
  33. skip: 0,
  34. limit: 6,
  35. page: 0,
  36. // 数据是否触底
  37. is_bottom: false,
  38. scrollTop: 0,
  39. };
  40. },
  41. onLoad: function(e) {
  42. const that = this;
  43. that.searchConfig();
  44. // 监听用户是否登录
  45. that.watchLogin();
  46. },
  47. methods: {
  48. // 查询基本设置
  49. searchConfig() {
  50. const that = this;
  51. uni.getStorage({
  52. key: 'config',
  53. success: function(res) {
  54. if (res.data) that.$set(that, `config`, res.data)
  55. },
  56. fail: function(err) {
  57. console.log(err);
  58. }
  59. })
  60. },
  61. // 监听用户是否登录
  62. watchLogin() {
  63. const that = this;
  64. uni.getStorage({
  65. key: 'token',
  66. success: function(res) {
  67. let user = that.$jwt(res.data);
  68. if (user) that.$set(that, `user`, user);
  69. that.search();
  70. },
  71. fail: function(err) {
  72. uni.navigateTo({
  73. url: `/pages/login/index`
  74. })
  75. }
  76. });
  77. },
  78. // 查询列表
  79. async search() {
  80. const that = this;
  81. let user = that.user;
  82. let info = {
  83. skip: that.skip,
  84. limit: that.limit,
  85. customer: user._id
  86. }
  87. const res = await that.$api(`/userCoupon`, 'GET', {
  88. ...info
  89. })
  90. if (res.errcode == '0') {
  91. let list = [...that.list, ...res.data];
  92. that.$set(that, `list`, list)
  93. that.$set(that, `total`, res.total)
  94. } else {
  95. uni.showToast({
  96. title: res.errmsg,
  97. });
  98. }
  99. },
  100. // 分页
  101. toPage(e) {
  102. const that = this;
  103. let list = that.list;
  104. let limit = that.limit;
  105. if (that.total > list.length) {
  106. uni.showLoading({
  107. title: '加载中',
  108. mask: true
  109. })
  110. let page = that.page + 1;
  111. that.$set(that, `page`, page)
  112. let skip = page * limit;
  113. that.$set(that, `skip`, skip)
  114. that.search();
  115. uni.hideLoading();
  116. } else that.$set(that, `is_bottom`, true)
  117. },
  118. toScroll(e) {
  119. const that = this;
  120. let up = that.scrollTop;
  121. that.$set(that, `scrollTop`, e.detail.scrollTop);
  122. let num = Math.sign(up - e.detail.scrollTop);
  123. if (num == 1) that.$set(that, `is_bottom`, false);
  124. },
  125. // 清空列表
  126. clearPage() {
  127. const that = this;
  128. that.$set(that, `list`, [])
  129. that.$set(that, `skip`, 0)
  130. that.$set(that, `limit`, 5)
  131. that.$set(that, `page`, 0)
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss">
  137. .main {
  138. background-color: var(--f5Color);
  139. }
  140. .scroll-view {
  141. position: absolute;
  142. top: 0;
  143. left: 0;
  144. right: 0;
  145. bottom: 0;
  146. .list-scroll-view {
  147. display: flex;
  148. flex-direction: column;
  149. }
  150. }
  151. .is_bottom {
  152. text-align: center;
  153. text {
  154. padding: 2vw 0;
  155. display: inline-block;
  156. color: #858585;
  157. font-size: 14px;
  158. }
  159. }
  160. </style>