hookehuyr

✨ feat(参加活动): 页面接口API联调

1 +/*
2 + * @Date: 2022-10-20 13:15:00
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-10-20 13:38:30
5 + * @FilePath: /swx/src/api/Reg/index.js
6 + * @Description: 报名信息
7 + */
8 +import { fn, fetch } from '../fn';
9 +
10 +const Api = {
11 + MY_INFO: '/srv/?a=reg_my_info',
12 + REG_ADD: '/srv/?a=reg_add',
13 +}
14 +
15 +/**
16 + * @description: 我的报名详情
17 + * @returns
18 + */
19 +export const myInfoAPI = (params) => fn(fetch.post(Api.MY_INFO, params));
20 +
21 +/**
22 + * @description: 活动报名
23 + * @returns
24 + */
25 +export const addRegAPI = (params) => fn(fetch.post(Api.REG_ADD, params));
1 <!-- 1 <!--
2 * @Date: 2022-09-26 16:10:35 2 * @Date: 2022-09-26 16:10:35
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-18 17:40:02 4 + * @LastEditTime: 2022-10-20 11:54:56
5 * @FilePath: /swx/src/components/activity-bar.vue 5 * @FilePath: /swx/src/components/activity-bar.vue
6 * @Description: 活动详情页底部导航栏 6 * @Description: 活动详情页底部导航栏
7 --> 7 -->
...@@ -61,7 +61,7 @@ const goTo = (type) => { ...@@ -61,7 +61,7 @@ const goTo = (type) => {
61 }) 61 })
62 } else if (type === 'join') { // 活动报名 62 } else if (type === 'join') { // 活动报名
63 Taro.navigateTo({ 63 Taro.navigateTo({
64 - url: '../joinActivity/index' 64 + url: '../joinActivity/index?id=' + getCurrentPageParam().id
65 }) 65 })
66 } else if (type === 'volunteer') { // 义工报名 66 } else if (type === 'volunteer') { // 义工报名
67 Taro.navigateTo({ 67 Taro.navigateTo({
......
1 <!-- 1 <!--
2 * @Date: 2022-09-27 17:13:05 2 * @Date: 2022-09-27 17:13:05
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-09-30 11:04:52 4 + * @LastEditTime: 2022-10-20 15:44:06
5 * @FilePath: /swx/src/pages/joinActivity/index.vue 5 * @FilePath: /swx/src/pages/joinActivity/index.vue
6 * @Description: 活动报名 6 * @Description: 活动报名
7 --> 7 -->
...@@ -29,18 +29,18 @@ ...@@ -29,18 +29,18 @@
29 @change="onSexChange" 29 @change="onSexChange"
30 direction="horizontal" 30 direction="horizontal"
31 > 31 >
32 - <van-radio name="female" checked-color="#199A74">男士</van-radio> 32 + <van-radio name="man" checked-color="#199A74">男士</van-radio>
33 - <van-radio name="male" checked-color="#199A74">女士</van-radio> 33 + <van-radio name="woman" checked-color="#199A74">女士</van-radio>
34 </van-radio-group> 34 </van-radio-group>
35 </view> 35 </view>
36 </view> 36 </view>
37 - <view v-for="(item, index) in arr" :key="index"> 37 + <view v-for="(item, index) in fields" :key="index">
38 <AtInput 38 <AtInput
39 - :required="item.required" 39 + :required="item.is_require"
40 :border="true" 40 :border="true"
41 - :title="item.title" 41 + :title="item.field"
42 type='text' 42 type='text'
43 - :placeholder="'请输入' + item.title" 43 + :placeholder="'请输入' + item.field"
44 v-model:value="item.value" /> 44 v-model:value="item.value" />
45 </view> 45 </view>
46 </view> 46 </view>
...@@ -53,17 +53,17 @@ ...@@ -53,17 +53,17 @@
53 <view class="form-item border"> 53 <view class="form-item border">
54 <view class="form-item-title fix">年龄最小值</view> 54 <view class="form-item-title fix">年龄最小值</view>
55 <view style="float: right;"> 55 <view style="float: right;">
56 - <van-field :value="min_number" type="number" label="" placeholder="请输入年龄最小值" 56 + <van-field :value="min_number" @change="changeMinNumber" label="" placeholder="请输入年龄最小值"
57 placeholder-style="color: #999; font-size: 1rem;" input-align="right" customStyle="" rightIcon="" 57 placeholder-style="color: #999; font-size: 1rem;" input-align="right" customStyle="" rightIcon=""
58 - maxlength="" :border="false" /> 58 + maxlength="3" :border="false" />
59 </view> 59 </view>
60 </view> 60 </view>
61 <view class="form-item border"> 61 <view class="form-item border">
62 <view class="form-item-title fix">年龄最大值</view> 62 <view class="form-item-title fix">年龄最大值</view>
63 <view style="float: right;"> 63 <view style="float: right;">
64 - <van-field :value="max_number" type="number" label="" placeholder="请输入年龄最大值" 64 + <van-field :value="max_number" @change="changeMaxNumber" label="" placeholder="请输入年龄最大值"
65 placeholder-style="color: #999; font-size: 1rem;" input-align="right" customStyle="" rightIcon="" 65 placeholder-style="color: #999; font-size: 1rem;" input-align="right" customStyle="" rightIcon=""
66 - maxlength="" :border="false" /> 66 + maxlength="3" :border="false" />
67 </view> 67 </view>
68 </view> 68 </view>
69 </view> 69 </view>
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
80 </van-col> 80 </van-col>
81 </van-row> 81 </van-row>
82 </van-popup> 82 </van-popup>
83 + <van-toast id="van-toast" />
83 </template> 84 </template>
84 85
85 <script setup> 86 <script setup>
...@@ -89,30 +90,50 @@ import "taro-ui-vue3/dist/style/components/input.scss"; ...@@ -89,30 +90,50 @@ import "taro-ui-vue3/dist/style/components/input.scss";
89 import icon_sel from '@/images/icon/sel@2x.png' 90 import icon_sel from '@/images/icon/sel@2x.png'
90 import bottomButton from "@/components/bottom-button"; 91 import bottomButton from "@/components/bottom-button";
91 import Taro from '@tarojs/taro' 92 import Taro from '@tarojs/taro'
93 +import { getCurrentPageParam } from "@/utils/weapp";
94 +import { activityInfoAPI } from '@/api/Host/index';
95 +import { addRegAPI } from '@/api/Reg/index';
96 +import mixin from '@/utils/mixin';
97 +import Toast from '@/components/vant-weapp/toast/toast';
92 98
93 const username = ref(''); 99 const username = ref('');
94 const phone = ref(''); 100 const phone = ref('');
95 const age_range = ref(''); 101 const age_range = ref('');
96 const user_sex = ref(''); 102 const user_sex = ref('');
97 -const arr = ref([]); 103 +const fields = ref([]);
104 +const min_number = ref('');
105 +const max_number = ref('');
98 106
99 -onMounted(() => { 107 +onMounted(async () => {
100 - arr.value = [{ 108 + const { code, data } = await activityInfoAPI({ i: getCurrentPageParam().id });
101 - title: '推荐人' , 109 + if (code) {
102 - key: 'recommender', 110 + // 额外的报名信息
103 - value: '', 111 + fields.value = data.activity.fields;
104 - required: false, 112 + fields.value.forEach(item => {
105 - }, { 113 + item.value = '';
106 - title: '推荐人' , 114 + });
107 - key: 'recommender', 115 + }
108 - value: '',
109 - required: true,
110 - }]
111 }) 116 })
112 117
113 -// const handleInput = (value) => { 118 +const temp_min_number = ref('');
114 -// console.warn(arr.value); 119 +const changeMinNumber = ({detail}) => {
115 -// } 120 + const pattern = /^([1-9][0-9]*){1,3}$/; // 非零正整数
121 + if (!pattern.test(detail)) {// 如果包含特殊字符返回false
122 + Toast('请输入非零正整数');
123 + return false;
124 + }
125 + temp_min_number.value = detail;
126 +}
127 +const temp_max_number = ref('');
128 +const changeMaxNumber = ({detail}) => {
129 + const pattern = /^([1-9][0-9]*){1,3}$/; // 非零正整数
130 + if (!pattern.test(detail)) {// 如果包含特殊字符返回false
131 + Toast('请输入非零正整数');
132 + return false;
133 + }
134 + temp_max_number.value = detail;
135 +}
136 +
116 const onSexChange = ({ detail }) => { 137 const onSexChange = ({ detail }) => {
117 user_sex.value = detail; 138 user_sex.value = detail;
118 } 139 }
...@@ -122,25 +143,86 @@ const closeEditLimit = () => { ...@@ -122,25 +143,86 @@ const closeEditLimit = () => {
122 show_popup.value = false; 143 show_popup.value = false;
123 } 144 }
124 const confirmEditLimit = () => { 145 const confirmEditLimit = () => {
146 + if (!temp_min_number.value) {
147 + Toast('年龄最小值不能为空');
148 + return false;
149 + }
150 + if (!temp_max_number.value) {
151 + Toast('年龄最大值不能为空');
152 + return false;
153 + }
154 + if (+temp_min_number.value > +temp_max_number.value) {
155 + Toast('年龄段非法录入');
156 + return false;
157 + }
158 + min_number.value = +temp_min_number.value;
159 + max_number.value = +temp_max_number.value;
160 + age_range.value = min_number.value + '岁' + ' ~ ' + max_number.value + '岁';
125 show_popup.value = false; 161 show_popup.value = false;
126 } 162 }
127 163
128 -const onSubmit = (val) => { 164 +const validForm = () => {
129 - console.warn(val); 165 + if (!username.value) {
130 - Taro.showToast({ 166 + Toast('姓名不能为空');
131 - title: '请检查输入项', 167 + return false;
132 - icon: 'error', 168 + }
133 - duration: 2000 169 + if (!phone.value) {
170 + Toast('手机号不能为空');
171 + return false;
172 + }
173 + const pattern = /^\d{11}$/;
174 + if (!pattern.test(phone.value)) {
175 + Toast('请输入正确手机号');
176 + }
177 + if (!age_range.value) {
178 + Toast('年龄段不能为空');
179 + return false;
180 + }
181 + if (!user_sex.value) {
182 + Toast('性别不能为空');
183 + return false;
184 + }
185 + fields.value.length && fields.value.forEach(item => {
186 + if (item.is_require && !item.value) {
187 + Toast(item.field + '不能为空');
188 + return false;
189 + }
134 }); 190 });
135 - Taro.redirectTo({ 191 + return true;
136 - url: '../joinSuccess/index' 192 +}
137 - }) 193 +
194 +const onSubmit = async (val) => {
195 + if (validForm()) {
196 + // 额外信息枚举字段
197 + const extend = {};
198 + fields.value.length && fields.value.forEach(item => {
199 + extend[item.field] = item.value;
200 + });
201 + const params = {
202 + activity_id: getCurrentPageParam().id,
203 + type: 'player',
204 + name: username.value,
205 + phone: phone.value,
206 + gender: user_sex.value,
207 + age_group: JSON.stringify([min_number.value, max_number.value]),
208 + post: '',
209 + extend
210 + }
211 + const { code } = await addRegAPI(params);
212 + if (code) {
213 + Taro.redirectTo({
214 + url: '../joinSuccess/index'
215 + })
216 + }
217 + }
138 } 218 }
139 </script> 219 </script>
140 220
141 <script> 221 <script>
142 import "./index.less"; 222 import "./index.less";
223 +
143 export default { 224 export default {
144 name: "demoPage", 225 name: "demoPage",
226 + mixins: [mixin.init],
145 }; 227 };
146 </script> 228 </script>
......