list.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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>{{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. 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. that.clearPage();
  127. uni.navigateTo({
  128. url: `/pagesRest/activity/info?id=${e._id}`
  129. })
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss">
  135. .main {
  136. display: flex;
  137. flex-direction: column;
  138. width: 100vw;
  139. height: 100vh;
  140. .one {
  141. border-bottom: 1px solid var(--f85Color);
  142. padding: 2vw;
  143. input {
  144. padding: 2vw;
  145. background-color: var(--f1Color);
  146. font-size: var(--font14Size);
  147. border-radius: 5px;
  148. }
  149. }
  150. .two {
  151. position: relative;
  152. flex-grow: 1;
  153. .list {
  154. margin: 2vw 2vw 0 2vw;
  155. width: 96vw;
  156. height: 22.5vw;
  157. overflow: hidden;
  158. border-radius: 10px;
  159. box-shadow: 0 0 5px #858585;
  160. position: relative;
  161. .img {
  162. .image {
  163. width: 100%;
  164. height: 14vh;
  165. box-shadow: 0 0 5px #f1f1f1;
  166. border-radius: 10px;
  167. }
  168. }
  169. .title {
  170. position: absolute;
  171. top: 5vw;
  172. text-align: center;
  173. width: 95%;
  174. left: 2vw;
  175. text {
  176. font-size: 20px;
  177. font-family: cursive;
  178. color: #000000;
  179. font-weight: bold;
  180. overflow: hidden;
  181. text-overflow: ellipsis;
  182. -webkit-line-clamp: 2;
  183. word-break: break-all;
  184. display: -webkit-box;
  185. -webkit-box-orient: vertical;
  186. }
  187. }
  188. .time {
  189. position: absolute;
  190. bottom: 2vw;
  191. right: 2vw;
  192. font-size: 12px;
  193. width: 100%;
  194. text-align: right;
  195. }
  196. }
  197. }
  198. }
  199. .scroll-view {
  200. position: absolute;
  201. top: 0;
  202. left: 0;
  203. right: 0;
  204. bottom: 0;
  205. .list-scroll-view {
  206. display: flex;
  207. flex-direction: row;
  208. flex-wrap: wrap;
  209. }
  210. }
  211. .is_bottom {
  212. text-align: center;
  213. text {
  214. padding: 1vw 0;
  215. display: inline-block;
  216. }
  217. }
  218. .is_bottom {
  219. text-align: center;
  220. width: 100vw;
  221. text {
  222. padding: 1vw 0;
  223. display: inline-block;
  224. }
  225. }
  226. </style>