index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <div class="login">
  3. <van-nav-bar title="自然人开票" />
  4. <div class="login-content">
  5. <div class="text">感谢您参加{{ pubName }}项目,请您登录系统开具发票。</div>
  6. <div class="bold-text">已注册电子税务局</div>
  7. <div class="form">
  8. <!-- 手机号输入 -->
  9. <van-cell-group inset class="grop">
  10. <van-field
  11. class="input"
  12. v-model="formData.mobile"
  13. placeholder="请输入手机号"
  14. clearable
  15. type="tel"
  16. maxlength="30"
  17. @update:model-value="onInputMobile"
  18. />
  19. </van-cell-group>
  20. <!-- 验证码输入 + 按钮 -->
  21. <van-cell-group inset class="grop">
  22. <van-field
  23. class="input code-input"
  24. v-model="formData.code"
  25. placeholder="请输入验证码"
  26. clearable
  27. type="tel"
  28. maxlength="6"
  29. @update:model-value="onInputCode"
  30. />
  31. <button class="code-btn" :disabled="isCounting || !formData.mobile" @click="sendCode">
  32. {{ isCounting ? countDown + 's后重发' : '获取验证码' }}
  33. </button>
  34. </van-cell-group>
  35. <!-- 同意协议 -->
  36. <div class="agree">
  37. <label>
  38. <van-checkbox v-model="agree" checked-color="#fe783d" shape="square" icon-size="4vw">
  39. 我已阅读并同意
  40. <a @click="toAgreement('auth')">《授权协议》</a>
  41. <a @click="toAgreement('privacy')">《隐私权政策》</a>
  42. </van-checkbox>
  43. </label>
  44. </div>
  45. <!-- 登录按钮 -->
  46. <div class="login-btn btn" @click="loginBtn">登录</div>
  47. </div>
  48. <div class="bold-text">未注册电子税务局</div>
  49. <div class="register-btn btn" @click="registerUrl">立即注册</div>
  50. <div class="footer">技术支持:要易云(北京)科技有限公司</div>
  51. <!-- 失败弹窗 -->
  52. <ModernDialog
  53. v-model:show="showDialog"
  54. title="提示"
  55. :message="codeMessage"
  56. cancelText="返回继续登录"
  57. @cancel="onCancel"
  58. />
  59. <!-- 注册弹窗 -->
  60. <ModernDialog
  61. v-model:show="loginDialog"
  62. title="提示"
  63. :message="loginMessage"
  64. cancelText="返回"
  65. @cancel="loginCancel"
  66. confirmText="立即注册"
  67. @confirm="loginConfirm"
  68. />
  69. </div>
  70. </div>
  71. </template>
  72. <script setup lang="ts">
  73. import { ref, reactive, onBeforeMount } from 'vue'
  74. import { useRouter, useRoute } from 'vue-router'
  75. import { showFailToast, showSuccessToast, showToast, showLoadingToast } from 'vant'
  76. import {
  77. getPubNameApi,
  78. sendEtsSmsApi,
  79. loginEtssmsApi,
  80. registerUrlApi,
  81. } from '@/services/modules/login'
  82. import { getStatusApi } from '@/services/modules/invoiceInformation'
  83. import type {
  84. SendTtsSmsRequest,
  85. LoginEtssmsRequest,
  86. RegisterUrlRequest,
  87. } from '@/services/modules/login/type.d'
  88. import { useUserStore } from '@/stores/modules/user'
  89. import { useDebounceFn } from '@/utils/util'
  90. import { REGISTER_URL_KEY } from '@/constants/storage'
  91. import ModernDialog from '@/components/ModernDialog.vue'
  92. const userStore = useUserStore()
  93. const router = useRouter()
  94. const route = useRoute()
  95. /* 表单数据 */
  96. const formData = reactive<LoginEtssmsRequest>({
  97. mobile: '',
  98. code: '',
  99. pushRecordId: '',
  100. })
  101. const sendEtsSms = reactive<SendTtsSmsRequest>({
  102. mobile: '',
  103. pushRecordId: '',
  104. })
  105. /* 限制手机号只能输入数字,最多 30 位 */
  106. const onInputMobile = (val: string) => {
  107. formData.mobile = val.replace(/\D/g, '').slice(0, 30)
  108. }
  109. /* 限制验证码只能输入数字,最多 6 位 */
  110. const onInputCode = (val: string) => {
  111. formData.code = val.replace(/\D/g, '').slice(0, 6)
  112. }
  113. /* 是否同意协议 */
  114. const agree = ref(false)
  115. /* 验证码按钮逻辑 */
  116. const isCounting = ref(false)
  117. const countDown = ref(60)
  118. let timer: number | undefined
  119. const sending = ref(false)
  120. const showDialog = ref(false)
  121. const codeMessage = ref()
  122. const onCancel = () => {
  123. showDialog.value = false
  124. }
  125. /* 发送验证码 */
  126. const sendCode = async () => {
  127. if (sending.value) return
  128. if (!/^1\d{10}$/.test(formData.mobile)) {
  129. showToast('请输入正确的手机号')
  130. return
  131. }
  132. sending.value = true
  133. const toast = showLoadingToast({ message: '发送中…', forbidClick: true, duration: 3000 })
  134. sendEtsSms.mobile = formData.mobile
  135. try {
  136. const res = await sendEtsSmsApi(sendEtsSms)
  137. if (res.code === 0 && res.data) {
  138. showSuccessToast('发送成功')
  139. startCountDown()
  140. } else if (res.code == 401) {
  141. loginMessage.value = res.msg
  142. loginDialog.value = true
  143. } else {
  144. codeMessage.value = res.msg
  145. showDialog.value = true
  146. }
  147. toast.close()
  148. } catch (err: any) {
  149. toast.close()
  150. showFailToast(err?.message || '获取验证码失败')
  151. } finally {
  152. sending.value = false
  153. }
  154. }
  155. /* 倒计时逻辑 */
  156. const startCountDown = () => {
  157. isCounting.value = true
  158. countDown.value = 60
  159. timer = window.setInterval(() => {
  160. countDown.value--
  161. if (countDown.value <= 0) {
  162. isCounting.value = false
  163. clearInterval(timer)
  164. }
  165. }, 1000)
  166. }
  167. const loginDialog = ref(false)
  168. const loginMessage = ref('')
  169. const loginCancel = () => {
  170. loginDialog.value = false
  171. }
  172. const loginConfirm = () => {
  173. registerUrl()
  174. }
  175. /* 登录逻辑 */
  176. const loginBtn = useDebounceFn(async () => {
  177. if (!formData.mobile) {
  178. showFailToast('请输入手机号')
  179. return
  180. }
  181. if (!formData.code) {
  182. showFailToast('验证码不能为空')
  183. return
  184. }
  185. if (!agree.value) {
  186. showFailToast('请勾选阅读并同意')
  187. return
  188. }
  189. const toast = showLoadingToast({
  190. message: '登录中…',
  191. forbidClick: true,
  192. duration: 0,
  193. })
  194. // 已提交状态映射
  195. const isSubmitStatusMap = ['PENDING']
  196. const isSubmitEventStatusMap = [
  197. 'SUBMITTED',
  198. 'PENDING_PAYMENT',
  199. 'PAID',
  200. 'FINAL_INVOICE_SUBMITTED',
  201. 'INVOICE_DOWNLOADABLE',
  202. ]
  203. try {
  204. const res: any = await loginEtssmsApi(formData)
  205. if (res?.access_token) {
  206. toast.close()
  207. userStore.setAccessToken(res.access_token)
  208. const statusRes = await getStatusApi({ pushRecordId: formData.pushRecordId })
  209. // 修改认证下的状态内容,如果已经提交,跳转到成功页
  210. if (statusRes.code == 0) {
  211. const { invoiceStatus, eventStatus } = statusRes.data
  212. const isInvoiceSubmitted = invoiceStatus && isSubmitStatusMap.includes(invoiceStatus)
  213. const isEventSubmitted = eventStatus && isSubmitEventStatusMap.includes(eventStatus)
  214. if (isInvoiceSubmitted && isEventSubmitted) {
  215. return router.replace({
  216. path: '/login-success',
  217. })
  218. }
  219. }
  220. router.replace({ path: '/invoice-information' })
  221. } else if (res.code == 401) {
  222. loginMessage.value = res.msg
  223. loginDialog.value = true
  224. }
  225. } catch (err: any) {
  226. toast.close()
  227. const { code, message } = err || {}
  228. if (code && message) {
  229. showFailToast(message)
  230. }
  231. }
  232. }, 800)
  233. // 获取注册链接
  234. const registerUrlParams = ref<RegisterUrlRequest>({
  235. areaId: '',
  236. returnUrl: '',
  237. pushRecordId: '',
  238. })
  239. const registerUrl = useDebounceFn(async () => {
  240. try {
  241. const res = await registerUrlApi(registerUrlParams.value)
  242. if (res.code === 0 && res.data.url) {
  243. // 保存一次性链接
  244. sessionStorage.setItem(REGISTER_URL_KEY, res.data.url as string)
  245. return router.push({ path: 'register' })
  246. }
  247. showFailToast('获取注册链接失败')
  248. } catch (err: any) {
  249. showFailToast(err?.message || '获取注册链接失败')
  250. }
  251. }, 800)
  252. // 项目名称
  253. const pubName = ref('')
  254. const getPubName = async () => {
  255. try {
  256. const res = await getPubNameApi({
  257. pushRecordId: sendEtsSms.pushRecordId,
  258. })
  259. if (res.code === 0) {
  260. pubName.value = res.data.projectName
  261. registerUrlParams.value.areaId = res.data.cityCode
  262. registerUrlParams.value.pushRecordId = sendEtsSms.pushRecordId
  263. }
  264. } catch (err) {
  265. console.log('err', err)
  266. }
  267. }
  268. /* 协议跳转 */
  269. const toAgreement = (type: string) => {
  270. router.push({
  271. path: '/agreement',
  272. query: { type },
  273. })
  274. }
  275. onBeforeMount(() => {
  276. userStore.LogOut()
  277. registerUrlParams.value.returnUrl = `${location.origin}${route.fullPath}`
  278. const pushRecordId = route?.query.pushRecordId || ''
  279. if (pushRecordId) {
  280. sendEtsSms.pushRecordId = pushRecordId as string
  281. userStore.setPushRecordId(pushRecordId as string)
  282. formData.pushRecordId = pushRecordId as string
  283. getPubName()
  284. } else {
  285. showToast('登录链接存在不完整或者输入错误,请重新复制链接登录')
  286. }
  287. })
  288. </script>
  289. <style lang="scss" scoped>
  290. .login {
  291. min-height: 100vh;
  292. display: flex;
  293. flex-direction: column;
  294. background: linear-gradient(180deg, #ffffff 0%, #f5f7fb 100%);
  295. overflow-x: hidden;
  296. .van-nav-bar {
  297. background-color: #fff;
  298. border-bottom: 1px solid #f2f2f2;
  299. font-weight: 600;
  300. }
  301. .login-content {
  302. flex: 1;
  303. padding: 6vw 6vw 12vw;
  304. display: flex;
  305. flex-direction: column;
  306. align-items: center;
  307. .text {
  308. width: 90%;
  309. font-size: 4vw;
  310. text-align: center;
  311. line-height: 6vw;
  312. color: #333;
  313. margin-top: 8vw;
  314. margin-bottom: 6vw;
  315. }
  316. .bold-text {
  317. width: 100%;
  318. font-weight: 700;
  319. font-size: 4.5vw;
  320. text-align: left;
  321. color: #222;
  322. margin: 4vw 0 2vw;
  323. }
  324. .form {
  325. width: 96%;
  326. margin-top: 20px;
  327. background: #fff;
  328. border-radius: 3vw;
  329. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  330. padding: 6vw 4vw;
  331. margin-bottom: 8vw;
  332. .grop {
  333. margin-top: 3vw;
  334. display: flex;
  335. align-items: center;
  336. justify-content: space-between;
  337. }
  338. .input {
  339. width: 100%;
  340. border-radius: 6vw;
  341. border: 1px solid #e5e5e5;
  342. padding-left: 5vw;
  343. font-size: 3.8vw;
  344. background: #fff;
  345. transition: 0.3s;
  346. &:focus {
  347. border-color: #fe783d;
  348. box-shadow: 0 0 8px rgba(254, 120, 61, 0.3);
  349. }
  350. }
  351. .code-input {
  352. width: 55%;
  353. }
  354. .code-btn {
  355. background: linear-gradient(90deg, #fe783d 0%, #ff994f 100%);
  356. border: none;
  357. border-radius: 25px;
  358. height: 9vw;
  359. width: 30%;
  360. color: #fff;
  361. font-weight: 600;
  362. font-size: 3.4vw;
  363. cursor: pointer;
  364. transition: all 0.3s;
  365. &:active {
  366. opacity: 0.85;
  367. }
  368. &:disabled {
  369. background: #ccc;
  370. cursor: not-allowed;
  371. }
  372. }
  373. .agree {
  374. text-align: left;
  375. font-size: 3vw;
  376. line-height: 5vw;
  377. margin: 4vw 0;
  378. color: #666;
  379. padding-left: 36px;
  380. .custom-checkbox {
  381. accent-color: #fe783d;
  382. }
  383. label {
  384. display: flex;
  385. align-items: center;
  386. flex-wrap: wrap;
  387. input {
  388. width: 3.5vw;
  389. height: 3.5vw;
  390. margin-right: 6px;
  391. }
  392. }
  393. a {
  394. color: #fe783d;
  395. text-decoration: none;
  396. margin-left: 2px;
  397. }
  398. }
  399. }
  400. .btn {
  401. box-sizing: border-box;
  402. width: 80%;
  403. height: 12vw;
  404. border-radius: 6vw;
  405. color: #fff;
  406. font-size: 4vw;
  407. line-height: 12vw;
  408. text-align: center;
  409. font-weight: 600;
  410. cursor: pointer;
  411. transition: all 0.3s ease;
  412. margin: 4vw 0;
  413. &:active {
  414. transform: scale(0.98);
  415. }
  416. }
  417. .login-btn {
  418. margin: 0 auto;
  419. background: linear-gradient(90deg, #ff8036 0%, #ffa253 100%);
  420. box-shadow: 0 4px 12px rgba(255, 128, 54, 0.3);
  421. }
  422. .register-btn {
  423. background: linear-gradient(90deg, #0072f8 0%, #3a9fff 100%);
  424. box-shadow: 0 4px 12px rgba(0, 114, 248, 0.25);
  425. }
  426. .footer {
  427. width: 100%;
  428. text-align: center;
  429. color: #999;
  430. font-size: 3vw;
  431. margin-top: auto;
  432. padding-bottom: 4vh;
  433. }
  434. }
  435. }
  436. </style>