baoMing.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="box">
  3. <u-navbar :autoBack="true" title="报名" bgColor="rgba(255,255,255,0)" :placeholder="true" titleStyle="font-weight:bold;color:#000000"></u-navbar>
  4. <!-- 表单 -->
  5. <view class="example">
  6. <uni-forms style="padding: 0 20rpx 0 20rpx" label-position="top" ref="valiForm" :rules="rules" :modelValue="valiFormData">
  7. <uni-forms-item label="您的姓名" label-width="80px" required name="name">
  8. <uni-easyinput v-model="valiFormData.name" placeholder="请输入姓名" />
  9. </uni-forms-item>
  10. <uni-forms-item label="您的联系电话" label-width="100px" required name="mobile">
  11. <uni-easyinput v-model="valiFormData.mobile" placeholder="请输联系电话" />
  12. </uni-forms-item>
  13. <uni-forms-item label="您的身份证" label-width="100px" required name="idCard">
  14. <uni-easyinput v-model="valiFormData.idCard" placeholder="请输入身份证号" />
  15. </uni-forms-item>
  16. </uni-forms>
  17. <view class="text-wrapper_3" @click="submit('valiForm')">
  18. <text>我要报名</text>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. let that;
  25. export default {
  26. data() {
  27. return {
  28. id: '' /* 活动id */,
  29. /* 表单数据 */
  30. valiFormData: {
  31. name: '',
  32. mobile: '',
  33. idCard: ''
  34. },
  35. /* 校验规则 */
  36. rules: {
  37. // 对name字段进行必填验证
  38. name: {
  39. // name 字段的校验规则
  40. rules: [
  41. // 校验 name 不能为空
  42. {
  43. required: true,
  44. errorMessage: '请填写姓名'
  45. },
  46. // 对name字段进行长度验证
  47. {
  48. minLength: 2,
  49. maxLength: 6,
  50. errorMessage: '{label}长度在 {minLength} 到 {maxLength} 个字符'
  51. }
  52. ],
  53. // 当前表单域的字段中文名,可不填写
  54. label: '姓名',
  55. validateTrigger: 'submit'
  56. },
  57. /* 手机号校验 */
  58. mobile: {
  59. // mobile 字段的校验规则
  60. rules: [
  61. // 校验 mobile 不能为空
  62. {
  63. required: true,
  64. errorMessage: '请填写联系电话'
  65. },
  66. // 对mobile字段进行长度验证
  67. {
  68. minLength: 11,
  69. maxLength: 11,
  70. errorMessage: '{label}长度为 {minLength} 个字符'
  71. }
  72. ],
  73. // 当前表单域的字段中文名,可不填写
  74. label: '手机号',
  75. validateTrigger: 'submit'
  76. },
  77. /* 身份证校验 */
  78. idCard: {
  79. // idCard 字段的校验规则
  80. rules: [
  81. // 校验 idCard 不能为空
  82. {
  83. required: true,
  84. errorMessage: '请填报名人数'
  85. },
  86. // 对idCard字段进行长度验证
  87. {
  88. minLength: 18,
  89. maxLength: 18,
  90. errorMessage: '{label}长度为 {minLength} 个字符'
  91. }
  92. ],
  93. // 当前表单域的字段中文名,可不填写
  94. label: '身份证号',
  95. validateTrigger: 'submit'
  96. }
  97. }
  98. };
  99. },
  100. onLoad(o) {
  101. that = this;
  102. this.id = o.id;
  103. },
  104. methods: {
  105. submit() {
  106. this.$refs.valiForm.validate(['id'], async (err, valiFormData) => {
  107. if (!err) {
  108. console.log('校验成功');
  109. this.$api.activitySignup(
  110. {
  111. main_body_id: 1,
  112. activity_id: this.id,
  113. name: this.valiFormData.name,
  114. mobile: this.valiFormData.mobile,
  115. id_card: this.valiFormData.idCard
  116. },
  117. function (res) {
  118. console.log(res, '报名');
  119. if (res.code == 1) {
  120. that.$common.errorToShow(res.msg);
  121. } else {
  122. that.$common.errorToShow('请稍后再试');
  123. }
  124. }
  125. );
  126. }
  127. });
  128. }
  129. }
  130. };
  131. </script>
  132. <style>
  133. .box {
  134. width: 100%;
  135. height: 100%;
  136. background-color: #efb781;
  137. }
  138. /deep/.uni-forms-item__error {
  139. color: #ea3535 !important;
  140. }
  141. .text-wrapper_3 {
  142. background-color: #fde6b0;
  143. border-radius: 40rpx;
  144. height: 80rpx;
  145. color: #312520;
  146. text-align: center;
  147. line-height: 80rpx;
  148. font-size: 32rpx;
  149. flex-direction: column;
  150. width: 620rpx;
  151. margin-top: 40rpx;
  152. margin-bottom: 20rpx;
  153. margin-left: 30rpx;
  154. font-weight: bold;
  155. position: fixed;
  156. bottom: 100rpx;
  157. }
  158. .example {
  159. height: 87%;
  160. background-color: rgba(255, 255, 255, 0.15);
  161. margin: 20rpx 32rpx 0 32rpx;
  162. }
  163. .uni-forms {
  164. padding: 0 20rpx 0 20rpx;
  165. }
  166. .uni-forms-item {
  167. margin-bottom: 30rpx !important;
  168. }
  169. </style>