index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!-- 实名认证 -->
  2. <template>
  3. <app-view class="g-form account-certification">
  4. <template #header>
  5. <app-navbar :title="t('user.authentication.title')" />
  6. </template>
  7. <Form ref="formRef" class="g-form__container" @submit="onSubmit">
  8. <CellGroup title="信息填写" inset>
  9. <Field v-model="formData.username" name="username" :label="t('user.authentication.customername')"
  10. :placeholder="t('user.authentication.pleaseentertheusername')" :rules="formRules.username" />
  11. <Field name="cardtype" :label="t('user.authentication.cardtype')" :rules="formRules.cardtype" is-link>
  12. <template #input>
  13. <app-select v-model="formData.cardtype"
  14. :placeholder="t('user.authentication.pleaseselectthecardtype')" :options="cerTypePersonList"
  15. @confirm="formRef?.validate('cardtype')" />
  16. </template>
  17. </Field>
  18. <Field v-model="formData.cardnum" name="cardnum" :label="t('user.authentication.cardnum')"
  19. :placeholder="t('user.authentication.pleaseenterthecardnum')" :rules="formRules.cardnum"
  20. v-if="formData.cardtype !== undefined" />
  21. <Field name="cardfrontphotourl" :label="t('user.authentication.cardfrontphoto')"
  22. :rules="formRules.cardfrontphotourl">
  23. <template #input>
  24. <app-uploader @success="b_afterRead" />
  25. </template>
  26. </Field>
  27. <Field name="cardbackphotourl" v-if="showCardBackPhoto" :label="t('user.authentication.cardbackphoto')"
  28. :rules="formRules.cardbackphotourl">
  29. <template #input>
  30. <app-uploader @success="f_afterRead" />
  31. </template>
  32. </Field>
  33. <Field name="halfbodyphotourl" v-if="showHalfBodyPhoto" :label="halfBodyPhotoTitle"
  34. :rules="formRules.halfbodyphotourl">
  35. <template #input>
  36. <app-uploader @success="h_afterRead" />
  37. </template>
  38. </Field>
  39. </CellGroup>
  40. </Form>
  41. <div class="g-form__footer inset">
  42. <Button type="primary" @click="formRef?.submit" round block>
  43. {{ t('user.authentication.submit') }}
  44. </Button>
  45. </div>
  46. </app-view>
  47. </template>
  48. <script lang="ts" setup>
  49. import { shallowRef } from 'vue'
  50. import { CellGroup, Button, Field, Form, FormInstance, showFailToast, FieldRule } from 'vant'
  51. import { addAuthReq } from '@/business/user'
  52. import { fullloading, dialog } from '@/utils/vant'
  53. import { getCerTypePersonList } from "@/constants/account"
  54. import { useNavigation } from '@mobile/router/navigation'
  55. import { useRequest } from '@/hooks/request'
  56. import { getWskhOpenAccountConfigs } from '@/services/api/account'
  57. import { i18n, useUserStore } from '@/stores'
  58. import AppUploader from '@mobile/components/modules/uploader/index.vue'
  59. import AppSelect from '@mobile/components/base/select/index.vue'
  60. const userStore = useUserStore()
  61. const formRef = shallowRef<FormInstance>()
  62. const { formData, formSubmit } = addAuthReq()
  63. const { router } = useNavigation()
  64. const { global: { t } } = i18n
  65. const cerTypePersonList = getCerTypePersonList() // 证件类型列表
  66. const showHalfBodyPhoto = shallowRef(false)
  67. const showCardBackPhoto = shallowRef(false)
  68. const halfBodyPhotoTitle = shallowRef('')
  69. // 获取网上开户配置
  70. useRequest(getWskhOpenAccountConfigs, {
  71. defaultParams: {
  72. configs: '53,54,78'
  73. },
  74. onSuccess: (res) => {
  75. const configMap = new Map(res.data.map((item) => [item.configid, item.configvalue]))
  76. /// 是否显示半身照和 证件背面照
  77. showCardBackPhoto.value = configMap.get(53) === '1'
  78. showHalfBodyPhoto.value = configMap.get(54) === '1'
  79. halfBodyPhotoTitle.value = configMap.get(78) ?? t('user.authentication.halfbodyphoto')
  80. }
  81. })
  82. const b_afterRead = (filePath: string) => {
  83. formData.cardfrontphotourl = filePath
  84. formRef.value?.validate('cardfrontphotourl')
  85. }
  86. const f_afterRead = (filePath: string) => {
  87. formData.cardbackphotourl = filePath
  88. formRef.value?.validate('cardbackphotourl')
  89. }
  90. const h_afterRead = (filePath: string) => {
  91. formData.halfbodyphotourl = filePath
  92. formRef.value?.validate('halfbodyphotourl')
  93. }
  94. // 表单验证规则
  95. const formRules: { [key: string]: FieldRule[] } = {
  96. username: [{
  97. required: true,
  98. message: t("user.authentication.pleaseentertheusername"),
  99. }],
  100. cardtype: [{
  101. message: t('user.authentication.pleaseselectthecardtype'),
  102. validator: () => formData.cardtype !== undefined
  103. }],
  104. cardnum: [{
  105. message: t("user.authentication.pleaseenterthecardnum"),
  106. validator: (val) => {
  107. // 任务 #7009
  108. const enumItem = cerTypePersonList.find((e) => e.enumitemname === formData.cardtype)
  109. if (enumItem && new RegExp(enumItem.param1).test(val)) {
  110. return true
  111. }
  112. return t('regex.cardno')
  113. }
  114. }],
  115. cardbackphotourl: [{
  116. message: t("user.authentication.pleaseuploadthecardbackphoto"),
  117. validator: () => !!formData.cardbackphotourl
  118. }],
  119. cardfrontphotourl: [{
  120. message: t("user.authentication.pleaseuploadthecardfrontphoto"),
  121. validator: () => !!formData.cardfrontphotourl
  122. }]
  123. }
  124. const onSubmit = () => {
  125. fullloading((hideLoading) => {
  126. formSubmit().then((res) => {
  127. /// 失败
  128. if (res.code.toString() === '0') {
  129. userStore.getUserData().finally(() => {
  130. hideLoading()
  131. dialog(t("user.authentication.opensuccess")).then(() => {
  132. router.back()
  133. })
  134. })
  135. } else {
  136. showFailToast(res.message)
  137. }
  138. }).catch((err) => {
  139. formData.cardnum = ''
  140. showFailToast(err)
  141. })
  142. })
  143. }
  144. </script>
  145. <style lang="less">
  146. @import './index.less';
  147. </style>