index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <template>
  2. <view class="bank-auth">
  3. <scroll-view scroll-y class="bank-auth__scroll">
  4. <view class="bank-auth__hero">
  5. <view class="bank-auth__hero-main">
  6. <text class="bank-auth__hero-title">银行卡认证</text>
  7. <text class="bank-auth__hero-desc">
  8. 请绑定本人 I 类银行账户借记卡,用于佣金结算发放
  9. </text>
  10. </view>
  11. <view class="bank-auth__hero-badge">
  12. {{ certified ? '已认证' : '待认证' }}
  13. </view>
  14. </view>
  15. <view class="notice-card">
  16. <view class="notice-card__icon">!</view>
  17. <text class="notice-card__text"> 需绑定本人 I 类银行账户借记卡,否则无法发放佣金。 </text>
  18. </view>
  19. <view class="form-card">
  20. <view class="form-header">
  21. <text class="form-title">银行卡信息</text>
  22. <text class="form-subtitle">请确认银行卡开户人与身份认证信息一致</text>
  23. </view>
  24. <view class="form-row">
  25. <text class="form-label">银行卡号</text>
  26. <input
  27. v-model="bankInfo.cardNumber"
  28. class="form-input"
  29. type="number"
  30. maxlength="19"
  31. placeholder="请输入银行卡号"
  32. placeholder-class="form-placeholder"
  33. :disabled="isFormDisabled"
  34. />
  35. </view>
  36. <view class="form-row">
  37. <text class="form-label">开户行</text>
  38. <input
  39. v-model="bankInfo.bankName"
  40. class="form-input"
  41. placeholder="请输入开户行"
  42. placeholder-class="form-placeholder"
  43. :disabled="isFormDisabled"
  44. />
  45. </view>
  46. <view class="form-row">
  47. <text class="form-label">预留手机号</text>
  48. <input
  49. v-model="bankInfo.phone"
  50. class="form-input"
  51. type="number"
  52. maxlength="11"
  53. placeholder="请输入银行预留手机号"
  54. placeholder-class="form-placeholder"
  55. :disabled="isFormDisabled"
  56. />
  57. </view>
  58. </view>
  59. </scroll-view>
  60. <view class="bottom-bar">
  61. <button class="bottom-btn bottom-btn--secondary" :disabled="loading" @click="handleBack">
  62. 返回
  63. </button>
  64. <button
  65. class="bottom-btn bottom-btn--primary"
  66. :disabled="loading || certified"
  67. @click="handleSubmit"
  68. >
  69. {{ submitButtonText }}
  70. </button>
  71. </view>
  72. <BaseAuthDialog
  73. v-model="bankPhoneAuthFailVisible"
  74. title="手机三要素认证未通过"
  75. confirm-text="我知道啦"
  76. >
  77. <view class="dialog-text"> 抱歉,您的预留手机号三要素认证未通过! </view>
  78. <view class="dialog-text"> 请确保您的手机号持卡人身份证号与您提供的身份证号一致: </view>
  79. <view class="dialog-text">
  80. 您可以登录银行卡 APP 或前往网点
  81. <text class="dialog-highlight">更换预留手机号</text>
  82. </view>
  83. </BaseAuthDialog>
  84. <BaseAuthDialog
  85. v-model="reSignVisible"
  86. title="重新签约提醒"
  87. confirm-text="去签约"
  88. @confirm="handleGoSign"
  89. >
  90. <view class="dialog-title-text"> 您更新了银行卡信息,需要与结算渠道重新签约。 </view>
  91. <view class="dialog-text">
  92. 请点击“去签约”完成结算渠道签约,在完成签约前将无法完成结算。
  93. </view>
  94. </BaseAuthDialog>
  95. </view>
  96. </template>
  97. <script setup lang="ts">
  98. import { computed, reactive, ref } from 'vue'
  99. import { onLoad, onUnload } from '@dcloudio/uni-app'
  100. import {
  101. bindBankInfoApi,
  102. gigCertPersonVerifyMobile3Api,
  103. personVerifyBank4Api,
  104. } from '@/services/modules/auth'
  105. import { useUserStore } from '@/stores/modules/user'
  106. import BaseAuthDialog from '@/components/BaseAuthDialog/index.vue'
  107. defineOptions({
  108. name: 'BankAuthPage',
  109. })
  110. const API_SUCCESS_CODE = 0
  111. const SIGN_URL = '/pages-sub-packages/mine/auth/index'
  112. const BACK_DELAY = 500
  113. interface CurrentUserForBankAuth {
  114. phone?: string
  115. realname?: string
  116. idCardNumber?: string
  117. bankCardNumber?: string
  118. bankPhone?: string
  119. }
  120. const userStore = useUserStore()
  121. const loading = ref(false)
  122. const certified = ref(false)
  123. const bankPhoneAuthFailVisible = ref(false)
  124. const reSignVisible = ref(false)
  125. let backTimer: ReturnType<typeof setTimeout> | null = null
  126. const bankInfo = reactive({
  127. cardNumber: '',
  128. bankName: '',
  129. phone: '',
  130. })
  131. const currentUserInfo = computed(() => {
  132. return (userStore.currentUserInfo ?? {}) as CurrentUserForBankAuth
  133. })
  134. const loginMobile = computed(() => currentUserInfo.value.phone ?? '')
  135. const realName = computed(() => currentUserInfo.value.realname ?? '')
  136. const idCardNumber = computed(() => currentUserInfo.value.idCardNumber ?? '')
  137. const hasExistingBankInfo = computed(() => {
  138. return Boolean(currentUserInfo.value.bankCardNumber || currentUserInfo.value.bankPhone)
  139. })
  140. const isFormDisabled = computed(() => loading.value || certified.value)
  141. const submitButtonText = computed(() => {
  142. if (certified.value) return '已认证'
  143. if (loading.value) return '提交中...'
  144. return '去认证'
  145. })
  146. const resetForm = () => {
  147. certified.value = false
  148. bankPhoneAuthFailVisible.value = false
  149. reSignVisible.value = false
  150. bankInfo.cardNumber = ''
  151. bankInfo.bankName = ''
  152. bankInfo.phone = ''
  153. }
  154. const normalizeForm = () => {
  155. bankInfo.cardNumber = bankInfo.cardNumber.replace(/\s+/g, '')
  156. bankInfo.bankName = bankInfo.bankName.trim()
  157. bankInfo.phone = bankInfo.phone.replace(/\s+/g, '')
  158. }
  159. const validateUserIdentity = () => {
  160. if (!realName.value || !idCardNumber.value) {
  161. uni.showToast({
  162. title: '请先完成身份信息认证',
  163. icon: 'none',
  164. })
  165. return false
  166. }
  167. return true
  168. }
  169. const validateForm = () => {
  170. normalizeForm()
  171. if (!/^\d{16,19}$/.test(bankInfo.cardNumber)) {
  172. uni.showToast({
  173. title: '银行卡号格式错误',
  174. icon: 'none',
  175. })
  176. return false
  177. }
  178. if (bankInfo.bankName.length < 2) {
  179. uni.showToast({
  180. title: '开户行名称过短',
  181. icon: 'none',
  182. })
  183. return false
  184. }
  185. if (!/^1[3-9]\d{9}$/.test(bankInfo.phone)) {
  186. uni.showToast({
  187. title: '手机号格式错误',
  188. icon: 'none',
  189. })
  190. return false
  191. }
  192. return true
  193. }
  194. const verifyBankPhoneIfNeeded = async () => {
  195. if (loginMobile.value === bankInfo.phone) return true
  196. const res = await gigCertPersonVerifyMobile3Api({
  197. mobile: bankInfo.phone,
  198. realName: realName.value,
  199. cardId: idCardNumber.value,
  200. })
  201. if (res.code !== API_SUCCESS_CODE) {
  202. bankPhoneAuthFailVisible.value = true
  203. return false
  204. }
  205. return true
  206. }
  207. const verifyBankCard = async () => {
  208. const res = await personVerifyBank4Api({
  209. mobile: bankInfo.phone,
  210. realName: realName.value,
  211. cardId: idCardNumber.value,
  212. bankCard: bankInfo.cardNumber,
  213. bankPhone: bankInfo.phone,
  214. bankName: bankInfo.bankName,
  215. })
  216. if (res.code !== API_SUCCESS_CODE) {
  217. uni.showToast({
  218. title: res.msg || '认证失败',
  219. icon: 'none',
  220. })
  221. return false
  222. }
  223. return true
  224. }
  225. const bindBankInfo = async () => {
  226. const res = await bindBankInfoApi({
  227. bankCardNumber: bankInfo.cardNumber,
  228. bankPhone: bankInfo.phone,
  229. })
  230. if (res.code !== API_SUCCESS_CODE) {
  231. uni.showToast({
  232. title: res.msg || '银行卡绑定失败',
  233. icon: 'none',
  234. })
  235. return false
  236. }
  237. return true
  238. }
  239. const handleSubmit = async () => {
  240. if (loading.value || certified.value) return
  241. if (!validateUserIdentity() || !validateForm()) return
  242. try {
  243. loading.value = true
  244. const bankPhonePassed = await verifyBankPhoneIfNeeded()
  245. if (!bankPhonePassed) return
  246. const bankCardPassed = await verifyBankCard()
  247. if (!bankCardPassed) return
  248. const bindPassed = await bindBankInfo()
  249. if (!bindPassed) return
  250. certified.value = true
  251. uni.showToast({
  252. title: '认证成功',
  253. icon: 'none',
  254. })
  255. if (hasExistingBankInfo.value) {
  256. reSignVisible.value = true
  257. return
  258. }
  259. await userStore.getUserInfoByCode()
  260. backTimer = setTimeout(() => {
  261. uni.navigateBack()
  262. }, BACK_DELAY)
  263. } catch {
  264. uni.showToast({
  265. title: '请求失败,请检查网络',
  266. icon: 'none',
  267. })
  268. } finally {
  269. loading.value = false
  270. }
  271. }
  272. const handleGoSign = () => {
  273. uni.navigateTo({
  274. url: SIGN_URL,
  275. })
  276. }
  277. const handleBack = () => {
  278. if (loading.value) return
  279. uni.navigateBack()
  280. }
  281. onLoad(() => {
  282. resetForm()
  283. })
  284. onUnload(() => {
  285. if (backTimer) {
  286. clearTimeout(backTimer)
  287. backTimer = null
  288. }
  289. })
  290. </script>
  291. <style lang="scss" scoped>
  292. .bank-auth {
  293. min-height: 100vh;
  294. background: linear-gradient(180deg, #eef6ff 0%, #f7f8fa 420rpx), #f7f8fa;
  295. }
  296. .bank-auth__scroll {
  297. height: 100vh;
  298. padding: 28rpx 28rpx 180rpx;
  299. box-sizing: border-box;
  300. }
  301. .bank-auth__hero {
  302. display: flex;
  303. align-items: flex-start;
  304. justify-content: space-between;
  305. margin-bottom: 24rpx;
  306. padding: 34rpx 32rpx;
  307. border-radius: 28rpx;
  308. background: linear-gradient(135deg, #1677ff 0%, #69b1ff 100%);
  309. box-shadow: 0 18rpx 40rpx rgba(22, 119, 255, 0.18);
  310. box-sizing: border-box;
  311. }
  312. .bank-auth__hero-main {
  313. flex: 1;
  314. padding-right: 24rpx;
  315. }
  316. .bank-auth__hero-title {
  317. display: block;
  318. color: #ffffff;
  319. font-size: 40rpx;
  320. font-weight: 700;
  321. line-height: 56rpx;
  322. }
  323. .bank-auth__hero-desc {
  324. display: block;
  325. margin-top: 12rpx;
  326. color: rgba(255, 255, 255, 0.88);
  327. font-size: 26rpx;
  328. line-height: 38rpx;
  329. }
  330. .bank-auth__hero-badge {
  331. flex-shrink: 0;
  332. height: 48rpx;
  333. padding: 0 18rpx;
  334. border-radius: 999rpx;
  335. background: rgba(255, 255, 255, 0.18);
  336. color: #ffffff;
  337. font-size: 24rpx;
  338. line-height: 48rpx;
  339. }
  340. .notice-card {
  341. display: flex;
  342. align-items: flex-start;
  343. margin-bottom: 24rpx;
  344. padding: 24rpx 26rpx;
  345. border: 1rpx solid #ffe3b8;
  346. border-radius: 22rpx;
  347. background: #fff8ec;
  348. box-sizing: border-box;
  349. }
  350. .notice-card__icon {
  351. flex-shrink: 0;
  352. width: 34rpx;
  353. height: 34rpx;
  354. margin-top: 2rpx;
  355. margin-right: 14rpx;
  356. border-radius: 50%;
  357. background: #fa8c16;
  358. color: #ffffff;
  359. font-size: 24rpx;
  360. font-weight: 700;
  361. line-height: 34rpx;
  362. text-align: center;
  363. }
  364. .notice-card__text {
  365. flex: 1;
  366. color: #b45309;
  367. font-size: 26rpx;
  368. line-height: 40rpx;
  369. }
  370. .form-card {
  371. padding: 32rpx;
  372. border-radius: 28rpx;
  373. background: #ffffff;
  374. box-shadow: 0 10rpx 32rpx rgba(15, 23, 42, 0.06);
  375. box-sizing: border-box;
  376. }
  377. .form-header {
  378. margin-bottom: 12rpx;
  379. }
  380. .form-title {
  381. display: block;
  382. color: #111827;
  383. font-size: 34rpx;
  384. font-weight: 700;
  385. line-height: 48rpx;
  386. }
  387. .form-subtitle {
  388. display: block;
  389. margin-top: 8rpx;
  390. color: #8a94a6;
  391. font-size: 24rpx;
  392. line-height: 34rpx;
  393. }
  394. .form-row {
  395. display: flex;
  396. align-items: center;
  397. min-height: 104rpx;
  398. border-bottom: 1rpx solid #eef0f3;
  399. }
  400. .form-row:last-child {
  401. border-bottom: none;
  402. }
  403. .form-label {
  404. width: 170rpx;
  405. flex-shrink: 0;
  406. color: #4b5563;
  407. font-size: 28rpx;
  408. line-height: 40rpx;
  409. }
  410. .form-input {
  411. flex: 1;
  412. height: 72rpx;
  413. color: #111827;
  414. font-size: 29rpx;
  415. line-height: 72rpx;
  416. text-align: right;
  417. }
  418. .form-placeholder {
  419. color: #b6beca;
  420. }
  421. .bottom-bar {
  422. position: fixed;
  423. right: 0;
  424. bottom: 0;
  425. left: 0;
  426. z-index: 20;
  427. display: flex;
  428. gap: 20rpx;
  429. padding: 20rpx 28rpx calc(20rpx + env(safe-area-inset-bottom));
  430. border-top: 1rpx solid rgba(229, 231, 235, 0.8);
  431. background: rgba(255, 255, 255, 0.96);
  432. box-sizing: border-box;
  433. }
  434. .bottom-btn {
  435. flex: 1;
  436. height: 88rpx;
  437. margin: 0;
  438. border-radius: 999rpx;
  439. font-size: 32rpx;
  440. font-weight: 600;
  441. line-height: 88rpx;
  442. }
  443. .bottom-btn::after {
  444. border: none;
  445. }
  446. .bottom-btn--secondary {
  447. background: #f3f4f6;
  448. color: #4b5563;
  449. }
  450. .bottom-btn--primary {
  451. background: linear-gradient(135deg, #1677ff 0%, #4096ff 100%);
  452. color: #ffffff;
  453. box-shadow: 0 12rpx 28rpx rgba(22, 119, 255, 0.22);
  454. }
  455. .bottom-btn[disabled] {
  456. opacity: 1;
  457. }
  458. .bottom-btn--secondary[disabled] {
  459. background: #f3f4f6 !important;
  460. color: #a1a1aa !important;
  461. }
  462. .bottom-btn--primary[disabled] {
  463. background: #d1d5db !important;
  464. color: #ffffff !important;
  465. box-shadow: none;
  466. }
  467. .dialog-title-text {
  468. margin-bottom: 32rpx;
  469. color: #111827;
  470. font-size: 32rpx;
  471. font-weight: 700;
  472. line-height: 48rpx;
  473. }
  474. .dialog-text {
  475. margin-bottom: 24rpx;
  476. color: #4b5563;
  477. font-size: 29rpx;
  478. line-height: 46rpx;
  479. }
  480. .dialog-text:last-child {
  481. margin-bottom: 0;
  482. }
  483. .dialog-highlight {
  484. color: #1677ff;
  485. font-weight: 700;
  486. }
  487. </style>