club-bind.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <div class="club-bind">
  3. <div class="form-container">
  4. <div class="logo">
  5. <img :src="supplierInfo.shopName" alt="" />
  6. <!-- <img :src="supplierInfo.logo" :alt="supplierInfo.shopName" /> -->
  7. </div>
  8. <div class="tip">
  9. 输入验证码即可完成账号注册及{{
  10. supplierInfo.shopName
  11. }}授权牌匾制作与寄送
  12. </div>
  13. <div class="form">
  14. <el-form
  15. :model="formData"
  16. :rules="rules"
  17. label-position="top"
  18. ref="formRef"
  19. >
  20. <el-form-item label="手机号:" prop="mobile">
  21. <el-input
  22. v-model="formData.mobile"
  23. maxlength="11"
  24. @input="handleMobileInput"
  25. />
  26. </el-form-item>
  27. <el-form-item label="验证码:" prop="verifyCode">
  28. <el-input v-model="formData.verifyCode" maxlength="6">
  29. <template #suffix>
  30. <i class="line"></i>
  31. <el-button
  32. type="text"
  33. size="mini"
  34. class="code"
  35. v-text="sendCodeBtnText"
  36. @click="onSend"
  37. ></el-button>
  38. </template>
  39. </el-input>
  40. </el-form-item>
  41. </el-form>
  42. <div id="slide-verify" class="verify-wrap"></div>
  43. <el-button type="primary" class="confirm" @click="onSubmit"
  44. >确定</el-button
  45. >
  46. </div>
  47. </div>
  48. <el-dialog
  49. title="提示"
  50. :visible.sync="dialogVisible"
  51. center
  52. @closed="onDialogClosed"
  53. >
  54. <div class="dialog-text text-center" v-text="dialogText"></div>
  55. <div slot="footer" class="dialog-footer">
  56. <el-button @click="onCancel" v-if="resultStatus === -2">取消</el-button>
  57. <el-button type="primary" @click="onConfirm">{{
  58. resultStatus === -2 ? '去登录' : '确定'
  59. }}</el-button>
  60. </div>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script>
  65. import { mapGetters } from 'vuex'
  66. import { isMobile } from '~/utils/validator'
  67. import { SlideVerify } from '@/utils/libs/slide-verify'
  68. export default {
  69. layout: 'app-hyt',
  70. data() {
  71. var validateMobile = (rule, value, callback) => {
  72. if (!value || isMobile(value)) {
  73. callback()
  74. } else {
  75. callback(new Error('手机号格式不正确'))
  76. }
  77. }
  78. return {
  79. resultStatus: 0,
  80. dialogVisible: false,
  81. slideVerifyStatus: false,
  82. slideVerify: null,
  83. formData: {
  84. mobile: '',
  85. verifyCode: '',
  86. authId: '',
  87. authUserId: '',
  88. },
  89. rules: {
  90. mobile: [
  91. { required: true, message: '手机号不能为空', trigger: ['blur'] },
  92. { validator: validateMobile, trigger: ['blur'] },
  93. ],
  94. verifyCode: [
  95. { required: true, message: '验证码不能为空', trigger: ['blur'] },
  96. ],
  97. },
  98. sendStatus: 0,
  99. timer: null,
  100. dialogTextMap: {
  101. 0: '账号注册成功,您可通过该手机号与短信发送的密码登录认证通!',
  102. '-2': '抱歉,该手机号已注册,您可以登录后再来进行正品授权申请!',
  103. },
  104. }
  105. },
  106. computed: {
  107. ...mapGetters(['authUserId', 'routePrefix', 'supplierInfo']),
  108. sendCodeBtnText() {
  109. return this.sendStatus === 0
  110. ? '发送验证码'
  111. : `再次发送${this.sendStatus}s`
  112. },
  113. dialogText() {
  114. return this.dialogTextMap[this.resultStatus]
  115. },
  116. },
  117. created() {
  118. this.$store.commit('app/HIDE_LAYOUT')
  119. this.initLinkInfo()
  120. this.initSlideVerify()
  121. },
  122. beforeDestroy() {
  123. this.$store.commit('app/SHOW_LAYOUT')
  124. },
  125. methods: {
  126. initSlideVerify() {
  127. this.$nextTick(() => {
  128. this.slideVerify = new SlideVerify('#slide-verify', {
  129. initText: '请向右滑动滑块', //设置 初始的 显示文字
  130. sucessText: '验证通过', //设置 验证通过 显示的文字
  131. getSuccessState: (status) => {
  132. //当验证完成的时候 会 返回 res 值 true,只留了这个应该够用了
  133. this.slideVerifyStatus = status
  134. },
  135. })
  136. })
  137. },
  138. // 取消操作
  139. onCancel() {
  140. this.dialogVisible = false
  141. },
  142. // 确认
  143. onConfirm() {
  144. this.$router.push(
  145. this.routePrefix + `/approve/club/detail?id=${this.formData.authId}`
  146. )
  147. },
  148. onDialogClosed() {
  149. if (this.resultStatus === 0) {
  150. this.$router.push(this.routePrefix)
  151. }
  152. },
  153. // 初始化链接信息
  154. async initLinkInfo() {
  155. this.formData.authUserId = this.authUserId
  156. const authId = this.$route.query.authId
  157. if (authId) {
  158. this.formData.authId = parseInt(authId)
  159. return
  160. }
  161. try {
  162. await this.$alert('链接已失效!请更换新链接', '提示', {
  163. confirmButtonText: '确定',
  164. cancelButtonText: '取消',
  165. type: 'warning',
  166. })
  167. } finally {
  168. this.$router.push(this.routePrefix)
  169. }
  170. },
  171. // 提交
  172. async onSubmit() {
  173. if (!this.slideVerifyStatus) {
  174. return this.$toast('滑动验证未通过')
  175. }
  176. try {
  177. await this.$refs.formRef.validate()
  178. this.onRegisterSubmit()
  179. } catch (error) {
  180. console.log(error)
  181. } finally {
  182. this.slideVerifyStatus = false
  183. setTimeout(() => {
  184. this.slideVerify?.resetVerify()
  185. }, 500)
  186. }
  187. },
  188. // 用户注册
  189. async onRegisterSubmit() {
  190. try {
  191. await this.$http.api.clubUserRegister(this.formData)
  192. this.resultStatus = 0
  193. this.dialogVisible = true
  194. } catch (error) {
  195. if (error.code === -2) {
  196. this.resultStatus = -2
  197. this.dialogVisible = true
  198. } else {
  199. this.$toast(error.msg)
  200. }
  201. }
  202. },
  203. // 发送验证码
  204. async onSend() {
  205. if (this.sendStatus > 0) return
  206. // 验证手机号是否合法
  207. if (!isMobile(this.formData.mobile)) {
  208. this.$toast('请输入正确的手机号')
  209. return
  210. }
  211. try {
  212. // 发送验证码
  213. await this.$http.api.clubUserCodeSend({
  214. mobile: this.formData.mobile,
  215. authUserId: this.authUserId,
  216. type: 1,
  217. })
  218. this.$toast('验证码已发送')
  219. // 开启倒计时
  220. this.countdown()
  221. } catch (error) {
  222. console.log(error)
  223. }
  224. },
  225. // 倒计时
  226. countdown() {
  227. this.sendStatus = 60
  228. this.timer = setInterval(() => {
  229. if (this.sendStatus === 0) {
  230. clearInterval(this.timer)
  231. return
  232. }
  233. this.sendStatus--
  234. }, 1000)
  235. },
  236. // 输入框输入时
  237. handleMobileInput() {
  238. this.formData.mobile = this.formData.mobile.replace(/[^\w\.\/]/gi, '')
  239. },
  240. },
  241. }
  242. </script>
  243. <style lang="scss" scoped>
  244. .el-button {
  245. border-radius: 0;
  246. }
  247. @media screen and (min-width: 768px) {
  248. ::v-deep {
  249. .el-dialog {
  250. width: 400px;
  251. padding: 40px 36px 32px;
  252. .dialog-text {
  253. font-size: 16px;
  254. color: #282828;
  255. line-height: 32px;
  256. }
  257. .el-dialog__header {
  258. padding: 0;
  259. .el-dialog__title {
  260. font-size: 24px;
  261. color: #282828;
  262. }
  263. }
  264. .el-dialog__body {
  265. padding: 64px 0 48px;
  266. }
  267. .el-dialog__footer {
  268. padding: 0;
  269. }
  270. .el-dialog__close {
  271. font-size: 24px;
  272. }
  273. .el-button {
  274. width: 100%;
  275. display: block;
  276. &:first-child {
  277. margin-bottom: 10px;
  278. }
  279. &:last-child {
  280. margin-left: 0;
  281. }
  282. }
  283. }
  284. }
  285. .club-bind {
  286. width: 100vw;
  287. height: 100vh;
  288. background: url(~assets/theme-images/common/pc-link-register-bg.png)
  289. no-repeat center;
  290. display: flex;
  291. justify-content: center;
  292. align-items: center;
  293. .form-container {
  294. display: flex;
  295. align-items: center;
  296. flex-direction: column;
  297. box-sizing: border-box;
  298. width: 528px;
  299. padding: 32px 0 60px;
  300. background: #fff;
  301. box-shadow: 0px 6px 30px rgba(64, 158, 255, 0.1);
  302. border-radius: 4px;
  303. .logo {
  304. width: 248px;
  305. height: 100px;
  306. margin-bottom: 20px;
  307. display: flex;
  308. justify-content: center;
  309. align-items: center;
  310. img {
  311. display: block;
  312. max-height: 100%;
  313. flex-shrink: 0;
  314. }
  315. }
  316. .tip {
  317. width: 412px;
  318. font-size: 20px;
  319. color: #282828;
  320. line-height: 32px;
  321. text-align: center;
  322. margin-bottom: 36px;
  323. }
  324. .form {
  325. width: 320px;
  326. .confirm {
  327. width: 100%;
  328. margin-top: 24px;
  329. border-radius: 0;
  330. }
  331. .line {
  332. width: 1px;
  333. height: 20px;
  334. background: #d8d8d8;
  335. display: inline-block;
  336. vertical-align: middle;
  337. }
  338. .code {
  339. margin: 0 10px;
  340. }
  341. .el-form-item {
  342. margin-bottom: 24px;
  343. ::v-deep {
  344. .el-form-item__label {
  345. line-height: initial;
  346. padding: 0 0 6px;
  347. }
  348. .el-input__inner {
  349. border-radius: 0;
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }
  356. }
  357. @media screen and (max-width: 768px) {
  358. ::v-deep {
  359. .el-dialog {
  360. width: 76vw;
  361. padding: 7vw 7vw 5.2vw;
  362. .dialog-text {
  363. font-size: 3.2vw;
  364. color: #282828;
  365. line-height: 5.6vw;
  366. }
  367. .el-dialog__header {
  368. padding: 0;
  369. .el-dialog__title {
  370. font-size: 4.8vw;
  371. color: #282828;
  372. }
  373. }
  374. .el-dialog__body {
  375. padding: 8vw 0 11.6vw;
  376. }
  377. .el-dialog__footer {
  378. padding: 0;
  379. }
  380. .el-dialog__close {
  381. font-size: 5.6vw;
  382. }
  383. .el-button {
  384. width: 100%;
  385. display: block;
  386. &:first-child {
  387. margin-bottom: 4vw;
  388. }
  389. &:last-child {
  390. margin-left: 0;
  391. }
  392. }
  393. }
  394. }
  395. .club-bind {
  396. width: 100vw;
  397. height: 100vh;
  398. background: url(~assets/theme-images/common/h5-link-register-bg.png)
  399. no-repeat center;
  400. display: flex;
  401. justify-content: center;
  402. align-items: center;
  403. .form-container {
  404. display: flex;
  405. align-items: center;
  406. flex-direction: column;
  407. box-sizing: border-box;
  408. width: 76vw;
  409. padding: 4vw 0 4.7vw;
  410. background: #fff;
  411. box-shadow: 0px 0.6vw 3vw rgba(64, 158, 255, 0.1);
  412. border-radius: 4px;
  413. .logo {
  414. width: 34vw;
  415. height: 13.8vw;
  416. margin-bottom: 4vw;
  417. display: flex;
  418. justify-content: center;
  419. align-items: center;
  420. img {
  421. display: block;
  422. height: 5.6vw;
  423. flex-shrink: 0;
  424. }
  425. }
  426. .tip {
  427. width: 59.8vw;
  428. font-size: 3.6vw;
  429. color: #282828;
  430. line-height: 5.6vw;
  431. text-align: center;
  432. margin-bottom: 8vw;
  433. }
  434. .form {
  435. width: 62vw;
  436. .confirm {
  437. width: 100%;
  438. margin-top: 3.2vw;
  439. border-radius: 0;
  440. }
  441. .line {
  442. width: 1px;
  443. height: 4vw;
  444. background: #d8d8d8;
  445. display: inline-block;
  446. vertical-align: middle;
  447. }
  448. .code {
  449. margin: 0 2.8vw;
  450. }
  451. .el-form-item {
  452. margin-bottom: 4vw;
  453. ::v-deep {
  454. .el-form-item__label {
  455. line-height: initial;
  456. padding: 0 0 1.2vw;
  457. }
  458. .el-input__inner {
  459. border-radius: 0;
  460. }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. }
  467. </style>