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

280 lines
7.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)">
  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(!this.$isRight(item.activity)) return;
  88. if(item.activity.is_expired) {
  89. this.$msg('该活动已过期!');
  90. }else {
  91. this.$url('/pages/user/my/myregister?activity_id='+item.id);
  92. }
  93. },
  94. // 页面触底,加载下一页
  95. onScrolltolower(){
  96. let tab_item = this.tab_list[this.tab_current];
  97. if(tab_item.isPage){
  98. tab_item.page = tab_item.page + 1;
  99. this.getMyActivity();
  100. }
  101. },
  102. // 下拉刷新处理
  103. refreshFn(options){
  104. let tab_item = this.tab_list[this.tab_current];
  105. tab_item.page = 1;
  106. tab_item.isPage = true;
  107. tab_item.loadingClass = true;
  108. tab_item.list = []
  109. tab_item.loadingText = '正在加载中';
  110. this.getMyActivity(options);
  111. },
  112. // scroll-view 下拉刷新
  113. onRefresherrefresh(){
  114. this.isRefresher = true;
  115. this.refreshFn({type: 'scrollRefresh'});
  116. },
  117. tabChange(event){
  118. this.tab_current = event;
  119. this.getMyActivity();
  120. },
  121. swiperChange(event){
  122. this.tab_current = event.detail.current;
  123. if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  124. this.getMyActivity();
  125. },
  126. getMyActivity(options = {}) {
  127. let tab_item = this.tab_list[this.tab_current];
  128. console.log(tab_item.state)
  129. this.$http
  130. .get({
  131. api: 'api/activity/my',
  132. data:{
  133. state: tab_item.state,
  134. page: tab_item.page,
  135. page_size: this.pageSize
  136. },
  137. header: {
  138. Authorization: this.$cookieStorage.get('user_token')
  139. },
  140. })
  141. .then(res => {
  142. if (res.data.code == 200) {
  143. if (res.data.status) {
  144. let isPage = res.data.next_page_url == null?false:true;
  145. tab_item.isPage = isPage;
  146. if(!isPage) {
  147. tab_item.loadingClass = false;
  148. tab_item.loadingText = '没有更多数据啦~';
  149. }
  150. if(options.type == 'pageRefresh') {
  151. uni.stopPullDownRefresh();
  152. }else if(options.type == 'scrollRefresh') {
  153. this.isRefresher = false;
  154. }
  155. if(tab_item.page == 1) {
  156. tab_item.list = res.data.data.data;
  157. }else {
  158. tab_item.list.push(...res.data.data.data);
  159. }
  160. console.log('数组列表',tab_item.list)
  161. } else {
  162. wx.showModal({
  163. content: res.data.message || '请下拉页面刷新重试',
  164. showCancel: false
  165. });
  166. }
  167. } else {
  168. wx.showModal({
  169. content: res.data.message || '请下拉页面刷新重试',
  170. showCancel: false
  171. });
  172. }
  173. wx.hideLoading();
  174. })
  175. .catch(() => {
  176. wx.hideLoading();
  177. wx.showModal({
  178. content: '请求失败',
  179. showCancel: false
  180. });
  181. });
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped="scoped">
  187. .scroll-content{
  188. width: 100%;
  189. display: flex;
  190. flex-wrap: wrap;
  191. justify-content: center;
  192. .card{
  193. width: 686rpx;
  194. height: max-content;
  195. background-color: #FFFFFF;
  196. box-shadow: 1rpx 1rpx 6rpx 3rpx #e5e5e5;
  197. margin-top: 30rpx;
  198. border-radius: 20rpx;
  199. overflow: hidden;
  200. .cover{
  201. width: 686rpx;
  202. height: 300rpx;
  203. position: relative;
  204. .img{
  205. width: 100%;
  206. height: 100%;
  207. background-color: #EEEEEE;
  208. }
  209. .label{
  210. position: absolute;
  211. top: 0;
  212. left: 0;
  213. width: 118rpx;
  214. height: 57rpx;
  215. border-radius: 20rpx 0rpx 20rpx 0rpx;
  216. text-align: center;
  217. line-height: 57rpx;
  218. color: #FFFFFF;
  219. font-size: 26rpx;
  220. }
  221. }
  222. .info{
  223. width: 686rpx;
  224. height: max-content;
  225. padding: 20rpx 30rpx;
  226. box-sizing: border-box;
  227. .title{
  228. font-size: 28rpx;
  229. color: #222222;
  230. font-weight: bold;
  231. }
  232. .date{
  233. margin-top: 20rpx;
  234. font-size: 24rpx;
  235. color: #555555;
  236. }
  237. }
  238. }
  239. }
  240. .theme-1{
  241. background-color: #15716E;
  242. }
  243. .theme-2{
  244. background-color: #1789E4;
  245. }
  246. .theme-3{
  247. background-color: #777777;
  248. }
  249. // tabs 样式修改
  250. /deep/.u-scroll-box {
  251. display: flex;
  252. justify-content: center;
  253. align-items: center;
  254. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  255. }
  256. /deep/.u-scroll-box .u-tab-bar {
  257. background-color: #15716E!important;
  258. width: 80rpx!important;
  259. position: absolute;
  260. left: 0;
  261. bottom: -12rpx;
  262. }
  263. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  264. background-color: #15716E!important;
  265. width: 56rpx!important;
  266. position: absolute;
  267. height: 5rpx!important;
  268. left: 8rpx;
  269. bottom: -4rpx;
  270. }
  271. /deep/ .u-tab-item {
  272. font-size: 28rpx!important;
  273. }
  274. </style>