index.vue 13 KB

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