topic.vue 4.5 KB

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