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

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