123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <template>
- <view class="box">
- <u-navbar :autoBack="true" title="报名" bgColor="rgba(255,255,255,0)" :placeholder="true" titleStyle="font-weight:bold;color:#000000"></u-navbar>
- <!-- 表单 -->
- <view class="example">
- <uni-forms style="padding: 0 20rpx 0 20rpx" label-position="top" ref="valiForm" :rules="rules" :modelValue="valiFormData">
- <uni-forms-item label="您的姓名" label-width="80px" required name="name">
- <uni-easyinput v-model="valiFormData.name" placeholder="请输入姓名" />
- </uni-forms-item>
- <uni-forms-item label="您的联系电话" label-width="100px" required name="mobile">
- <uni-easyinput v-model="valiFormData.mobile" placeholder="请输联系电话" />
- </uni-forms-item>
- <uni-forms-item label="您的身份证" label-width="100px" required name="idCard">
- <uni-easyinput v-model="valiFormData.idCard" placeholder="请输入身份证号" />
- </uni-forms-item>
- </uni-forms>
- <view class="text-wrapper_3" @click="submit('valiForm')">
- <text>我要报名</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- let that;
- export default {
- data() {
- return {
- id: '' /* 活动id */,
- /* 表单数据 */
- valiFormData: {
- name: '',
- mobile: '',
- idCard: ''
- },
- /* 校验规则 */
- rules: {
- // 对name字段进行必填验证
- name: {
- // name 字段的校验规则
- rules: [
- // 校验 name 不能为空
- {
- required: true,
- errorMessage: '请填写姓名'
- },
- // 对name字段进行长度验证
- {
- minLength: 2,
- maxLength: 6,
- errorMessage: '{label}长度在 {minLength} 到 {maxLength} 个字符'
- }
- ],
- // 当前表单域的字段中文名,可不填写
- label: '姓名',
- validateTrigger: 'submit'
- },
- /* 手机号校验 */
- mobile: {
- // mobile 字段的校验规则
- rules: [
- // 校验 mobile 不能为空
- {
- required: true,
- errorMessage: '请填写联系电话'
- },
- // 对mobile字段进行长度验证
- {
- minLength: 11,
- maxLength: 11,
- errorMessage: '{label}长度为 {minLength} 个字符'
- }
- ],
- // 当前表单域的字段中文名,可不填写
- label: '手机号',
- validateTrigger: 'submit'
- },
- /* 身份证校验 */
- idCard: {
- // idCard 字段的校验规则
- rules: [
- // 校验 idCard 不能为空
- {
- required: true,
- errorMessage: '请填报名人数'
- },
- // 对idCard字段进行长度验证
- {
- minLength: 18,
- maxLength: 18,
- errorMessage: '{label}长度为 {minLength} 个字符'
- }
- ],
- // 当前表单域的字段中文名,可不填写
- label: '身份证号',
- validateTrigger: 'submit'
- }
- }
- };
- },
- onLoad(o) {
- that = this;
- this.id = o.id;
- },
- methods: {
- submit() {
- this.$refs.valiForm.validate(['id'], async (err, valiFormData) => {
- if (!err) {
- console.log('校验成功');
- this.$api.activitySignup(
- {
- main_body_id: 1,
- activity_id: this.id,
- name: this.valiFormData.name,
- mobile: this.valiFormData.mobile,
- id_card: this.valiFormData.idCard
- },
- function (res) {
- console.log(res, '报名');
- if (res.code == 1) {
- that.$common.errorToShow(res.msg);
- } else {
- that.$common.errorToShow('请稍后再试');
- }
- }
- );
- }
- });
- }
- }
- };
- </script>
- <style>
- .box {
- width: 100%;
- height: 100%;
- background-color: #efb781;
- }
- /deep/.uni-forms-item__error {
- color: #ea3535 !important;
- }
- .text-wrapper_3 {
- background-color: #fde6b0;
- border-radius: 40rpx;
- height: 80rpx;
- color: #312520;
- text-align: center;
- line-height: 80rpx;
- font-size: 32rpx;
- flex-direction: column;
- width: 620rpx;
- margin-top: 40rpx;
- margin-bottom: 20rpx;
- margin-left: 30rpx;
- font-weight: bold;
- position: fixed;
- bottom: 100rpx;
- }
- .example {
- height: 87%;
- background-color: rgba(255, 255, 255, 0.15);
- margin: 20rpx 32rpx 0 32rpx;
- }
- .uni-forms {
- padding: 0 20rpx 0 20rpx;
- }
- .uni-forms-item {
- margin-bottom: 30rpx !important;
- }
- </style>
|