list.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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: 10,
  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. onPullDownRefresh: async function() {
  54. const that = this;
  55. that.clearPage();
  56. await that.search();
  57. uni.stopPullDownRefresh();
  58. },
  59. methods: {
  60. // 查询基本设置
  61. searchConfig() {
  62. const that = this;
  63. uni.getStorage({
  64. key: 'config',
  65. success: function(res) {
  66. if (res.data) that.$set(that, `config`, res.data)
  67. },
  68. fail: function(err) {
  69. console.log(err);
  70. }
  71. })
  72. },
  73. async search() {
  74. const that = this;
  75. let info = {
  76. skip: that.skip,
  77. limit: that.limit
  78. }
  79. let res = await that.$api(`/platformAct`, 'GET', {
  80. ...info,
  81. ...that.searchInfo
  82. });
  83. if (res.errcode == '0') {
  84. let list = [...that.list, ...res.data]
  85. that.$set(that, `list`, list);
  86. that.$set(that, `total`, res.total);
  87. }
  88. },
  89. toPage() {
  90. const that = this;
  91. let list = that.list;
  92. let limit = that.limit;
  93. if (that.total > list.length) {
  94. uni.showLoading({
  95. title: '加载中',
  96. mask: true
  97. })
  98. let page = that.page + 1;
  99. that.$set(that, `page`, page)
  100. let skip = page * limit;
  101. that.$set(that, `skip`, skip)
  102. that.search();
  103. uni.hideLoading();
  104. } else that.$set(that, `is_bottom`, true)
  105. },
  106. toScroll(e) {
  107. const that = this;
  108. let up = that.scrollTop;
  109. that.$set(that, `scrollTop`, e.detail.scrollTop);
  110. let num = Math.sign(up - e.detail.scrollTop);
  111. if (num == 1) that.$set(that, `is_bottom`, false);
  112. },
  113. // 输入框
  114. toInput(e) {
  115. const that = this;
  116. if (e.detail.value) that.$set(that.searchInfo, `title`, e.detail.value);
  117. else that.$set(that, `searchInfo`, {});
  118. that.clearPage();
  119. that.search();
  120. },
  121. toInfo(e) {
  122. const that = this;
  123. uni.navigateTo({
  124. url: `/pagesRest/activity/info?id=${e._id}`
  125. })
  126. },
  127. // 清空列表
  128. clearPage() {
  129. const that = this;
  130. that.$set(that, `list`, [])
  131. that.$set(that, `skip`, 0)
  132. that.$set(that, `limit`, 6)
  133. that.$set(that, `page`, 0)
  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: 14vh;
  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>