list.vue 4.8 KB

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