cycle-selection.vue
5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<template>
<div class="cycle-selection-page">
<van-config-provider :theme-vars="themeVars">
<div class="cycle-popup">
<div class="popup-header">
<h3>选择周期</h3>
</div>
<div class="popup-content">
<van-radio-group v-model="selectedCycle">
<div v-for="cycle in cycleList" :key="cycle.id" class="cycle-item">
<van-radio :name="cycle.id">
<div class="cycle-info">
<div class="cycle-title">{{ cycle.title }}</div>
<div class="cycle-time">
<div v-if="cycle.start_date">活动开始时间: {{ cycle.start_date }}</div>
<div v-if="cycle.end_date">活动结束时间: {{ cycle.end_date }}</div>
<div v-if="cycle.reg_begin_time">报名开始时间: {{ cycle.reg_begin_time }}</div>
<div v-if="cycle.reg_end_time">报名结束时间: {{ cycle.reg_end_time }}</div>
<div v-if="cycle.description">说明: {{ cycle.description }}</div>
</div>
</div>
</van-radio>
</div>
</van-radio-group>
</div>
<div class="popup-footer">
<van-button type="primary" class="confirm-btn" @click="confirmCycleSelection" :disabled="!selectedCycle">
确认选择
</van-button>
</div>
</div>
</van-config-provider>
</div>
</template>
<script setup>
import { ref, onMounted, nextTick } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { getCycleListAPI } from '@/api/cycle';
import { styleColor } from '@/constant.js';
const $router = useRouter();
const $route = useRoute();
// 主题配置
const themeVars = {
// 主色调配置
radioCheckedIconColor: styleColor.baseColor,
buttonPrimaryBackground: styleColor.baseColor,
buttonPrimaryBorderColor: styleColor.baseColor,
};
// 周期选择相关变量
const cycleList = ref([]);
const selectedCycle = ref('');
/**
* 动态计算弹窗内容区域高度
*/
const calculatePopupContentHeight = () => {
nextTick(() => {
const popupElement = document.querySelector('.cycle-popup');
const headerElement = document.querySelector('.popup-header');
const footerElement = document.querySelector('.popup-footer');
const contentElement = document.querySelector('.popup-content');
if (popupElement && headerElement && footerElement && contentElement) {
const popupHeight = popupElement.offsetHeight;
const headerHeight = headerElement.offsetHeight;
const footerHeight = footerElement.offsetHeight;
const padding = 100; // 上下padding和margin的总和
const contentHeight = popupHeight - headerHeight - footerHeight - padding;
contentElement.style.height = `${contentHeight}px`;
}
});
};
/**
* 获取周期列表
* @param {string} form_code 表单唯一标识
*/
const getCycleList = async (form_code) => {
try {
const { data } = await getCycleListAPI({ form_code });
if (data.is_cycle) {
if (!data.cycle_list || data.cycle_list.length === 0) {
// 如果is_cycle是true但cycle_list为空,跳转到停用页面
$router.push("/stop?status=disable");
return;
}
// 设置周期列表
cycleList.value = data.cycle_list;
// 计算高度
calculatePopupContentHeight();
} else {
// 如果不需要周期选择,直接跳转到目标页面
const targetRoute = sessionStorage.getItem('cycle_target_route');
if (targetRoute) {
sessionStorage.removeItem('cycle_target_route');
$router.replace(JSON.parse(targetRoute));
} else {
$router.replace('/');
}
}
} catch (error) {
console.error('获取周期列表失败:', error);
}
};
/**
* 确认选择周期
*/
const confirmCycleSelection = () => {
if (selectedCycle.value) {
// 获取目标路由
const targetRoute = sessionStorage.getItem('cycle_target_route');
if (targetRoute) {
const route = JSON.parse(targetRoute);
// 添加周期参数
route.query = {
...route.query,
x_cycle: selectedCycle.value,
cycle_selected: '1'
};
// 清除临时存储
sessionStorage.removeItem('cycle_target_route');
// 跳转到目标页面
$router.replace(route);
} else {
// 如果没有目标路由,跳转到首页
$router.replace({
path: '/',
query: {
x_cycle: selectedCycle.value,
cycle_selected: '1'
}
});
}
}
};
onMounted(() => {
const form_code = $route.query.code;
if (form_code) {
getCycleList(form_code);
} else {
console.error('缺少表单代码参数');
$router.replace('/');
}
});
</script>
<style lang="less" scoped>
.cycle-selection-page {
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
}
.cycle-popup {
width: 100%;
max-width: 500px;
height: 70vh;
background: white;
border-radius: 12px;
display: flex;
flex-direction: column;
overflow: hidden;
}
.popup-header {
padding: 20px;
text-align: center;
border-bottom: 1px solid #eee;
flex-shrink: 0;
h3 {
margin: 0;
font-size: 18px;
font-weight: 600;
color: #333;
}
}
.popup-content {
flex: 1;
overflow-y: auto;
padding: 0 20px;
min-height: 0;
}
.cycle-item {
padding: 15px 0;
border-bottom: 1px solid #f5f5f5;
&:last-child {
border-bottom: none;
}
}
.cycle-info {
margin-left: 10px;
}
.cycle-title {
font-size: 16px;
font-weight: 500;
color: #333;
margin-bottom: 8px;
}
.cycle-time {
font-size: 14px;
color: #666;
line-height: 1.5;
div {
margin-bottom: 4px;
&:last-child {
margin-bottom: 0;
}
}
}
.popup-footer {
padding: 20px;
border-top: 1px solid #eee;
flex-shrink: 0;
}
.confirm-btn {
width: 100%;
height: 44px;
border-radius: 8px;
font-size: 16px;
font-weight: 500;
}
</style>