list.vue 4.9 KB

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