index.vue 3.3 KB

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