Index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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="onCheckCardNum" :loading="loading">
  7. <CellGroup inset>
  8. <Field v-model="formData.username" name="username" label="姓名" placeholder="请输入用户姓名" :rules="formRules.username"
  9. :readonly="isReadonly" />
  10. <Field v-model="formData.mobile" name="mobile" readonly label="手机号码" />
  11. <Field name="idCardType" label="证件类型" :rules="formRules.cardtype" is-link>
  12. <template #input>
  13. <app-select v-model="formData.cardtype" placeholder="请选择证件类型"
  14. :options="getCerTypePersonList()" :readonly="isReadonly" />
  15. </template>
  16. </Field>
  17. <Field v-model="formData.cardnum" name="cardnum" label="证件号码" placeholder="请输入证件号码" :rules="formRules.cardnum"
  18. :readonly="isReadonly" />
  19. <Field name="cardfrontphotourl" label="证件正面照片" :rules="formRules.cardfrontphotourl">
  20. <template #input>
  21. <Image fit="contain" :src="getFileUrl(formData.cardfrontphotourl)" width="100" height="100"
  22. v-if="isReadonly" />
  23. <app-uploader @success="f_afterRead" v-else />
  24. </template>
  25. </Field>
  26. <Field name="cardbackphotourl" label="证件反面照片" :rules="formRules.cardbackphotourl">
  27. <template #input>
  28. <Image fit="contain" :src="getFileUrl(formData.cardbackphotourl)" width="100" height="100"
  29. v-if="isReadonly" />
  30. <app-uploader @success="b_afterRead" v-else />
  31. </template>
  32. </Field>
  33. </CellGroup>
  34. </Form>
  35. <img src="../../../assets/images/certification.png" />
  36. <template #footer>
  37. <div class="g-form__footer inset">
  38. <Button type="danger" :loading="buttonLoading" @click="formRef?.submit" round block>提交实名认证</Button>
  39. </div>
  40. </template>
  41. </app-view>
  42. </template>
  43. <script lang="ts" setup>
  44. import { shallowRef, onMounted } from 'vue'
  45. import { CellGroup, Button, Field, Form, FormInstance, showFailToast, FieldRule, Image } from 'vant'
  46. import { fullloading, dialog } from '@/utils/vant';
  47. import { getFileUrl } from '@/filters';
  48. import { getCerTypePersonList } from "@/constants/account";
  49. import { useRequest } from '@/hooks/request'
  50. import { queryTencentUsereSignRecords, requestCheckCardNum } from '@/services/api/account';
  51. import { addAuthReq } from '@/business/user/account';
  52. import { validateRules } from '@/constants/regex';
  53. import { useUserStore } from '@/stores'
  54. import AppSelect from '@mobile/components/base/select/index.vue'
  55. import AppUploader from '@mobile/components/base/uploader/index.vue'
  56. import { useNavigation } from '@mobile/router/navigation'
  57. import { getUserId, getMemberUserId } from '@/services/methods/user'
  58. const { router } = useNavigation()
  59. const userStore = useUserStore()
  60. const formRef = shallowRef<FormInstance>()
  61. const { formData, formSubmit, loading } = addAuthReq()
  62. const isReadonly = false//computed(() => userESignRecords.value.some((e) => e.recordstatus === 3))
  63. /// 查询记录
  64. const { loading: buttonLoading } = useRequest(queryTencentUsereSignRecords, {
  65. params: {
  66. userId: getUserId(),
  67. memberUserId: getMemberUserId()
  68. },
  69. onError: (err) => {
  70. showFailToast(err)
  71. }
  72. })
  73. const b_afterRead = (filePath: string) => {
  74. formData.cardbackphotourl = filePath
  75. }
  76. const f_afterRead = (filePath: string) => {
  77. formData.cardfrontphotourl = filePath
  78. }
  79. // 表单验证规则
  80. const formRules: { [key in keyof Model.AddAuthReq]?: FieldRule[] } = {
  81. username: [{
  82. required: true,
  83. message: '请输入用户姓名',
  84. }],
  85. mobile: [{
  86. required: true,
  87. message: '请输入手机号码',
  88. validator: (val) => {
  89. if (validateRules.phone.validate(val)) {
  90. return true
  91. }
  92. return validateRules.phone.message
  93. }
  94. }],
  95. cardnum: [{
  96. required: true,
  97. message: '请输入证件号码',
  98. validator: (val) => {
  99. if (validateRules.cardno.validate(val)) {
  100. return true
  101. }
  102. return validateRules.cardno.message
  103. }
  104. }],
  105. cardbackphotourl: [{
  106. required: true,
  107. message: '请上传证件背面照片',
  108. }],
  109. cardfrontphotourl: [{
  110. required: true,
  111. message: '请上传证件正面照片',
  112. }],
  113. }
  114. const onCheckCardNum = () => {
  115. fullloading((hideLoading) => {
  116. requestCheckCardNum({
  117. data: {
  118. cardnum: formData.cardnum
  119. }
  120. }).then(() => {
  121. formSubmit().then(() => {
  122. hideLoading()
  123. dialog('提交请求成功,请耐心等待审核!').then(() => {
  124. router.back()
  125. })
  126. }).catch((err) => {
  127. hideLoading(err, 'fail')
  128. })
  129. }).catch((err) => {
  130. hideLoading(err, 'fail')
  131. })
  132. })
  133. }
  134. onMounted(() => {
  135. formData.mobile = userStore.userInfo?.mobile2 ?? ''
  136. })
  137. </script>