club-bind.vue 11 KB

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