金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
6.2 KiB

  1. <template>
  2. <view>
  3. <lf-nav title="热门活动" :showIcon="true" bgColor="#fff" @changeHeight="e => nav_height = e"></lf-nav>
  4. <view v-if="tab_list.length">
  5. <u-tabs :list="tab_list" active-color="#15716E" inactive-color='#777777' :is-scroll="true" :current="tab_current" @change="tabChange"></u-tabs>
  6. </view>
  7. <swiper :style="{height: autoHeight}" :current="tab_current" @change="swiperChange">
  8. <swiper-item v-for="(tab, tabIndex) in tab_list" :key="tabIndex">
  9. <scroll-view :style="{height: autoHeight}" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher"
  10. @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
  11. <view class="scroll-content">
  12. <view class="card" v-for="(item, index) in tab.list" :key="index" @click="goDetails(item.id)">
  13. <view class="cover">
  14. <image class="img" :src="item.image" mode="aspectFill"></image>
  15. </view>
  16. <view class="info">
  17. <view class="title">{{item.name}}</view>
  18. <view class="date">{{item.time_start}}-{{item.time_end}}</view>
  19. </view>
  20. </view>
  21. <!-- 空数据的情况 -->
  22. <view class="loading-more">
  23. <text v-if="tab.list.length"
  24. :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text>
  25. <lf-nocontent v-else></lf-nocontent>
  26. </view>
  27. </view>
  28. <view style="height: 30rpx;"></view>
  29. </scroll-view>
  30. </swiper-item>
  31. </swiper>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data(){
  37. let _public = {
  38. page: 1,
  39. isPage: true,
  40. loadingClass: true,
  41. loadingText: '正在加载中'
  42. }
  43. return {
  44. tab_current: 0,
  45. tab_list: [{
  46. name: '正在进行',
  47. list: [],
  48. ..._public
  49. },{
  50. name: '往期回顾',
  51. list: [],
  52. ..._public
  53. }],
  54. scrollH: 0,
  55. nav_height: 0,
  56. isRefresher: true
  57. }
  58. },
  59. computed: {
  60. autoHeight(){
  61. return `calc(${this.scrollH}px - ${this.nav_height}px - 86rpx)`;
  62. }
  63. },
  64. onLoad(){
  65. let info = uni.getSystemInfoSync();
  66. this.scrollH = info.screenHeight;
  67. this.getHotActivity()
  68. },
  69. methods: {
  70. goDetails(id) {
  71. console.log('当前tabcurrent',this.tab_current)
  72. if(this.tab_current == 0) {
  73. this.$url('/pages/index/activity/detail?enter_type=0&is_end=0&activity_id='+id)
  74. }else {
  75. this.$url('/pages/index/activity/detail?enter_type=0&is_end=1&activity_id='+id)
  76. }
  77. },
  78. // 页面触底,加载下一页
  79. onScrolltolower(){
  80. let tab_item = this.tab_list[this.tab_current];
  81. if(tab_item.isPage){
  82. tab_item.page = tab_item.page + 1;
  83. this.getHotActivity();
  84. }
  85. },
  86. // 下拉刷新处理
  87. refreshFn(options){
  88. let tab_item = this.tab_list[this.tab_current];
  89. tab_item.page = 1;
  90. tab_item.isPage = true;
  91. tab_item.loadingClass = true;
  92. tab_item.list = []
  93. tab_item.loadingText = '正在加载中';
  94. this.getHotActivity(options);
  95. },
  96. // scroll-view 下拉刷新
  97. onRefresherrefresh(){
  98. this.isRefresher = true;
  99. this.refreshFn({type: 'scrollRefresh'});
  100. },
  101. tabChange(event){
  102. this.tab_current = event;
  103. this.getHotActivity();
  104. },
  105. swiperChange(event){
  106. this.tab_current = event.detail.current;
  107. if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  108. this.getHotActivity();
  109. },
  110. getHotActivity(options = {}) {
  111. this.$http
  112. .get({
  113. api: 'api/activity',
  114. data:{
  115. is_expired: this.tab_current+1
  116. }
  117. })
  118. .then(res => {
  119. let tab_item = this.tab_list[this.tab_current];
  120. if (res.data.code == 200) {
  121. if (res.data.status) {
  122. let isPage = res.data.next_page_url == null?false:true;
  123. tab_item.isPage = isPage;
  124. if(!isPage) {
  125. tab_item.loadingClass = false;
  126. tab_item.loadingText = '没有更多数据啦~';
  127. }
  128. if(options.type == 'pageRefresh') {
  129. uni.stopPullDownRefresh();
  130. }else if(options.type == 'scrollRefresh') {
  131. this.isRefresher = false;
  132. }
  133. if(tab_item.page == 1) {
  134. tab_item.list = res.data.data.data;
  135. }else {
  136. tab_item.list.push(...res.data.data.data);
  137. }
  138. console.log('数组列表',tab_item.list)
  139. } else {
  140. wx.showModal({
  141. content: res.message || '请下拉页面刷新重试',
  142. showCancel: false
  143. });
  144. }
  145. } else {
  146. wx.showModal({
  147. content: '请下拉页面刷新重试',
  148. showCancel: false
  149. });
  150. }
  151. wx.hideLoading();
  152. })
  153. .catch(() => {
  154. wx.hideLoading();
  155. wx.showModal({
  156. content: '请求失败',
  157. showCancel: false
  158. });
  159. });
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss" scoped="scoped">
  165. .scroll-content{
  166. width: 100%;
  167. display: flex;
  168. flex-wrap: wrap;
  169. justify-content: center;
  170. .card{
  171. width: 686rpx;
  172. height: max-content;
  173. background-color: #FFFFFF;
  174. box-shadow: 1rpx 1rpx 6rpx 3rpx #e5e5e5;
  175. margin-top: 30rpx;
  176. border-radius: 20rpx;
  177. overflow: hidden;
  178. .cover{
  179. width: 686rpx;
  180. height: 300rpx;
  181. position: relative;
  182. .img{
  183. width: 100%;
  184. height: 100%;
  185. background-color: #EEEEEE;
  186. }
  187. }
  188. .info{
  189. width: 686rpx;
  190. height: max-content;
  191. padding: 20rpx 30rpx;
  192. box-sizing: border-box;
  193. .title{
  194. font-size: 28rpx;
  195. color: #222222;
  196. font-weight: bold;
  197. }
  198. .date{
  199. margin-top: 20rpx;
  200. font-size: 24rpx;
  201. color: #555555;
  202. }
  203. }
  204. }
  205. }
  206. // tabs 样式修改
  207. /deep/.u-scroll-box {
  208. display: flex;
  209. justify-content: center;
  210. align-items: center;
  211. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  212. }
  213. /deep/.u-scroll-box .u-tab-bar {
  214. background-color: #15716E!important;
  215. width: 80rpx!important;
  216. position: absolute;
  217. left: 0;
  218. bottom: -12rpx;
  219. }
  220. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  221. background-color: #15716E!important;
  222. width: 56rpx!important;
  223. position: absolute;
  224. height: 5rpx!important;
  225. left: 8rpx;
  226. bottom: -4rpx;
  227. }
  228. /deep/ .u-tab-item {
  229. font-size: 28rpx!important;
  230. }
  231. </style>