list.vue 5.0 KB

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