hookehuyr

✨ feat: 我参加的活动功能API联调

1 +/*
2 + * @Date: 2022-10-20 13:15:00
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-10-25 15:37:28
5 + * @FilePath: /swx/src/api/Activity/index.js
6 + * @Description: 活动信息
7 + */
8 +import { fn, fetch } from '../fn';
9 +
10 +const Api = {
11 + ACTIVITY_JOIN_LIST: '/srv/?a=activity_join_list',
12 +}
13 +
14 +/**
15 + * @description: 我加入的活动列表
16 + * @returns
17 + */
18 +export const joinListAPI = (params) => fn(fetch.get(Api.ACTIVITY_JOIN_LIST, params));
1 <!-- 1 <!--
2 * @Date: 2022-09-20 15:39:37 2 * @Date: 2022-09-20 15:39:37
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-18 14:21:21 4 + * @LastEditTime: 2022-10-25 16:11:42
5 * @FilePath: /swx/src/components/activity-card.vue 5 * @FilePath: /swx/src/components/activity-card.vue
6 * @Description: 活动卡片组件 6 * @Description: 活动卡片组件
7 --> 7 -->
8 <template> 8 <template>
9 - <view class="activity-card-page"> 9 + <view @tap="goTo(data.id)" class="activity-card-page">
10 <view class="card-main"> 10 <view class="card-main">
11 <van-row> 11 <van-row>
12 <van-col :span="10"> 12 <van-col :span="10">
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
18 <view class="status-text"> 18 <view class="status-text">
19 <van-tag v-if="data.mode === 'offline'" :round="true" color="#E9FAF4" text-color="#199A74" size="large">现场活动</van-tag> 19 <van-tag v-if="data.mode === 'offline'" :round="true" color="#E9FAF4" text-color="#199A74" size="large">现场活动</van-tag>
20 <van-tag v-if="data.mode === 'online'" :round="true" color="#E9FAF4" text-color="#199A74" size="large">线上活动</van-tag> 20 <van-tag v-if="data.mode === 'online'" :round="true" color="#E9FAF4" text-color="#199A74" size="large">线上活动</van-tag>
21 - <van-tag v-if="register" :round="true" color="#D7FFD7" text-color="#019200" size="large">报名中</van-tag> 21 + <van-tag v-if="formatStatus(data) === '未发布'" :round="true" color="#FFF5E4" text-color="#FF7300" size="large">{{ formatStatus(data) }}</van-tag>
22 + <van-tag v-else-if="formatStatus(data) === '已结束'" :round="true" color="#EDEDED" text-color="#909090" size="large">{{ formatStatus(data) }}</van-tag>
23 + <van-tag v-else :round="true" color="#D7FFD7" text-color="#019200" size="large">{{ formatStatus(data) }}</van-tag>
22 </view> 24 </view>
23 <view style="font-size: 0.95rem;"> 25 <view style="font-size: 0.95rem;">
24 <van-icon name="clock-o" color="#BBBBBB" />&nbsp;{{ formatDate(data.activity_time) }} 26 <van-icon name="clock-o" color="#BBBBBB" />&nbsp;{{ formatDate(data.activity_time) }}
...@@ -74,6 +76,23 @@ const formatDate = (date) => { ...@@ -74,6 +76,23 @@ const formatDate = (date) => {
74 return dayjs(date).format('YYYY-MM-DD HH:mm') 76 return dayjs(date).format('YYYY-MM-DD HH:mm')
75 } 77 }
76 78
79 +const formatStatus = (item) => {
80 + if (item?.is_end) {
81 + return '已结束';
82 + } else if (item?.status === 'disable') {
83 + return '未发布';
84 + } else if (dayjs(item.server_time).isBefore(dayjs(item.reg_begin_time))) {
85 + return '报名未开始';
86 + } else if (dayjs(item.reg_begin_time).isBefore(dayjs(item.server_time)) && dayjs(item.server_time).isBefore(dayjs(item.reg_end_time))) {
87 + return '报名中';
88 + } else if (dayjs(item.reg_end_time).isBefore(dayjs(item.server_time)) && dayjs(item.server_time).isBefore(dayjs(item.activity_time))) {
89 + return '报名截止';
90 + } else if (dayjs(item.activity_time).isBefore(dayjs(item.server_time))) {
91 + return '活动进行中';
92 + }
93 + return 'mo'
94 +}
95 +
77 const goTo = (id) => { 96 const goTo = (id) => {
78 Taro.navigateTo({ 97 Taro.navigateTo({
79 url: '../activityDetail/index?id=' + id 98 url: '../activityDetail/index?id=' + id
......
1 <template> 1 <template>
2 <view class="join-list-page"> 2 <view class="join-list-page">
3 - <view class="join-list-header"> 3 + <view id="page-header" class="join-list-header">
4 <view class="activity-title"> 4 <view class="activity-title">
5 <view class="box"> 5 <view class="box">
6 <text class="bg-gradient" style="font-size: 1.15rem;">活动统计</text> 6 <text class="bg-gradient" style="font-size: 1.15rem;">活动统计</text>
...@@ -8,21 +8,21 @@ ...@@ -8,21 +8,21 @@
8 </view> 8 </view>
9 <view class="header-info"> 9 <view class="header-info">
10 <view class="activity"> 10 <view class="activity">
11 - <view><text style="font-size: 1.25rem;">5</text>场</view> 11 + <view><text style="font-size: 1.25rem;">{{ reg_count }}</text>场</view>
12 <view> 12 <view>
13 <van-icon :name="icon_join" size="1.5rem" color="" style="vertical-align: sub;" /> 13 <van-icon :name="icon_join" size="1.5rem" color="" style="vertical-align: sub;" />
14 <text style="font-size: 0.9rem; color: #999999;">活动报名</text> 14 <text style="font-size: 0.9rem; color: #999999;">活动报名</text>
15 </view> 15 </view>
16 </view> 16 </view>
17 <view class="job"> 17 <view class="job">
18 - <text style="font-size: 1.25rem;">2</text>场 18 + <text style="font-size: 1.25rem;">{{ volunteer_count }}</text>场
19 <view> 19 <view>
20 <van-icon :name="icon_job" size="1.25rem" color="" style="vertical-align: sub;" /> 20 <van-icon :name="icon_job" size="1.25rem" color="" style="vertical-align: sub;" />
21 <text style="font-size: 0.9rem; color: #999999;">岗位报名</text> 21 <text style="font-size: 0.9rem; color: #999999;">岗位报名</text>
22 </view> 22 </view>
23 </view> 23 </view>
24 <view class="sign"> 24 <view class="sign">
25 - <view><text style="font-size: 1.25rem;">3</text>场</view> 25 + <view><text style="font-size: 1.25rem;">{{ sign_count }}</text>场</view>
26 <view> 26 <view>
27 <van-icon :name="icon_sign" size="1.25rem" color="" style="vertical-align: sub;" /> 27 <van-icon :name="icon_sign" size="1.25rem" color="" style="vertical-align: sub;" />
28 <text style="font-size: 0.9rem; color: #999999;">实际参加</text> 28 <text style="font-size: 0.9rem; color: #999999;">实际参加</text>
...@@ -31,30 +31,33 @@ ...@@ -31,30 +31,33 @@
31 </view> 31 </view>
32 </view> 32 </view>
33 <view class="list-wrapper" style="margin: 1rem;"> 33 <view class="list-wrapper" style="margin: 1rem;">
34 - <view style="background-color: white; border-radius: 0.65rem; padding: 1rem;overflow: auto; margin-bottom: 1px;"> 34 + <view id="navbar-page" style="background-color: white; border-radius: 0.65rem; padding: 1rem;overflow: auto; margin-bottom: 1px;">
35 <view style="display: inline-block; margin-right: 1rem; line-height: 60rpx;"> 35 <view style="display: inline-block; margin-right: 1rem; line-height: 60rpx;">
36 - <view @tap="toggleColum('activity')" :class="[activated === 1 ? 'bg-gradient' : 'inactivate']" style="font-size: 1rem;">活动报名</view> 36 + <view @tap="toggleColum('player')" :class="[activated === 1 ? 'bg-gradient' : 'inactivate']" style="font-size: 1rem;">活动报名</view>
37 </view> 37 </view>
38 <view style="display: inline-block; line-height: 60rpx;"> 38 <view style="display: inline-block; line-height: 60rpx;">
39 - <view @tap="toggleColum('join')" :class="[activated === 2 ? 'bg-gradient' : 'inactivate']">岗位报名</view> 39 + <view @tap="toggleColum('volunteer')" :class="[activated === 2 ? 'bg-gradient' : 'inactivate']">岗位报名</view>
40 </view> 40 </view>
41 <view @tap="show_status_popup=true" style="float: right; color: #666666; font-size: 0.9rem; border: 1px solid #DBDBDB; border-radius: 1rem; padding: 0.3rem 1rem 0.3rem 1rem;"> 41 <view @tap="show_status_popup=true" style="float: right; color: #666666; font-size: 0.9rem; border: 1px solid #DBDBDB; border-radius: 1rem; padding: 0.3rem 1rem 0.3rem 1rem;">
42 &nbsp;{{ status_type === '' ? '全部' : status_type }}&nbsp;&nbsp; 42 &nbsp;{{ status_type === '' ? '全部' : status_type }}&nbsp;&nbsp;
43 <van-icon :name="icon_sel2" size="0.8rem" color="" style="vertical-align: middle;" /> 43 <van-icon :name="icon_sel2" size="0.8rem" color="" style="vertical-align: middle;" />
44 </view> 44 </view>
45 </view> 45 </view>
46 + <scroll-view :scroll-y="true" :style="scrollStyle" @scrolltolower="onScrollToLower">
46 <view> 47 <view>
47 <activity-card v-for="(item, index) in activity_list" :key="index" :data="item" style="margin-bottom: 1rem;"></activity-card> 48 <activity-card v-for="(item, index) in activity_list" :key="index" :data="item" style="margin-bottom: 1rem;"></activity-card>
48 </view> 49 </view>
50 + </scroll-view>
49 </view> 51 </view>
50 <view style="height: 2rem;"></view> 52 <view style="height: 2rem;"></view>
51 </view> 53 </view>
52 54
53 <!-- 切换状态弹出框 --> 55 <!-- 切换状态弹出框 -->
54 - <van-popup :show="show_status_popup" position="bottom" custom-style="height: 40%;" :lock-scroll="true"> 56 + <van-popup :show="show_status_popup" position="bottom" custom-style="height: 50%;" :lock-scroll="true">
55 <van-picker :show-toolbar="true" title="" confirm-button-text="确定" :columns="status_type_columns" 57 <van-picker :show-toolbar="true" title="" confirm-button-text="确定" :columns="status_type_columns"
56 toolbar-class="picker-toolbar" @confirm="onStatusTypeConfirm" @cancel="onStatusTypeCancel" @change="onStatusTypeChange" /> 58 toolbar-class="picker-toolbar" @confirm="onStatusTypeConfirm" @cancel="onStatusTypeCancel" @change="onStatusTypeChange" />
57 </van-popup> 59 </van-popup>
60 + <van-toast id="van-toast" />
58 </template> 61 </template>
59 62
60 <script setup> 63 <script setup>
...@@ -66,53 +69,7 @@ import icon_sel2 from '@/images/icon/sel02@2x.png' ...@@ -66,53 +69,7 @@ import icon_sel2 from '@/images/icon/sel02@2x.png'
66 import icon_tel from '@/images/icon/tel@2x.png' 69 import icon_tel from '@/images/icon/tel@2x.png'
67 import Taro from '@tarojs/taro' 70 import Taro from '@tarojs/taro'
68 import activityCard from '@/components/activity-card.vue' 71 import activityCard from '@/components/activity-card.vue'
69 - 72 +import Toast from '@/components/vant-weapp/toast/toast';
70 -const activity_list = ref([{
71 - title: '智慧没有烦恼',
72 - address: '上海市杨浦区军工路100号A座05室',
73 -}, {
74 - title: '万人共乘浪漫热气球',
75 - address: '',
76 -}, {
77 - title: '八段锦',
78 - address: '',
79 -}, {
80 - title: '智慧没有烦恼',
81 - address: '上海市杨浦区军工路100号A座05室',
82 -}, {
83 - title: '万人共乘浪漫热气球',
84 - address: '',
85 -}, {
86 - title: '八段锦',
87 - address: '',
88 -}]);
89 -
90 -const show_status_popup = ref(false);
91 -const status_type = ref('');
92 -const status_type_columns = ref(['已报名', '未出席', '已签到']);
93 -const onStatusTypeChange = (event) => {
94 - const { picker, value, index } = event.detail;
95 -}
96 -const onStatusTypeConfirm = (event) => {
97 - const { picker, value, index } = event.detail;
98 - show_status_popup.value = false;
99 - status_type.value = value;
100 - console.warn('查询新数据');
101 -}
102 -const onStatusTypeCancel = (event) => {
103 - show_status_popup.value = false;
104 -}
105 -
106 -const activated = ref(1);
107 -const toggleColum = (type) => {
108 - if (type === 'activity') {
109 - activity_list.value = [];
110 - activated.value = 1
111 - } else {
112 - activity_list.value = [];
113 - activated.value = 2
114 - }
115 -}
116 73
117 const goToUserInfo = () => { 74 const goToUserInfo = () => {
118 Taro.navigateTo({ 75 Taro.navigateTo({
...@@ -123,8 +80,124 @@ const goToUserInfo = () => { ...@@ -123,8 +80,124 @@ const goToUserInfo = () => {
123 80
124 <script> 81 <script>
125 import "./index.less"; 82 import "./index.less";
83 +import { joinListAPI } from '@/api/Activity/index';
84 +import { $ } from '@tarojs/extend'
85 +import mixin from '@/utils/mixin';
86 +import { getCurrentPageParam } from "@/utils/weapp";
126 87
127 export default { 88 export default {
128 name: "joinListPage", 89 name: "joinListPage",
90 + mixins: [mixin.init],
91 + async onShow () {
92 + // 获取活动和轮播信息
93 + const { code, data } = await joinListAPI({ type: this.role, status: '', is_stat: 1, page: this.page, limit: this.limit });
94 + if (code) {
95 + this.activity_list = data.activity_list;
96 + this.reg_count = data.reg_count;
97 + this.sign_count = data.sign_count;
98 + this.volunteer_count = data.volunteer_count;
99 + this.page = this.page + 1;
100 + }
101 + },
102 + onHide () { // 离开当前页面
103 + this.page = 0;
104 + this.flag = true;
105 + },
106 + mounted () {
107 + // 设置滚动列表可视高度
108 + const windowHeight = wx.getSystemInfoSync().windowHeight;
109 + setTimeout(async () => {
110 + const headerHeight = await $('#page-header').height();
111 + const navHeight = await $('#navbar-page').height();
112 + this.scrollStyle = {
113 + height: windowHeight - headerHeight - navHeight - 50 + 'px'
114 + }
115 + }, 500);
116 + },
117 + data() {
118 + return {
119 + activity_list: [],
120 + role: 'player',
121 + flag: true,
122 + page: 0,
123 + limit: 10,
124 + scrollStyle: { height: '1000rpx' },
125 + activated: 1,
126 + status: '',
127 + reg_count: '',
128 + sign_count: '',
129 + volunteer_count: '',
130 + show_status_popup: false,
131 + status_type: '',
132 + status_type_columns: [{
133 + text: '全部',
134 + key: ''
135 + }, {
136 + text: '报名中',
137 + key: 'reg'
138 + }, {
139 + text: '报名结束',
140 + key: 'reg_end'
141 + }, {
142 + text: '活动进行中',
143 + key: 'start'
144 + }, {
145 + text: '活动结束',
146 + key: 'stop'
147 + }],
148 + };
149 + },
150 + methods: {
151 + onScrollToLower () {
152 + if(!this.flag){
153 + return
154 + }
155 + this.flag = false;
156 + this.getList();
157 + },
158 + async getList () {
159 + // 获取推荐活动列表
160 + const { code, data } = await joinListAPI({ type: this.role, status: this.status, is_stat: 1, page: this.page, limit: this.limit });
161 + if (code) {
162 + if (data.activity_list.length) {
163 + this.activity_list = this.activity_list.concat(data.activity_list);
164 + this.reg_count = data.reg_count;
165 + this.sign_count = data.sign_count;
166 + this.volunteer_count = data.volunteer_count;
167 + this.page = this.page + 1;
168 + this.flag = true;
169 + } else {
170 + Toast('没有数据')
171 + }
172 + }
173 + },
174 + toggleColum (type) {
175 + if (type === 'player') {
176 + this.activated = 1;
177 + this.role = 'player';
178 + } else {
179 + this.activated = 2;
180 + this.role = 'volunteer';
181 + }
182 + this.activity_list = [];
183 + this.flag = true;
184 + this.page = 0;
185 + this.getList();
186 + },
187 + onStatusTypeConfirm (event) {
188 + const { picker, value, index } = event.detail;
189 + this.show_status_popup = false;
190 + this.status_type = value.text;
191 + this.status = value.key;
192 + // 查询数据
193 + this.activity_list = [];
194 + this.flag = true;
195 + this.page = 0;
196 + this.getList();
197 + },
198 + onStatusTypeCancel (event) {
199 + this.show_status_popup = false;
200 + }
201 + },
129 }; 202 };
130 </script> 203 </script>
......