index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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-auth/settlement-channel-sign/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. 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. return true
  217. }
  218. const bindBankInfo = async () => {
  219. await bindBankInfoApi({
  220. bankCardNumber: bankInfo.cardNumber,
  221. bankPhone: bankInfo.phone,
  222. })
  223. return true
  224. }
  225. const handleSubmit = async () => {
  226. if (loading.value || certified.value) return
  227. if (!validateUserIdentity() || !validateForm()) return
  228. try {
  229. loading.value = true
  230. const bankPhonePassed = await verifyBankPhoneIfNeeded()
  231. if (!bankPhonePassed) return
  232. const bankCardPassed = await verifyBankCard()
  233. if (!bankCardPassed) return
  234. const bindPassed = await bindBankInfo()
  235. if (!bindPassed) return
  236. certified.value = true
  237. uni.showToast({
  238. title: '认证成功',
  239. icon: 'none',
  240. })
  241. if (hasExistingBankInfo.value) {
  242. reSignVisible.value = true
  243. return
  244. }
  245. await userStore.getUserInfoByCode()
  246. backTimer = setTimeout(() => {
  247. uni.navigateBack()
  248. }, BACK_DELAY)
  249. } finally {
  250. loading.value = false
  251. }
  252. }
  253. const handleGoSign = () => {
  254. uni.navigateTo({
  255. url: SIGN_URL,
  256. })
  257. }
  258. const handleBack = () => {
  259. if (loading.value) return
  260. uni.navigateBack()
  261. }
  262. onLoad(() => {
  263. resetForm()
  264. })
  265. onUnload(() => {
  266. if (backTimer) {
  267. clearTimeout(backTimer)
  268. backTimer = null
  269. }
  270. })
  271. </script>
  272. <style lang="scss" scoped>
  273. .bank-auth {
  274. min-height: 100vh;
  275. background: linear-gradient(180deg, #eef6ff 0%, #f7f8fa 420rpx), #f7f8fa;
  276. }
  277. .bank-auth__scroll {
  278. height: 100vh;
  279. padding: 28rpx 28rpx 180rpx;
  280. box-sizing: border-box;
  281. }
  282. .bank-auth__hero {
  283. display: flex;
  284. align-items: flex-start;
  285. justify-content: space-between;
  286. margin-bottom: 24rpx;
  287. padding: 34rpx 32rpx;
  288. border-radius: 28rpx;
  289. background: linear-gradient(135deg, #1677ff 0%, #69b1ff 100%);
  290. box-shadow: 0 18rpx 40rpx rgba(22, 119, 255, 0.18);
  291. box-sizing: border-box;
  292. }
  293. .bank-auth__hero-main {
  294. flex: 1;
  295. padding-right: 24rpx;
  296. }
  297. .bank-auth__hero-title {
  298. display: block;
  299. color: #ffffff;
  300. font-size: 40rpx;
  301. font-weight: 700;
  302. line-height: 56rpx;
  303. }
  304. .bank-auth__hero-desc {
  305. display: block;
  306. margin-top: 12rpx;
  307. color: rgba(255, 255, 255, 0.88);
  308. font-size: 26rpx;
  309. line-height: 38rpx;
  310. }
  311. .bank-auth__hero-badge {
  312. flex-shrink: 0;
  313. height: 48rpx;
  314. padding: 0 18rpx;
  315. border-radius: 999rpx;
  316. background: rgba(255, 255, 255, 0.18);
  317. color: #ffffff;
  318. font-size: 24rpx;
  319. line-height: 48rpx;
  320. }
  321. .notice-card {
  322. display: flex;
  323. align-items: flex-start;
  324. margin-bottom: 24rpx;
  325. padding: 24rpx 26rpx;
  326. border: 1rpx solid #ffe3b8;
  327. border-radius: 22rpx;
  328. background: #fff8ec;
  329. box-sizing: border-box;
  330. }
  331. .notice-card__icon {
  332. flex-shrink: 0;
  333. width: 34rpx;
  334. height: 34rpx;
  335. margin-top: 2rpx;
  336. margin-right: 14rpx;
  337. border-radius: 50%;
  338. background: #fa8c16;
  339. color: #ffffff;
  340. font-size: 24rpx;
  341. font-weight: 700;
  342. line-height: 34rpx;
  343. text-align: center;
  344. }
  345. .notice-card__text {
  346. flex: 1;
  347. color: #b45309;
  348. font-size: 26rpx;
  349. line-height: 40rpx;
  350. }
  351. .form-card {
  352. padding: 32rpx;
  353. border-radius: 28rpx;
  354. background: #ffffff;
  355. box-shadow: 0 10rpx 32rpx rgba(15, 23, 42, 0.06);
  356. box-sizing: border-box;
  357. }
  358. .form-header {
  359. margin-bottom: 12rpx;
  360. }
  361. .form-title {
  362. display: block;
  363. color: #111827;
  364. font-size: 34rpx;
  365. font-weight: 700;
  366. line-height: 48rpx;
  367. }
  368. .form-subtitle {
  369. display: block;
  370. margin-top: 8rpx;
  371. color: #8a94a6;
  372. font-size: 24rpx;
  373. line-height: 34rpx;
  374. }
  375. .form-row {
  376. display: flex;
  377. align-items: center;
  378. min-height: 104rpx;
  379. border-bottom: 1rpx solid #eef0f3;
  380. }
  381. .form-row:last-child {
  382. border-bottom: none;
  383. }
  384. .form-label {
  385. width: 170rpx;
  386. flex-shrink: 0;
  387. color: #4b5563;
  388. font-size: 28rpx;
  389. line-height: 40rpx;
  390. }
  391. .form-input {
  392. flex: 1;
  393. height: 72rpx;
  394. color: #111827;
  395. font-size: 29rpx;
  396. line-height: 72rpx;
  397. text-align: right;
  398. }
  399. .form-placeholder {
  400. color: #b6beca;
  401. }
  402. .bottom-bar {
  403. position: fixed;
  404. right: 0;
  405. bottom: 0;
  406. left: 0;
  407. z-index: 20;
  408. display: flex;
  409. gap: 20rpx;
  410. padding: 20rpx 28rpx calc(20rpx + env(safe-area-inset-bottom));
  411. border-top: 1rpx solid rgba(229, 231, 235, 0.8);
  412. background: rgba(255, 255, 255, 0.96);
  413. box-sizing: border-box;
  414. }
  415. .bottom-btn {
  416. flex: 1;
  417. height: 88rpx;
  418. margin: 0;
  419. border-radius: 999rpx;
  420. font-size: 32rpx;
  421. font-weight: 600;
  422. line-height: 88rpx;
  423. }
  424. .bottom-btn::after {
  425. border: none;
  426. }
  427. .bottom-btn--secondary {
  428. background: #f3f4f6;
  429. color: #4b5563;
  430. }
  431. .bottom-btn--primary {
  432. background: linear-gradient(135deg, #1677ff 0%, #4096ff 100%);
  433. color: #ffffff;
  434. box-shadow: 0 12rpx 28rpx rgba(22, 119, 255, 0.22);
  435. }
  436. .bottom-btn[disabled] {
  437. opacity: 1;
  438. }
  439. .bottom-btn--secondary[disabled] {
  440. background: #f3f4f6 !important;
  441. color: #a1a1aa !important;
  442. }
  443. .bottom-btn--primary[disabled] {
  444. background: #d1d5db !important;
  445. color: #ffffff !important;
  446. box-shadow: none;
  447. }
  448. .dialog-title-text {
  449. margin-bottom: 32rpx;
  450. color: #111827;
  451. font-size: 32rpx;
  452. font-weight: 700;
  453. line-height: 48rpx;
  454. }
  455. .dialog-text {
  456. margin-bottom: 24rpx;
  457. color: #4b5563;
  458. font-size: 29rpx;
  459. line-height: 46rpx;
  460. }
  461. .dialog-text:last-child {
  462. margin-bottom: 0;
  463. }
  464. .dialog-highlight {
  465. color: #1677ff;
  466. font-weight: 700;
  467. }
  468. </style>