index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <template>
  2. <div class="register-pages">
  3. <div class="register-bos">
  4. <img class="head-img" src="@/assets/images/head.png" alt="" />
  5. <div class="register-login flex-row-between">
  6. <div></div>
  7. <div @click="goLogin">
  8. <span>已有账号?直接</span>
  9. <span class="zhu">登录>></span>
  10. </div>
  11. </div>
  12. <div class="progress-bos">
  13. <div class="progress-bar" :class="nextNum == 1 ? 'hig1' : 'hig2'">
  14. <div>01、基本资料</div>
  15. </div>
  16. <div class="progress-bar progress-bar2" :class="nextNum == 2 || nextNum == 3 ? 'hig1' : 'hig2'">
  17. <div>02、企业信息</div>
  18. </div>
  19. <div class="progress-bar progress-bar2" :class="nextNum == 4 ? 'hig1' : ''">
  20. <div>03、完成</div>
  21. </div>
  22. </div>
  23. <template v-if="nextNum == 1">
  24. <div class="form-bos">
  25. <div class="form-title flex-row-start">
  26. <div class="star">*</div>
  27. <div>姓名</div>
  28. </div>
  29. <el-input style="width: 448px" v-model="form.purchaseName" placeholder="请输入姓名" />
  30. <div class="form-tip">请输入采购人全名,方便与您联系!</div>
  31. </div>
  32. <div class="form-bos" style="margin-top: 8px">
  33. <div class="form-title flex-row-start">
  34. <div class="star">*</div>
  35. <div>手机号码</div>
  36. </div>
  37. <el-input :maxlength="11" style="width: 448px" v-model="form.purchasePhone" placeholder="请输入手机号码">
  38. <template #suffix>
  39. <span @click="sendSmsCode" :class="['code', countdown > 0 ? 'disabled' : '']">
  40. {{ codeText }}
  41. </span>
  42. </template>
  43. </el-input>
  44. </div>
  45. <div class="form-bos form-bos1">
  46. <div class="form-title flex-row-start">
  47. <div class="star">*</div>
  48. <div>验证码</div>
  49. </div>
  50. <el-input style="width: 448px" v-model="form.code" placeholder="请输入验证码" />
  51. </div>
  52. <div class="form-bos form-bos1">
  53. <div class="form-title flex-row-start">
  54. <div class="star">*</div>
  55. <div>密码</div>
  56. </div>
  57. <el-input type="password" show-password style="width: 448px" v-model="form.password" placeholder="请输入密码" />
  58. </div>
  59. <div class="form-bos form-bos1">
  60. <div class="form-title flex-row-start">
  61. <div class="star">*</div>
  62. <div>请再次输入密码</div>
  63. </div>
  64. <el-input type="password" show-password style="width: 448px" v-model="form.confirmPassword" placeholder="请输入密码" />
  65. </div>
  66. </template>
  67. <template v-if="nextNum == 2">
  68. <div class="form-bos">
  69. <div class="form-title flex-row-start">
  70. <div class="star">*</div>
  71. <div>企业全称</div>
  72. </div>
  73. <el-input style="width: 448px" v-model="form.customerName" placeholder="请输入企业全称" />
  74. </div>
  75. </template>
  76. <template v-if="nextNum == 3">
  77. <div style="padding: 0 20px">
  78. <div class="descriptions-head">{{ enterprise.businessCustomerName || '' }}</div>
  79. <el-descriptions class="margin-top" :column="2" border>
  80. <template #title>
  81. <div class="descriptions-title">工商信息</div>
  82. </template>
  83. <el-descriptions-item label="企业名称" :span="2">{{ enterprise.businessCustomerName || '' }}</el-descriptions-item>
  84. <el-descriptions-item label="法定代表人">{{ enterprise.legalPersonName || '' }}</el-descriptions-item>
  85. <el-descriptions-item label="成立时间">{{ enterprise.establishmentDate || '' }}</el-descriptions-item>
  86. <el-descriptions-item label="登记状态">{{ enterprise.registrationStatus || '' }}</el-descriptions-item>
  87. <el-descriptions-item label="统一社会信用代码">{{ enterprise.socialCreditCode || '' }}</el-descriptions-item>
  88. <el-descriptions-item label="注册资本">{{ enterprise.registeredCapital || '' }}</el-descriptions-item>
  89. <el-descriptions-item label="注册地址">{{ enterprise.businessAddress || '' }}</el-descriptions-item>
  90. </el-descriptions>
  91. </div>
  92. </template>
  93. <template v-if="nextNum == 4">
  94. <div class="register-success flex-column-center">
  95. <img src="@/assets/images/breg.png" alt="" />
  96. <div class="success-text">您的账户还在审核中,如有疑问,请致电{{ servicePhone }}</div>
  97. <el-button @click="goLogin" type="primary">返回登录</el-button>
  98. </div>
  99. </template>
  100. <div class="agreement flex-row-start" v-if="nextNum == 1">
  101. <el-checkbox v-model="radio" />
  102. <span class="agreement1">我已阅读并同意</span>
  103. <span class="agreement2" @click="openDialog">《用户服务协议》</span>
  104. </div>
  105. </div>
  106. <div class="pay-foot" v-if="nextNum != 4">
  107. <div class="foot-bos">
  108. <el-button @click="previousStep" v-if="nextNum == 2 || nextNum == 3" class="bnt1">返回上一步</el-button>
  109. <el-button @click="nextStep" class="bnt2" type="primary" :loading="loading">{{ nextNum == 3 ? '提交并完成注册' : '下一步' }}</el-button>
  110. <el-button @click="onPath('/greg')" v-if="nextNum == 1" class="bnt1">供应商注册</el-button>
  111. </div>
  112. </div>
  113. <el-dialog
  114. v-model="dialogVisible"
  115. title="《用户服务协议》"
  116. width="50%"
  117. :before-close="
  118. () => {
  119. dialogVisible = false;
  120. }
  121. "
  122. >
  123. <div>
  124. <div v-html="content"></div>
  125. </div>
  126. <template #footer>
  127. <span class="dialog-footer">
  128. <el-button type="primary" @click="onAgree">同意</el-button>
  129. <el-button @click="dialogVisible = false">取消</el-button>
  130. </span>
  131. </template>
  132. </el-dialog>
  133. </div>
  134. </template>
  135. <script setup lang="ts">
  136. import {
  137. smsCode,
  138. selectBusinessByCustomerName,
  139. registerCustomer,
  140. selectByPhone,
  141. selectBycustomerName,
  142. getPlatformConfigList
  143. } from '@/api/breg/index';
  144. import { onUnmounted } from 'vue';
  145. import { onPath } from '@/utils/siteConfig';
  146. const nextNum = ref<any>(1);
  147. const codeText = ref<string>('发送验证码');
  148. const countdown = ref<number>(0);
  149. const timer = ref<any>(null);
  150. const enterprise = ref<any>({});
  151. const loading = ref(false);
  152. const servicePhone = ref<any>('');
  153. const form = ref<any>({
  154. purchaseName: '',
  155. purchasePhone: '',
  156. code: '',
  157. password: '',
  158. confirmPassword: '',
  159. customerName: ''
  160. });
  161. const dialogVisible = ref(false);
  162. const content = ref('');
  163. getPlatformConfigList({ configKey: 'customerLoginAgreement' }).then((res) => {
  164. if (res.code == 200) {
  165. if (res.rows && res.rows.length > 0) {
  166. content.value = res.rows[0].value;
  167. }
  168. }
  169. });
  170. getPlatformConfigList({ configKey: 'servicePhone' }).then((res) => {
  171. if (res.code == 200) {
  172. if (res.rows && res.rows.length > 0) {
  173. servicePhone.value = res.rows[0].value;
  174. }
  175. }
  176. });
  177. // 启动倒计时
  178. const startCountdown = () => {
  179. countdown.value = 60;
  180. codeText.value = `${countdown.value}s 后重新发送`;
  181. timer.value = setInterval(() => {
  182. countdown.value--;
  183. if (countdown.value > 0) {
  184. codeText.value = `${countdown.value}s 后重新发送`;
  185. } else {
  186. clearInterval(timer.value);
  187. timer.value = null;
  188. codeText.value = '发送验证码';
  189. }
  190. }, 1000);
  191. };
  192. // 获取验证码
  193. const sendSmsCode = () => {
  194. // 防止倒计时期间重复点击
  195. if (countdown.value > 0) return;
  196. const phone = form.value.purchasePhone;
  197. // 1. 基础格式校验
  198. if (!validateMobile(phone)) {
  199. ElMessage({
  200. message: '请输入正确的手机号码',
  201. type: 'warning'
  202. });
  203. return;
  204. }
  205. // 2. 【新增】先调用接口查询用户是否存在
  206. selectByPhone(phone, '3')
  207. .then((res: any) => {
  208. // --- 后端返回 200 ---
  209. // 根据你的后端逻辑:返回 200 代表 "用户不存在" (R.ok),允许注册
  210. if (res.code === 200) {
  211. // 手机号可用,继续执行发送验证码逻辑
  212. smsCode({ phonenumber: phone })
  213. .then((smsRes: any) => {
  214. if (smsRes.code === 200) {
  215. ElMessage({
  216. message: '验证码已发送',
  217. type: 'success'
  218. });
  219. startCountdown(); // 开始倒计时
  220. } else {
  221. // 发送短信接口业务失败
  222. ElMessage.error(smsRes.msg || '发送验证码失败');
  223. }
  224. })
  225. .catch((err: any) => {
  226. // 发送短信接口网络错误或异常
  227. ElMessage.error(err.msg || '发送验证码请求异常');
  228. });
  229. } else {
  230. }
  231. })
  232. .catch((error: any) => {
  233. // --- 后端返回非 200 (进入 catch) ---
  234. // 根据你的后端逻辑:返回 fail 代表 "用户已存在" (R.fail("该手机号已注册"))
  235. const msg = error.msg || '该手机号已注册,请直接登录';
  236. ElMessage({
  237. message: msg,
  238. type: 'warning' // 或者使用 'error'
  239. });
  240. });
  241. };
  242. // 验证手机号
  243. const validateMobile = (phone: any) => {
  244. const reg = /^1[3-9]\d{9}$/;
  245. return reg.test(phone);
  246. };
  247. // 验证企业名字
  248. const validateStrict = (str: any) => {
  249. if (typeof str !== 'string') return false;
  250. const trimmed = str.trim();
  251. if (trimmed.length === 0) return false; // 去空格后为空
  252. return /^[^a-zA-Z0-9]+$/.test(trimmed);
  253. };
  254. const nextStep = () => {
  255. if (nextNum.value == 1) {
  256. if (!radio.value) {
  257. ElMessage({
  258. message: '请勾选协议内容~',
  259. type: 'warning'
  260. });
  261. return;
  262. }
  263. const errorMsg = {
  264. purchaseName: '请输入姓名',
  265. purchasePhone: '请输入手机号码',
  266. code: '请输入验证码',
  267. password: '请输入密码',
  268. confirmPassword: '请再次输入密码'
  269. };
  270. let next1 = true;
  271. Object.keys(errorMsg).forEach((key) => {
  272. if ((form.value[key] == '' || form.value[key] == undefined || form.value[key] == null) && next1) {
  273. next1 = false;
  274. ElMessage({
  275. message: `${errorMsg[key]}`,
  276. type: 'warning'
  277. });
  278. return;
  279. }
  280. });
  281. if (!next1) return;
  282. if (form.value.password != form.value.confirmPassword) {
  283. ElMessage({
  284. message: `密码不一致`,
  285. type: 'warning'
  286. });
  287. return;
  288. }
  289. nextNum.value = 2;
  290. } else if (nextNum.value == 2) {
  291. if (validateStrict(form.value.customerName)) {
  292. loading.value = true;
  293. // 1. 首先检查客户是否存在
  294. selectBycustomerName(form.value.customerName)
  295. .then((res: any) => {
  296. if (res.code == 200) {
  297. // 2. 如果客户已存在,直接提示并中断后续逻辑
  298. if (res.data.length > 0) {
  299. ElMessage({
  300. message: '该客户已存在',
  301. type: 'warning'
  302. });
  303. loading.value = false;
  304. return; // 这里的 return 会跳出当前的 .then() 回调
  305. }
  306. }
  307. // 3. 只有当客户不存在时,才会执行下面的代码
  308. selectBusinessByCustomerName(form.value.customerName)
  309. .then((res: any) => {
  310. if (res.code == 200) {
  311. enterprise.value = res.data;
  312. nextNum.value = 3;
  313. }
  314. })
  315. .finally(() => {
  316. loading.value = false;
  317. });
  318. })
  319. .catch(() => {
  320. // 4. 处理第一个请求失败的情况,并关闭 loading
  321. loading.value = false;
  322. });
  323. } else {
  324. ElMessage({
  325. message: '企业全称不能有数字或字母',
  326. type: 'warning'
  327. });
  328. }
  329. } else {
  330. loading.value = true;
  331. registerCustomer(form.value)
  332. .then((res: any) => {
  333. loading.value = false;
  334. if (res.code == 200) {
  335. nextNum.value = 4;
  336. }
  337. })
  338. .finally(() => {
  339. loading.value = false;
  340. });
  341. }
  342. };
  343. //上一步
  344. const previousStep = () => {
  345. if (nextNum.value == 2) {
  346. nextNum.value = 1;
  347. }
  348. if (nextNum.value == 3) {
  349. nextNum.value = 2;
  350. }
  351. };
  352. const goLogin = () => {
  353. onPath('/login');
  354. };
  355. const radio = ref<any>(false);
  356. // 组件卸载时清除定时器
  357. onUnmounted(() => {
  358. if (timer.value) {
  359. clearInterval(timer.value);
  360. timer.value = null;
  361. }
  362. });
  363. const openDialog = () => {
  364. dialogVisible.value = true;
  365. };
  366. const onAgree = () => {
  367. radio.value = true;
  368. dialogVisible.value = false;
  369. };
  370. </script>
  371. <style lang="scss" scoped>
  372. .register-pages {
  373. width: 100%;
  374. background-color: #ffffff;
  375. display: flex;
  376. flex-direction: column;
  377. .register-bos {
  378. flex: 1;
  379. width: 100%;
  380. min-width: 1200px;
  381. max-width: 1500px;
  382. margin: 0 auto;
  383. padding-top: 20px;
  384. .head-img {
  385. width: 185px;
  386. height: 90px;
  387. }
  388. .register-login {
  389. font-weight: 400;
  390. font-size: 14px;
  391. color: #101828;
  392. margin-top: 20px;
  393. padding-bottom: 10px;
  394. border-bottom: 1px solid #e5e7eb;
  395. .zhu {
  396. color: #e7000b;
  397. cursor: pointer;
  398. }
  399. }
  400. .progress-bos {
  401. padding: 20px;
  402. display: flex;
  403. margin-bottom: 24px;
  404. .progress-bar {
  405. width: 320px;
  406. height: 40px;
  407. background: #f7f8fa;
  408. font-weight: 500;
  409. font-size: 16px;
  410. line-height: 40px;
  411. padding-left: 16px;
  412. color: #4e5969;
  413. position: relative;
  414. &.hig1 {
  415. background: #e7000b;
  416. color: #ffffff;
  417. }
  418. &.hig2 {
  419. background: #ffe8e8;
  420. color: #1d2129;
  421. }
  422. .triangle10 {
  423. position: absolute;
  424. width: 0;
  425. height: 0;
  426. border-left: 20px solid transparent;
  427. /* 左边透明 */
  428. border-right: 20px solid transparent;
  429. /* 右边透明 */
  430. border-bottom: 20px solid #f7f8fa;
  431. /* 底部边为实际显示的三角形部分 */
  432. transform: rotate(90deg);
  433. /* 向左旋转90度 */
  434. top: 10px;
  435. right: -30px;
  436. transform-origin: 50% 50%;
  437. /* 设置旋转中心点在元素的中心 */
  438. z-index: 3;
  439. }
  440. .triangle20 {
  441. position: absolute;
  442. width: 0;
  443. height: 0;
  444. border-left: 20px solid transparent;
  445. /* 左边透明 */
  446. border-right: 20px solid transparent;
  447. /* 右边透明 */
  448. border-bottom: 20px solid #ffffff;
  449. /* 底部边为实际显示的三角形部分 */
  450. transform: rotate(90deg);
  451. /* 向左旋转90度 */
  452. top: 10px;
  453. right: -35px;
  454. transform-origin: 50% 50%;
  455. /* 设置旋转中心点在元素的中心 */
  456. z-index: 2;
  457. }
  458. }
  459. .progress-bar2 {
  460. width: 354px;
  461. }
  462. }
  463. .form-bos {
  464. padding-left: 20px;
  465. // :deep(.el-input__wrapper) {
  466. // border: none;
  467. // box-shadow: none;
  468. // outline: none;
  469. // background: #f4f6f8;
  470. // }
  471. .form-title {
  472. font-size: 14px;
  473. color: #1d2129;
  474. margin-bottom: 8px;
  475. .star {
  476. width: 10px;
  477. color: #f53f3f;
  478. }
  479. }
  480. .form-tip {
  481. font-size: 12px;
  482. color: #86909c;
  483. margin-top: 4px;
  484. }
  485. .code {
  486. font-size: 14px;
  487. color: #e7000b;
  488. cursor: pointer;
  489. &.disabled {
  490. color: #999;
  491. cursor: not-allowed;
  492. }
  493. }
  494. }
  495. .form-bos1 {
  496. margin-top: 30px;
  497. }
  498. .agreement {
  499. padding-left: 20px;
  500. margin-top: 30px;
  501. font-size: 13px;
  502. .agreement1 {
  503. color: #999999;
  504. margin-left: 5px;
  505. }
  506. .agreement2 {
  507. color: #e7000b;
  508. cursor: pointer;
  509. }
  510. }
  511. }
  512. .pay-foot {
  513. width: 100%;
  514. height: 82px;
  515. background: #ffffff;
  516. box-shadow: 0px -2px 13px 0px rgba(0, 0, 0, 0.05);
  517. margin-top: 47px;
  518. .foot-bos {
  519. width: 100%;
  520. min-width: 1200px;
  521. max-width: 1500px;
  522. margin: 0 auto;
  523. padding-top: 16px;
  524. padding-left: 20px;
  525. .bnt1 {
  526. width: 120px;
  527. height: 32px;
  528. background: #f7f8fa;
  529. }
  530. .bnt2 {
  531. width: 120px;
  532. height: 32px;
  533. }
  534. }
  535. }
  536. .descriptions-head {
  537. width: 448px;
  538. height: 32px;
  539. background: #f2f3f5;
  540. border-radius: 2px 2px 2px 2px;
  541. padding: 0 12px;
  542. margin-bottom: 30px;
  543. font-size: 14px;
  544. color: #1d2129;
  545. line-height: 32px;
  546. }
  547. .descriptions-title {
  548. font-weight: 500;
  549. font-size: 16px;
  550. color: #1d2129;
  551. padding-left: 10px;
  552. position: relative;
  553. &::after {
  554. content: '';
  555. width: 4px;
  556. height: 16px;
  557. background: #e7000b;
  558. position: absolute;
  559. left: 0;
  560. top: 4px;
  561. }
  562. }
  563. .register-success {
  564. width: 100%;
  565. padding-bottom: 30px;
  566. img {
  567. width: 324px;
  568. }
  569. .success-text {
  570. font-weight: 400;
  571. font-size: 14px;
  572. color: #000000;
  573. margin: 20px 0 30px 0;
  574. }
  575. }
  576. :deep(.is-bordered-label) {
  577. font-weight: 400;
  578. }
  579. }
  580. </style>