club-bind.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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-normal',
  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.routePrefix + `/approve/club/detail?id=${this.formData.authId}`
  145. },
  146. onDialogClosed() {
  147. if (this.resultStatus === 0) {
  148. this.$router.replace(this.routePrefix)
  149. }
  150. },
  151. // 初始化链接信息
  152. async initLinkInfo() {
  153. this.formData.authUserId = this.authUserId
  154. const authId = this.$route.query.authId
  155. if (authId) {
  156. this.formData.authId = parseInt(authId)
  157. return
  158. }
  159. try {
  160. await this.$alert('链接已失效!请更换新链接', '提示', {
  161. confirmButtonText: '确定',
  162. cancelButtonText: '取消',
  163. type: 'warning',
  164. })
  165. } finally {
  166. this.$router.replace(this.routePrefix)
  167. }
  168. },
  169. // 提交
  170. async onSubmit() {
  171. if (!this.slideVerifyStatus) {
  172. return this.$toast('滑动验证未通过')
  173. }
  174. try {
  175. await this.$refs.formRef.validate()
  176. this.onRegisterSubmit()
  177. } catch (error) {
  178. console.log(error)
  179. } finally {
  180. this.slideVerifyStatus = false
  181. setTimeout(() => {
  182. this.slideVerify?.resetVerify()
  183. }, 500)
  184. }
  185. },
  186. // 用户注册
  187. async onRegisterSubmit() {
  188. try {
  189. await this.$http.api.clubUserRegister(this.formData)
  190. this.resultStatus = 0
  191. this.dialogVisible = true
  192. } catch (error) {
  193. if (error.code === -2) {
  194. this.resultStatus = -2
  195. this.dialogVisible = true
  196. } else {
  197. this.$toast(error.msg)
  198. }
  199. }
  200. },
  201. // 发送验证码
  202. async onSend() {
  203. if (this.sendStatus > 0) return
  204. // 验证手机号是否合法
  205. if (!isMobile(this.formData.mobile)) {
  206. this.$toast('请输入正确的手机号')
  207. return
  208. }
  209. try {
  210. // 发送验证码
  211. await this.$http.api.clubUserCodeSend({
  212. mobile: this.formData.mobile,
  213. authUserId: this.authUserId,
  214. type: 1,
  215. })
  216. this.$toast('验证码已发送')
  217. // 开启倒计时
  218. this.countdown()
  219. } catch (error) {
  220. console.log(error)
  221. }
  222. },
  223. // 倒计时
  224. countdown() {
  225. this.sendStatus = 60
  226. this.timer = setInterval(() => {
  227. if (this.sendStatus === 0) {
  228. clearInterval(this.timer)
  229. return
  230. }
  231. this.sendStatus--
  232. }, 1000)
  233. },
  234. // 输入框输入时
  235. handleMobileInput() {
  236. this.formData.mobile = this.formData.mobile.replace(/[^\w\.\/]/gi, '')
  237. },
  238. },
  239. }
  240. </script>
  241. <style lang="scss" scoped>
  242. .el-button {
  243. border-radius: 0;
  244. }
  245. @media screen and (min-width: 768px) {
  246. ::v-deep {
  247. .el-dialog {
  248. width: 400px;
  249. padding: 40px 36px 32px;
  250. .dialog-text {
  251. font-size: 16px;
  252. color: #282828;
  253. line-height: 32px;
  254. }
  255. .el-dialog__header {
  256. padding: 0;
  257. .el-dialog__title {
  258. font-size: 24px;
  259. color: #282828;
  260. }
  261. }
  262. .el-dialog__body {
  263. padding: 64px 0 48px;
  264. }
  265. .el-dialog__footer {
  266. padding: 0;
  267. }
  268. .el-dialog__close {
  269. font-size: 24px;
  270. }
  271. .el-button {
  272. width: 100%;
  273. display: block;
  274. &:first-child {
  275. margin-bottom: 10px;
  276. }
  277. &:last-child {
  278. margin-left: 0;
  279. }
  280. }
  281. }
  282. }
  283. .club-bind {
  284. width: 100vw;
  285. height: 100vh;
  286. background: url(~assets/theme-images/common/pc-link-register-bg.png)
  287. no-repeat center;
  288. display: flex;
  289. justify-content: center;
  290. align-items: center;
  291. .form-container {
  292. display: flex;
  293. align-items: center;
  294. flex-direction: column;
  295. box-sizing: border-box;
  296. width: 528px;
  297. padding: 32px 0 60px;
  298. background: #fff;
  299. box-shadow: 0px 6px 30px rgba(64, 158, 255, 0.1);
  300. border-radius: 4px;
  301. .logo {
  302. width: 248px;
  303. height: 100px;
  304. margin-bottom: 20px;
  305. display: flex;
  306. justify-content: center;
  307. align-items: center;
  308. img {
  309. display: block;
  310. max-height: 100%;
  311. flex-shrink: 0;
  312. }
  313. }
  314. .tip {
  315. width: 412px;
  316. font-size: 20px;
  317. color: #282828;
  318. line-height: 32px;
  319. text-align: center;
  320. margin-bottom: 36px;
  321. }
  322. .form {
  323. width: 320px;
  324. .confirm {
  325. width: 100%;
  326. margin-top: 24px;
  327. border-radius: 0;
  328. }
  329. .line {
  330. width: 1px;
  331. height: 20px;
  332. background: #d8d8d8;
  333. display: inline-block;
  334. vertical-align: middle;
  335. }
  336. .code {
  337. margin: 0 10px;
  338. }
  339. .el-form-item {
  340. margin-bottom: 24px;
  341. ::v-deep {
  342. .el-form-item__label {
  343. line-height: initial;
  344. padding: 0 0 6px;
  345. }
  346. .el-input__inner {
  347. border-radius: 0;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. @media screen and (max-width: 768px) {
  356. ::v-deep {
  357. .el-dialog {
  358. width: 76vw;
  359. padding: 7vw 7vw 5.2vw;
  360. .dialog-text {
  361. font-size: 3.2vw;
  362. color: #282828;
  363. line-height: 5.6vw;
  364. }
  365. .el-dialog__header {
  366. padding: 0;
  367. .el-dialog__title {
  368. font-size: 4.8vw;
  369. color: #282828;
  370. }
  371. }
  372. .el-dialog__body {
  373. padding: 8vw 0 11.6vw;
  374. }
  375. .el-dialog__footer {
  376. padding: 0;
  377. }
  378. .el-dialog__close {
  379. font-size: 5.6vw;
  380. }
  381. .el-button {
  382. width: 100%;
  383. display: block;
  384. &:first-child {
  385. margin-bottom: 4vw;
  386. }
  387. &:last-child {
  388. margin-left: 0;
  389. }
  390. }
  391. }
  392. }
  393. .club-bind {
  394. width: 100vw;
  395. height: 100vh;
  396. background: url(~assets/theme-images/common/h5-link-register-bg.png)
  397. no-repeat center;
  398. display: flex;
  399. justify-content: center;
  400. align-items: center;
  401. .form-container {
  402. display: flex;
  403. align-items: center;
  404. flex-direction: column;
  405. box-sizing: border-box;
  406. width: 76vw;
  407. padding: 4vw 0 4.7vw;
  408. background: #fff;
  409. box-shadow: 0px 0.6vw 3vw rgba(64, 158, 255, 0.1);
  410. border-radius: 4px;
  411. .logo {
  412. width: 34vw;
  413. height: 13.8vw;
  414. margin-bottom: 4vw;
  415. display: flex;
  416. justify-content: center;
  417. align-items: center;
  418. img {
  419. display: block;
  420. height: 5.6vw;
  421. flex-shrink: 0;
  422. }
  423. }
  424. .tip {
  425. width: 59.8vw;
  426. font-size: 3.6vw;
  427. color: #282828;
  428. line-height: 5.6vw;
  429. text-align: center;
  430. margin-bottom: 8vw;
  431. }
  432. .form {
  433. width: 62vw;
  434. .confirm {
  435. width: 100%;
  436. margin-top: 3.2vw;
  437. border-radius: 0;
  438. }
  439. .line {
  440. width: 1px;
  441. height: 4vw;
  442. background: #d8d8d8;
  443. display: inline-block;
  444. vertical-align: middle;
  445. }
  446. .code {
  447. margin: 0 2.8vw;
  448. }
  449. .el-form-item {
  450. margin-bottom: 4vw;
  451. ::v-deep {
  452. .el-form-item__label {
  453. line-height: initial;
  454. padding: 0 0 1.2vw;
  455. }
  456. .el-input__inner {
  457. border-radius: 0;
  458. }
  459. }
  460. }
  461. }
  462. }
  463. }
  464. }
  465. </style>