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

278 lines
7.2 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)">
  13. <view class="cover">
  14. <image class="img" :src="item.activity.image"></image>
  15. <view class="label" :class="'theme-'+ (index+1)" v-if="item.activity.is_expired==false && item.state =='待使用'">待使用</view>
  16. <view class="label lf-bg-gray" :class="'theme-'+ (index+1)" v-if="item.activity.is_expired==true">已过期</view>
  17. <view class="label" :class="'theme-'+ (index+1)" v-if="item.activity.is_expired==false">{{item.state}}</view>
  18. </view>
  19. <view class="info">
  20. <view class="title">{{item.activity.name}}</view>
  21. <view class="date">{{item.created_at}}</view>
  22. </view>
  23. </view>
  24. <!-- 空数据的情况 -->
  25. <view class="loading-more">
  26. <text v-if="tab.list.length"
  27. :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text>
  28. <lf-nocontent src="/static/images/empty.png" v-else></lf-nocontent>
  29. </view>
  30. </view>
  31. <view style="height: 30rpx;"></view>
  32. </scroll-view>
  33. </swiper-item>
  34. </swiper>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data(){
  40. let _public = {
  41. page: 1,
  42. isPage: true,
  43. loadingClass: true,
  44. loadingText: '正在加载中'
  45. }
  46. return {
  47. tab_current: 0,
  48. tab_list: [{
  49. name: '全部',
  50. state: '',
  51. list: [],
  52. ..._public
  53. },{
  54. name: '待参加',
  55. state: '待使用',
  56. list: [],
  57. ..._public
  58. },{
  59. name: '已参加',
  60. state: '已使用',
  61. list: [],
  62. ..._public
  63. },{
  64. name: '已过期',
  65. state: '已过期',
  66. list: [],
  67. ..._public
  68. }],
  69. scrollH: 0,
  70. nav_height: 0,
  71. isRefresher: true,
  72. pageSize: 10
  73. }
  74. },
  75. computed: {
  76. autoHeight(){
  77. return `calc(${this.scrollH}px - ${this.nav_height}px - 86rpx)`;
  78. }
  79. },
  80. onLoad(){
  81. let info = uni.getSystemInfoSync();
  82. this.scrollH = info.screenHeight;
  83. this.getMyActivity()
  84. },
  85. methods: {
  86. goDetails(item) {
  87. if(item.activity.is_expired) {
  88. this.$msg('该活动已过期!');
  89. }else {
  90. this.$url('/pages/user/my/myregister?activity_id='+item.id);
  91. }
  92. },
  93. // 页面触底,加载下一页
  94. onScrolltolower(){
  95. let tab_item = this.tab_list[this.tab_current];
  96. if(tab_item.isPage){
  97. tab_item.page = tab_item.page + 1;
  98. this.getMyActivity();
  99. }
  100. },
  101. // 下拉刷新处理
  102. refreshFn(options){
  103. let tab_item = this.tab_list[this.tab_current];
  104. tab_item.page = 1;
  105. tab_item.isPage = true;
  106. tab_item.loadingClass = true;
  107. tab_item.list = []
  108. tab_item.loadingText = '正在加载中';
  109. this.getMyActivity(options);
  110. },
  111. // scroll-view 下拉刷新
  112. onRefresherrefresh(){
  113. this.isRefresher = true;
  114. this.refreshFn({type: 'scrollRefresh'});
  115. },
  116. tabChange(event){
  117. this.tab_current = event;
  118. this.getMyActivity();
  119. },
  120. swiperChange(event){
  121. this.tab_current = event.detail.current;
  122. if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  123. this.getMyActivity();
  124. },
  125. getMyActivity(options = {}) {
  126. let tab_item = this.tab_list[this.tab_current];
  127. this.$http
  128. .get({
  129. api: 'api/activity/my',
  130. data:{
  131. state: tab_item.state,
  132. page: tab_item.page,
  133. page_size: this.pageSize
  134. },
  135. header: {
  136. Authorization: this.$cookieStorage.get('user_token')
  137. },
  138. })
  139. .then(res => {
  140. if (res.data.code == 200) {
  141. if (res.data.status) {
  142. let isPage = res.data.next_page_url == null?false:true;
  143. tab_item.isPage = isPage;
  144. if(!isPage) {
  145. tab_item.loadingClass = false;
  146. tab_item.loadingText = '没有更多数据啦~';
  147. }
  148. if(options.type == 'pageRefresh') {
  149. uni.stopPullDownRefresh();
  150. }else if(options.type == 'scrollRefresh') {
  151. this.isRefresher = false;
  152. }
  153. if(tab_item.page == 1) {
  154. tab_item.list = res.data.data.data;
  155. }else {
  156. tab_item.list.push(...res.data.data.data);
  157. }
  158. console.log('数组列表',tab_item.list)
  159. } else {
  160. wx.showModal({
  161. content: res.data.message || '请下拉页面刷新重试',
  162. showCancel: false
  163. });
  164. }
  165. } else {
  166. wx.showModal({
  167. content: res.data.message || '请下拉页面刷新重试',
  168. showCancel: false
  169. });
  170. }
  171. wx.hideLoading();
  172. })
  173. .catch(() => {
  174. wx.hideLoading();
  175. wx.showModal({
  176. content: '请求失败',
  177. showCancel: false
  178. });
  179. });
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped="scoped">
  185. .scroll-content{
  186. width: 100%;
  187. display: flex;
  188. flex-wrap: wrap;
  189. justify-content: center;
  190. .card{
  191. width: 686rpx;
  192. height: max-content;
  193. background-color: #FFFFFF;
  194. box-shadow: 1rpx 1rpx 6rpx 3rpx #e5e5e5;
  195. margin-top: 30rpx;
  196. border-radius: 20rpx;
  197. overflow: hidden;
  198. .cover{
  199. width: 686rpx;
  200. height: 300rpx;
  201. position: relative;
  202. .img{
  203. width: 100%;
  204. height: 100%;
  205. background-color: #EEEEEE;
  206. }
  207. .label{
  208. position: absolute;
  209. top: 0;
  210. left: 0;
  211. width: 118rpx;
  212. height: 57rpx;
  213. border-radius: 20rpx 0rpx 20rpx 0rpx;
  214. text-align: center;
  215. line-height: 57rpx;
  216. color: #FFFFFF;
  217. font-size: 26rpx;
  218. }
  219. }
  220. .info{
  221. width: 686rpx;
  222. height: max-content;
  223. padding: 20rpx 30rpx;
  224. box-sizing: border-box;
  225. .title{
  226. font-size: 28rpx;
  227. color: #222222;
  228. font-weight: bold;
  229. }
  230. .date{
  231. margin-top: 20rpx;
  232. font-size: 24rpx;
  233. color: #555555;
  234. }
  235. }
  236. }
  237. }
  238. .theme-1{
  239. background-color: #15716E;
  240. }
  241. .theme-2{
  242. background-color: #1789E4;
  243. }
  244. .theme-3{
  245. background-color: #777777;
  246. }
  247. // tabs 样式修改
  248. /deep/.u-scroll-box {
  249. display: flex;
  250. justify-content: center;
  251. align-items: center;
  252. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  253. }
  254. /deep/.u-scroll-box .u-tab-bar {
  255. background-color: #15716E!important;
  256. width: 80rpx!important;
  257. position: absolute;
  258. left: 0;
  259. bottom: -12rpx;
  260. }
  261. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  262. background-color: #15716E!important;
  263. width: 56rpx!important;
  264. position: absolute;
  265. height: 5rpx!important;
  266. left: 8rpx;
  267. bottom: -4rpx;
  268. }
  269. /deep/ .u-tab-item {
  270. font-size: 28rpx!important;
  271. }
  272. </style>