index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. onHide: function() {
  48. const that = this;
  49. that.clearPage();
  50. },
  51. methods: {
  52. // 查询基本设置
  53. searchConfig() {
  54. const that = this;
  55. uni.getStorage({
  56. key: 'config',
  57. success: function(res) {
  58. if (res.data) that.$set(that, `config`, res.data)
  59. },
  60. fail: function(err) {
  61. console.log(err);
  62. }
  63. })
  64. },
  65. // 监听用户是否登录
  66. watchLogin() {
  67. const that = this;
  68. uni.getStorage({
  69. key: 'token',
  70. success: function(res) {
  71. let user = that.$jwt(res.data);
  72. if (user) that.$set(that, `user`, user);
  73. that.search();
  74. },
  75. fail: function(err) {
  76. uni.navigateTo({
  77. url: `/pages/login/index`
  78. })
  79. }
  80. });
  81. },
  82. // 查询列表
  83. async search() {
  84. const that = this;
  85. let user = that.user;
  86. let info = {
  87. skip: that.skip,
  88. limit: that.limit,
  89. customer: user._id
  90. }
  91. const res = await that.$api(`/userCoupon`, 'GET', {
  92. ...info
  93. })
  94. if (res.errcode == '0') {
  95. let list = [...that.list, ...res.data];
  96. that.$set(that, `list`, list)
  97. that.$set(that, `total`, res.total)
  98. } else {
  99. uni.showToast({
  100. title: res.errmsg,
  101. });
  102. }
  103. },
  104. // 分页
  105. toPage(e) {
  106. const that = this;
  107. let list = that.list;
  108. let limit = that.limit;
  109. if (that.total > list.length) {
  110. uni.showLoading({
  111. title: '加载中',
  112. mask: true
  113. })
  114. let page = that.page + 1;
  115. that.$set(that, `page`, page)
  116. let skip = page * limit;
  117. that.$set(that, `skip`, skip)
  118. that.search();
  119. uni.hideLoading();
  120. } else that.$set(that, `is_bottom`, true)
  121. },
  122. toScroll(e) {
  123. const that = this;
  124. let up = that.scrollTop;
  125. that.$set(that, `scrollTop`, e.detail.scrollTop);
  126. let num = Math.sign(up - e.detail.scrollTop);
  127. if (num == 1) that.$set(that, `is_bottom`, false);
  128. },
  129. // 清空列表
  130. clearPage() {
  131. const that = this;
  132. that.$set(that, `list`, [])
  133. that.$set(that, `skip`, 0)
  134. that.$set(that, `limit`, 5)
  135. that.$set(that, `page`, 0)
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss">
  141. .main {
  142. background-color: var(--f5Color);
  143. }
  144. .scroll-view {
  145. position: absolute;
  146. top: 0;
  147. left: 0;
  148. right: 0;
  149. bottom: 0;
  150. .list-scroll-view {
  151. display: flex;
  152. flex-direction: column;
  153. }
  154. }
  155. .is_bottom {
  156. text-align: center;
  157. text {
  158. padding: 2vw 0;
  159. display: inline-block;
  160. color: #858585;
  161. font-size: 14px;
  162. }
  163. }
  164. </style>