list.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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" v-if="item.act_time.is_use=='0'">
  16. <text>{{item.act_time.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>{{config.bottom_title}}</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. // 平台信息
  36. config: {},
  37. searchInfo: {},
  38. list: [],
  39. total: 0,
  40. page: 0,
  41. skip: 0,
  42. limit: 6,
  43. // 数据是否触底
  44. is_bottom: false,
  45. scrollTop: 0,
  46. };
  47. },
  48. onLoad: function() {
  49. const that = this;
  50. that.searchConfig();
  51. that.search();
  52. // 下拉刷新
  53. },
  54. methods: {
  55. // 查询基本设置
  56. searchConfig() {
  57. const that = this;
  58. uni.getStorage({
  59. key: 'config',
  60. success: function(res) {
  61. if (res.data) that.$set(that, `config`, res.data)
  62. },
  63. fail: function(err) {
  64. console.log(err);
  65. }
  66. })
  67. },
  68. async search() {
  69. const that = this;
  70. let info = {
  71. skip: that.skip,
  72. limit: that.limit
  73. }
  74. let res = await that.$api(`/platformAct`, 'GET', {
  75. ...info,
  76. ...that.searchInfo
  77. });
  78. if (res.errcode == '0') {
  79. let list = [...that.list, ...res.data]
  80. that.$set(that, `list`, list);
  81. that.$set(that, `total`, res.total);
  82. }
  83. },
  84. toPage() {
  85. const that = this;
  86. let list = that.list;
  87. let limit = that.limit;
  88. if (that.total > list.length) {
  89. uni.showLoading({
  90. title: '加载中',
  91. mask: true
  92. })
  93. let page = that.page + 1;
  94. that.$set(that, `page`, page)
  95. let skip = page * limit;
  96. that.$set(that, `skip`, skip)
  97. that.search();
  98. uni.hideLoading();
  99. } else that.$set(that, `is_bottom`, true)
  100. },
  101. toScroll(e) {
  102. const that = this;
  103. let up = that.scrollTop;
  104. that.$set(that, `scrollTop`, e.detail.scrollTop);
  105. let num = Math.sign(up - e.detail.scrollTop);
  106. if (num == 1) that.$set(that, `is_bottom`, false);
  107. },
  108. // 输入框
  109. toInput(e) {
  110. const that = this;
  111. if (e.detail.value) that.$set(that.searchInfo, `title`, e.detail.value);
  112. else that.$set(that, `searchInfo`, {});
  113. that.clearPage();
  114. that.search();
  115. },
  116. // 清空列表
  117. clearPage() {
  118. const that = this;
  119. that.$set(that, `list`, [])
  120. that.$set(that, `skip`, 0)
  121. that.$set(that, `limit`, 6)
  122. that.$set(that, `page`, 0)
  123. },
  124. toInfo(e) {
  125. const that = this;
  126. uni.navigateTo({
  127. url: `/pagesRest/activity/info?id=${e._id}`
  128. })
  129. }
  130. },
  131. onPullDownRefresh: async function() {
  132. const that = this;
  133. that.$set(that, `list`, [])
  134. that.$set(that, `skip`, 0)
  135. that.$set(that, `limit`, 6)
  136. that.$set(that, `page`, 0)
  137. await that.search();
  138. uni.stopPullDownRefresh();
  139. }
  140. }
  141. </script>
  142. <style lang="scss">
  143. .main {
  144. display: flex;
  145. flex-direction: column;
  146. width: 100vw;
  147. height: 100vh;
  148. .one {
  149. border-bottom: 1px solid var(--f85Color);
  150. padding: 2vw;
  151. input {
  152. padding: 2vw;
  153. background-color: var(--f1Color);
  154. font-size: var(--font14Size);
  155. border-radius: 5px;
  156. }
  157. }
  158. .two {
  159. position: relative;
  160. flex-grow: 1;
  161. .list {
  162. margin: 2vw 2vw 0 2vw;
  163. width: 96vw;
  164. height: 14vh;
  165. overflow: hidden;
  166. border-radius: 10px;
  167. box-shadow: 0 0 5px #858585;
  168. position: relative;
  169. .img {
  170. .image {
  171. width: 100%;
  172. height: 14vh;
  173. box-shadow: 0 0 5px #f1f1f1;
  174. border-radius: 10px;
  175. }
  176. }
  177. .title {
  178. position: absolute;
  179. top: 5vw;
  180. text-align: center;
  181. width: 95%;
  182. left: 2vw;
  183. text {
  184. font-size: 20px;
  185. font-family: cursive;
  186. color: #000000;
  187. font-weight: bold;
  188. overflow: hidden;
  189. text-overflow: ellipsis;
  190. -webkit-line-clamp: 2;
  191. word-break: break-all;
  192. display: -webkit-box;
  193. -webkit-box-orient: vertical;
  194. }
  195. }
  196. .time {
  197. position: absolute;
  198. bottom: 2vw;
  199. right: 2vw;
  200. font-size: 12px;
  201. width: 100%;
  202. text-align: right;
  203. }
  204. }
  205. }
  206. }
  207. .scroll-view {
  208. position: absolute;
  209. top: 0;
  210. left: 0;
  211. right: 0;
  212. bottom: 0;
  213. .list-scroll-view {
  214. display: flex;
  215. flex-direction: row;
  216. flex-wrap: wrap;
  217. }
  218. }
  219. .is_bottom {
  220. text-align: center;
  221. text {
  222. padding: 1vw 0;
  223. display: inline-block;
  224. }
  225. }
  226. .is_bottom {
  227. text-align: center;
  228. width: 100vw;
  229. text {
  230. padding: 1vw 0;
  231. display: inline-block;
  232. }
  233. }
  234. </style>