list.vue 4.7 KB

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