verification.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <Navbar :title="t('实名认证')" fixed />
  5. <view class="form">
  6. <view class="form_item">
  7. <view class="item_label">
  8. <trans _t="证件类型" />
  9. </view>
  10. <view class="item_value flex">
  11. <Select iconColor="#adb8cc" :disabled="isDisabled" v-model:current="form.auth_type" :options="documentsList"
  12. isTran class="country_select" @select="countryChange" ref="countryRef" @selectClick="inputFocus">
  13. <template #text>
  14. <view class="select_label" style="color: var(--inputText)" v-if="form.auth_name">
  15. {{ form.auth_name }}
  16. </view>
  17. <view class="select_label" v-else>
  18. <trans _t="证件类型" />
  19. </view>
  20. </template>
  21. </Select>
  22. </view>
  23. </view>
  24. <view class="form_item">
  25. <view class="item_label">
  26. <trans _t="姓名" />
  27. </view>
  28. <view class="item_value">
  29. <Input :disabled="isDisabled" :placeholder="t('姓名')" border="surround" @focus="inputFocus"
  30. v-model="form.realname" />
  31. </view>
  32. </view>
  33. <view class="form_item">
  34. <view class="item_label">
  35. <trans _t="证件号码" />
  36. </view>
  37. <view class="item_value">
  38. <Input :disabled="isDisabled" :placeholder="t('证件号码')" border="surround" @focus="inputFocus"
  39. v-model="form.cardid" />
  40. </view>
  41. </view>
  42. <view class="form_item">
  43. <view class="item_label">
  44. <trans _t="上传证件正面照片" />
  45. </view>
  46. <view class="item_value">
  47. <imgUp :modelValue="form.card_front ? [form.card_front] : []" @update:modelValue="handleImageUrl"
  48. :disabled="isDisabled" />
  49. </view>
  50. </view>
  51. <view class="form_item">
  52. <view class="item_label">
  53. <trans _t="上传证件反面照片" />
  54. </view>
  55. <view class="item_value">
  56. <imgUp :modelValue="form.card_back ? [form.card_back] : []" @update:modelValue="handleBackImageUrl"
  57. :disabled="isDisabled" />
  58. </view>
  59. </view>
  60. </view>
  61. <view class="footer" v-if="!isDisabled">
  62. <view class="submit_btn" @click="submit">
  63. <trans _t="确认" />
  64. </view>
  65. </view>
  66. </view>
  67. </Theme>
  68. </template>
  69. <script setup>
  70. import Navbar from '@/components/navbar';
  71. import Select from "@/components/select"
  72. import { reactive, ref, watch, nextTick } from 'vue';
  73. import { t } from "@/locale";
  74. import Input from "@/components/input";
  75. import imgUp from '@/components/imgUp.vue';
  76. import { USERS_LEVELAUTH, GET_USERS_LEVELAUTH } from '@/api'
  77. import { Toast, Modal } from "@/utils"
  78. import { useUserStore } from "@/store"
  79. const useUser = useUserStore();
  80. let userInfo = useUser.getuserInfo
  81. const form = reactive({
  82. level: 2,
  83. auth_code: 0,
  84. auth_type: 'card',
  85. auth_name: t('身份证'),
  86. realname: '',
  87. cardid: '',
  88. card_back: '',
  89. card_front: '',
  90. })
  91. const provinceRef = ref(null)
  92. const countryChange = (item) => {
  93. form.auth_code = item.code;
  94. form.auth_type = item.type;
  95. form.auth_name = item.name;
  96. provinceRef.value && provinceRef.value.close();
  97. }
  98. const documentsList = ref(
  99. [
  100. { code: 0, type: 'card', name: t('身份证') },
  101. { code: 1, type: 'driver', name: t('驾驶证') },
  102. { code: 2, type: 'passport', name: t('护照') },
  103. ]
  104. )
  105. const getDetail = async () => {
  106. try {
  107. const res = await GET_USERS_LEVELAUTH();
  108. if (res.data && res.data.auth_data) {
  109. form.realname = res.data.auth_data.realname;
  110. form.cardid = res.data.auth_data.cardid;
  111. form.card_back = res.data.auth_data.card_back;
  112. form.card_front = res.data.auth_data.card_front;
  113. form.auth_type = res.data.auth_data.auth_type;
  114. const correctDocument = documentsList.value.find(doc => doc.type === res.data.auth_data.auth_type);
  115. if (correctDocument) {
  116. form.auth_code = correctDocument.code;
  117. form.auth_name = correctDocument.name;
  118. } else {
  119. form.auth_code = 0;
  120. form.auth_name = t('身份证');
  121. }
  122. }
  123. } catch (error) { }
  124. }
  125. const isDisabled = ref(false)
  126. const watchUserInfo = () => {
  127. watch(() => userInfo, (item) => {
  128. isDisabled.value = (item.auth_check === 2 || item.auth_level === 2);
  129. if (isDisabled.value) {
  130. getDetail()
  131. }
  132. }, { immediate: true })
  133. }
  134. watchUserInfo()
  135. const handleImageUrl = (item) => {
  136. form.card_front = item.length ? item[0].url : ''
  137. };
  138. const handleBackImageUrl = (item) => {
  139. form.card_back = item.length ? item[0].url : ''
  140. };
  141. const inputFocus = () => {
  142. provinceRef.value && provinceRef.value.close();
  143. }
  144. const submit = () => {
  145. if (!form.realname) return Toast(t('请填写姓名'));
  146. if (!form.cardid) return Toast(t('请填写身份证号码'));
  147. if (!form.card_front) return Toast(t('上传身份证正面照片'));
  148. if (!form.card_back) return Toast(t('上传身份证反面照片'));
  149. Modal({ content: t('verification_text') }).then(() => {
  150. verificationAdd();
  151. });
  152. }
  153. const verificationAdd = async () => {
  154. try {
  155. const res = await USERS_LEVELAUTH({ ...form });
  156. Toast(res.msg, 1000).then(() => {
  157. setTimeout(() => {
  158. uni.navigateBack();
  159. }, 1000);
  160. })
  161. // Toast(res.msg);
  162. // nextTick(() => {
  163. // useUser.getUserInfo();
  164. // watchUserInfo()
  165. // uni.navigateBack();
  166. // })
  167. } catch (error) {
  168. Toast(error.msg);
  169. close();
  170. }
  171. }
  172. </script>
  173. <style lang="less" scoped>
  174. @import url('@/style.less');
  175. .wrap {
  176. background: var(--bg);
  177. min-height: 100vh;
  178. padding: 24rpx;
  179. .form {
  180. &_item {
  181. margin-top: 24rpx;
  182. &:first-child {
  183. margin-top: 0;
  184. }
  185. .item_label {
  186. font-weight: 700;
  187. color: var(--text);
  188. .size(28rpx);
  189. line-height: 60rpx;
  190. white-space: nowrap;
  191. padding-right: 24rpx;
  192. height: 64rpx;
  193. width: fit-content;
  194. position: relative;
  195. &::before {
  196. content: '*';
  197. color: #f56c6c;
  198. margin-right: 8rpx;
  199. }
  200. }
  201. ._required {
  202. &::before {
  203. content: '';
  204. margin-right: 0rpx;
  205. }
  206. }
  207. .item_value {
  208. column-gap: 24rpx;
  209. flex: 1;
  210. /deep/ .u-input {
  211. border-radius: 16rpx;
  212. padding: 0 24rpx !important;
  213. background-color: var(--bg);
  214. .u-input__content {
  215. display: unset;
  216. }
  217. }
  218. /deep/ .u-select {
  219. flex: 1;
  220. height: 32px;
  221. padding: 0 24rpx;
  222. border-radius: 16rpx;
  223. background-color: var(--bg);
  224. border-color: var(--borderColor) !important;
  225. box-shadow: 0 0 0 1px var(--borderColor) inset;
  226. .u-select__label {
  227. margin: 0;
  228. line-height: 32px;
  229. .select_label {
  230. flex: 1;
  231. color: #adb8cc;
  232. .size(28rpx);
  233. .ellipsis();
  234. width: 100%;
  235. }
  236. .u-select__options {
  237. width: 80vw;
  238. }
  239. }
  240. }
  241. .country_select,
  242. .province_select {
  243. /deep/ .u-select__options {
  244. width: 80vw;
  245. .u-select__options_item {
  246. .size(24rpx);
  247. height: 80rpx;
  248. line-height: 80rpx;
  249. padding: 0 64rpx;
  250. .u-select__item_text {
  251. color: var(--inputText);
  252. }
  253. }
  254. .active {
  255. .u-select__item_text {
  256. font-weight: 700;
  257. color: var(--primary) !important;
  258. }
  259. }
  260. }
  261. }
  262. .province_select {
  263. /deep/ .u-select__options {
  264. width: 300rpx;
  265. }
  266. }
  267. }
  268. .labels {
  269. margin-top: 24rpx;
  270. .ver();
  271. gap: 24rpx;
  272. &_item {
  273. border: 1px solid #7d8fb3;
  274. border-radius: 8rpx;
  275. color: #7d8fb3;
  276. padding: 0 28rpx;
  277. line-height: 64rpx;
  278. .size(24rpx);
  279. }
  280. .labels_active {
  281. background-color: var(--black);
  282. border: 1px solid var(--black);
  283. color: var(--light);
  284. }
  285. }
  286. }
  287. }
  288. .submit_btn {
  289. height: 38px;
  290. padding: 16rpx 30rpx;
  291. background-color: var(--black);
  292. color: var(--light);
  293. .flex_center();
  294. border-radius: 16rpx;
  295. .size(24rpx);
  296. margin-top: 20rpx;
  297. }
  298. }
  299. </style>