PhoneStepNew.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <div class="validation">
  3. <div class="container">
  4. <div class="content">
  5. <div class="content-top">
  6. <h3>验证手机</h3>
  7. <div class="step">
  8. <img src="/images/all/step02.png" alt=""/>
  9. <div class="step-item"><span class="active">账号验证</span><span class="active">新手机号码</span><span>设置完成</span></div>
  10. </div>
  11. </div>
  12. <div class="content-bottom">
  13. <div>
  14. <el-form :model="valid2" :rules="rules2" ref="valid2" label-width="100px" class="demo-ruleForm">
  15. <el-form-item prop="mobile">
  16. <el-input v-model="valid2.mobile"
  17. v-bind:class="{active: mobileSecondExit}"
  18. placeholder="新手机号码"></el-input>
  19. <span class="tip tip-mobile" v-show="mobileSecondExit">该手机已被注册</span>
  20. </el-form-item>
  21. <el-form-item prop="code">
  22. <el-input type="text" v-model="valid2.code"
  23. v-bind:class="{ active: secondStepCodeErrorChecked }"
  24. auto-complete="off"
  25. class="msg"
  26. placeholder="短信验证码"></el-input>
  27. <el-button type="primary" class="code"
  28. v-show="showSecondStepCode"
  29. @click="getSecondCheckCode"
  30. :disabled="getCodeBtnIsDisabled">获取验证码</el-button>
  31. <el-button type="primary" v-show="!showSecondStepCode" class="code code-send">已发送({{second_step_time}}s)</el-button>
  32. <span v-show="secondStepCodeErrorChecked" class="tip codeError-tip">{{secondCodeErrorMsg}}</span>
  33. </el-form-item>
  34. <el-form-item>
  35. <a class="btn finish"
  36. :disabled="!mobileSecondChecked || !secondCodeChecked"
  37. @click="setNewMobile">确认</a>
  38. </el-form-item>
  39. </el-form>
  40. </div>
  41. </div>
  42. </div>
  43. <loading v-show="isShowLoading"/>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import Loading from '~components/common/loading/Loading.vue'
  49. export default {
  50. name: 'validation',
  51. components: {
  52. Loading
  53. },
  54. props: ['tokenId'],
  55. middleware: 'authenticated',
  56. data () {
  57. // 第二步验证手机
  58. var validateSecondMobile = (rule, value, callback) => {
  59. if (value === '') {
  60. callback(new Error('请填写正确的手机号'))
  61. this.getCodeBtnIsDisabled = true
  62. this.mobileSecondChecked = false
  63. this.mobileSecondExit = false
  64. } else {
  65. if (this.valid2.mobile !== '') {
  66. var reg = /^1[0-9]{10}$/
  67. if (!reg.test(value)) {
  68. callback(new Error('请填写正确的手机号'))
  69. this.getCodeBtnIsDisabled = true
  70. this.mobileSecondChecked = false
  71. this.mobileSecondExit = false
  72. } else {
  73. this.$http.get(`/update/user/mobile/hasRegister`, {params: {mobile: this.valid2.mobile}})
  74. .then(response => {
  75. console.log(response.data.content.hasRegister, '111')
  76. if (response.data.content.hasRegister) {
  77. this.getCodeBtnIsDisabled = true
  78. this.mobileSecondChecked = false
  79. this.mobileSecondExit = true
  80. } else {
  81. this.getCodeBtnIsDisabled = false
  82. this.mobileSecondChecked = true
  83. this.mobileSecondExit = false
  84. }
  85. })
  86. }
  87. }
  88. callback()
  89. }
  90. }
  91. var validateSecondCode = (rule, value, callback) => {
  92. if (value === '') {
  93. callback(new Error('请填写正确的验证码'))
  94. this.secondStepCodeErrorChecked = false
  95. this.secondCodeChecked = false
  96. } else {
  97. if (this.valid2.code !== '') {
  98. if (this.valid2.mobile === '') {
  99. callback(new Error('请先填写正确的手机号'))
  100. } else {
  101. if (this.secondToken) {
  102. let param = new FormData()
  103. param.append('mobile', this.valid2.mobile)
  104. param.append('code', this.valid2.code)
  105. param.append('token', this.secondToken)
  106. let config = {
  107. headers: {'Content-Type': 'multipart/form-data'}
  108. }
  109. this.$http.post(`/update/user/checkCode/mobile`, param, config)
  110. .then(response => {
  111. if (response.data.success) {
  112. this.secondCodeChecked = true
  113. this.secondStepCodeErrorChecked = false
  114. } else {
  115. this.secondStepCodeErrorChecked = true
  116. this.secondCodeChecked = false
  117. return Promise.reject(response.data)
  118. }
  119. }).catch(err => {
  120. this.secondCodeErrorMsg = err.errMsg
  121. })
  122. } else {
  123. callback(new Error('请先获取验证码'))
  124. this.codeChecked = false
  125. this.codeErrorChecked = false
  126. }
  127. }
  128. }
  129. callback()
  130. }
  131. }
  132. return {
  133. isShowLoading: false,
  134. second_step_time: 0,
  135. codeErrorChecked: false,
  136. secondStepCodeErrorChecked: false,
  137. secondCodeChecked: false,
  138. secondCodeErrorMsg: '',
  139. mobileSecondChecked: false,
  140. getCodeBtnIsDisabled: true,
  141. showSecondStepCode: true,
  142. mobileSecondExit: false,
  143. secondToken: '',
  144. valid2: {
  145. mobile: '',
  146. code: ''
  147. },
  148. rules2: {
  149. mobile: [
  150. {validator: validateSecondMobile, trigger: 'blur'}
  151. ],
  152. code: [
  153. {validator: validateSecondCode, trigger: 'blur'}
  154. ]
  155. }
  156. }
  157. },
  158. methods: {
  159. // 获取第二步手机验证码
  160. getSecondCheckCode () {
  161. this.isShowLoading = true
  162. this.$http.get(`/update/user/setMobile`, {params: {mobile: this.valid2.mobile, token: this.$route.query.token ? this.$route.query.token : this.tokenId}})
  163. .then(response => {
  164. this.isShowLoading = false
  165. if (response.data.success) {
  166. this.secondToken = response.data.content.token
  167. if (this.secondToken !== '') {
  168. this.$message({
  169. message: '验证码已经发送到您的手机,请注意查收',
  170. type: 'success'
  171. })
  172. this.showSecondStepCode = false
  173. this.second_step_time = 60
  174. var secondStepTime = setInterval(() => {
  175. this.second_step_time--
  176. if (this.second_step_time <= 0) {
  177. this.showSecondStepCode = true
  178. clearInterval(secondStepTime)
  179. }
  180. }, 1000)
  181. }
  182. } else {
  183. return Promise.reject(response.data)
  184. }
  185. }).catch(err => {
  186. this.isShowLoading = false
  187. this.$message.error(err.errMsg)
  188. })
  189. },
  190. // 设置新手机号
  191. setNewMobile () {
  192. if (this.mobileSecondChecked && this.secondCodeChecked) {
  193. this.isShowLoading = true
  194. let param = new FormData()
  195. param.append('mobile', this.valid2.mobile)
  196. param.append('code', this.valid2.code)
  197. param.append('token', this.secondToken)
  198. let config = {
  199. headers: {'Content-Type': 'multipart/form-data'}
  200. }
  201. this.$http.post(`/update/user/setMobile`, param, config)
  202. .then(response => {
  203. this.isShowLoading = false
  204. if (response.data.success) {
  205. this.$emit('stepEvent', 'last')
  206. this.$emit('lastEvent', 'last')
  207. } else {
  208. return Promise.reject(response.data)
  209. }
  210. }).catch(err => {
  211. this.$message.error(err.errMsg)
  212. this.isShowLoading = false
  213. this.secondStepCodeErrorChecked = true
  214. this.secondCodeChecked = false
  215. this.second_step_time = 0
  216. })
  217. }
  218. }
  219. }
  220. }
  221. </script>
  222. <style lang="scss" scoped>
  223. .validation {
  224. margin: 0 auto;
  225. width: 100%;
  226. background: #eee;
  227. .container{
  228. padding-top: 50px;
  229. margin: 0 auto;
  230. width: 980px;
  231. text-align: center;
  232. .content{
  233. padding: 0 50px;
  234. margin: 50px auto 0;
  235. width: 100%;
  236. /*height: 540px;*/
  237. text-align: center;
  238. background: #fff;
  239. .content-top{
  240. height: 80px;
  241. line-height: 80px;
  242. h3{
  243. margin-bottom: 0;
  244. font-size: 24px;
  245. color: #000;
  246. border-bottom: 1px solid #dcdcdc;
  247. }
  248. .step{
  249. position: relative;
  250. margin-top: 10px;
  251. img{
  252. width: 315px;
  253. height: 46px;
  254. }
  255. .step-item{
  256. position: absolute;
  257. top: 45px;
  258. left: 265px;
  259. span{
  260. margin-right: 78px;
  261. font-size: 14px;
  262. color: #b4b4b4;
  263. }
  264. span.active {
  265. color: #0076ad;
  266. }
  267. }
  268. }
  269. }
  270. form {
  271. margin-top: 150px;
  272. padding-bottom: 44px;
  273. input{
  274. padding: 0 0 0 18px;
  275. width: 360px;
  276. height: 44px;
  277. line-height: 44px;
  278. font-size: 14px;
  279. color: #000;
  280. border-radius: 0;
  281. }
  282. input.answer {
  283. background: url("/images/all/more.png") no-repeat 325px center;
  284. cursor: pointer;
  285. }
  286. ul{
  287. display: none;
  288. position: absolute;
  289. top: 44px;
  290. left: 0;
  291. width: 360px;
  292. background: #fff;
  293. box-shadow: 0 0 5px rgba(0,0,0,.5);
  294. -moz-box-shadow: 0 0 5px rgba(0,0,0,.5);
  295. -o-box-shadow: 0 0 5px rgba(0,0,0,.5);
  296. -webkit-box-shadow: 0 0 5px rgba(0,0,0,.5);
  297. z-index: 10;
  298. li{
  299. padding-left: 18px;
  300. width: 100%;
  301. height: 30px;
  302. line-height: 30px;
  303. text-align: left;
  304. font-size: 14px;
  305. color: #000;
  306. cursor: pointer;
  307. &:hover{
  308. background: #0076ad;
  309. color: #fff;
  310. }
  311. }
  312. }
  313. span.tip{
  314. position: absolute;
  315. top: 0;
  316. right: -238px;
  317. font-size: 13px;
  318. color: #8c8c8c;
  319. a{
  320. font-size: 13px;
  321. color: #0076ad;
  322. }
  323. }
  324. span.tip.tip-mobile{
  325. top: 3px;
  326. right: -105px;
  327. color: #ff4949;
  328. font-size: 12px;
  329. }
  330. span.tip.codeError-tip{
  331. position: absolute;
  332. top: 3px;
  333. left: 378px;
  334. width: 200px;
  335. text-align: left;
  336. color: #ff4949;
  337. font-size: 12px;
  338. }
  339. i{
  340. position: absolute;
  341. top: 13px;
  342. left: 20px;
  343. font-size: 20px;
  344. color: #a0a0a0;
  345. }
  346. .btn {
  347. margin: 34px 0 16px 0;
  348. width: 360px;
  349. height: 44px;
  350. line-height: 44px;
  351. font-size: 16px;
  352. color: #fff;
  353. background: #0076AD;
  354. border-radius: 3px;
  355. }
  356. }
  357. .content-bottom{
  358. margin: 155px auto 0;
  359. padding-bottom: 50px;
  360. width: 360px;
  361. div.warp{
  362. padding-bottom: 65px;
  363. }
  364. p{
  365. font-size: 24px;
  366. color: #323232;
  367. img{
  368. margin-right: 20px;
  369. width: 30px;
  370. height: 28px;
  371. }
  372. }
  373. p.pass{
  374. font-size: 24px;
  375. color: #e77405;
  376. img{
  377. height: 30px;
  378. }
  379. }
  380. p.passed {
  381. color: #2ab300;
  382. img{
  383. height: 30px;
  384. }
  385. }
  386. span{
  387. display: inline-block;
  388. font-size: 14px;
  389. color: #8b8b8b;
  390. }
  391. span.close-tip{
  392. margin: 15px 0 140px 0;
  393. }
  394. .close-btn{
  395. margin: 0 auto;
  396. width: 200px;
  397. height: 36px;
  398. line-height: 36px;
  399. font-size: 14px;
  400. text-align: center;
  401. color: #323232;
  402. border: 1px solid #d2d2d2;
  403. border-radius: 3px;
  404. cursor: pointer ;
  405. }
  406. span.use{
  407. display: inline-block;
  408. margin-bottom: 30px;
  409. width: 360px;
  410. font-size: 14px;
  411. color: #000;
  412. text-align: left;
  413. em{
  414. font-size: 14px;
  415. font-style: normal;
  416. color: #000;
  417. }
  418. }
  419. .form-group {
  420. margin: 0 auto 16px;
  421. position: relative;
  422. width: 360px;
  423. height: 44px;
  424. line-height: 44px;
  425. input{
  426. padding: 0 0 0 18px;
  427. width: 360px;
  428. height: 44px;
  429. line-height: 44px;
  430. font-size: 14px;
  431. color: #000;
  432. border-radius: 0;
  433. }
  434. input.msg{
  435. float: left;
  436. width: 210px;
  437. padding: 0 0 0 18px;
  438. height: 44px;
  439. line-height: 44px;
  440. font-size: 14px;
  441. color: #000;
  442. border-radius: 0;
  443. }
  444. span.msg{
  445. float: right;
  446. margin: 0;
  447. width: 130px;
  448. height: 44px;
  449. line-height: 44px;
  450. text-align: center ;
  451. font-size: 14px;
  452. color: #5a5a5a;
  453. background: #f4f4f4;
  454. border: 1px solid #dcdcdc;
  455. cursor: pointer;
  456. }
  457. span.msg.send{
  458. background: #d2d2d2;
  459. color: #fff;
  460. }
  461. }
  462. .btn {
  463. margin: 34px 0 10px 0;
  464. width: 360px;
  465. height: 44px;
  466. line-height: 44px;
  467. font-size: 16px;
  468. color: #fff;
  469. background: #0076AD;
  470. border-radius: 3px;
  471. }
  472. }
  473. .choose{
  474. margin: 155px auto 0;
  475. padding-bottom: 44px;
  476. div{
  477. padding: 0 15px;
  478. margin: 0 auto 16px;
  479. width: 360px;
  480. height: 60px;
  481. line-height: 60px;
  482. text-align: left;
  483. overflow: hidden;
  484. border: 1px solid #d2d2d2;
  485. cursor: pointer;
  486. &:hover,&.active{
  487. border-color: #0076ad;
  488. span{
  489. color: #0076ad;
  490. }
  491. i.second {
  492. color: #0076ad;
  493. }
  494. }
  495. img.first{
  496. float: left;
  497. margin: 24px 20px 0 0;
  498. font-size: 20px;
  499. color: #323232;
  500. }
  501. img.first.mob{
  502. margin: 22px 20px 0 5px;
  503. font-size: 28px;
  504. }
  505. i.second {
  506. float: right;
  507. margin: 20px 0 0 5px;
  508. font-size: 20px;
  509. color: #323232;
  510. }
  511. span{
  512. float: left;
  513. font-size: 14px;
  514. color: #323232;
  515. }
  516. }
  517. }
  518. a.return{
  519. position: absolute;
  520. left: 0;
  521. top: -15px;
  522. img{
  523. width: 34px !important;
  524. height: 34px !important;
  525. }
  526. }
  527. }
  528. }
  529. }
  530. </style>