topic.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <view class="container">
  3. <scroll-view v-if="topicList.length >0" class="topic-list" :scroll-y="true" :scroll-top="scrollTop">
  4. <navigator class="item" v-for="(item, index) in topicList" :key="index" :url="'../topicDetail/topicDetail?id='+item.id">
  5. <image class="img" :src="item.scene_pic_url"></image>
  6. <view class="info">
  7. <text class="title">{{item.title}}</text>
  8. <text class="desc">{{item.subtitle}}</text>
  9. <text class="price">{{item.price_info}}元起</text>
  10. </view>
  11. </navigator>
  12. <view class="page" v-if="showPage">
  13. <view :class="'prev ' + (page <= 1 ? 'disabled' : '')" @tap="prevPage">上一页</view>
  14. <view :class="'next ' + ((count / size) < page +1 ? 'disabled' : '')" @tap="nextPage">下一页</view>
  15. </view>
  16. </scroll-view>
  17. <tui-show-empty v-else text="暂无专题"></tui-show-empty>
  18. </view>
  19. </template>
  20. <script>
  21. const util = require("@/utils/util.js")
  22. const api = require('@/utils/api.js');
  23. export default {
  24. data() {
  25. return {
  26. // text:"这是一个页面"
  27. topicList: [],
  28. page: 1,
  29. size: 10,
  30. count: 0,
  31. scrollTop: 0,
  32. showPage: false
  33. }
  34. },
  35. methods: {
  36. nextPage: function(event) {
  37. let that = this;
  38. if (this.page + 1 > that.count / that.size) {
  39. return true;
  40. }
  41. that.page = parseInt(that.page) + 1
  42. this.getTopic();
  43. },
  44. getTopic: function() {
  45. let that = this;
  46. that.scrollTop = 0
  47. that.showPage = false
  48. that.topicList = []
  49. // 页面渲染完成
  50. uni.showToast({
  51. title: '加载中...',
  52. icon: 'loading',
  53. duration: 2000
  54. });
  55. util.request(api.TopicList, {
  56. page: that.page,
  57. size: that.size
  58. }).then(function(res) {
  59. if (res.errno === 0) {
  60. that.scrollTop = 0
  61. that.topicList = res.data.data
  62. that.showPage = true
  63. that.count = res.data.count
  64. }
  65. uni.hideToast();
  66. });
  67. },
  68. prevPage: function(event) {
  69. if (this.page <= 1) {
  70. return false;
  71. }
  72. var that = this;
  73. that.page = parseInt(that.page) - 1
  74. this.getTopic();
  75. }
  76. },
  77. onLoad: function(options) {
  78. // 页面初始化 options为页面跳转所带来的参数
  79. this.getTopic();
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. page,
  85. .container {
  86. width: 750rpx;
  87. height: 100%;
  88. overflow: hidden;
  89. background: #f4f4f4;
  90. }
  91. .topic-list {
  92. width: 750rpx;
  93. height: 100%;
  94. overflow: hidden;
  95. background: #f4f4f4;
  96. }
  97. .topic-list .item {
  98. width: 100%;
  99. height: 625rpx;
  100. overflow: hidden;
  101. background: #fff;
  102. margin-bottom: 20rpx;
  103. }
  104. .topic-list .img {
  105. width: 100%;
  106. height: 415rpx;
  107. }
  108. .topic-list .info {
  109. width: 100%;
  110. height: 210rpx;
  111. overflow: hidden;
  112. }
  113. .topic-list .title {
  114. display: block;
  115. text-align: center;
  116. width: 100%;
  117. height: 33rpx;
  118. line-height: 35rpx;
  119. color: #333;
  120. overflow: hidden;
  121. font-size: 35rpx;
  122. margin-top: 30rpx;
  123. }
  124. .topic-list .desc {
  125. display: block;
  126. text-align: center;
  127. position: relative;
  128. width: auto;
  129. height: 24rpx;
  130. line-height: 24rpx;
  131. overflow: hidden;
  132. color: #999;
  133. font-size: 24rpx;
  134. margin-top: 16rpx;
  135. margin-bottom: 30rpx;
  136. }
  137. .topic-list .price {
  138. display: block;
  139. text-align: center;
  140. width: 100%;
  141. height: 27rpx;
  142. line-height: 27rpx;
  143. overflow: hidden;
  144. color: #b4282d;
  145. font-size: 27rpx;
  146. }
  147. .page {
  148. width: 750rpx;
  149. height: 108rpx;
  150. background: #fff;
  151. margin-bottom: 20rpx;
  152. }
  153. .page view {
  154. height: 108rpx;
  155. width: 50%;
  156. float: left;
  157. font-size: 29rpx;
  158. color: #333;
  159. text-align: center;
  160. line-height: 108rpx;
  161. }
  162. .page .prev {
  163. border-right: 1px solid #D9D9D9;
  164. }
  165. .page .disabled {
  166. color: #ccc;
  167. }
  168. </style>