nameAuthentication.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <uni-section title="实名认证" type="line">
  3. <view class="example">
  4. <!-- 自定义表单校验 -->
  5. <uni-forms ref="customForm" :rules="customRules" :modelValue="form">
  6. <uni-forms-item label="姓名" required name="name">
  7. <uni-easyinput v-model="form.name" placeholder="请输入姓名" maxlength="20"/>
  8. </uni-forms-item>
  9. <uni-forms-item label="电话" required name="phone">
  10. <uni-easyinput v-model="form.phone" placeholder="请输入电话" maxlength="13"/>
  11. </uni-forms-item>
  12. <uni-forms-item label="身份证号" required name="idCard">
  13. <uni-easyinput v-model="form.idCard" placeholder="请输入身份证号" maxlength="18"/>
  14. </uni-forms-item>
  15. <uni-forms-item label="身份证正反面" required name="path">
  16. <upload :imgArr="imageList" name="path" v-model="form.path" :fileSize="1" :limit="2"
  17. @updateImg="updateImg"></upload>
  18. </uni-forms-item>
  19. </uni-forms>
  20. <button type="primary" @click="submitForm('customForm')">提交</button>
  21. </view>
  22. </uni-section>
  23. </template>
  24. <script>
  25. import upload from '../../components/upload/index.vue'
  26. import {appletAdd} from '@/api/me/nameAuthentication.js'
  27. export default {
  28. components: {
  29. upload
  30. },
  31. onReady() {
  32. // 设置自定义表单校验规则,必须在节点渲染完毕后执行
  33. this.$refs.customForm.setRules(this.customRules)
  34. },
  35. data() {
  36. return {
  37. form: {},
  38. // 表单校验
  39. customRules: {
  40. name: {
  41. rules: [{
  42. required: true,
  43. errorMessage: '姓名不能为空'
  44. }]
  45. },
  46. phone: {
  47. rules: [{
  48. required: true,
  49. errorMessage: '电话不能为空'
  50. },
  51. {
  52. pattern:'^1[3456789]\\d{9}$',
  53. errorMessage: '请填写正确的手机号'
  54. }]
  55. },
  56. idCard: {
  57. rules: [{
  58. required: true,
  59. errorMessage: '身份证号不能为空'
  60. },
  61. {
  62. pattern: '/(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)/',
  63. errorMessage: '请填写正确的身份号'
  64. }]
  65. },
  66. path: {
  67. rules: [{
  68. required: true,
  69. errorMessage: '身份证正反面不能为空'
  70. }]
  71. },
  72. },
  73. imageList: []
  74. }
  75. },
  76. methods: {
  77. // 取消按钮
  78. cancel() {
  79. this.open = false;
  80. this.reset();
  81. },
  82. /** 提交按钮 */
  83. submitForm(e) {
  84. this.$refs[e].validate().then(res => {
  85. appletAdd(this.form).then(res => {
  86. uni.navigateBack();
  87. });
  88. }).catch(err => {
  89. })
  90. },
  91. updateImg(imgList) {
  92. this.imageList = imgList;
  93. this.form.path = this.imageList.join(',');
  94. }
  95. }
  96. };
  97. </script>
  98. <style>
  99. </style>