list.vue 5.0 KB

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