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