list.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <input type="text" v-model="searchInfo.title" @blur="toInput" placeholder="请输入活动名称">
  6. </view>
  7. <view class="two">
  8. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  9. <view class="list-scroll-view">
  10. <view class="list" v-for="(item,index) in list" :key="index" @tap="toInfo(item)">
  11. <view class="img">
  12. <image class="image" :src="item.cover&&item.cover.length>0?item.cover[0].url:''" mode="">
  13. </image>
  14. </view>
  15. <view class="title">
  16. <text>{{item.title}}</text>
  17. </view>
  18. <view class="time" v-if="item.act_time.is_use=='0'">
  19. <text>{{item.act_time.value}}</text>
  20. </view>
  21. </view>
  22. <view class="is_bottom" v-if="is_bottom">
  23. <text>我们也是有底线的!</text>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. </view>
  28. </view>
  29. </mobile-frame>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. searchInfo: {},
  36. list: [],
  37. total: 0,
  38. page: 0,
  39. skip: 0,
  40. limit: 6,
  41. // 数据是否触底
  42. is_bottom: false,
  43. scrollTop: 0,
  44. };
  45. },
  46. onLoad: function(e) {},
  47. onShow: function() {
  48. const that = this;
  49. that.search();
  50. },
  51. methods: {
  52. async search() {
  53. const that = this;
  54. let info = {
  55. skip: that.skip,
  56. limit: that.limit
  57. }
  58. let res = await that.$api(`/platformAct`, 'GET', {
  59. ...info,
  60. ...that.searchInfo
  61. });
  62. if (res.errcode == '0') {
  63. let list = [...that.list, ...res.data]
  64. that.$set(that, `list`, list);
  65. that.$set(that, `total`, res.total);
  66. }
  67. },
  68. toPage() {
  69. const that = this;
  70. let list = that.list;
  71. let limit = that.limit;
  72. if (that.total > list.length) {
  73. uni.showLoading({
  74. title: '加载中',
  75. mask: true
  76. })
  77. let page = that.page + 1;
  78. that.$set(that, `page`, page)
  79. let skip = page * limit;
  80. that.$set(that, `skip`, skip)
  81. that.search();
  82. uni.hideLoading();
  83. } else that.$set(that, `is_bottom`, true)
  84. },
  85. toScroll(e) {
  86. const that = this;
  87. let up = that.scrollTop;
  88. that.$set(that, `scrollTop`, e.detail.scrollTop);
  89. let num = Math.sign(up - e.detail.scrollTop);
  90. if (num == 1) that.$set(that, `is_bottom`, false);
  91. },
  92. // 输入框
  93. toInput(e) {
  94. const that = this;
  95. if (e.detail.value) that.$set(that.searchInfo, `title`, e.detail.value);
  96. else that.$set(that, `searchInfo`, {});
  97. that.clearPage();
  98. that.search();
  99. },
  100. // 清空列表
  101. clearPage() {
  102. const that = this;
  103. that.$set(that, `list`, [])
  104. that.$set(that, `skip`, 0)
  105. that.$set(that, `limit`, 6)
  106. that.$set(that, `page`, 0)
  107. },
  108. toInfo(e) {
  109. const that = this;
  110. that.clearPage();
  111. uni.navigateTo({
  112. url: `/pagesRest/activity/info?id=${e._id}`
  113. })
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss">
  119. .main {
  120. display: flex;
  121. flex-direction: column;
  122. width: 100vw;
  123. height: 100vh;
  124. .one {
  125. border-bottom: 1px solid var(--f85Color);
  126. padding: 2vw;
  127. input {
  128. padding: 2vw;
  129. background-color: var(--f1Color);
  130. font-size: var(--font14Size);
  131. border-radius: 5px;
  132. }
  133. }
  134. .two {
  135. position: relative;
  136. flex-grow: 1;
  137. .list {
  138. margin: 2vw 2vw 0 2vw;
  139. width: 96vw;
  140. border-radius: 10px;
  141. box-shadow: 0 0 5px #858585;
  142. position: relative;
  143. .img {
  144. .image {
  145. width: 100%;
  146. height: 14vh;
  147. box-shadow: 0 0 5px #f1f1f1;
  148. border-radius: 10px;
  149. }
  150. }
  151. .title {
  152. position: absolute;
  153. top: 5vw;
  154. text-align: center;
  155. width: 95%;
  156. left: 2vw;
  157. text {
  158. font-size: 20px;
  159. font-family: cursive;
  160. color: #000000;
  161. font-weight: bold;
  162. overflow: hidden;
  163. text-overflow: ellipsis;
  164. -webkit-line-clamp: 2;
  165. word-break: break-all;
  166. display: -webkit-box;
  167. -webkit-box-orient: vertical;
  168. }
  169. }
  170. .time {
  171. position: absolute;
  172. bottom: 2vw;
  173. right: 2vw;
  174. font-size: 12px;
  175. width: 100%;
  176. text-align: right;
  177. }
  178. }
  179. }
  180. }
  181. .scroll-view {
  182. position: absolute;
  183. top: 0;
  184. left: 0;
  185. right: 0;
  186. bottom: 0;
  187. .list-scroll-view {
  188. display: flex;
  189. flex-direction: row;
  190. flex-wrap: wrap;
  191. }
  192. }
  193. .is_bottom {
  194. text-align: center;
  195. text {
  196. padding: 1vw 0;
  197. display: inline-block;
  198. }
  199. }
  200. .is_bottom {
  201. text-align: center;
  202. width: 100vw;
  203. text {
  204. padding: 1vw 0;
  205. display: inline-block;
  206. }
  207. }
  208. </style>