Index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <app-view class="g-form account-certification">
  3. <template #header>
  4. <app-navbar title="实名认证" />
  5. </template>
  6. <Form ref="formRef" class="g-form__container" @submit="onSubmit">
  7. <CellGroup inset>
  8. <Field v-model="formData.username" name="username" label="姓名" placeholder="请输入用户姓名"
  9. :rules="formRules.username" />
  10. <Field name="cardtype" label="证件类型" :rules="formRules.cardtype" is-link>
  11. <template #input>
  12. <app-select v-model="formData.cardtype" placeholder="请选择证件类型" :options="enums" />
  13. </template>
  14. </Field>
  15. <Field v-model="formData.cardnum" name="cardnum" label="证件号码" placeholder="请输入证件号码"
  16. :rules="formRules.cardnum" />
  17. <Field name="cardfrontphotourl" label="证件正面照片" :rules="formRules.cardfrontphotourl">
  18. <template #input>
  19. <app-uploader @success="b_afterRead" />
  20. </template>
  21. </Field>
  22. <Field name="cardbackphotourl" label="证件反面照片" :rules="formRules.cardbackphotourl">
  23. <template #input>
  24. <app-uploader @success="f_afterRead" />
  25. </template>
  26. </Field>
  27. </CellGroup>
  28. </Form>
  29. <img src="../../../assets/images/certification.png" />
  30. <template #footer>
  31. <div class="g-form__footer inset">
  32. <Button type="danger" @click="formRef?.submit" round block>提交实名认证</Button>
  33. </div>
  34. </template>
  35. </app-view>
  36. </template>
  37. <script lang="ts" setup>
  38. import { shallowRef, computed } from 'vue'
  39. import { CellGroup, Button, Field, Form, FormInstance, showFailToast, FieldRule } from 'vant'
  40. import { addAuthReq } from '@/business/user'
  41. import { fullloading, dialog } from '@/utils/vant';
  42. import { getCertificateTypeList } from "@/constants/account";
  43. import AppSelect from '../../../components/base/select/index.vue'
  44. import { useNavigation } from '../../../router/navigation'
  45. import AppUploader from '../../../components/base/uploader/index.vue'
  46. const formRef = shallowRef<FormInstance>()
  47. const { formData, formSubmit } = addAuthReq()
  48. const { router } = useNavigation()
  49. /// 获取对应的证件枚举类型
  50. const enums = computed(() => { return getCertificateTypeList().map(obj => { return { label: obj.label, value: obj.value } }) })
  51. const b_afterRead = (filePath: string) => {
  52. formData.cardfrontphotourl = filePath
  53. }
  54. const f_afterRead = (filePath: string) => {
  55. formData.cardbackphotourl = filePath
  56. }
  57. // 表单验证规则
  58. const formRules: { [key in keyof Model.AddAuthReq]?: FieldRule[] } = {
  59. username: [{
  60. required: true,
  61. message: '请输入用户姓名',
  62. }],
  63. cardnum: [{
  64. required: true,
  65. message: '请输入证件号码',
  66. }],
  67. cardbackphotourl: [{
  68. required: true,
  69. message: '请上传证件背面照片',
  70. }],
  71. cardfrontphotourl: [{
  72. required: true,
  73. message: '请上传证件正面照片',
  74. }],
  75. }
  76. const onSubmit = () => {
  77. fullloading((hideLoading) => {
  78. formSubmit().then(() => {
  79. hideLoading()
  80. dialog('实名认证提交请求成功').then(() => {
  81. router.back()
  82. })
  83. }).catch((err) => {
  84. showFailToast(err)
  85. })
  86. })
  87. }
  88. </script>