金诚优选前端代码
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.

239 lines
6.3 KiB

4 years ago
4 years ago
  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 src="/static/images/empty.png" 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. header: {
  118. Authorization: this.$cookieStorage.get('user_token')
  119. },
  120. })
  121. .then(res => {
  122. let tab_item = this.tab_list[this.tab_current];
  123. if (res.data.code == 200) {
  124. if (res.data.status) {
  125. let isPage = res.data.next_page_url == null?false:true;
  126. tab_item.isPage = isPage;
  127. if(!isPage) {
  128. tab_item.loadingClass = false;
  129. tab_item.loadingText = '没有更多数据啦~';
  130. }
  131. if(options.type == 'pageRefresh') {
  132. uni.stopPullDownRefresh();
  133. }else if(options.type == 'scrollRefresh') {
  134. this.isRefresher = false;
  135. }
  136. if(tab_item.page == 1) {
  137. tab_item.list = res.data.data.data;
  138. }else {
  139. tab_item.list.push(...res.data.data.data);
  140. }
  141. console.log('数组列表',tab_item.list)
  142. } else {
  143. wx.showModal({
  144. content: res.message || '请下拉页面刷新重试',
  145. showCancel: false
  146. });
  147. }
  148. } else {
  149. wx.showModal({
  150. content: '请下拉页面刷新重试',
  151. showCancel: false
  152. });
  153. }
  154. wx.hideLoading();
  155. })
  156. .catch(() => {
  157. wx.hideLoading();
  158. wx.showModal({
  159. content: '请求失败',
  160. showCancel: false
  161. });
  162. });
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped="scoped">
  168. .scroll-content{
  169. width: 100%;
  170. display: flex;
  171. flex-wrap: wrap;
  172. justify-content: center;
  173. .card{
  174. width: 686rpx;
  175. height: max-content;
  176. background-color: #FFFFFF;
  177. box-shadow: 1rpx 1rpx 6rpx 3rpx #e5e5e5;
  178. margin-top: 30rpx;
  179. border-radius: 20rpx;
  180. overflow: hidden;
  181. .cover{
  182. width: 686rpx;
  183. height: 300rpx;
  184. position: relative;
  185. .img{
  186. width: 100%;
  187. height: 100%;
  188. background-color: #EEEEEE;
  189. }
  190. }
  191. .info{
  192. width: 686rpx;
  193. height: max-content;
  194. padding: 20rpx 30rpx;
  195. box-sizing: border-box;
  196. .title{
  197. font-size: 28rpx;
  198. color: #222222;
  199. font-weight: bold;
  200. }
  201. .date{
  202. margin-top: 20rpx;
  203. font-size: 24rpx;
  204. color: #555555;
  205. }
  206. }
  207. }
  208. }
  209. // tabs 样式修改
  210. /deep/.u-scroll-box {
  211. display: flex;
  212. justify-content: center;
  213. align-items: center;
  214. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  215. }
  216. /deep/.u-scroll-box .u-tab-bar {
  217. background-color: #15716E!important;
  218. width: 80rpx!important;
  219. position: absolute;
  220. left: 0;
  221. bottom: -12rpx;
  222. }
  223. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  224. background-color: #15716E!important;
  225. width: 56rpx!important;
  226. position: absolute;
  227. height: 5rpx!important;
  228. left: 8rpx;
  229. bottom: -4rpx;
  230. }
  231. /deep/ .u-tab-item {
  232. font-size: 28rpx!important;
  233. }
  234. </style>